Use BIO not FILE for test file
Allow multiple file arguments. Split bntests.txt into separate files. Reviewed-by: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/3471)
This commit is contained in:
parent
007d272530
commit
e1cfd184da
8 changed files with 10620 additions and 10593 deletions
30
test/bnexp.txt
Normal file
30
test/bnexp.txt
Normal file
|
@ -0,0 +1,30 @@
|
|||
# Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the OpenSSL license (the "License"). You may not use
|
||||
# this file except in compliance with the License. You can obtain a copy
|
||||
# in the file LICENSE in the source distribution or at
|
||||
# https://www.openssl.org/source/license.html
|
||||
|
||||
# Exp tests.
|
||||
#
|
||||
# These test vectors satisfy A ^ E = Exp.
|
||||
|
||||
Exp = aa6d7ac431
|
||||
A = d0e07
|
||||
E = 2
|
||||
|
||||
Exp = 12d416b110dbb4e467ff0c89a22122f4da8240
|
||||
A = 1a18cf6
|
||||
E = 6
|
||||
|
||||
Exp = 49a3b33e23d84f1ce0d5d83f5dcb651d50cf3920f0143da2310d0512a90a06cd8f38977df8a756c30883de38df092000
|
||||
A = 2a3acbd2
|
||||
E = d
|
||||
|
||||
Exp = 5b4a0d5a956f885f275712b194459980f24708bfb6393d71bd37dce852ce455724f5ee5030775fb86b4295edc98afaafc097e4d82a97c0078ec0eac763db16549c5145c4cf2d3124f88cf9a5c71da0625afb99b26801786fe49a778415dc025954021753d08691947a208b613f0be5c1
|
||||
A = 54b3ae461
|
||||
E = 1a
|
||||
|
||||
Exp = a0ea5f6a4de49beb8fb7f0dab280d6a32c5a3814c9a5153a7944cec0a9028497846a8a89044348721a0bb5f0c3ded3e980574ea321b0cdb0ead4f4e93841ea7478a7f15d9729b646a8165813a0750e8124f5465dda9b105e1bbeff18fd09c09a2e26610d9176d253b877c3a8908a6be521cbe1e472a7a1b7820e4e890f8f28aacd34609c686e76e15b01bd9324a71290812724ea564d11c874a6765b262c3e57d479da0287a76026a1e8fe53da0b02405da1d379eaa30fc65f
|
||||
A = fccec0f6df
|
||||
E = 25
|
2802
test/bnmod.txt
Normal file
2802
test/bnmod.txt
Normal file
File diff suppressed because it is too large
Load diff
2678
test/bnmul.txt
Normal file
2678
test/bnmul.txt
Normal file
File diff suppressed because it is too large
Load diff
2427
test/bnshift.txt
Normal file
2427
test/bnshift.txt
Normal file
File diff suppressed because it is too large
Load diff
2626
test/bnsum.txt
Normal file
2626
test/bnsum.txt
Normal file
File diff suppressed because it is too large
Load diff
|
@ -67,7 +67,7 @@ typedef struct mpitest_st {
|
|||
|
||||
static const int NUM0 = 100; /* number of tests */
|
||||
static const int NUM1 = 50; /* additional tests for some functions */
|
||||
static FILE *fp;
|
||||
static BIO *fp;
|
||||
static BN_CTX *ctx;
|
||||
|
||||
/*
|
||||
|
@ -2011,7 +2011,7 @@ static int readstanza(STANZA *s, int *linesread)
|
|||
char *p, *equals, *key, *value;
|
||||
char buff[1024];
|
||||
|
||||
while (fgets(buff, sizeof(buff), fp) != NULL) {
|
||||
while (BIO_gets(fp, buff, sizeof(buff))) {
|
||||
(*linesread)++;
|
||||
if (!TEST_ptr(p = strchr(buff, '\n'))) {
|
||||
TEST_info("Line %d too long", s->start);
|
||||
|
@ -2089,14 +2089,20 @@ static int file_test_run(STANZA *s)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int file_tests()
|
||||
static char * const *testfiles;
|
||||
|
||||
static int run_file_tests(int i)
|
||||
{
|
||||
STANZA s;
|
||||
int linesread = 0, errcnt = 0;
|
||||
|
||||
if (!TEST_ptr(fp = BIO_new_file(testfiles[i], "rb")))
|
||||
return 0;
|
||||
|
||||
/* Read test file. */
|
||||
set_test_title(testfiles[i]);
|
||||
memset(&s, 0, sizeof(s));
|
||||
while (!feof(fp) && readstanza(&s, &linesread)) {
|
||||
while (!BIO_eof(fp) && readstanza(&s, &linesread)) {
|
||||
if (s.numpairs == 0)
|
||||
continue;
|
||||
if (!file_test_run(&s)) {
|
||||
|
@ -2105,58 +2111,57 @@ static int file_tests()
|
|||
clearstanza(&s);
|
||||
s.start = linesread;
|
||||
}
|
||||
BIO_free(fp);
|
||||
|
||||
return errcnt == 0;
|
||||
}
|
||||
|
||||
|
||||
int test_main(int argc, char *argv[])
|
||||
{
|
||||
static const char rnd_seed[] =
|
||||
"If not seeded, BN_generate_prime might fail";
|
||||
int result = 0;
|
||||
int result = EXIT_FAILURE;
|
||||
|
||||
if (argc != 2) {
|
||||
TEST_error("%s TEST_FILE", argv[0]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ADD_TEST(test_sub);
|
||||
ADD_TEST(test_div_recip);
|
||||
ADD_TEST(test_mod);
|
||||
ADD_TEST(test_modexp_mont5);
|
||||
ADD_TEST(test_kronecker);
|
||||
ADD_TEST(test_rand);
|
||||
ADD_TEST(test_bn2padded);
|
||||
ADD_TEST(test_dec2bn);
|
||||
ADD_TEST(test_hex2bn);
|
||||
ADD_TEST(test_asc2bn);
|
||||
ADD_ALL_TESTS(test_mpi, (int)OSSL_NELEM(kMPITests));
|
||||
ADD_TEST(test_negzero);
|
||||
ADD_TEST(test_badmod);
|
||||
ADD_TEST(test_expmodzero);
|
||||
ADD_TEST(test_smallprime);
|
||||
#ifndef OPENSSL_NO_EC2M
|
||||
ADD_TEST(test_gf2m_add);
|
||||
ADD_TEST(test_gf2m_mod);
|
||||
ADD_TEST(test_gf2m_mul);
|
||||
ADD_TEST(test_gf2m_sqr);
|
||||
ADD_TEST(test_gf2m_modinv);
|
||||
ADD_TEST(test_gf2m_moddiv);
|
||||
ADD_TEST(test_gf2m_modexp);
|
||||
ADD_TEST(test_gf2m_modsqrt);
|
||||
ADD_TEST(test_gf2m_modsolvequad);
|
||||
#endif
|
||||
ADD_TEST(test_3_is_prime);
|
||||
ADD_TEST(file_tests);
|
||||
|
||||
RAND_seed(rnd_seed, sizeof rnd_seed);
|
||||
ctx = BN_CTX_new();
|
||||
TEST_check(ctx != NULL);
|
||||
|
||||
if (!TEST_ptr(fp = fopen(argv[1], "r")))
|
||||
if (!TEST_ptr(ctx = BN_CTX_new()))
|
||||
goto end;
|
||||
|
||||
if (argc < 2) {
|
||||
ADD_TEST(test_sub);
|
||||
ADD_TEST(test_div_recip);
|
||||
ADD_TEST(test_mod);
|
||||
ADD_TEST(test_modexp_mont5);
|
||||
ADD_TEST(test_kronecker);
|
||||
ADD_TEST(test_rand);
|
||||
ADD_TEST(test_bn2padded);
|
||||
ADD_TEST(test_dec2bn);
|
||||
ADD_TEST(test_hex2bn);
|
||||
ADD_TEST(test_asc2bn);
|
||||
ADD_ALL_TESTS(test_mpi, (int)OSSL_NELEM(kMPITests));
|
||||
ADD_TEST(test_negzero);
|
||||
ADD_TEST(test_badmod);
|
||||
ADD_TEST(test_expmodzero);
|
||||
ADD_TEST(test_smallprime);
|
||||
#ifndef OPENSSL_NO_EC2M
|
||||
ADD_TEST(test_gf2m_add);
|
||||
ADD_TEST(test_gf2m_mod);
|
||||
ADD_TEST(test_gf2m_mul);
|
||||
ADD_TEST(test_gf2m_sqr);
|
||||
ADD_TEST(test_gf2m_modinv);
|
||||
ADD_TEST(test_gf2m_moddiv);
|
||||
ADD_TEST(test_gf2m_modexp);
|
||||
ADD_TEST(test_gf2m_modsqrt);
|
||||
ADD_TEST(test_gf2m_modsolvequad);
|
||||
#endif
|
||||
ADD_TEST(test_3_is_prime);
|
||||
} else {
|
||||
testfiles = &argv[1];
|
||||
ADD_ALL_TESTS(run_file_tests, argc - 1);
|
||||
}
|
||||
|
||||
result = run_tests(argv[0]);
|
||||
fclose(fp);
|
||||
|
||||
end:
|
||||
BN_CTX_free(ctx);
|
||||
|
|
10547
test/bntests.txt
10547
test/bntests.txt
File diff suppressed because it is too large
Load diff
|
@ -16,7 +16,13 @@ use OpenSSL::Test qw/:DEFAULT srctop_file/;
|
|||
|
||||
setup("test_bn");
|
||||
|
||||
plan tests => 1;
|
||||
my @files = (
|
||||
"bnexp.txt", "bnmod.txt", "bnmul.txt", "bnshift.txt", "bnsum.txt"
|
||||
);
|
||||
plan tests => 1 + scalar(@files);
|
||||
|
||||
ok(run(test(["bntest", srctop_file("test", "bntests.txt")])),
|
||||
"running bntest bntests.txt");
|
||||
foreach my $f ( @files ) {
|
||||
ok(run(test(["bntest", srctop_file("test", $f)])),
|
||||
"running bntest $f");
|
||||
}
|
||||
ok(run(test(["bntest"])), "running bntest");
|
||||
|
|
Loading…
Reference in a new issue