summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2023-03-26 18:46:23 +0000
committertb <>2023-03-26 18:46:23 +0000
commite38cf77b1ca206b636cffd867656a62dd8cf3d98 (patch)
tree129643f5857f3d9a8e4eabb579312ce4e29998d8 /src
parent95750a6de606505162ce4f3fcc3d026deadd1fb0 (diff)
downloadopenbsd-e38cf77b1ca206b636cffd867656a62dd8cf3d98.tar.gz
openbsd-e38cf77b1ca206b636cffd867656a62dd8cf3d98.tar.bz2
openbsd-e38cf77b1ca206b636cffd867656a62dd8cf3d98.zip
Add regress coverage for an issue with BN_mod_exp2_mont() reported
by Guido Vranken in ossfuzz #55997. This test currently fails and will be fixed momentarily. This also checks sensible behavior with respect to zero exponents for this functions.
Diffstat (limited to 'src')
-rw-r--r--src/regress/lib/libcrypto/bn/bn_mod_exp.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/regress/lib/libcrypto/bn/bn_mod_exp.c b/src/regress/lib/libcrypto/bn/bn_mod_exp.c
index 7009a6096a..68e44cf9e7 100644
--- a/src/regress/lib/libcrypto/bn/bn_mod_exp.c
+++ b/src/regress/lib/libcrypto/bn/bn_mod_exp.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_mod_exp.c,v 1.16 2023/03/26 14:50:23 tb Exp $ */ 1/* $OpenBSD: bn_mod_exp.c,v 1.17 2023/03/26 18:46:23 tb Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2022,2023 Theo Buehler <tb@openbsd.org> 4 * Copyright (c) 2022,2023 Theo Buehler <tb@openbsd.org>
@@ -27,6 +27,24 @@
27#define INIT_MOD_EXP_FN(f) { .name = #f, .mod_exp_fn = (f), } 27#define INIT_MOD_EXP_FN(f) { .name = #f, .mod_exp_fn = (f), }
28#define INIT_MOD_EXP_MONT_FN(f) { .name = #f, .mod_exp_mont_fn = (f), } 28#define INIT_MOD_EXP_MONT_FN(f) { .name = #f, .mod_exp_mont_fn = (f), }
29 29
30static int
31bn_mod_exp2_mont_first(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
32 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *mctx)
33{
34 const BIGNUM *one = BN_value_one();
35
36 return BN_mod_exp2_mont(r, a, p, one, one, m, ctx, mctx);
37}
38
39static int
40bn_mod_exp2_mont_second(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
41 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *mctx)
42{
43 const BIGNUM *one = BN_value_one();
44
45 return BN_mod_exp2_mont(r, one, one, a, p, m, ctx, mctx);
46}
47
30static const struct mod_exp_zero_test { 48static const struct mod_exp_zero_test {
31 const char *name; 49 const char *name;
32 int (*mod_exp_fn)(BIGNUM *, const BIGNUM *, const BIGNUM *, 50 int (*mod_exp_fn)(BIGNUM *, const BIGNUM *, const BIGNUM *,
@@ -43,6 +61,8 @@ static const struct mod_exp_zero_test {
43 INIT_MOD_EXP_MONT_FN(BN_mod_exp_mont_ct), 61 INIT_MOD_EXP_MONT_FN(BN_mod_exp_mont_ct),
44 INIT_MOD_EXP_MONT_FN(BN_mod_exp_mont_consttime), 62 INIT_MOD_EXP_MONT_FN(BN_mod_exp_mont_consttime),
45 INIT_MOD_EXP_MONT_FN(BN_mod_exp_mont_nonct), 63 INIT_MOD_EXP_MONT_FN(BN_mod_exp_mont_nonct),
64 INIT_MOD_EXP_MONT_FN(bn_mod_exp2_mont_first),
65 INIT_MOD_EXP_MONT_FN(bn_mod_exp2_mont_second),
46}; 66};
47 67
48#define N_MOD_EXP_ZERO_TESTS \ 68#define N_MOD_EXP_ZERO_TESTS \
@@ -193,6 +213,8 @@ static const struct mod_exp_test {
193 INIT_MOD_EXP_MONT_FN(BN_mod_exp_mont_ct), 213 INIT_MOD_EXP_MONT_FN(BN_mod_exp_mont_ct),
194 INIT_MOD_EXP_MONT_FN(BN_mod_exp_mont_consttime), 214 INIT_MOD_EXP_MONT_FN(BN_mod_exp_mont_consttime),
195 INIT_MOD_EXP_MONT_FN(BN_mod_exp_mont_nonct), 215 INIT_MOD_EXP_MONT_FN(BN_mod_exp_mont_nonct),
216 INIT_MOD_EXP_MONT_FN(bn_mod_exp2_mont_first),
217 INIT_MOD_EXP_MONT_FN(bn_mod_exp2_mont_second),
196}; 218};
197 219
198#define N_MOD_EXP_FN (sizeof(mod_exp_fn) / sizeof(mod_exp_fn[0])) 220#define N_MOD_EXP_FN (sizeof(mod_exp_fn) / sizeof(mod_exp_fn[0]))