1 /*
2  * Copyright (c) 2001-2021, Arm Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 #ifndef ECP_COMMON_H
7 #define ECP_COMMON_H
8 #ifdef __cplusplus
9 extern "C"
10 {
11 #endif
12 
13 
14 #include "cc_pal_types_plat.h"
15 #include "cc_ecpki_types.h"
16 #include "mbedtls/ecp.h"
17 
18 /*
19  *\brief         Curve types
20  *
21  */
22 typedef enum
23 {
24     ECP_TYPE_NONE = 0,
25     ECP_TYPE_SHORT_WEIERSTRASS,    /* y^2 = x^3 + a x + b      */
26     ECP_TYPE_25519,         /* MONTGOMERY : y^2 = x^3 + a x^2 + x  EDWARDS: x^2 + y^2 = 1 + dx^2y^2 (modp) */
27 } ecp_curve_type;
28 
29 /**
30  * \brief           mapping CC ECP return codes to mbedtls
31  *
32  */
33 int error_mapping_cc_to_mbedtls_ecc (CCError_t cc_error);
34 
35 /**
36  * \brief           get the cfurve type
37  *
38  */
ecp_get_type(const mbedtls_ecp_group * grp)39 static inline ecp_curve_type ecp_get_type(const mbedtls_ecp_group *grp)
40 {
41     if (grp->G.MBEDTLS_PRIVATE(X).MBEDTLS_PRIVATE(p) == NULL)
42         return (ECP_TYPE_NONE);
43 
44     if (grp->G.MBEDTLS_PRIVATE(Y).MBEDTLS_PRIVATE(p) == NULL)
45         return (ECP_TYPE_25519);
46     else
47         return (ECP_TYPE_SHORT_WEIERSTRASS);
48 }
49 
50 /**
51  * \brief           map mbedtls group id to CC domain id
52  *
53  */
54 
55 int ecp_grp_id_to_domain_id (const mbedtls_ecp_group_id id, CCEcpkiDomainID_t *domain_id);
56 
57 #ifdef __cplusplus
58 }
59 #endif
60 
61 #endif  /* MBEDTLS_COMMON_H */
62