Remove STATIC_BIGNUM
and GFp_BN_value_one
which uses it.
This removes one pointer cast, in particular a const-to-non-const cast.
This commit is contained in:
parent
eab25d3dfb
commit
83b73724d8
@ -115,15 +115,6 @@ int GFp_BN_copy(BIGNUM *dest, const BIGNUM *src) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
const BIGNUM *GFp_BN_value_one(void) {
|
||||
static const BN_ULONG kOneLimbs[1] = { 1 };
|
||||
STATIC_BIGNUM_DIAGNOSTIC_PUSH
|
||||
static const BIGNUM kOne = STATIC_BIGNUM(kOneLimbs);
|
||||
STATIC_BIGNUM_DIAGNOSTIC_POP
|
||||
|
||||
return &kOne;
|
||||
}
|
||||
|
||||
/* GFp_BN_num_bits_word returns the minimum number of bits needed to represent
|
||||
* the value in |l|. */
|
||||
unsigned GFp_BN_num_bits_word(BN_ULONG l) {
|
||||
|
@ -730,14 +730,16 @@ static bool TestBadModulus() {
|
||||
ScopedBIGNUM a(GFp_BN_new());
|
||||
ScopedBIGNUM b(GFp_BN_new());
|
||||
ScopedBIGNUM zero(GFp_BN_new());
|
||||
ScopedBIGNUM one(GFp_BN_new());
|
||||
ScopedBN_MONT_CTX mont(GFp_BN_MONT_CTX_new());
|
||||
if (!a || !b || !zero || !mont) {
|
||||
if (!a || !b || !zero || !one || !mont ||
|
||||
!GFp_BN_set_word(one.get(), 1)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
GFp_BN_zero(zero.get());
|
||||
|
||||
if (GFp_BN_div(a.get(), b.get(), GFp_BN_value_one(), zero.get())) {
|
||||
if (GFp_BN_div(a.get(), b.get(), one.get(), zero.get())) {
|
||||
fprintf(stderr, "Division by zero unexpectedly succeeded.\n");
|
||||
return false;
|
||||
}
|
||||
@ -904,9 +906,15 @@ static bool TestModInvRejectUnreduced(RAND *rng) {
|
||||
static bool TestCmpWord() {
|
||||
static const BN_ULONG kMaxWord = (BN_ULONG)-1;
|
||||
|
||||
ScopedBIGNUM one(GFp_BN_new());
|
||||
ScopedBIGNUM r(GFp_BN_new());
|
||||
if (!r ||
|
||||
!GFp_BN_set_word(r.get(), 0)) {
|
||||
if (!one ||
|
||||
!GFp_BN_set_word(one.get(), 1) ||
|
||||
!r) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!GFp_BN_set_word(r.get(), 0)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -950,7 +958,7 @@ static bool TestCmpWord() {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!GFp_BN_add(r.get(), r.get(), GFp_BN_value_one())) {
|
||||
if (!GFp_BN_add(r.get(), r.get(), one.get())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -249,7 +249,8 @@ int GFp_BN_mod_exp_mont_vartime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
|
||||
/* Upper words will be zero if the corresponding words of 'm'
|
||||
* were 0xfff[...], so decrement r.top accordingly. */
|
||||
GFp_bn_correct_top(&r);
|
||||
} else if (!GFp_BN_to_mont(&r, GFp_BN_value_one(), mont)) {
|
||||
} else if (!GFp_BN_set_word(&r, 1) ||
|
||||
!GFp_BN_to_mont(&r, &r, mont)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
@ -531,7 +532,8 @@ int GFp_BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
|
||||
tmp.d[i] = (~m->d[i]) & BN_MASK2;
|
||||
}
|
||||
tmp.top = top;
|
||||
} else if (!GFp_BN_to_mont(&tmp, GFp_BN_value_one(), mont)) {
|
||||
} else if (!GFp_BN_set_word(&tmp, 1) ||
|
||||
!GFp_BN_to_mont(&tmp, &tmp, mont)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
|
@ -182,23 +182,6 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#define STATIC_BIGNUM_DIAGNOSTIC_PUSH \
|
||||
_Pragma("GCC diagnostic push") \
|
||||
_Pragma("GCC diagnostic ignored \"-Wcast-qual\"")
|
||||
#define STATIC_BIGNUM_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
|
||||
#else
|
||||
#define STATIC_BIGNUM_DIAGNOSTIC_PUSH
|
||||
#define STATIC_BIGNUM_DIAGNOSTIC_POP
|
||||
#endif
|
||||
|
||||
#define STATIC_BIGNUM(x) \
|
||||
{ \
|
||||
(BN_ULONG *)x, sizeof(x) / sizeof(BN_ULONG), \
|
||||
sizeof(x) / sizeof(BN_ULONG), 0, BN_FLG_STATIC_DATA \
|
||||
}
|
||||
|
||||
|
||||
BN_ULONG GFp_bn_mul_add_words(BN_ULONG *rp, const BN_ULONG *ap, int num,
|
||||
BN_ULONG w);
|
||||
BN_ULONG GFp_bn_mul_words(BN_ULONG *rp, const BN_ULONG *ap, int num,
|
||||
|
@ -176,9 +176,6 @@ OPENSSL_EXPORT void GFp_BN_free(BIGNUM *bn);
|
||||
* failure. */
|
||||
OPENSSL_EXPORT int GFp_BN_copy(BIGNUM *dest, const BIGNUM *src);
|
||||
|
||||
/* GFp_BN_value_one returns a static BIGNUM with value 1. */
|
||||
OPENSSL_EXPORT const BIGNUM *GFp_BN_value_one(void);
|
||||
|
||||
|
||||
/* Basic functions. */
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user