summaryrefslogtreecommitdiff
path: root/src/regress/lib
diff options
context:
space:
mode:
authorjsing <>2024-04-17 08:51:11 +0000
committerjsing <>2024-04-17 08:51:11 +0000
commit9081df50fd54559141cf8c71929ca001ed031abc (patch)
tree90fe5eeecb93e33cc31fc1db8d68edf2b06d58cc /src/regress/lib
parent23380829ee38bf67638fa510aebf161b5cc21015 (diff)
downloadopenbsd-9081df50fd54559141cf8c71929ca001ed031abc.tar.gz
openbsd-9081df50fd54559141cf8c71929ca001ed031abc.tar.bz2
openbsd-9081df50fd54559141cf8c71929ca001ed031abc.zip
Add regress coverage for BN_lebin2bn().
Diffstat (limited to 'src/regress/lib')
-rw-r--r--src/regress/lib/libcrypto/bn/bn_convert.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/regress/lib/libcrypto/bn/bn_convert.c b/src/regress/lib/libcrypto/bn/bn_convert.c
index c787036cc4..65f014693d 100644
--- a/src/regress/lib/libcrypto/bn/bn_convert.c
+++ b/src/regress/lib/libcrypto/bn/bn_convert.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_convert.c,v 1.5 2024/04/09 16:06:01 tb Exp $ */ 1/* $OpenBSD: bn_convert.c,v 1.6 2024/04/17 08:51:11 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2023 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -25,7 +25,6 @@
25 * 25 *
26 * - BN_bn2binpad() 26 * - BN_bn2binpad()
27 * - BN_bn2lebinpad() 27 * - BN_bn2lebinpad()
28 * - BN_lebin2bn()
29 * - BN_print()/BN_print_fp() 28 * - BN_print()/BN_print_fp()
30 * 29 *
31 * - Invalid inputs to {asc,dec,hex,mpi}2bn 30 * - Invalid inputs to {asc,dec,hex,mpi}2bn
@@ -440,9 +439,10 @@ test_bn_convert(void)
440 const struct bn_convert_test *bct; 439 const struct bn_convert_test *bct;
441 uint8_t *mpi_out = NULL; 440 uint8_t *mpi_out = NULL;
442 char *out_str = NULL; 441 char *out_str = NULL;
442 uint8_t lebin[64];
443 BIGNUM *bn = NULL; 443 BIGNUM *bn = NULL;
444 int mpi_len; 444 int mpi_len;
445 size_t i; 445 size_t i, j;
446 int failed = 1; 446 int failed = 1;
447 447
448 for (i = 0; i < N_BN_CONVERT_TESTS; i++) { 448 for (i = 0; i < N_BN_CONVERT_TESTS; i++) {
@@ -459,6 +459,20 @@ test_bn_convert(void)
459 bn) != 0) 459 bn) != 0)
460 goto failure; 460 goto failure;
461 461
462 for (j = 0; j < bct->bin_len; j++)
463 lebin[j] = bct->bin[bct->bin_len - j - 1];
464
465 BN_free(bn);
466 if ((bn = BN_lebin2bn(lebin, bct->bin_len, NULL)) == NULL) {
467 fprintf(stderr, "FAIL: BN_lebin2bn() failed\n");
468 goto failure;
469 }
470 BN_set_negative(bn, bct->neg);
471
472 if (check_bin_output(i, "BN_lebin2bn()", bct->bin, bct->bin_len,
473 bn) != 0)
474 goto failure;
475
462 free(out_str); 476 free(out_str);
463 if ((out_str = BN_bn2dec(bn)) == NULL) { 477 if ((out_str = BN_bn2dec(bn)) == NULL) {
464 fprintf(stderr, "FAIL: BN_bn2dec() failed\n"); 478 fprintf(stderr, "FAIL: BN_bn2dec() failed\n");