summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorRichard Levitte <levitte@openssl.org>2021-11-25 09:55:09 +0100
committerRichard Levitte <levitte@openssl.org>2021-11-30 09:59:19 +0100
commit162bd56e99b2e73cfdc6777acb3f1b3dafccc9ba (patch)
treebaf3864927d922f96495992ed3ef9ec3ce1628c9 /test
parent37dc4f9530d131b4f581582c34c08074abbc9923 (diff)
TEST: Enable and fix test_bn2padded() in test/bntest.c
This looks like old code, written when the padded variety of BN_bn2bin() was developped, and disabled by default... and forgotten. A few simple changes to update it to the current API is all that was needed to enable it. Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/17133) (cherry picked from commit 23750f677ef61b6bea4e81f23f335ad08fc49b51)
Diffstat (limited to 'test')
-rw-r--r--test/bntest.c34
1 files changed, 15 insertions, 19 deletions
diff --git a/test/bntest.c b/test/bntest.c
index 236501e679..b58028a301 100644
--- a/test/bntest.c
+++ b/test/bntest.c
@@ -27,7 +27,6 @@
/*
* Things in boring, not in openssl. TODO we should add them.
*/
-#define HAVE_BN_PADDED 0
#define HAVE_BN_SQRT 0
typedef struct filetest_st {
@@ -1731,52 +1730,52 @@ static int file_gcd(STANZA *s)
static int test_bn2padded(void)
{
-#if HAVE_BN_PADDED
uint8_t zeros[256], out[256], reference[128];
- BIGNUM *n = BN_new();
+ size_t bytes;
+ BIGNUM *n;
int st = 0;
/* Test edge case at 0. */
- if (n == NULL)
+ if (!TEST_ptr((n = BN_new())))
goto err;
- if (!TEST_true(BN_bn2bin_padded(NULL, 0, n)))
+ if (!TEST_int_eq(BN_bn2binpad(n, NULL, 0), 0))
goto err;
memset(out, -1, sizeof(out));
- if (!TEST_true(BN_bn2bin_padded(out, sizeof(out)), n))
+ if (!TEST_int_eq(BN_bn2binpad(n, out, sizeof(out)), sizeof(out)))
goto err;
memset(zeros, 0, sizeof(zeros));
if (!TEST_mem_eq(zeros, sizeof(zeros), out, sizeof(out)))
goto err;
/* Test a random numbers at various byte lengths. */
- for (size_t bytes = 128 - 7; bytes <= 128; bytes++) {
+ for (bytes = 128 - 7; bytes <= 128; bytes++) {
# define TOP_BIT_ON 0
# define BOTTOM_BIT_NOTOUCH 0
if (!TEST_true(BN_rand(n, bytes * 8, TOP_BIT_ON, BOTTOM_BIT_NOTOUCH)))
goto err;
- if (!TEST_int_eq(BN_num_bytes(n),A) bytes
- || TEST_int_eq(BN_bn2bin(n, reference), bytes))
+ if (!TEST_int_eq(BN_num_bytes(n), bytes)
+ || !TEST_int_eq(BN_bn2bin(n, reference), bytes))
goto err;
/* Empty buffer should fail. */
- if (!TEST_int_eq(BN_bn2bin_padded(NULL, 0, n)), 0)
+ if (!TEST_int_eq(BN_bn2binpad(n, NULL, 0), -1))
goto err;
/* One byte short should fail. */
- if (BN_bn2bin_padded(out, bytes - 1, n))
+ if (!TEST_int_eq(BN_bn2binpad(n, out, bytes - 1), -1))
goto err;
/* Exactly right size should encode. */
- if (!TEST_true(BN_bn2bin_padded(out, bytes, n))
- || TEST_mem_eq(out, bytes, reference, bytes))
+ if (!TEST_int_eq(BN_bn2binpad(n, out, bytes), bytes)
+ || !TEST_mem_eq(out, bytes, reference, bytes))
goto err;
/* Pad up one byte extra. */
- if (!TEST_true(BN_bn2bin_padded(out, bytes + 1, n))
+ if (!TEST_int_eq(BN_bn2binpad(n, out, bytes + 1), bytes + 1)
|| !TEST_mem_eq(out + 1, bytes, reference, bytes)
|| !TEST_mem_eq(out, 1, zeros, 1))
goto err;
/* Pad up to 256. */
- if (!TEST_true(BN_bn2bin_padded(out, sizeof(out)), n)
+ if (!TEST_int_eq(BN_bn2binpad(n, out, sizeof(out)), sizeof(out))
|| !TEST_mem_eq(out + sizeof(out) - bytes, bytes,
reference, bytes)
- || !TEST_mem_eq(out, sizseof(out) - bytes,
+ || !TEST_mem_eq(out, sizeof(out) - bytes,
zeros, sizeof(out) - bytes))
goto err;
}
@@ -1785,9 +1784,6 @@ static int test_bn2padded(void)
err:
BN_free(n);
return st;
-#else
- return ctx != NULL;
-#endif
}
static int test_dec2bn(void)