mirror of
https://github.com/QuasarApp/openssl.git
synced 2025-05-03 13:09:38 +00:00
Add GCD testing infrastructure.
This commit adds testing and Known Answer Tests (KATs) to OpenSSL for the `BN_gcd` function. Reviewed-by: Paul Dale <paul.dale@oracle.com> Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/10122)
This commit is contained in:
parent
f3c4adfc7e
commit
b75d631085
@ -1634,6 +1634,30 @@ static int file_modsqrt(STANZA *s)
|
|||||||
return st;
|
return st;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int file_gcd(STANZA *s)
|
||||||
|
{
|
||||||
|
BIGNUM *a = NULL, *b = NULL, *gcd = NULL, *ret = NULL;
|
||||||
|
int st = 0;
|
||||||
|
|
||||||
|
if (!TEST_ptr(a = getBN(s, "A"))
|
||||||
|
|| !TEST_ptr(b = getBN(s, "B"))
|
||||||
|
|| !TEST_ptr(gcd = getBN(s, "GCD"))
|
||||||
|
|| !TEST_ptr(ret = BN_new()))
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
if (!TEST_true(BN_gcd(ret, a, b, ctx))
|
||||||
|
|| !equalBN("gcd(A,B)", gcd, ret))
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
st = 1;
|
||||||
|
err:
|
||||||
|
BN_free(a);
|
||||||
|
BN_free(b);
|
||||||
|
BN_free(gcd);
|
||||||
|
BN_free(ret);
|
||||||
|
return st;
|
||||||
|
}
|
||||||
|
|
||||||
static int test_bn2padded(void)
|
static int test_bn2padded(void)
|
||||||
{
|
{
|
||||||
#if HAVE_BN_PADDED
|
#if HAVE_BN_PADDED
|
||||||
@ -2432,6 +2456,34 @@ static int test_ctx_consttime_flag(void)
|
|||||||
return st;
|
return st;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int test_gcd_prime(void)
|
||||||
|
{
|
||||||
|
BIGNUM *a = NULL, *b = NULL, *gcd = NULL;
|
||||||
|
int i, st = 0;
|
||||||
|
|
||||||
|
if (!TEST_ptr(a = BN_new())
|
||||||
|
|| !TEST_ptr(b = BN_new())
|
||||||
|
|| !TEST_ptr(gcd = BN_new()))
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
if (!TEST_true(BN_generate_prime_ex(a, 1024, 0, NULL, NULL, NULL)))
|
||||||
|
goto err;
|
||||||
|
for (i = 0; i < NUM0; i++) {
|
||||||
|
if (!TEST_true(BN_generate_prime_ex(b, 1024, 0,
|
||||||
|
NULL, NULL, NULL))
|
||||||
|
|| !TEST_true(BN_gcd(gcd, a, b, ctx))
|
||||||
|
|| !TEST_true(BN_is_one(gcd)))
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
|
st = 1;
|
||||||
|
err:
|
||||||
|
BN_free(a);
|
||||||
|
BN_free(b);
|
||||||
|
BN_free(gcd);
|
||||||
|
return st;
|
||||||
|
}
|
||||||
|
|
||||||
static int file_test_run(STANZA *s)
|
static int file_test_run(STANZA *s)
|
||||||
{
|
{
|
||||||
static const FILETEST filetests[] = {
|
static const FILETEST filetests[] = {
|
||||||
@ -2446,6 +2498,7 @@ static int file_test_run(STANZA *s)
|
|||||||
{"ModExp", file_modexp},
|
{"ModExp", file_modexp},
|
||||||
{"Exp", file_exp},
|
{"Exp", file_exp},
|
||||||
{"ModSqrt", file_modsqrt},
|
{"ModSqrt", file_modsqrt},
|
||||||
|
{"GCD", file_gcd},
|
||||||
};
|
};
|
||||||
int numtests = OSSL_NELEM(filetests);
|
int numtests = OSSL_NELEM(filetests);
|
||||||
const FILETEST *tp = filetests;
|
const FILETEST *tp = filetests;
|
||||||
@ -2567,6 +2620,7 @@ int setup_tests(void)
|
|||||||
#endif
|
#endif
|
||||||
ADD_ALL_TESTS(test_is_prime, (int)OSSL_NELEM(primes));
|
ADD_ALL_TESTS(test_is_prime, (int)OSSL_NELEM(primes));
|
||||||
ADD_ALL_TESTS(test_not_prime, (int)OSSL_NELEM(not_primes));
|
ADD_ALL_TESTS(test_not_prime, (int)OSSL_NELEM(not_primes));
|
||||||
|
ADD_TEST(test_gcd_prime);
|
||||||
if (stochastic)
|
if (stochastic)
|
||||||
ADD_TEST(test_rand_range);
|
ADD_TEST(test_rand_range);
|
||||||
} else {
|
} else {
|
||||||
|
@ -16,9 +16,8 @@ use OpenSSL::Test qw/:DEFAULT data_file/;
|
|||||||
|
|
||||||
setup("test_bn");
|
setup("test_bn");
|
||||||
|
|
||||||
my @files = (
|
my @files = qw( bnexp.txt bnmod.txt bnmul.txt bnshift.txt bnsum.txt bngcd.txt );
|
||||||
"bnexp.txt", "bnmod.txt", "bnmul.txt", "bnshift.txt", "bnsum.txt"
|
|
||||||
);
|
|
||||||
plan tests => 1 + scalar(@files);
|
plan tests => 1 + scalar(@files);
|
||||||
|
|
||||||
foreach my $f ( @files ) {
|
foreach my $f ( @files ) {
|
||||||
|
17179
test/recipes/10-test_bn_data/bngcd.txt
Normal file
17179
test/recipes/10-test_bn_data/bngcd.txt
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user