diff options
| author | tb <> | 2023-04-07 22:14:20 +0000 |
|---|---|---|
| committer | tb <> | 2023-04-07 22:14:20 +0000 |
| commit | f593920787b705ac874bbd2f1c8be19129bd36ac (patch) | |
| tree | e3477a180a97d357fb1d33aff12c545a27d48024 /src | |
| parent | 12add2938751c4ab868b4efbc8833b9767b89bf2 (diff) | |
| download | openbsd-f593920787b705ac874bbd2f1c8be19129bd36ac.tar.gz openbsd-f593920787b705ac874bbd2f1c8be19129bd36ac.tar.bz2 openbsd-f593920787b705ac874bbd2f1c8be19129bd36ac.zip | |
bn_test: inline the only use of lst[]
lst[] can be converted from a bit string to a hex string. Use BN_hex2bn()
isntead of BN_bin2bn(). Handle this inside test_lshift() rather than doing
artistic ownership dances.
Diffstat (limited to 'src')
| -rw-r--r-- | src/regress/lib/libcrypto/bn/bn_test.c | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/src/regress/lib/libcrypto/bn/bn_test.c b/src/regress/lib/libcrypto/bn/bn_test.c index 33050862ce..d95d826535 100644 --- a/src/regress/lib/libcrypto/bn/bn_test.c +++ b/src/regress/lib/libcrypto/bn/bn_test.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: bn_test.c,v 1.3 2023/03/27 08:52:57 tb Exp $ */ | 1 | /* $OpenBSD: bn_test.c,v 1.4 2023/04/07 22:14:20 tb Exp $ */ |
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * | 4 | * |
| @@ -92,7 +92,7 @@ const int num2 = 5; /* number of tests for slow functions */ | |||
| 92 | int test_add(BIO *bp); | 92 | int test_add(BIO *bp); |
| 93 | int test_sub(BIO *bp); | 93 | int test_sub(BIO *bp); |
| 94 | int test_lshift1(BIO *bp); | 94 | int test_lshift1(BIO *bp); |
| 95 | int test_lshift(BIO *bp, BN_CTX *ctx, BIGNUM *a_); | 95 | int test_lshift(BIO *bp, BN_CTX *ctx, int use_lst); |
| 96 | int test_rshift1(BIO *bp); | 96 | int test_rshift1(BIO *bp); |
| 97 | int test_rshift(BIO *bp, BN_CTX *ctx); | 97 | int test_rshift(BIO *bp, BN_CTX *ctx); |
| 98 | int test_div(BIO *bp, BN_CTX *ctx); | 98 | int test_div(BIO *bp, BN_CTX *ctx); |
| @@ -122,10 +122,6 @@ int test_sqrt(BIO *bp, BN_CTX *ctx); | |||
| 122 | int rand_neg(void); | 122 | int rand_neg(void); |
| 123 | static int results = 0; | 123 | static int results = 0; |
| 124 | 124 | ||
| 125 | static unsigned char lst[] = | ||
| 126 | "\xC6\x4F\x43\x04\x2A\xEA\xCA\x6E\x58\x36\x80\x5B\xE8\xC9" | ||
| 127 | "\x9B\x04\x5D\x48\x36\xC2\xFD\x16\xC9\x64\xF0"; | ||
| 128 | |||
| 129 | #define PRINT_ERROR printf("Error in %s [%s:%d]\n", __func__, __FILE__, \ | 125 | #define PRINT_ERROR printf("Error in %s [%s:%d]\n", __func__, __FILE__, \ |
| 130 | __LINE__) | 126 | __LINE__) |
| 131 | 127 | ||
| @@ -205,12 +201,12 @@ main(int argc, char *argv[]) | |||
| 205 | (void)BIO_flush(out); | 201 | (void)BIO_flush(out); |
| 206 | 202 | ||
| 207 | message(out, "BN_lshift (fixed)"); | 203 | message(out, "BN_lshift (fixed)"); |
| 208 | if (!test_lshift(out, ctx, BN_bin2bn(lst, sizeof(lst) - 1, NULL))) | 204 | if (!test_lshift(out, ctx, 1)) |
| 209 | goto err; | 205 | goto err; |
| 210 | (void)BIO_flush(out); | 206 | (void)BIO_flush(out); |
| 211 | 207 | ||
| 212 | message(out, "BN_lshift"); | 208 | message(out, "BN_lshift"); |
| 213 | if (!test_lshift(out, ctx, NULL)) | 209 | if (!test_lshift(out, ctx, 0)) |
| 214 | goto err; | 210 | goto err; |
| 215 | (void)BIO_flush(out); | 211 | (void)BIO_flush(out); |
| 216 | 212 | ||
| @@ -2354,12 +2350,14 @@ test_sqrt(BIO *bp, BN_CTX *ctx) | |||
| 2354 | } | 2350 | } |
| 2355 | 2351 | ||
| 2356 | int | 2352 | int |
| 2357 | test_lshift(BIO *bp, BN_CTX *ctx, BIGNUM *a_) | 2353 | test_lshift(BIO *bp, BN_CTX *ctx, int use_lst) |
| 2358 | { | 2354 | { |
| 2359 | BIGNUM *a = NULL, *b = NULL, *c = NULL, *d = NULL; | 2355 | BIGNUM *a = NULL, *b = NULL, *c = NULL, *d = NULL; |
| 2360 | int i; | 2356 | int i; |
| 2361 | int rc = 1; | 2357 | int rc = 1; |
| 2362 | 2358 | ||
| 2359 | if ((a = BN_new()) == NULL) | ||
| 2360 | goto err; | ||
| 2363 | if ((b = BN_new()) == NULL) | 2361 | if ((b = BN_new()) == NULL) |
| 2364 | goto err; | 2362 | goto err; |
| 2365 | if ((c = BN_new()) == NULL) | 2363 | if ((c = BN_new()) == NULL) |
| @@ -2368,11 +2366,11 @@ test_lshift(BIO *bp, BN_CTX *ctx, BIGNUM *a_) | |||
| 2368 | goto err; | 2366 | goto err; |
| 2369 | CHECK_GOTO(BN_one(c)); | 2367 | CHECK_GOTO(BN_one(c)); |
| 2370 | 2368 | ||
| 2371 | if (a_) | 2369 | if (use_lst) { |
| 2372 | a = a_; | 2370 | if (!BN_hex2bn(&a, "C64F43042AEACA6E5836805BE8C99B04" |
| 2373 | else { | 2371 | "5D4836C2FD16C964F0")) |
| 2374 | if ((a = BN_new()) == NULL) | 2372 | goto err; |
| 2375 | goto err; | 2373 | } else { |
| 2376 | CHECK_GOTO(BN_bntest_rand(a, 200, 0, 0)); | 2374 | CHECK_GOTO(BN_bntest_rand(a, 200, 0, 0)); |
| 2377 | BN_set_negative(a, rand_neg()); | 2375 | BN_set_negative(a, rand_neg()); |
| 2378 | } | 2376 | } |
