From: jsing Date: Wed, 15 Mar 2023 04:26:23 +0000 (+0000) Subject: Include tests with negative values in BN_mod_exp* regress. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=6b6aa922fa0cfc156d20f66d39ba7a8d6b705f87;p=openbsd Include tests with negative values in BN_mod_exp* regress. This currently fails. --- diff --git a/regress/lib/libcrypto/bn/bn_mod_exp.c b/regress/lib/libcrypto/bn/bn_mod_exp.c index aca2ee68fdc..a2dc2a4e36f 100644 --- a/regress/lib/libcrypto/bn/bn_mod_exp.c +++ b/regress/lib/libcrypto/bn/bn_mod_exp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bn_mod_exp.c,v 1.11 2022/12/08 07:18:47 tb Exp $ */ +/* $OpenBSD: bn_mod_exp.c,v 1.12 2023/03/15 04:26:23 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -88,6 +88,15 @@ static const struct mod_exp_test { #define N_MOD_EXP_FN (sizeof(mod_exp_fn) / sizeof(mod_exp_fn[0])) +static int +rand_neg(void) +{ + static unsigned int neg = 0; + static int sign[8] = { 0, 0, 0, 1, 1, 0, 1, 1 }; + + return (sign[(neg++) % 8]); +} + static int test_mod_exp(const BIGNUM *result_simple, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, BN_CTX *ctx, const struct mod_exp_test *test) @@ -161,15 +170,19 @@ main(int argc, char *argv[]) if ((result_simple = BN_CTX_get(ctx)) == NULL) goto err; - for (i = 0; i < 200; i++) { + for (i = 0; i < 1000; i++) { c = arc4random() % BN_BITS - BN_BITS2; if (!BN_rand(a, NUM_BITS + c, 0, 0)) goto err; + BN_set_negative(a, rand_neg()); + c = arc4random() % BN_BITS - BN_BITS2; if (!BN_rand(b, NUM_BITS + c, 0, 0)) goto err; + BN_set_negative(b, rand_neg()); + c = arc4random() % BN_BITS - BN_BITS2; if (!BN_rand(m, NUM_BITS + c, 0, 1)) goto err;