diff options
| author | tb <> | 2022-06-27 12:25:49 +0000 |
|---|---|---|
| committer | tb <> | 2022-06-27 12:25:49 +0000 |
| commit | f7cbb53a0bb8b068fd645ed3e51f11fffcbe78d9 (patch) | |
| tree | 7b4a6abb880cf5d62bcb7e49bc31d80ddbaa539d /src | |
| parent | 1c45f06eaf444cdc05079c52a06296706b42f26d (diff) | |
| download | openbsd-f7cbb53a0bb8b068fd645ed3e51f11fffcbe78d9.tar.gz openbsd-f7cbb53a0bb8b068fd645ed3e51f11fffcbe78d9.tar.bz2 openbsd-f7cbb53a0bb8b068fd645ed3e51f11fffcbe78d9.zip | |
Prepare to provide BN_security_bits()
ok beck jsing
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/libcrypto/bn/bn.h | 6 | ||||
| -rw-r--r-- | src/lib/libcrypto/bn/bn_lib.c | 33 |
2 files changed, 37 insertions, 2 deletions
diff --git a/src/lib/libcrypto/bn/bn.h b/src/lib/libcrypto/bn/bn.h index abf8cfcf70..5abd489003 100644 --- a/src/lib/libcrypto/bn/bn.h +++ b/src/lib/libcrypto/bn/bn.h | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: bn.h,v 1.52 2022/01/14 08:01:47 tb Exp $ */ | 1 | /* $OpenBSD: bn.h,v 1.53 2022/06/27 12:25:49 tb Exp $ */ |
| 2 | /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * | 4 | * |
| @@ -471,6 +471,10 @@ BIGNUM *BN_mod_sqrt(BIGNUM *ret, | |||
| 471 | 471 | ||
| 472 | void BN_consttime_swap(BN_ULONG swap, BIGNUM *a, BIGNUM *b, int nwords); | 472 | void BN_consttime_swap(BN_ULONG swap, BIGNUM *a, BIGNUM *b, int nwords); |
| 473 | 473 | ||
| 474 | #ifdef LIBRESSL_INTERNAL | ||
| 475 | int BN_security_bits(int L, int N); | ||
| 476 | #endif | ||
| 477 | |||
| 474 | /* Deprecated versions */ | 478 | /* Deprecated versions */ |
| 475 | #ifndef OPENSSL_NO_DEPRECATED | 479 | #ifndef OPENSSL_NO_DEPRECATED |
| 476 | BIGNUM *BN_generate_prime(BIGNUM *ret, int bits, int safe, | 480 | BIGNUM *BN_generate_prime(BIGNUM *ret, int bits, int safe, |
diff --git a/src/lib/libcrypto/bn/bn_lib.c b/src/lib/libcrypto/bn/bn_lib.c index 6e828f1e74..599a744822 100644 --- a/src/lib/libcrypto/bn/bn_lib.c +++ b/src/lib/libcrypto/bn/bn_lib.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: bn_lib.c,v 1.53 2021/12/27 15:12:22 jsing Exp $ */ | 1 | /* $OpenBSD: bn_lib.c,v 1.54 2022/06/27 12:25:49 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 | * |
| @@ -1105,6 +1105,37 @@ BN_is_negative(const BIGNUM *a) | |||
| 1105 | return a->neg != 0; | 1105 | return a->neg != 0; |
| 1106 | } | 1106 | } |
| 1107 | 1107 | ||
| 1108 | /* | ||
| 1109 | * Bits of security, see SP800-57, section 5.6.11, table 2. | ||
| 1110 | */ | ||
| 1111 | int | ||
| 1112 | BN_security_bits(int L, int N) | ||
| 1113 | { | ||
| 1114 | int secbits, bits; | ||
| 1115 | |||
| 1116 | if (L >= 15360) | ||
| 1117 | secbits = 256; | ||
| 1118 | else if (L >= 7680) | ||
| 1119 | secbits = 192; | ||
| 1120 | else if (L >= 3072) | ||
| 1121 | secbits = 128; | ||
| 1122 | else if (L >= 2048) | ||
| 1123 | secbits = 112; | ||
| 1124 | else if (L >= 1024) | ||
| 1125 | secbits = 80; | ||
| 1126 | else | ||
| 1127 | return 0; | ||
| 1128 | |||
| 1129 | if (N == -1) | ||
| 1130 | return secbits; | ||
| 1131 | |||
| 1132 | bits = N / 2; | ||
| 1133 | if (bits < 80) | ||
| 1134 | return 0; | ||
| 1135 | |||
| 1136 | return bits >= secbits ? secbits : bits; | ||
| 1137 | } | ||
| 1138 | |||
| 1108 | BN_GENCB * | 1139 | BN_GENCB * |
| 1109 | BN_GENCB_new(void) | 1140 | BN_GENCB_new(void) |
| 1110 | { | 1141 | { |
