Skip to content

Commit a329b21

Browse files
parmi93TofMassilia13320
authored andcommitted
Use indexed ECC info table
Rework `stse_ecc_info_table` to use explicit indexing via `stse_ecc_key_type_t` values instead of relying on positional ordering. This improves readability, maintains a direct mapping between key types and table entries, and prevents potential issues caused by configuration-dependent ordering.
1 parent 8458183 commit a329b21

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

core/stse_generic_typedef.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const stse_ecc_info_t stse_ecc_info_table[] =
2626
#else
2727
{
2828
#ifdef STSE_CONF_ECC_NIST_P_256
29-
{/* NIST P 256 */
29+
[STSE_ECC_KT_NIST_P_256] = {/* NIST P 256 */
3030
.curve_id_total_length = (STSE_NIST_P_256_ID_VALUE_SIZE + STSE_ECC_CURVE_ID_LENGTH_SIZE),
3131
.curve_id = {{UI16_B1(STSE_NIST_P_256_ID_VALUE_SIZE), UI16_B0(STSE_NIST_P_256_ID_VALUE_SIZE)},
3232
STSE_NIST_P_256_ID_VALUE},
@@ -37,7 +37,7 @@ const stse_ecc_info_t stse_ecc_info_table[] =
3737
.signature_size = (STSE_NIST_P_256_SIGNATURE_R_VALUE_SIZE + STSE_NIST_P_256_SIGNATURE_S_VALUE_SIZE)},
3838
#endif
3939
#ifdef STSE_CONF_ECC_NIST_P_384
40-
{/* NIST P_384 */
40+
[STSE_ECC_KT_NIST_P_384] = {/* NIST P_384 */
4141
.curve_id_total_length = (STSE_NIST_P_384_ID_VALUE_SIZE + STSE_ECC_CURVE_ID_LENGTH_SIZE),
4242
.curve_id = {{UI16_B1(STSE_NIST_P_384_ID_VALUE_SIZE), UI16_B0(STSE_NIST_P_384_ID_VALUE_SIZE)},
4343
STSE_NIST_P_384_ID_VALUE},
@@ -48,7 +48,7 @@ const stse_ecc_info_t stse_ecc_info_table[] =
4848
.signature_size = (STSE_NIST_P_384_SIGNATURE_R_VALUE_SIZE + STSE_NIST_P_384_SIGNATURE_S_VALUE_SIZE)},
4949
#endif
5050
#ifdef STSE_CONF_ECC_NIST_P_521
51-
{/* NIST P 521 */
51+
[STSE_ECC_KT_NIST_P_521] = {/* NIST P 521 */
5252
.curve_id_total_length = (STSE_NIST_P_521_ID_VALUE_SIZE + STSE_ECC_CURVE_ID_LENGTH_SIZE),
5353
.curve_id = {{UI16_B1(STSE_NIST_P_521_ID_VALUE_SIZE), UI16_B0(STSE_NIST_P_521_ID_VALUE_SIZE)},
5454
STSE_NIST_P_521_ID_VALUE},
@@ -59,7 +59,7 @@ const stse_ecc_info_t stse_ecc_info_table[] =
5959
.signature_size = (STSE_NIST_P_521_SIGNATURE_R_VALUE_SIZE + STSE_NIST_P_521_SIGNATURE_S_VALUE_SIZE)},
6060
#endif
6161
#ifdef STSE_CONF_ECC_BRAINPOOL_P_256
62-
{/* BRAINPOOL P 256 */
62+
[STSE_ECC_KT_BP_P_256] = {/* BRAINPOOL P 256 */
6363
.curve_id_total_length = (STSE_BRAINPOOL_P_256_ID_VALUE_SIZE + STSE_ECC_CURVE_ID_LENGTH_SIZE),
6464
.curve_id = {{UI16_B1(STSE_BRAINPOOL_P_256_ID_VALUE_SIZE), UI16_B0(STSE_BRAINPOOL_P_256_ID_VALUE_SIZE)},
6565
STSE_BRAINPOOL_P_256_ID_VALUE},
@@ -70,7 +70,7 @@ const stse_ecc_info_t stse_ecc_info_table[] =
7070
.signature_size = (STSE_BRAINPOOL_P_256_SIGNATURE_R_VALUE_SIZE + STSE_BRAINPOOL_P_256_SIGNATURE_S_VALUE_SIZE)},
7171
#endif
7272
#ifdef STSE_CONF_ECC_BRAINPOOL_P_384
73-
{/* BRAINPOOL P 384 */
73+
[STSE_ECC_KT_BP_P_384] = {/* BRAINPOOL P 384 */
7474
.curve_id_total_length = (STSE_BRAINPOOL_P_384_ID_VALUE_SIZE + STSE_ECC_CURVE_ID_LENGTH_SIZE),
7575
.curve_id = {{UI16_B1(STSE_BRAINPOOL_P_384_ID_VALUE_SIZE), UI16_B0(STSE_BRAINPOOL_P_384_ID_VALUE_SIZE)},
7676
STSE_BRAINPOOL_P_384_ID_VALUE},
@@ -81,7 +81,7 @@ const stse_ecc_info_t stse_ecc_info_table[] =
8181
.signature_size = (STSE_BRAINPOOL_P_384_SIGNATURE_R_VALUE_SIZE + STSE_BRAINPOOL_P_384_SIGNATURE_S_VALUE_SIZE)},
8282
#endif
8383
#ifdef STSE_CONF_ECC_BRAINPOOL_P_512
84-
{/* BRAINPOOL P 512 */
84+
[STSE_ECC_KT_BP_P_512] = {/* BRAINPOOL P 512 */
8585
.curve_id_total_length = (STSE_BRAINPOOL_P_512_ID_VALUE_SIZE + STSE_ECC_CURVE_ID_LENGTH_SIZE),
8686
.curve_id = {{UI16_B1(STSE_BRAINPOOL_P_512_ID_VALUE_SIZE), UI16_B0(STSE_BRAINPOOL_P_512_ID_VALUE_SIZE)},
8787
STSE_BRAINPOOL_P_512_ID_VALUE},
@@ -92,7 +92,7 @@ const stse_ecc_info_t stse_ecc_info_table[] =
9292
.signature_size = (STSE_BRAINPOOL_P_512_SIGNATURE_R_VALUE_SIZE + STSE_BRAINPOOL_P_512_SIGNATURE_S_VALUE_SIZE)},
9393
#endif
9494
#ifdef STSE_CONF_ECC_CURVE_25519
95-
{/* X25519 */
95+
[STSE_ECC_KT_CURVE25519] = {/* X25519 */
9696
.curve_id_total_length = (STSE_X25519_ID_VALUE_SIZE + STSE_ECC_CURVE_ID_LENGTH_SIZE),
9797
.curve_id = {{UI16_B1(STSE_X25519_ID_VALUE_SIZE), UI16_B0(STSE_X25519_ID_VALUE_SIZE)},
9898
STSE_X25519_ID_VALUE},
@@ -103,7 +103,7 @@ const stse_ecc_info_t stse_ecc_info_table[] =
103103
.signature_size = 0},
104104
#endif
105105
#ifdef STSE_CONF_ECC_EDWARD_25519
106-
{/* ED25519 */
106+
[STSE_ECC_KT_ED25519] = {/* ED25519 */
107107
.curve_id_total_length = (STSE_ED25519_ID_VALUE_SIZE + STSE_ECC_CURVE_ID_LENGTH_SIZE),
108108
.curve_id = {{UI16_B1(STSE_ED25519_ID_VALUE_SIZE), UI16_B0(STSE_ED25519_ID_VALUE_SIZE)},
109109
STSE_ED25519_ID_VALUE},

core/stse_generic_typedef.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@
7171
/*!
7272
* \enum stse_ecc_key_type_t
7373
* \brief STSE ECC key type
74+
*
75+
* \note Do not assign any value to these enumerators, as they are used as indices in the `stse_ecc_info_table` array.
7476
*/
7577
typedef enum stse_ecc_key_type_t {
7678
#ifdef STSE_CONF_ECC_NIST_P_256

0 commit comments

Comments
 (0)