@@ -57,6 +57,74 @@ extern "C" {
5757
5858/**@}*/
5959
60+ #if defined(MBEDTLS_ECP_C )
61+ #include <mbedtls/ecp.h>
62+
63+ /** Convert an ECC curve identifier from the Mbed TLS encoding to PSA.
64+ *
65+ * \note This function is provided solely for the convenience of
66+ * Mbed TLS and may be removed at any time without notice.
67+ *
68+ * \param grpid An Mbed TLS elliptic curve identifier
69+ * (`MBEDTLS_ECP_DP_xxx`).
70+ * \param[out] bits On success, the bit size of the curve.
71+ *
72+ * \return The corresponding PSA elliptic curve identifier
73+ * (`PSA_ECC_FAMILY_xxx`).
74+ * \return \c 0 on failure (\p grpid is not recognized).
75+ */
76+ static inline psa_ecc_family_t mbedtls_ecc_group_to_psa ( mbedtls_ecp_group_id grpid ,
77+ size_t * bits )
78+ {
79+ switch ( grpid )
80+ {
81+ case MBEDTLS_ECP_DP_SECP192R1 :
82+ * bits = 192 ;
83+ return ( PSA_ECC_FAMILY_SECP_R1 );
84+ case MBEDTLS_ECP_DP_SECP224R1 :
85+ * bits = 224 ;
86+ return ( PSA_ECC_FAMILY_SECP_R1 );
87+ case MBEDTLS_ECP_DP_SECP256R1 :
88+ * bits = 256 ;
89+ return ( PSA_ECC_FAMILY_SECP_R1 );
90+ case MBEDTLS_ECP_DP_SECP384R1 :
91+ * bits = 384 ;
92+ return ( PSA_ECC_FAMILY_SECP_R1 );
93+ case MBEDTLS_ECP_DP_SECP521R1 :
94+ * bits = 521 ;
95+ return ( PSA_ECC_FAMILY_SECP_R1 );
96+ case MBEDTLS_ECP_DP_BP256R1 :
97+ * bits = 256 ;
98+ return ( PSA_ECC_FAMILY_BRAINPOOL_P_R1 );
99+ case MBEDTLS_ECP_DP_BP384R1 :
100+ * bits = 384 ;
101+ return ( PSA_ECC_FAMILY_BRAINPOOL_P_R1 );
102+ case MBEDTLS_ECP_DP_BP512R1 :
103+ * bits = 512 ;
104+ return ( PSA_ECC_FAMILY_BRAINPOOL_P_R1 );
105+ case MBEDTLS_ECP_DP_CURVE25519 :
106+ * bits = 255 ;
107+ return ( PSA_ECC_FAMILY_MONTGOMERY );
108+ case MBEDTLS_ECP_DP_SECP192K1 :
109+ * bits = 192 ;
110+ return ( PSA_ECC_FAMILY_SECP_K1 );
111+ case MBEDTLS_ECP_DP_SECP224K1 :
112+ * bits = 224 ;
113+ return ( PSA_ECC_FAMILY_SECP_K1 );
114+ case MBEDTLS_ECP_DP_SECP256K1 :
115+ * bits = 256 ;
116+ return ( PSA_ECC_FAMILY_SECP_K1 );
117+ case MBEDTLS_ECP_DP_CURVE448 :
118+ * bits = 448 ;
119+ return ( PSA_ECC_FAMILY_MONTGOMERY );
120+ default :
121+ * bits = 0 ;
122+ return ( 0 );
123+ }
124+ }
125+
126+ #endif /* MBEDTLS_ECP_C */
127+
60128#ifdef __cplusplus
61129}
62130#endif
0 commit comments