summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/bn/bn_exp.c
diff options
context:
space:
mode:
authorjsing <>2022-11-26 13:56:33 +0000
committerjsing <>2022-11-26 13:56:33 +0000
commitbcbac728558eebfaa4404c405e7dc22769585345 (patch)
tree9f1339c5b70b0cfa4e8a0a5c70345e837a21ce77 /src/lib/libcrypto/bn/bn_exp.c
parent90d0616c736d954d327f399daa636de8e6a2c4d5 (diff)
downloadopenbsd-bcbac728558eebfaa4404c405e7dc22769585345.tar.gz
openbsd-bcbac728558eebfaa4404c405e7dc22769585345.tar.bz2
openbsd-bcbac728558eebfaa4404c405e7dc22769585345.zip
Remove BIGNUM consistency macros.
Compiling with BN_DEBUG (and if you want to take it further, BN_DEBUG_RAND) supposedly adds consistency checks to the BN code. These are rarely if ever used and introduce a bunch of clutter in the code. Furthermore, there are hacks in place to undo things that the debugging code does. Remove all of this mess and instead rely on always enabled checks, more readable code and proper regress coverage to ensure correct behaviour. "Good riddance." tb@
Diffstat (limited to 'src/lib/libcrypto/bn/bn_exp.c')
-rw-r--r--src/lib/libcrypto/bn/bn_exp.c19
1 files changed, 1 insertions, 18 deletions
diff --git a/src/lib/libcrypto/bn/bn_exp.c b/src/lib/libcrypto/bn/bn_exp.c
index 64156f716f..3bb0dd1304 100644
--- a/src/lib/libcrypto/bn/bn_exp.c
+++ b/src/lib/libcrypto/bn/bn_exp.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_exp.c,v 1.33 2022/11/24 01:30:01 jsing Exp $ */ 1/* $OpenBSD: bn_exp.c,v 1.34 2022/11/26 13:56:33 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -168,7 +168,6 @@ err:
168 if (r != rr && rr != NULL) 168 if (r != rr && rr != NULL)
169 BN_copy(r, rr); 169 BN_copy(r, rr);
170 BN_CTX_end(ctx); 170 BN_CTX_end(ctx);
171 bn_check_top(r);
172 return (ret); 171 return (ret);
173} 172}
174 173
@@ -178,9 +177,6 @@ BN_mod_exp_internal(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m
178{ 177{
179 int ret; 178 int ret;
180 179
181 bn_check_top(a);
182 bn_check_top(p);
183 bn_check_top(m);
184 180
185 /* For even modulus m = 2^k*m_odd, it might make sense to compute 181 /* For even modulus m = 2^k*m_odd, it might make sense to compute
186 * a^p mod m_odd and a^p mod 2^k separately (with Montgomery 182 * a^p mod m_odd and a^p mod 2^k separately (with Montgomery
@@ -222,7 +218,6 @@ BN_mod_exp_internal(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m
222 ret = BN_mod_exp_recp(r, a,p, m, ctx); 218 ret = BN_mod_exp_recp(r, a,p, m, ctx);
223 } 219 }
224 220
225 bn_check_top(r);
226 return (ret); 221 return (ret);
227} 222}
228 223
@@ -381,7 +376,6 @@ BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,
381err: 376err:
382 BN_CTX_end(ctx); 377 BN_CTX_end(ctx);
383 BN_RECP_CTX_free(&recp); 378 BN_RECP_CTX_free(&recp);
384 bn_check_top(r);
385 return (ret); 379 return (ret);
386} 380}
387 381
@@ -401,9 +395,6 @@ BN_mod_exp_mont_internal(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p, const BIG
401 return BN_mod_exp_mont_consttime(rr, a, p, m, ctx, in_mont); 395 return BN_mod_exp_mont_consttime(rr, a, p, m, ctx, in_mont);
402 } 396 }
403 397
404 bn_check_top(a);
405 bn_check_top(p);
406 bn_check_top(m);
407 398
408 if (!BN_is_odd(m)) { 399 if (!BN_is_odd(m)) {
409 BNerror(BN_R_CALLED_WITH_EVEN_MODULUS); 400 BNerror(BN_R_CALLED_WITH_EVEN_MODULUS);
@@ -533,7 +524,6 @@ err:
533 if ((in_mont == NULL) && (mont != NULL)) 524 if ((in_mont == NULL) && (mont != NULL))
534 BN_MONT_CTX_free(mont); 525 BN_MONT_CTX_free(mont);
535 BN_CTX_end(ctx); 526 BN_CTX_end(ctx);
536 bn_check_top(rr);
537 return (ret); 527 return (ret);
538} 528}
539 529
@@ -658,9 +648,6 @@ BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
658 unsigned char *powerbuf = NULL; 648 unsigned char *powerbuf = NULL;
659 BIGNUM tmp, am; 649 BIGNUM tmp, am;
660 650
661 bn_check_top(a);
662 bn_check_top(p);
663 bn_check_top(m);
664 651
665 if (!BN_is_odd(m)) { 652 if (!BN_is_odd(m)) {
666 BNerror(BN_R_CALLED_WITH_EVEN_MODULUS); 653 BNerror(BN_R_CALLED_WITH_EVEN_MODULUS);
@@ -937,8 +924,6 @@ BN_mod_exp_mont_word(BIGNUM *rr, BN_ULONG a, const BIGNUM *p, const BIGNUM *m,
937 return -1; 924 return -1;
938 } 925 }
939 926
940 bn_check_top(p);
941 bn_check_top(m);
942 927
943 if (!BN_is_odd(m)) { 928 if (!BN_is_odd(m)) {
944 BNerror(BN_R_CALLED_WITH_EVEN_MODULUS); 929 BNerror(BN_R_CALLED_WITH_EVEN_MODULUS);
@@ -1052,7 +1037,6 @@ err:
1052 if ((in_mont == NULL) && (mont != NULL)) 1037 if ((in_mont == NULL) && (mont != NULL))
1053 BN_MONT_CTX_free(mont); 1038 BN_MONT_CTX_free(mont);
1054 BN_CTX_end(ctx); 1039 BN_CTX_end(ctx);
1055 bn_check_top(rr);
1056 return (ret); 1040 return (ret);
1057} 1041}
1058 1042
@@ -1172,6 +1156,5 @@ BN_mod_exp_simple(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,
1172 1156
1173err: 1157err:
1174 BN_CTX_end(ctx); 1158 BN_CTX_end(ctx);
1175 bn_check_top(r);
1176 return (ret); 1159 return (ret);
1177} 1160}