summaryrefslogtreecommitdiff
path: root/regress
diff options
context:
space:
mode:
authorJoel Sing <jsing@cvs.openbsd.org>2024-04-17 08:51:12 +0000
committerJoel Sing <jsing@cvs.openbsd.org>2024-04-17 08:51:12 +0000
commitd5dd2857a13ce3175f712d8a547cfc2160b1c23a (patch)
tree478506d0661a90edb67d9b39fa00ebfa4577d992 /regress
parent148f0d2ac5b68c13b74963df481e29e4dbd671b6 (diff)
Add regress coverage for BN_lebin2bn().
Diffstat (limited to 'regress')
-rw-r--r--regress/lib/libcrypto/bn/bn_convert.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/regress/lib/libcrypto/bn/bn_convert.c b/regress/lib/libcrypto/bn/bn_convert.c
index c787036cc4f..65f014693d1 100644
--- a/regress/lib/libcrypto/bn/bn_convert.c
+++ b/regress/lib/libcrypto/bn/bn_convert.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bn_convert.c,v 1.5 2024/04/09 16:06:01 tb Exp $ */
+/* $OpenBSD: bn_convert.c,v 1.6 2024/04/17 08:51:11 jsing Exp $ */
/*
* Copyright (c) 2023 Joel Sing <jsing@openbsd.org>
*
@@ -25,7 +25,6 @@
*
* - BN_bn2binpad()
* - BN_bn2lebinpad()
- * - BN_lebin2bn()
* - BN_print()/BN_print_fp()
*
* - Invalid inputs to {asc,dec,hex,mpi}2bn
@@ -440,9 +439,10 @@ test_bn_convert(void)
const struct bn_convert_test *bct;
uint8_t *mpi_out = NULL;
char *out_str = NULL;
+ uint8_t lebin[64];
BIGNUM *bn = NULL;
int mpi_len;
- size_t i;
+ size_t i, j;
int failed = 1;
for (i = 0; i < N_BN_CONVERT_TESTS; i++) {
@@ -459,6 +459,20 @@ test_bn_convert(void)
bn) != 0)
goto failure;
+ for (j = 0; j < bct->bin_len; j++)
+ lebin[j] = bct->bin[bct->bin_len - j - 1];
+
+ BN_free(bn);
+ if ((bn = BN_lebin2bn(lebin, bct->bin_len, NULL)) == NULL) {
+ fprintf(stderr, "FAIL: BN_lebin2bn() failed\n");
+ goto failure;
+ }
+ BN_set_negative(bn, bct->neg);
+
+ if (check_bin_output(i, "BN_lebin2bn()", bct->bin, bct->bin_len,
+ bn) != 0)
+ goto failure;
+
free(out_str);
if ((out_str = BN_bn2dec(bn)) == NULL) {
fprintf(stderr, "FAIL: BN_bn2dec() failed\n");