forked from wolfSSL/wolfssl
wolfssl/wolfcrypt/sp_int.h and wolfcrypt/src/sp_int.c: add struct sp_int_minimal, with same structure as struct sp_int but only one digit, to allow error-free access to sp_ints allocated with ALLOC_SP_INT() with fewer than SP_INT_DIGITS digits, and use the new type in _sp_zero() and sp_init_size() to eliminate -Werror=array-bounds on _sp_zero() under gcc-13.
This commit is contained in:
@ -4352,10 +4352,10 @@ static int _sp_mont_red(sp_int* a, sp_int* m, sp_int_digit mp);
|
|||||||
*/
|
*/
|
||||||
static void _sp_zero(sp_int* a)
|
static void _sp_zero(sp_int* a)
|
||||||
{
|
{
|
||||||
a->used = 0;
|
((sp_int_minimal *)a)->used = 0;
|
||||||
a->dp[0] = 0;
|
((sp_int_minimal *)a)->dp[0] = 0;
|
||||||
#ifdef WOLFSSL_SP_INT_NEGATIVE
|
#ifdef WOLFSSL_SP_INT_NEGATIVE
|
||||||
a->sign = MP_ZPOS;
|
((sp_int_minimal *)a)->sign = MP_ZPOS;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4394,10 +4394,20 @@ int sp_init(sp_int* a)
|
|||||||
*/
|
*/
|
||||||
int sp_init_size(sp_int* a, int size)
|
int sp_init_size(sp_int* a, int size)
|
||||||
{
|
{
|
||||||
int err = sp_init(a);
|
int err = MP_OKAY;
|
||||||
|
|
||||||
|
if (a == NULL) {
|
||||||
|
err = MP_VAL;
|
||||||
|
}
|
||||||
|
if (err == MP_OKAY) {
|
||||||
|
#ifdef HAVE_WOLF_BIGINT
|
||||||
|
wc_bigint_init(&a->raw);
|
||||||
|
#endif
|
||||||
|
_sp_zero(a);
|
||||||
|
}
|
||||||
|
|
||||||
if (err == MP_OKAY) {
|
if (err == MP_OKAY) {
|
||||||
a->size = size;
|
((sp_int_minimal *)a)->size = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
|
@ -778,6 +778,19 @@ typedef struct sp_int {
|
|||||||
sp_int_digit dp[SP_INT_DIGITS];
|
sp_int_digit dp[SP_INT_DIGITS];
|
||||||
} sp_int;
|
} sp_int;
|
||||||
|
|
||||||
|
typedef struct sp_int_minimal {
|
||||||
|
int used;
|
||||||
|
int size;
|
||||||
|
#ifdef WOLFSSL_SP_INT_NEGATIVE
|
||||||
|
int sign;
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_WOLF_BIGINT
|
||||||
|
struct WC_BIGINT raw;
|
||||||
|
#endif
|
||||||
|
/** First digit of number. */
|
||||||
|
sp_int_digit dp[1];
|
||||||
|
} sp_int_minimal;
|
||||||
|
|
||||||
/* Multi-precision integer type is SP integer type. */
|
/* Multi-precision integer type is SP integer type. */
|
||||||
typedef sp_int mp_int;
|
typedef sp_int mp_int;
|
||||||
/* Multi-precision integer digit type is SP integer digit type.
|
/* Multi-precision integer digit type is SP integer digit type.
|
||||||
|
Reference in New Issue
Block a user