diff options
Diffstat (limited to 'src/crypto/bn/bn_test.cc')
-rw-r--r-- | src/crypto/bn/bn_test.cc | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/crypto/bn/bn_test.cc b/src/crypto/bn/bn_test.cc index 6a7d48c..95b7bbb 100644 --- a/src/crypto/bn/bn_test.cc +++ b/src/crypto/bn/bn_test.cc @@ -122,6 +122,7 @@ static bool test_dec2bn(FILE *fp, BN_CTX *ctx); static bool test_hex2bn(FILE *fp, BN_CTX *ctx); static bool test_asc2bn(FILE *fp, BN_CTX *ctx); static bool test_rand(); +static bool TestBN2Dec(); static const uint8_t kSample[] = "\xC6\x4F\x43\x04\x2A\xEA\xCA\x6E\x58\x36\x80\x5B\xE8\xC9" @@ -341,6 +342,12 @@ int main(int argc, char *argv[]) { } flush_fp(bc_file.get()); + message(bc_file.get(), "BN_bn2dec"); + if (!TestBN2Dec()) { + return 1; + } + flush_fp(bc_file.get()); + printf("PASS\n"); return 0; } @@ -1628,3 +1635,38 @@ static bool test_rand() { return true; } + +static bool TestBN2Dec() { + static const char *kBN2DecTests[] = { + "0", + "1", + "-1", + "100", + "-100", + "123456789012345678901234567890", + "-123456789012345678901234567890", + "123456789012345678901234567890123456789012345678901234567890", + "-123456789012345678901234567890123456789012345678901234567890", + }; + + for (const char *test : kBN2DecTests) { + ScopedBIGNUM bn; + int ret = DecimalToBIGNUM(&bn, test); + if (ret == 0) { + return false; + } + + ScopedOpenSSLString dec(BN_bn2dec(bn.get())); + if (!dec) { + fprintf(stderr, "BN_bn2dec failed on %s.\n", test); + return false; + } + + if (strcmp(dec.get(), test) != 0) { + fprintf(stderr, "BN_bn2dec gave %s, wanted %s.\n", dec.get(), test); + return false; + } + } + + return true; +} |