1 /* 2 * Copyright (c) 2024, The TrustedFirmware-M Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 * 6 */ 7 8 #ifndef __CC3XX_EC_CURVE_DATA_H__ 9 #define __CC3XX_EC_CURVE_DATA_H__ 10 11 #include <stdint.h> 12 #include <stddef.h> 13 #include "cc3xx_ec.h" 14 15 #include "cc3xx_config.h" 16 17 #ifdef __cplusplus 18 extern "C" { 19 #endif 20 21 #if defined(CC3XX_CONFIG_EC_CURVE_SECP_521_R1_ENABLE) 22 #define CC3XX_EC_MAX_POINT_SIZE 68 23 #elif defined(CC3XX_CONFIG_EC_CURVE_BRAINPOOLP_512_R1_ENABLE) 24 #define CC3XX_EC_MAX_POINT_SIZE 64 25 #elif defined(CC3XX_CONFIG_EC_CURVE_SECP_384_R1_ENABLE) \ 26 || defined(CC3XX_CONFIG_EC_CURVE_BRAINPOOLP_384_R1_ENABLE) 27 #define CC3XX_EC_MAX_POINT_SIZE 48 28 #elif defined(CC3XX_CONFIG_EC_CURVE_BRAINPOOLP_320_R1_ENABLE) 29 #define CC3XX_EC_MAX_POINT_SIZE 40 30 #elif defined(CC3XX_CONFIG_EC_CURVE_SECP_256_R1_ENABLE) \ 31 || defined(CC3XX_CONFIG_EC_CURVE_SECP_256_K1_ENABLE) \ 32 || defined(CC3XX_CONFIG_EC_CURVE_BRAINPOOLP_256_R1_ENABLE) \ 33 || defined(CC3XX_CONFIG_EC_CURVE_FRP_256_V1_ENABLE) 34 #define CC3XX_EC_MAX_POINT_SIZE 32 35 #elif defined(CC3XX_CONFIG_EC_CURVE_SECP_224_R1_ENABLE) \ 36 || defined(CC3XX_CONFIG_EC_CURVE_SECP_224_K1_ENABLE) \ 37 || defined(CC3XX_CONFIG_EC_CURVE_BRAINPOOLP_224_R1_ENABLE) 38 #define CC3XX_EC_MAX_POINT_SIZE 28 39 #elif defined(CC3XX_CONFIG_EC_CURVE_SECP_192_R1_ENABLE) \ 40 || defined(CC3XX_CONFIG_EC_CURVE_SECP_192_K1_ENABLE) \ 41 || defined(CC3XX_CONFIG_EC_CURVE_BRAINPOOLP_192_R1_ENABLE) 42 #define CC3XX_EC_MAX_POINT_SIZE 24 43 #else 44 #define CC3XX_EC_MAX_POINT_SIZE 0 45 #endif 46 47 #if defined(CC3XX_CONFIG_EC_CURVE_SECP_192_R1_ENABLE) \ 48 || defined(CC3XX_CONFIG_EC_CURVE_SECP_224_R1_ENABLE) \ 49 || defined(CC3XX_CONFIG_EC_CURVE_SECP_256_R1_ENABLE) \ 50 || defined(CC3XX_CONFIG_EC_CURVE_SECP_384_R1_ENABLE) \ 51 || defined(CC3XX_CONFIG_EC_CURVE_SECP_512_R1_ENABLE) \ 52 || defined(CC3XX_CONFIG_EC_CURVE_SECP_192_K1_ENABLE) \ 53 || defined(CC3XX_CONFIG_EC_CURVE_SECP_224_K1_ENABLE) \ 54 || defined(CC3XX_CONFIG_EC_CURVE_SECP_256_K1_ENABLE) 55 #define CC3XX_EC_MAX_BARRETT_TAG_SIZE 40 56 #elif defined(CC3XX_CONFIG_EC_CURVE_BRAINPOOLP_192_R1_ENABLE) \ 57 || defined(CC3XX_CONFIG_EC_CURVE_BRAINPOOLP_224_R1_ENABLE) \ 58 || defined(CC3XX_CONFIG_EC_CURVE_BRAINPOOLP_256_R1_ENABLE) \ 59 || defined(CC3XX_CONFIG_EC_CURVE_BRAINPOOLP_320_R1_ENABLE) \ 60 || defined(CC3XX_CONFIG_EC_CURVE_BRAINPOOLP_384_R1_ENABLE) \ 61 || defined(CC3XX_CONFIG_EC_CURVE_BRAINPOOLP_512_R1_ENABLE) \ 62 || defined(CC3XX_CONFIG_EC_CURVE_FRP_256_V1_ENABLE) 63 #define CC3XX_EC_MAX_BARRETT_TAG_SIZE 12 64 #else 65 #define CC3XX_EC_MAX_BARRETT_TAG_SIZE 0 66 #endif 67 68 /** 69 * @brief Structure describing Elliptic Curve parameters 70 * 71 */ 72 typedef struct { 73 cc3xx_ec_curve_type_t type; 74 75 size_t modulus_size; 76 size_t barrett_tag_size; 77 size_t register_size; 78 79 uint32_t field_modulus[CC3XX_EC_MAX_POINT_SIZE / sizeof(uint32_t)]; 80 uint32_t barrett_tag[CC3XX_EC_MAX_BARRETT_TAG_SIZE / sizeof(uint32_t)]; 81 82 uint32_t field_param_a[CC3XX_EC_MAX_POINT_SIZE / sizeof(uint32_t)]; 83 uint32_t field_param_b[CC3XX_EC_MAX_POINT_SIZE / sizeof(uint32_t)]; 84 85 uint32_t generator_x[CC3XX_EC_MAX_POINT_SIZE / sizeof(uint32_t)]; 86 uint32_t generator_y[CC3XX_EC_MAX_POINT_SIZE / sizeof(uint32_t)]; 87 88 uint32_t order[CC3XX_EC_MAX_POINT_SIZE / sizeof(uint32_t)]; 89 uint32_t cofactor; 90 } cc3xx_ec_curve_data_t; 91 92 extern cc3xx_ec_curve_data_t secp_192_r1; 93 extern cc3xx_ec_curve_data_t secp_224_r1; 94 extern cc3xx_ec_curve_data_t secp_256_r1; 95 extern cc3xx_ec_curve_data_t secp_384_r1; 96 extern cc3xx_ec_curve_data_t secp_521_r1; 97 98 extern cc3xx_ec_curve_data_t secp_192_k1; 99 extern cc3xx_ec_curve_data_t secp_224_k1; 100 extern cc3xx_ec_curve_data_t secp_256_k1; 101 102 extern cc3xx_ec_curve_data_t brainpoolp_192_r1; 103 extern cc3xx_ec_curve_data_t brainpoolp_224_r1; 104 extern cc3xx_ec_curve_data_t brainpoolp_256_r1; 105 extern cc3xx_ec_curve_data_t brainpoolp_320_r1; 106 extern cc3xx_ec_curve_data_t brainpoolp_384_r1; 107 extern cc3xx_ec_curve_data_t brainpoolp_512_r1; 108 109 extern cc3xx_ec_curve_data_t frp_256_v1; 110 111 extern cc3xx_ec_curve_data_t curve_25519; 112 extern cc3xx_ec_curve_data_t curve_448; 113 114 extern cc3xx_ec_curve_data_t ed25519; 115 extern cc3xx_ec_curve_data_t ed448; 116 117 #ifdef __cplusplus 118 } 119 #endif 120 121 #endif /* __CC3XX_EC_CURVE_DATA_H__ */ 122