summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/dh
diff options
context:
space:
mode:
authorbcook <>2016-06-30 02:02:06 +0000
committerbcook <>2016-06-30 02:02:06 +0000
commitf38e0f193e7bb5faea955cd4afea248b830afa18 (patch)
tree0ceecace65c38593a01c1d41cce469bd98529f43 /src/lib/libcrypto/dh
parentaa239d08d6dc87fdd121f62e3130aa5d5357cfff (diff)
downloadopenbsd-f38e0f193e7bb5faea955cd4afea248b830afa18.tar.gz
openbsd-f38e0f193e7bb5faea955cd4afea248b830afa18.tar.bz2
openbsd-f38e0f193e7bb5faea955cd4afea248b830afa18.zip
Remove flags for disabling constant-time operations.
This removes support for DSA_FLAG_NO_EXP_CONSTTIME, DH_FLAG_NO_EXP_CONSTTIME, and RSA_FLAG_NO_CONSTTIME flags, making all of these operations unconditionally constant-time. Based on the original patch by César Pereid. ok beck@
Diffstat (limited to 'src/lib/libcrypto/dh')
-rw-r--r--src/lib/libcrypto/dh/dh.h9
-rw-r--r--src/lib/libcrypto/dh/dh_key.c37
2 files changed, 12 insertions, 34 deletions
diff --git a/src/lib/libcrypto/dh/dh.h b/src/lib/libcrypto/dh/dh.h
index a20467c9d0..631cd5c685 100644
--- a/src/lib/libcrypto/dh/dh.h
+++ b/src/lib/libcrypto/dh/dh.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: dh.h,v 1.16 2014/06/12 15:49:28 deraadt Exp $ */ 1/* $OpenBSD: dh.h,v 1.17 2016/06/30 02:02:06 bcook 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 *
@@ -78,13 +78,6 @@
78#endif 78#endif
79 79
80#define DH_FLAG_CACHE_MONT_P 0x01 80#define DH_FLAG_CACHE_MONT_P 0x01
81#define DH_FLAG_NO_EXP_CONSTTIME 0x02 /* new with 0.9.7h; the built-in DH
82 * implementation now uses constant time
83 * modular exponentiation for secret exponents
84 * by default. This flag causes the
85 * faster variable sliding window method to
86 * be used for all exponents.
87 */
88 81
89/* If this flag is set the DH method is FIPS compliant and can be used 82/* If this flag is set the DH method is FIPS compliant and can be used
90 * in FIPS mode. This is set in the validated module method. If an 83 * in FIPS mode. This is set in the validated module method. If an
diff --git a/src/lib/libcrypto/dh/dh_key.c b/src/lib/libcrypto/dh/dh_key.c
index 31bc7b3dfd..25e8968ef5 100644
--- a/src/lib/libcrypto/dh/dh_key.c
+++ b/src/lib/libcrypto/dh/dh_key.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dh_key.c,v 1.23 2015/02/09 15:49:22 jsing Exp $ */ 1/* $OpenBSD: dh_key.c,v 1.24 2016/06/30 02:02:06 bcook 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 *
@@ -147,21 +147,16 @@ generate_key(DH *dh)
147 } 147 }
148 148
149 { 149 {
150 BIGNUM local_prk; 150 BIGNUM prk;
151 BIGNUM *prk;
152 151
153 if ((dh->flags & DH_FLAG_NO_EXP_CONSTTIME) == 0) { 152 BN_with_flags(&prk, priv_key, BN_FLG_CONSTTIME);
154 BN_init(&local_prk);
155 prk = &local_prk;
156 BN_with_flags(prk, priv_key, BN_FLG_CONSTTIME);
157 } else
158 prk = priv_key;
159 153
160 if (!dh->meth->bn_mod_exp(dh, pub_key, dh->g, prk, dh->p, ctx, 154 if (!dh->meth->bn_mod_exp(dh, pub_key, dh->g, &prk, dh->p, ctx,
161 mont)) 155 mont)) {
162 goto err; 156 goto err;
157 }
163 } 158 }
164 159
165 dh->pub_key = pub_key; 160 dh->pub_key = pub_key;
166 dh->priv_key = priv_key; 161 dh->priv_key = priv_key;
167 ok = 1; 162 ok = 1;
@@ -206,10 +201,9 @@ compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh)
206 if (dh->flags & DH_FLAG_CACHE_MONT_P) { 201 if (dh->flags & DH_FLAG_CACHE_MONT_P) {
207 mont = BN_MONT_CTX_set_locked(&dh->method_mont_p, 202 mont = BN_MONT_CTX_set_locked(&dh->method_mont_p,
208 CRYPTO_LOCK_DH, dh->p, ctx); 203 CRYPTO_LOCK_DH, dh->p, ctx);
209 if ((dh->flags & DH_FLAG_NO_EXP_CONSTTIME) == 0) { 204
210 /* XXX */ 205 BN_set_flags(dh->priv_key, BN_FLG_CONSTTIME);
211 BN_set_flags(dh->priv_key, BN_FLG_CONSTTIME); 206
212 }
213 if (!mont) 207 if (!mont)
214 goto err; 208 goto err;
215 } 209 }
@@ -238,16 +232,7 @@ static int
238dh_bn_mod_exp(const DH *dh, BIGNUM *r, const BIGNUM *a, const BIGNUM *p, 232dh_bn_mod_exp(const DH *dh, BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
239 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx) 233 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
240{ 234{
241 /* 235 return BN_mod_exp_mont(r, a, p, m, ctx, m_ctx);
242 * If a is only one word long and constant time is false, use the faster
243 * exponenentiation function.
244 */
245 if (a->top == 1 && (dh->flags & DH_FLAG_NO_EXP_CONSTTIME) != 0) {
246 BN_ULONG A = a->d[0];
247
248 return BN_mod_exp_mont_word(r, A, p, m, ctx, m_ctx);
249 } else
250 return BN_mod_exp_mont(r, a, p, m, ctx, m_ctx);
251} 236}
252 237
253static int 238static int