summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/bn/bn_exp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/bn/bn_exp.c')
-rw-r--r--src/lib/libcrypto/bn/bn_exp.c13
1 files changed, 4 insertions, 9 deletions
diff --git a/src/lib/libcrypto/bn/bn_exp.c b/src/lib/libcrypto/bn/bn_exp.c
index d388758927..b778d5d67c 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.30 2017/01/29 17:49:22 beck Exp $ */ 1/* $OpenBSD: bn_exp.c,v 1.31 2017/05/02 03:59:44 deraadt 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 *
@@ -706,12 +706,10 @@ BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
706 numPowers = 1 << window; 706 numPowers = 1 << window;
707 powerbufLen = sizeof(m->d[0]) * (top * numPowers + 707 powerbufLen = sizeof(m->d[0]) * (top * numPowers +
708 ((2*top) > numPowers ? (2*top) : numPowers)); 708 ((2*top) > numPowers ? (2*top) : numPowers));
709 if ((powerbufFree = malloc(powerbufLen + 709 if ((powerbufFree = calloc(powerbufLen +
710 MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH)) == NULL) 710 MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH, 1)) == NULL)
711 goto err; 711 goto err;
712
713 powerbuf = MOD_EXP_CTIME_ALIGN(powerbufFree); 712 powerbuf = MOD_EXP_CTIME_ALIGN(powerbufFree);
714 memset(powerbuf, 0, powerbufLen);
715 713
716 /* lay down tmp and am right after powers table */ 714 /* lay down tmp and am right after powers table */
717 tmp.d = (BN_ULONG *)(powerbuf + sizeof(m->d[0]) * top * numPowers); 715 tmp.d = (BN_ULONG *)(powerbuf + sizeof(m->d[0]) * top * numPowers);
@@ -901,10 +899,7 @@ BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
901err: 899err:
902 if ((in_mont == NULL) && (mont != NULL)) 900 if ((in_mont == NULL) && (mont != NULL))
903 BN_MONT_CTX_free(mont); 901 BN_MONT_CTX_free(mont);
904 if (powerbuf != NULL) { 902 freezero(powerbufFree, powerbufLen + MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH);
905 explicit_bzero(powerbuf, powerbufLen);
906 free(powerbufFree);
907 }
908 BN_CTX_end(ctx); 903 BN_CTX_end(ctx);
909 return (ret); 904 return (ret);
910} 905}