diff options
author | tb <> | 2023-07-04 15:09:31 +0000 |
---|---|---|
committer | tb <> | 2023-07-04 15:09:31 +0000 |
commit | 9d190ec0e534650cdc84b1cd4b55351f19456cbe (patch) | |
tree | c8818e400aed57a0f8fd1e48aa76f778774458ff /src/lib | |
parent | c6e12a51459163768f29eb01b0356016f3f5b793 (diff) | |
download | openbsd-9d190ec0e534650cdc84b1cd4b55351f19456cbe.tar.gz openbsd-9d190ec0e534650cdc84b1cd4b55351f19456cbe.tar.bz2 openbsd-9d190ec0e534650cdc84b1cd4b55351f19456cbe.zip |
Avoid outputting invalid signatures
The caller can provide an r which will be added to the ECDSA_SIG unchecked.
This can happen via ECDSA_{,do_}sign_ex() or ECDSA_sign_setup() or else via
a custom sign_sig() handler. Therefore add a check that it is in the bounds
required.
Since k was long thrown away, there's no way to check kinv, so it needs to
be trusted. Misdesigned APIs that will output garbage everywhere...
ok jsing
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/libcrypto/ecdsa/ecs_ossl.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/lib/libcrypto/ecdsa/ecs_ossl.c b/src/lib/libcrypto/ecdsa/ecs_ossl.c index de51d3aa4a..0ca2651f25 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.70 2023/07/04 14:59:32 tb Exp $ */ | 1 | /* $OpenBSD: ecs_ossl.c,v 1.71 2023/07/04 15:09:31 tb Exp $ */ |
2 | /* | 2 | /* |
3 | * Written by Nils Larsch for the OpenSSL project | 3 | * Written by Nils Larsch for the OpenSSL project |
4 | */ | 4 | */ |
@@ -316,6 +316,16 @@ ecdsa_compute_s(BIGNUM **out_s, const BIGNUM *e, const BIGNUM *kinv, | |||
316 | if ((s = BN_new()) == NULL) | 316 | if ((s = BN_new()) == NULL) |
317 | goto err; | 317 | goto err; |
318 | 318 | ||
319 | /* | ||
320 | * In a valid ECDSA signature, r must be in [1, order). Since r can be | ||
321 | * caller provided - either directly or by replacing sign_setup() - we | ||
322 | * can't rely on this being the case. | ||
323 | */ | ||
324 | if (BN_cmp(r, BN_value_one()) < 0 || BN_cmp(r, order) >= 0) { | ||
325 | ECDSAerror(ECDSA_R_BAD_SIGNATURE); | ||
326 | goto err; | ||
327 | } | ||
328 | |||
319 | if (!bn_rand_interval(b, BN_value_one(), order)) { | 329 | if (!bn_rand_interval(b, BN_value_one(), order)) { |
320 | ECDSAerror(ERR_R_BN_LIB); | 330 | ECDSAerror(ERR_R_BN_LIB); |
321 | goto err; | 331 | goto err; |