From 1bed740710cec1f88892c266838c4de2bbf2b27a Mon Sep 17 00:00:00 2001 From: Daniel Pouzzner Date: Fri, 14 Apr 2023 15:07:05 -0500 Subject: [PATCH] address peer review: make C89-compatible refactors in sakke_pairing() and sakke_modexp_loop(); add explanatory comment for WOLF_ENUM_DUMMY_LAST_ELEMENT() in types.h. --- wolfcrypt/src/sakke.c | 24 ++++-------------------- wolfssl/wolfcrypt/types.h | 6 ++++++ 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/wolfcrypt/src/sakke.c b/wolfcrypt/src/sakke.c index 23161818e..17d61d93a 100644 --- a/wolfcrypt/src/sakke.c +++ b/wolfcrypt/src/sakke.c @@ -2228,19 +2228,13 @@ static int sakke_pairing(SakkeKey* key, ecc_point* p, ecc_point* q, mp_int* r, mp_proj* t2 = key->tmp.p3; mp_int* t3 = &key->tmp.m2; mp_int* prime = &key->params.prime; - mp_int* t[] -#ifndef WOLF_C89 - = { &key->tmp.m1, t3 } -#endif - ; + mp_int* t[2]; int i; mp_digit mp = 0; SakkeKeyParams* params = &key->params; -#ifdef WOLF_C89 t[0] = &key->tmp.m1; t[1] = t3; -#endif (void)table; (void)len; @@ -2584,25 +2578,16 @@ static int sakke_modexp_loop(SakkeKey* key, mp_int* b, mp_int* e, mp_proj* r, { int err; #ifdef WC_NO_CACHE_RESISTANT - mp_proj* c[2] -#ifndef WOLF_C89 - = { r, key->tmp.p2 } -#endif - ; + mp_proj* c[2]; #else - mp_proj* c[3] -#ifndef WOLF_C89 - = { r, key->tmp.p3, key->tmp.p2 } + mp_proj* c[3]; #endif - ; -#endif /* WC_NO_CACHE_RESISTANT */ mp_int* t1 = &key->tmp.m1; mp_int* t2 = &key->tmp.m2; mp_int* by = key->tmp.p1->z; mp_int* prime = &key->params.prime; int i; -#ifdef WOLF_C89 #ifdef WC_NO_CACHE_RESISTANT c[0] = r; c[1] = key->tmp.p2; @@ -2610,8 +2595,7 @@ static int sakke_modexp_loop(SakkeKey* key, mp_int* b, mp_int* e, mp_proj* r, c[0] = r; c[1] = key->tmp.p3; c[2] = key->tmp.p2; -#endif /* WC_NO_CACHE_RESISTANT */ -#endif /* WOLF_C89 */ +#endif /* Set the working value to the base in PF_p[q] */ err = mp_montgomery_calc_normalization(c[0]->x, prime); diff --git a/wolfssl/wolfcrypt/types.h b/wolfssl/wolfcrypt/types.h index 64250ce1c..4fdc88a82 100644 --- a/wolfssl/wolfcrypt/types.h +++ b/wolfssl/wolfcrypt/types.h @@ -122,6 +122,12 @@ decouple library dependencies with standard string, memory and so on. #endif #endif + /* With a true C89-dialect compiler (simulate with gcc -std=c89 -Wall + * -Wextra -pedantic), a trailing comma on the last value in an enum + * definition is a syntax error. We use this macro to accommodate that + * without disrupting clean flow/syntax when some enum values are + * preprocessor-gated. + */ #if defined(WOLF_C89) || defined(WOLF_NO_TRAILING_ENUM_COMMAS) #define WOLF_ENUM_DUMMY_LAST_ELEMENT(prefix) _wolf_ ## prefix ## _enum_dummy_last_element #else