Add BN_get_rfc3526_prime_1536.

In OpenSSL 1.1.0, this API has been renamed to gain a BN prefix. Now
that it's no longer squatting on a namespace, provide the function so
wpa_supplicant needn't carry a BoringSSL #ifdef here.

BUG=91

Change-Id: Iac8e90238c816caae6acf0e359893c14a7a970f1
Reviewed-on: https://boringssl-review.googlesource.com/10223
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: Adam Langley <agl@google.com>
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
This commit is contained in:
David Benjamin 2016-08-10 13:38:51 -04:00 committed by CQ bot account: commit-bot@chromium.org
parent fbe3a7bb61
commit 96e1a25943
3 changed files with 80 additions and 2 deletions

View File

@ -75,6 +75,7 @@ static bool RunBasicTests();
static bool RunRFC5114Tests();
static bool TestBadY();
static bool TestASN1();
static bool TestRFC3526();
int main(int argc, char *argv[]) {
CRYPTO_library_init();
@ -82,7 +83,8 @@ int main(int argc, char *argv[]) {
if (!RunBasicTests() ||
!RunRFC5114Tests() ||
!TestBadY() ||
!TestASN1()) {
!TestASN1() ||
!TestRFC3526()) {
ERR_print_errors_fp(stderr);
return 1;
}
@ -624,3 +626,39 @@ static bool TestASN1() {
return true;
}
static bool TestRFC3526() {
ScopedBIGNUM bn(BN_get_rfc3526_prime_1536(nullptr));
if (!bn) {
return false;
}
static const uint8_t kPrime1536[] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc9, 0x0f, 0xda, 0xa2,
0x21, 0x68, 0xc2, 0x34, 0xc4, 0xc6, 0x62, 0x8b, 0x80, 0xdc, 0x1c, 0xd1,
0x29, 0x02, 0x4e, 0x08, 0x8a, 0x67, 0xcc, 0x74, 0x02, 0x0b, 0xbe, 0xa6,
0x3b, 0x13, 0x9b, 0x22, 0x51, 0x4a, 0x08, 0x79, 0x8e, 0x34, 0x04, 0xdd,
0xef, 0x95, 0x19, 0xb3, 0xcd, 0x3a, 0x43, 0x1b, 0x30, 0x2b, 0x0a, 0x6d,
0xf2, 0x5f, 0x14, 0x37, 0x4f, 0xe1, 0x35, 0x6d, 0x6d, 0x51, 0xc2, 0x45,
0xe4, 0x85, 0xb5, 0x76, 0x62, 0x5e, 0x7e, 0xc6, 0xf4, 0x4c, 0x42, 0xe9,
0xa6, 0x37, 0xed, 0x6b, 0x0b, 0xff, 0x5c, 0xb6, 0xf4, 0x06, 0xb7, 0xed,
0xee, 0x38, 0x6b, 0xfb, 0x5a, 0x89, 0x9f, 0xa5, 0xae, 0x9f, 0x24, 0x11,
0x7c, 0x4b, 0x1f, 0xe6, 0x49, 0x28, 0x66, 0x51, 0xec, 0xe4, 0x5b, 0x3d,
0xc2, 0x00, 0x7c, 0xb8, 0xa1, 0x63, 0xbf, 0x05, 0x98, 0xda, 0x48, 0x36,
0x1c, 0x55, 0xd3, 0x9a, 0x69, 0x16, 0x3f, 0xa8, 0xfd, 0x24, 0xcf, 0x5f,
0x83, 0x65, 0x5d, 0x23, 0xdc, 0xa3, 0xad, 0x96, 0x1c, 0x62, 0xf3, 0x56,
0x20, 0x85, 0x52, 0xbb, 0x9e, 0xd5, 0x29, 0x07, 0x70, 0x96, 0x96, 0x6d,
0x67, 0x0c, 0x35, 0x4e, 0x4a, 0xbc, 0x98, 0x04, 0xf1, 0x74, 0x6c, 0x08,
0xca, 0x23, 0x73, 0x27, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
};
uint8_t buffer[sizeof(kPrime1536)];
if (BN_num_bytes(bn.get()) != sizeof(kPrime1536) ||
BN_bn2bin(bn.get(), buffer) != sizeof(kPrime1536) ||
memcmp(buffer, kPrime1536, sizeof(kPrime1536)) != 0) {
fprintf(stderr, "1536-bit MODP prime did not match.\n");
return false;
}
return true;
}

View File

@ -247,7 +247,7 @@ static const BIGNUM dh1024_safe_prime[] = {
STATIC_BIGNUM(dh1024_safe_prime_4)
};
static BIGNUM bn_two = STATIC_BIGNUM(bn_two_data);
static const BIGNUM bn_two = STATIC_BIGNUM(bn_two_data);
static DH *get_standard_parameters(const struct standard_parameters *params,
const ENGINE *engine) {
@ -279,6 +279,41 @@ DH *DH_get_2048_256(const ENGINE *engine) {
return get_standard_parameters(&dh2048_256, engine);
}
BIGNUM *BN_get_rfc3526_prime_1536(BIGNUM *ret) {
static const BN_ULONG kPrime1536Data[] = {
TOBN(0xffffffff, 0xffffffff), TOBN(0xf1746c08, 0xca237327),
TOBN(0x670c354e, 0x4abc9804), TOBN(0x9ed52907, 0x7096966d),
TOBN(0x1c62f356, 0x208552bb), TOBN(0x83655d23, 0xdca3ad96),
TOBN(0x69163fa8, 0xfd24cf5f), TOBN(0x98da4836, 0x1c55d39a),
TOBN(0xc2007cb8, 0xa163bf05), TOBN(0x49286651, 0xece45b3d),
TOBN(0xae9f2411, 0x7c4b1fe6), TOBN(0xee386bfb, 0x5a899fa5),
TOBN(0x0bff5cb6, 0xf406b7ed), TOBN(0xf44c42e9, 0xa637ed6b),
TOBN(0xe485b576, 0x625e7ec6), TOBN(0x4fe1356d, 0x6d51c245),
TOBN(0x302b0a6d, 0xf25f1437), TOBN(0xef9519b3, 0xcd3a431b),
TOBN(0x514a0879, 0x8e3404dd), TOBN(0x020bbea6, 0x3b139b22),
TOBN(0x29024e08, 0x8a67cc74), TOBN(0xc4c6628b, 0x80dc1cd1),
TOBN(0xc90fdaa2, 0x2168c234), TOBN(0xffffffff, 0xffffffff),
};
static const BIGNUM kPrime1536BN = STATIC_BIGNUM(kPrime1536Data);
BIGNUM *alloc = NULL;
if (ret == NULL) {
alloc = BN_new();
if (alloc == NULL) {
return NULL;
}
ret = alloc;
}
if (!BN_copy(ret, &kPrime1536BN)) {
BN_free(alloc);
return NULL;
}
return ret;
}
void DH_check_standard_parameters(DH *dh) {
unsigned i;

View File

@ -110,6 +110,11 @@ OPENSSL_EXPORT DH *DH_get_1024_160(const ENGINE *engine);
OPENSSL_EXPORT DH *DH_get_2048_224(const ENGINE *engine);
OPENSSL_EXPORT DH *DH_get_2048_256(const ENGINE *engine);
/* BN_get_rfc3526_prime_1536 sets |*ret| to the 1536-bit MODP group from RFC
* 3526 and returns |ret|. If |ret| is NULL then a fresh |BIGNUM| is allocated
* and returned. It returns NULL on allocation failure. */
OPENSSL_EXPORT BIGNUM *BN_get_rfc3526_prime_1536(BIGNUM *ret);
/* Parameter generation. */