summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/ecdsa/ecs_ossl.c
diff options
context:
space:
mode:
authortb <>2022-04-07 17:37:25 +0000
committertb <>2022-04-07 17:37:25 +0000
commit1061feec63ce8eec5e559ca2697b80bc73044484 (patch)
treed24b9a5f8727ef577e3036c13bcebc52ae475072 /src/lib/libcrypto/ecdsa/ecs_ossl.c
parenta46afc15b79c1deda49ec8ee141c1c5cdcd050d9 (diff)
downloadopenbsd-1061feec63ce8eec5e559ca2697b80bc73044484.tar.gz
openbsd-1061feec63ce8eec5e559ca2697b80bc73044484.tar.bz2
openbsd-1061feec63ce8eec5e559ca2697b80bc73044484.zip
Avoid infinite loop for custom curves of order 1
If a private key encoded with EC parameters happens to have order 1 and is used for ECDSA signatures, this causes an infinite loop since a random integer x in the interval [0,1) will be 0, so do ... while (x == 0); will loop indefinitely. Found and reported with a reproducer by Hanno Boeck. Helpful comments and analysis from David Benjamin. ok beck jsing
Diffstat (limited to 'src/lib/libcrypto/ecdsa/ecs_ossl.c')
-rw-r--r--src/lib/libcrypto/ecdsa/ecs_ossl.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/lib/libcrypto/ecdsa/ecs_ossl.c b/src/lib/libcrypto/ecdsa/ecs_ossl.c
index 2429e36b59..0203b01bb5 100644
--- a/src/lib/libcrypto/ecdsa/ecs_ossl.c
+++ b/src/lib/libcrypto/ecdsa/ecs_ossl.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecs_ossl.c,v 1.23 2022/01/20 11:03:48 inoguchi Exp $ */ 1/* $OpenBSD: ecs_ossl.c,v 1.24 2022/04/07 17:37:25 tb Exp $ */
2/* 2/*
3 * Written by Nils Larsch for the OpenSSL project 3 * Written by Nils Larsch for the OpenSSL project
4 */ 4 */
@@ -163,6 +163,11 @@ ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)
163 goto err; 163 goto err;
164 } 164 }
165 165
166 if (BN_cmp(order, BN_value_one()) <= 0) {
167 ECDSAerror(EC_R_INVALID_GROUP_ORDER);
168 goto err;
169 }
170
166 /* Preallocate space. */ 171 /* Preallocate space. */
167 order_bits = BN_num_bits(order); 172 order_bits = BN_num_bits(order);
168 if (!BN_set_bit(k, order_bits) || 173 if (!BN_set_bit(k, order_bits) ||