blob: 43633ff41015e201d038e0f6ab08d7347eab165e [file] [log] [blame]
Raef Coles59cf5d82024-12-09 15:41:13 +00001#!/usr/bin/env python3
2#-------------------------------------------------------------------------------
3# SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
4#
5# SPDX-License-Identifier: BSD-3-Clause
6#
7#-------------------------------------------------------------------------------
8
9from cryptography.hazmat.primitives.asymmetric import ec
10from cryptography.hazmat.primitives import hashes
11
12import logging
13logger = logging.getLogger("TF-M")
14
15def convert_curve_define(define_name : str,
16 define_prefix : str = "",
17 ) -> ec.EllipticCurve:
18 curve_name = define_name.replace(define_prefix,"").replace("_", "")
19
20 if not hasattr(ec, curve_name):
21 curve_name = "SEC{}R1".format(curve_name)
22
23 return getattr(ec, curve_name)
24
25def convert_hash_define(define_name : str,
26 define_prefix : str = "",
27 ) -> hashes.HashAlgorithm:
28 hash_name = define_name.replace(define_prefix,"").replace("_", "")
29 return getattr(hashes, hash_name)