diff options
author | jsing <> | 2023-03-07 06:28:36 +0000 |
---|---|---|
committer | jsing <> | 2023-03-07 06:28:36 +0000 |
commit | 1a1a85dd49b0d95ad37da975c7f03d879de1a8f1 (patch) | |
tree | 06b1106ed32703f0e6d26673ee1c52d2e310c0ef /src/lib | |
parent | 4320ee92fb55c991eec4cdc78f60c762533babb7 (diff) | |
download | openbsd-1a1a85dd49b0d95ad37da975c7f03d879de1a8f1.tar.gz openbsd-1a1a85dd49b0d95ad37da975c7f03d879de1a8f1.tar.bz2 openbsd-1a1a85dd49b0d95ad37da975c7f03d879de1a8f1.zip |
Limit bn_mul_mont() usage to sizes less than or equal to 8192 bits.
The assembly bn_mul_mont() implementations effectively use alloca() to
allocate space for computation (at up to 8x the input size), without
any limitation. This means that sufficiently large inputs lead to the
stack being blown. Prevent this by using the C based implementation
instead.
Thanks to Jiayi Lin <jlin139 at asu dot edu> for reporting this to us.
ok beck@ tb@
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/libcrypto/bn/bn_mont.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/lib/libcrypto/bn/bn_mont.c b/src/lib/libcrypto/bn/bn_mont.c index e92ceae5f4..314d683782 100644 --- a/src/lib/libcrypto/bn/bn_mont.c +++ b/src/lib/libcrypto/bn/bn_mont.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bn_mont.c,v 1.50 2023/03/07 06:19:44 jsing Exp $ */ | 1 | /* $OpenBSD: bn_mont.c,v 1.51 2023/03/07 06:28:36 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 | * |
@@ -435,6 +435,14 @@ bn_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, | |||
435 | if (mctx->N.top <= 1 || a->top != mctx->N.top || b->top != mctx->N.top) | 435 | if (mctx->N.top <= 1 || a->top != mctx->N.top || b->top != mctx->N.top) |
436 | return bn_mod_mul_montgomery_simple(r, a, b, mctx, ctx); | 436 | return bn_mod_mul_montgomery_simple(r, a, b, mctx, ctx); |
437 | 437 | ||
438 | /* | ||
439 | * Legacy bn_mul_mont() performs stack based allocation, without | ||
440 | * size limitation. Allowing a large size results in the stack | ||
441 | * being blown. | ||
442 | */ | ||
443 | if (mctx->N.top > (8 * 1024 / sizeof(BN_ULONG))) | ||
444 | return bn_montgomery_multiply(r, a, b, mctx, ctx); | ||
445 | |||
438 | if (!bn_wexpand(r, mctx->N.top)) | 446 | if (!bn_wexpand(r, mctx->N.top)) |
439 | return 0; | 447 | return 0; |
440 | 448 | ||