diff options
author | Richard Levitte <levitte@openssl.org> | 2023-01-12 11:10:01 +0100 |
---|---|---|
committer | Hugo Landau <hlandau@openssl.org> | 2023-01-20 07:38:40 +0000 |
commit | 15192335c8bbfb78bc02086bcd77a0d82efffbce (patch) | |
tree | ba8460ebd44f5f7889b0e14ac088e4f2ea721cdb /test/bntest.c | |
parent | 1b24b5a1b43c2af0a6c1cb2d196f5132ee723488 (diff) |
Add a test for public variants of bn2bin()
We test with binary input of length 1, length 0, and NULL input with length 0
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/20033)
Diffstat (limited to 'test/bntest.c')
-rw-r--r-- | test/bntest.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/test/bntest.c b/test/bntest.c index b35b53df7e..241765c9f1 100644 --- a/test/bntest.c +++ b/test/bntest.c @@ -2219,6 +2219,36 @@ static int test_mpi(int i) return st; } +static int test_bin2zero(void) +{ + unsigned char input[] = { 0 }; + BIGNUM *zbn = NULL; + int ret = 0; + + if (!TEST_ptr(zbn = BN_new())) + goto err; + +#define zerotest(fn) \ + if (!TEST_ptr(fn(input, 1, zbn)) \ + || !TEST_true(BN_is_zero(zbn)) \ + || !TEST_ptr(fn(input, 0, zbn)) \ + || !TEST_true(BN_is_zero(zbn)) \ + || !TEST_ptr(fn(NULL, 0, zbn)) \ + || !TEST_true(BN_is_zero(zbn))) \ + goto err + + zerotest(BN_bin2bn); + zerotest(BN_signed_bin2bn); + zerotest(BN_lebin2bn); + zerotest(BN_signed_lebin2bn); +#undef zerotest + + ret = 1; + err: + BN_free(zbn); + return ret; +} + static int test_rand(void) { BIGNUM *bn = NULL; @@ -3213,6 +3243,7 @@ int setup_tests(void) ADD_TEST(test_dec2bn); ADD_TEST(test_hex2bn); ADD_TEST(test_asc2bn); + ADD_TEST(test_bin2zero); ADD_ALL_TESTS(test_mpi, (int)OSSL_NELEM(kMPITests)); ADD_ALL_TESTS(test_bn2signed, (int)OSSL_NELEM(kSignedTests_BE)); ADD_TEST(test_negzero); |