mirror of
https://github.com/openssl/openssl.git
synced 2026-01-18 17:11:31 +01:00
bn: Remove the BN_RECURSION cpp define
Just like in previous commit, this define does not represent a toggleable feature, but is entirely dependent on the OPENSSL_SMALL_FOOTPRINT define. Reviewed-by: Frederik Wedel-Heinen <fwh.openssl@gmail.com> Reviewed-by: Tomas Mraz <tomas@openssl.org> MergeDate: Mon Jan 12 18:44:27 2026 (Merged from https://github.com/openssl/openssl/pull/29204)
This commit is contained in:
@@ -52,10 +52,6 @@
|
||||
#define BN_SOFT_LIMIT (4096 / BN_BYTES)
|
||||
#endif
|
||||
|
||||
#ifndef OPENSSL_SMALL_FOOTPRINT
|
||||
#define BN_RECURSION
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This next option uses the C libraries (2 word)/(1 word) function. If it is
|
||||
* not defined, I use my C version (which is slower). The reason for this
|
||||
|
||||
@@ -154,7 +154,7 @@ BN_ULONG bn_sub_part_words(BN_ULONG *r,
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef BN_RECURSION
|
||||
#ifndef OPENSSL_SMALL_FOOTPRINT
|
||||
/*
|
||||
* Karatsuba recursive multiplication algorithm (cf. Knuth, The Art of
|
||||
* Computer Programming, Vol. 2)
|
||||
@@ -180,7 +180,6 @@ void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,
|
||||
unsigned int neg, zero;
|
||||
BN_ULONG ln, lo, *p;
|
||||
|
||||
#ifndef OPENSSL_SMALL_FOOTPRINT
|
||||
/*
|
||||
* Only call bn_mul_comba 8 if n2 == 8 and the two arrays are complete
|
||||
* [steve]
|
||||
@@ -189,7 +188,7 @@ void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,
|
||||
bn_mul_comba8(r, a, b);
|
||||
return;
|
||||
}
|
||||
#endif /* OPENSSL_SMALL_FOOTPRINT */
|
||||
|
||||
/* Else do normal multiply */
|
||||
if (n2 < BN_MUL_RECURSIVE_SIZE_NORMAL) {
|
||||
bn_mul_normal(r, a, n2 + dna, b, n2 + dnb);
|
||||
@@ -234,7 +233,6 @@ void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,
|
||||
break;
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_SMALL_FOOTPRINT
|
||||
if (n == 4 && dna == 0 && dnb == 0) { /* XXX: bn_mul_comba4 could take
|
||||
* extra args to do this well */
|
||||
if (!zero)
|
||||
@@ -254,9 +252,7 @@ void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,
|
||||
|
||||
bn_mul_comba8(r, a, b);
|
||||
bn_mul_comba8(&(r[n2]), &(a[n]), &(b[n]));
|
||||
} else
|
||||
#endif /* OPENSSL_SMALL_FOOTPRINT */
|
||||
{
|
||||
} else {
|
||||
p = &(t[n2 * 2]);
|
||||
if (!zero)
|
||||
bn_mul_recursive(&(t[n2]), t, &(t[n]), n, 0, 0, p);
|
||||
@@ -486,7 +482,7 @@ void bn_mul_low_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,
|
||||
bn_add_words(&(r[n]), &(r[n]), &(t[n]), n);
|
||||
}
|
||||
}
|
||||
#endif /* BN_RECURSION */
|
||||
#endif /* OPENSSL_SMALL_FOOTPRINT */
|
||||
|
||||
int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
|
||||
{
|
||||
@@ -503,10 +499,8 @@ int bn_mul_fixed_top(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
|
||||
int ret = 0;
|
||||
int top, al, bl;
|
||||
BIGNUM *rr;
|
||||
#if !defined(OPENSSL_SMALL_FOOTPRINT) || defined(BN_RECURSION)
|
||||
#if !defined(OPENSSL_SMALL_FOOTPRINT)
|
||||
int i;
|
||||
#endif
|
||||
#ifdef BN_RECURSION
|
||||
BIGNUM *t = NULL;
|
||||
int j = 0, k;
|
||||
#endif
|
||||
@@ -531,10 +525,9 @@ int bn_mul_fixed_top(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
|
||||
} else
|
||||
rr = r;
|
||||
|
||||
#if !defined(OPENSSL_SMALL_FOOTPRINT) || defined(BN_RECURSION)
|
||||
#if !defined(OPENSSL_SMALL_FOOTPRINT)
|
||||
i = al - bl;
|
||||
#endif
|
||||
#ifndef OPENSSL_SMALL_FOOTPRINT
|
||||
|
||||
if (i == 0) {
|
||||
#if 0
|
||||
if (al == 4) {
|
||||
@@ -553,8 +546,7 @@ int bn_mul_fixed_top(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
#endif /* OPENSSL_SMALL_FOOTPRINT */
|
||||
#ifdef BN_RECURSION
|
||||
|
||||
if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL)) {
|
||||
if (i >= -1 && i <= 1) {
|
||||
/*
|
||||
@@ -592,13 +584,13 @@ int bn_mul_fixed_top(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
#endif /* BN_RECURSION */
|
||||
#endif /* OPENSSL_SMALL_FOOTPRINT */
|
||||
if (bn_wexpand(rr, top) == NULL)
|
||||
goto err;
|
||||
rr->top = top;
|
||||
bn_mul_normal(rr->d, a->d, al, b->d, bl);
|
||||
|
||||
#if !defined(OPENSSL_SMALL_FOOTPRINT) || defined(BN_RECURSION)
|
||||
#if !defined(OPENSSL_SMALL_FOOTPRINT)
|
||||
end:
|
||||
#endif
|
||||
rr->neg = a->neg ^ b->neg;
|
||||
|
||||
@@ -64,7 +64,11 @@ int bn_sqr_fixed_top(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)
|
||||
bn_sqr_comba8(rr->d, a->d);
|
||||
#endif
|
||||
} else {
|
||||
#if defined(BN_RECURSION)
|
||||
#ifdef OPENSSL_SMALL_FOOTPRINT
|
||||
if (bn_wexpand(tmp, max) == NULL)
|
||||
goto err;
|
||||
bn_sqr_normal(rr->d, a->d, al, tmp->d);
|
||||
#else
|
||||
if (al < BN_SQR_RECURSIVE_SIZE_NORMAL) {
|
||||
BN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL * 2];
|
||||
bn_sqr_normal(rr->d, a->d, al, t);
|
||||
@@ -84,10 +88,6 @@ int bn_sqr_fixed_top(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)
|
||||
bn_sqr_normal(rr->d, a->d, al, tmp->d);
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (bn_wexpand(tmp, max) == NULL)
|
||||
goto err;
|
||||
bn_sqr_normal(rr->d, a->d, al, tmp->d);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)
|
||||
bn_add_words(r, r, tmp, max);
|
||||
}
|
||||
|
||||
#ifdef BN_RECURSION
|
||||
#ifndef OPENSSL_SMALL_FOOTPRINT
|
||||
/*-
|
||||
* r is 2*n words in size,
|
||||
* a and b are both n words in size. (There's not actually a 'b' here ...)
|
||||
@@ -160,18 +160,10 @@ void bn_sqr_recursive(BN_ULONG *r, const BN_ULONG *a, int n2, BN_ULONG *t)
|
||||
BN_ULONG ln, lo, *p;
|
||||
|
||||
if (n2 == 4) {
|
||||
#ifdef OPENSSL_SMALL_FOOTPRINT
|
||||
bn_sqr_normal(r, a, 4, t);
|
||||
#else
|
||||
bn_sqr_comba4(r, a);
|
||||
#endif
|
||||
return;
|
||||
} else if (n2 == 8) {
|
||||
#ifdef OPENSSL_SMALL_FOOTPRINT
|
||||
bn_sqr_normal(r, a, 8, t);
|
||||
#else
|
||||
bn_sqr_comba8(r, a);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
if (n2 < BN_SQR_RECURSIVE_SIZE_NORMAL) {
|
||||
|
||||
Reference in New Issue
Block a user