Skip to content

Commit

Permalink
wolfcrypt/src/sp_int.c: address peer review around _sp_zero(), sp_ini…
Browse files Browse the repository at this point in the history
…t(), and sp_init_size(), re sp_int_minimal.
  • Loading branch information
douzzer committed Sep 15, 2022
1 parent 5d2610c commit d18a654
Showing 1 changed file with 19 additions and 29 deletions.
48 changes: 19 additions & 29 deletions wolfcrypt/src/sp_int.c
Original file line number Diff line number Diff line change
Expand Up @@ -4352,65 +4352,55 @@ static int _sp_mont_red(sp_int* a, sp_int* m, sp_int_digit mp);
*/
static void _sp_zero(sp_int* a)
{
((sp_int_minimal *)a)->used = 0;
((sp_int_minimal *)a)->dp[0] = 0;
sp_int_minimal* am = (sp_int_minimal *)a;
am->used = 0;
am->dp[0] = 0;
#ifdef WOLFSSL_SP_INT_NEGATIVE
((sp_int_minimal *)a)->sign = MP_ZPOS;
am->sign = MP_ZPOS;
#endif
}

/* Initialize the multi-precision number to be zero.

/* Initialize the multi-precision number to be zero with a given max size.
*
* @param [out] a SP integer.
* @param [out] a SP integer.
* @param [in] size Number of words to say are available.
*
* @return MP_OKAY on success.
* @return MP_VAL when a is NULL.
*/
int sp_init(sp_int* a)
int sp_init_size(sp_int* a, int size)
{
sp_int_minimal* am = (sp_int_minimal *)a;
int err = MP_OKAY;

if (a == NULL) {
err = MP_VAL;
}
if (err == MP_OKAY) {
#ifdef HAVE_WOLF_BIGINT
wc_bigint_init(&a->raw);
wc_bigint_init(&am->raw);
#endif
_sp_zero(a);
a->size = SP_INT_DIGITS;
}

if (err == MP_OKAY) {
am->size = size;
}

return err;
}

/* Initialize the multi-precision number to be zero and have a maximum size.
/* Initialize the multi-precision number to be zero.
*
* @param [out] a SP integer.
* @param [in] size Number of words to say are available.
* @param [out] a SP integer.
*
* @return MP_OKAY on success.
* @return MP_VAL when a is NULL.
*/
int sp_init_size(sp_int* a, int size)
int sp_init(sp_int* 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) {
((sp_int_minimal *)a)->size = size;
}

return err;
return sp_init_size(a, SP_INT_DIGITS);
}

#if !defined(WOLFSSL_RSA_PUBLIC_ONLY) || !defined(NO_DH) || defined(HAVE_ECC)
Expand Down

0 comments on commit d18a654

Please sign in to comment.