Raef Coles | 59cf5d8 | 2024-12-09 15:41:13 +0000 | [diff] [blame] | 1 | #------------------------------------------------------------------------------- |
| 2 | # SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors |
| 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | # |
| 6 | #------------------------------------------------------------------------------- |
| 7 | |
| 8 | from cryptography.hazmat.primitives.asymmetric import ec |
| 9 | from cryptography.hazmat.primitives import hashes |
| 10 | |
| 11 | import logging |
Raef Coles | cfc3124 | 2025-04-04 09:38:47 +0100 | [diff] [blame^] | 12 | logger = logging.getLogger("TF-M.{}".format(__name__)) |
Raef Coles | 59cf5d8 | 2024-12-09 15:41:13 +0000 | [diff] [blame] | 13 | |
| 14 | def convert_curve_define(define_name : str, |
| 15 | define_prefix : str = "", |
| 16 | ) -> ec.EllipticCurve: |
| 17 | curve_name = define_name.replace(define_prefix,"").replace("_", "") |
| 18 | |
| 19 | if not hasattr(ec, curve_name): |
| 20 | curve_name = "SEC{}R1".format(curve_name) |
| 21 | |
| 22 | return getattr(ec, curve_name) |
| 23 | |
| 24 | def convert_hash_define(define_name : str, |
| 25 | define_prefix : str = "", |
| 26 | ) -> hashes.HashAlgorithm: |
| 27 | hash_name = define_name.replace(define_prefix,"").replace("_", "") |
| 28 | return getattr(hashes, hash_name) |