|
|
@@ -72,12 +72,14 @@ |
|
|
|
|
|
|
|
static bool RunBasicTests(); |
|
|
|
static bool RunRFC5114Tests(); |
|
|
|
static bool TestBadY(); |
|
|
|
|
|
|
|
int main(int argc, char *argv[]) { |
|
|
|
CRYPTO_library_init(); |
|
|
|
|
|
|
|
if (!RunBasicTests() || |
|
|
|
!RunRFC5114Tests()) { |
|
|
|
!RunRFC5114Tests() || |
|
|
|
!TestBadY()) { |
|
|
|
ERR_print_errors_fp(stderr); |
|
|
|
return 1; |
|
|
|
} |
|
|
@@ -477,3 +479,57 @@ static bool RunRFC5114Tests() { |
|
|
|
|
|
|
|
return 1; |
|
|
|
} |
|
|
|
|
|
|
|
// kRFC5114_2048_224BadY is a bad y-coordinate for RFC 5114's 2048-bit MODP |
|
|
|
// Group with 224-bit Prime Order Subgroup (section 2.2). |
|
|
|
static const uint8_t kRFC5114_2048_224BadY[] = { |
|
|
|
0x45, 0x32, 0x5f, 0x51, 0x07, 0xe5, 0xdf, 0x1c, 0xd6, 0x02, 0x82, 0xb3, |
|
|
|
0x32, 0x8f, 0xa4, 0x0f, 0x87, 0xb8, 0x41, 0xfe, 0xb9, 0x35, 0xde, 0xad, |
|
|
|
0xc6, 0x26, 0x85, 0xb4, 0xff, 0x94, 0x8c, 0x12, 0x4c, 0xbf, 0x5b, 0x20, |
|
|
|
0xc4, 0x46, 0xa3, 0x26, 0xeb, 0xa4, 0x25, 0xb7, 0x68, 0x8e, 0xcc, 0x67, |
|
|
|
0xba, 0xea, 0x58, 0xd0, 0xf2, 0xe9, 0xd2, 0x24, 0x72, 0x60, 0xda, 0x88, |
|
|
|
0x18, 0x9c, 0xe0, 0x31, 0x6a, 0xad, 0x50, 0x6d, 0x94, 0x35, 0x8b, 0x83, |
|
|
|
0x4a, 0x6e, 0xfa, 0x48, 0x73, 0x0f, 0x83, 0x87, 0xff, 0x6b, 0x66, 0x1f, |
|
|
|
0xa8, 0x82, 0xc6, 0x01, 0xe5, 0x80, 0xb5, 0xb0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
}; |
|
|
|
|
|
|
|
static bool TestBadY() { |
|
|
|
ScopedDH dh(DH_get_2048_224(nullptr)); |
|
|
|
ScopedBIGNUM pub_key( |
|
|
|
BN_bin2bn(kRFC5114_2048_224BadY, sizeof(kRFC5114_2048_224BadY), nullptr)); |
|
|
|
if (!dh || !pub_key || !DH_generate_key(dh.get())) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
int flags; |
|
|
|
if (!DH_check_pub_key(dh.get(), pub_key.get(), &flags)) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
if (!(flags & DH_CHECK_PUBKEY_INVALID)) { |
|
|
|
fprintf(stderr, "DH_check_pub_key did not reject the key.\n"); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
std::vector<uint8_t> result(DH_size(dh.get())); |
|
|
|
if (DH_compute_key(result.data(), pub_key.get(), dh.get()) >= 0) { |
|
|
|
fprintf(stderr, "DH_compute_key unexpectedly succeeded.\n"); |
|
|
|
return false; |
|
|
|
} |
|
|
|
ERR_clear_error(); |
|
|
|
|
|
|
|
return true; |
|
|
|
} |