diff options
Diffstat (limited to 'crypto/ec/curve448/scalar.c')
-rw-r--r-- | crypto/ec/curve448/scalar.c | 47 |
1 files changed, 26 insertions, 21 deletions
diff --git a/crypto/ec/curve448/scalar.c b/crypto/ec/curve448/scalar.c index 2923859e5a..fe2bb5b01b 100644 --- a/crypto/ec/curve448/scalar.c +++ b/crypto/ec/curve448/scalar.c @@ -38,8 +38,8 @@ static const curve448_scalar_t sc_p = { #define WBITS C448_WORD_BITS /* NB this may be different from ARCH_WORD_BITS */ -const curve448_scalar_t curve448_scalar_one = {{{1}}}; -const curve448_scalar_t curve448_scalar_zero = {{{0}}}; +const curve448_scalar_t ossl_curve448_scalar_one = {{{1}}}; +const curve448_scalar_t ossl_curve448_scalar_zero = {{{0}}}; /* * {extra,accum} - sub +? p @@ -106,20 +106,22 @@ static void sc_montmul(curve448_scalar_t out, const curve448_scalar_t a, sc_subx(out, accum, sc_p, sc_p, hi_carry); } -void curve448_scalar_mul(curve448_scalar_t out, const curve448_scalar_t a, - const curve448_scalar_t b) +void ossl_curve448_scalar_mul(curve448_scalar_t out, const curve448_scalar_t a, + const curve448_scalar_t b) { sc_montmul(out, a, b); sc_montmul(out, out, sc_r2); } -void curve448_scalar_sub(curve448_scalar_t out, const curve448_scalar_t a, +void +ossl_curve448_scalar_sub(curve448_scalar_t out, const curve448_scalar_t a, const curve448_scalar_t b) { sc_subx(out, a->limb, b, sc_p, 0); } -void curve448_scalar_add(curve448_scalar_t out, const curve448_scalar_t a, +void +ossl_curve448_scalar_add(curve448_scalar_t out, const curve448_scalar_t a, const curve448_scalar_t b) { c448_dword_t chain = 0; @@ -148,9 +150,9 @@ static ossl_inline void scalar_decode_short(curve448_scalar_t s, } } -c448_error_t curve448_scalar_decode( - curve448_scalar_t s, - const unsigned char ser[C448_SCALAR_BYTES]) +c448_error_t +ossl_curve448_scalar_decode(curve448_scalar_t s, + const unsigned char ser[C448_SCALAR_BYTES]) { unsigned int i; c448_dsword_t accum = 0; @@ -160,24 +162,25 @@ c448_error_t curve448_scalar_decode( accum = (accum + s->limb[i] - sc_p->limb[i]) >> WBITS; /* Here accum == 0 or -1 */ - curve448_scalar_mul(s, s, curve448_scalar_one); /* ham-handed reduce */ + ossl_curve448_scalar_mul(s, s, ossl_curve448_scalar_one); /* ham-handed reduce */ return c448_succeed_if(~word_is_zero((uint32_t)accum)); } -void curve448_scalar_destroy(curve448_scalar_t scalar) +void ossl_curve448_scalar_destroy(curve448_scalar_t scalar) { OPENSSL_cleanse(scalar, sizeof(curve448_scalar_t)); } -void curve448_scalar_decode_long(curve448_scalar_t s, +void +ossl_curve448_scalar_decode_long(curve448_scalar_t s, const unsigned char *ser, size_t ser_len) { size_t i; curve448_scalar_t t1, t2; if (ser_len == 0) { - curve448_scalar_copy(s, curve448_scalar_zero); + curve448_scalar_copy(s, ossl_curve448_scalar_zero); return; } @@ -190,24 +193,25 @@ void curve448_scalar_decode_long(curve448_scalar_t s, if (ser_len == sizeof(curve448_scalar_t)) { assert(i == 0); /* ham-handed reduce */ - curve448_scalar_mul(s, t1, curve448_scalar_one); - curve448_scalar_destroy(t1); + ossl_curve448_scalar_mul(s, t1, ossl_curve448_scalar_one); + ossl_curve448_scalar_destroy(t1); return; } while (i) { i -= C448_SCALAR_BYTES; sc_montmul(t1, t1, sc_r2); - (void)curve448_scalar_decode(t2, ser + i); - curve448_scalar_add(t1, t1, t2); + (void)ossl_curve448_scalar_decode(t2, ser + i); + ossl_curve448_scalar_add(t1, t1, t2); } curve448_scalar_copy(s, t1); - curve448_scalar_destroy(t1); - curve448_scalar_destroy(t2); + ossl_curve448_scalar_destroy(t1); + ossl_curve448_scalar_destroy(t2); } -void curve448_scalar_encode(unsigned char ser[C448_SCALAR_BYTES], +void +ossl_curve448_scalar_encode(unsigned char ser[C448_SCALAR_BYTES], const curve448_scalar_t s) { unsigned int i, j, k = 0; @@ -218,7 +222,8 @@ void curve448_scalar_encode(unsigned char ser[C448_SCALAR_BYTES], } } -void curve448_scalar_halve(curve448_scalar_t out, const curve448_scalar_t a) +void +ossl_curve448_scalar_halve(curve448_scalar_t out, const curve448_scalar_t a) { c448_word_t mask = 0 - (a->limb[0] & 1); c448_dword_t chain = 0; |