diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/regress/lib/libcrypto/bn/bn_unit.c | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/src/regress/lib/libcrypto/bn/bn_unit.c b/src/regress/lib/libcrypto/bn/bn_unit.c index 95764dfce1..24c7569ff9 100644 --- a/src/regress/lib/libcrypto/bn/bn_unit.c +++ b/src/regress/lib/libcrypto/bn/bn_unit.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: bn_unit.c,v 1.4 2023/03/31 19:40:08 tb Exp $ */ | 1 | /* $OpenBSD: bn_unit.c,v 1.5 2023/06/20 06:36:09 jsing Exp $ */ |
| 2 | 2 | ||
| 3 | /* | 3 | /* |
| 4 | * Copyright (c) 2022 Theo Buehler <tb@openbsd.org> | 4 | * Copyright (c) 2022 Theo Buehler <tb@openbsd.org> |
| @@ -70,6 +70,39 @@ test_bn_print_null_derefs(void) | |||
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | static int | 72 | static int |
| 73 | test_bn_num_bits(void) | ||
| 74 | { | ||
| 75 | BIGNUM *bn; | ||
| 76 | int i, num_bits; | ||
| 77 | int failed = 0; | ||
| 78 | |||
| 79 | if ((bn = BN_new()) == NULL) | ||
| 80 | errx(1, "BN_new"); | ||
| 81 | |||
| 82 | if ((num_bits = BN_num_bits(bn)) != 0) { | ||
| 83 | warnx("BN_num_bits_word(0): want 0, got %d", num_bits); | ||
| 84 | failed |= 1; | ||
| 85 | } | ||
| 86 | |||
| 87 | if (!BN_set_word(bn, 1)) | ||
| 88 | errx(1, "BN_set_word"); | ||
| 89 | |||
| 90 | for (i = 0; i <= 5 * BN_BITS2; i++) { | ||
| 91 | if ((num_bits = BN_num_bits(bn)) != i + 1) { | ||
| 92 | warnx("BN_num_bits(1 << %d): want %d, got %d", | ||
| 93 | i, i + 1, num_bits); | ||
| 94 | failed |= 1; | ||
| 95 | } | ||
| 96 | if (!BN_lshift1(bn, bn)) | ||
| 97 | errx(1, "BN_lshift1"); | ||
| 98 | } | ||
| 99 | |||
| 100 | BN_free(bn); | ||
| 101 | |||
| 102 | return failed; | ||
| 103 | } | ||
| 104 | |||
| 105 | static int | ||
| 73 | test_bn_num_bits_word(void) | 106 | test_bn_num_bits_word(void) |
| 74 | { | 107 | { |
| 75 | BN_ULONG w = 1; | 108 | BN_ULONG w = 1; |
| @@ -255,6 +288,7 @@ main(void) | |||
| 255 | int failed = 0; | 288 | int failed = 0; |
| 256 | 289 | ||
| 257 | failed |= test_bn_print_null_derefs(); | 290 | failed |= test_bn_print_null_derefs(); |
| 291 | failed |= test_bn_num_bits(); | ||
| 258 | failed |= test_bn_num_bits_word(); | 292 | failed |= test_bn_num_bits_word(); |
| 259 | failed |= test_bn_copy_copies_flags(); | 293 | failed |= test_bn_copy_copies_flags(); |
| 260 | failed |= test_bn_copy_consttime_is_sticky(); | 294 | failed |= test_bn_copy_consttime_is_sticky(); |
