diff options
author | Shane Lontis <shane.lontis@oracle.com> | 2019-03-27 17:38:28 +1000 |
---|---|---|
committer | Bernd Edlinger <bernd.edlinger@hotmail.de> | 2019-03-30 14:51:47 +0100 |
commit | 73ab470edc23aa5862a7e737cfbd0cc49e45fb4a (patch) | |
tree | 034fc02185404807e0f32d3b4d0627122f025df8 /test | |
parent | 392c095388941db594c12fa7408c228da884a3ae (diff) |
fixed public range check in ec_GF2m_simple_oct2point
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
(Merged from https://github.com/openssl/openssl/pull/8607)
(cherry picked from commit cad8347be23c5e0c0d9eea02d090d42daf2dd7a9)
Diffstat (limited to 'test')
-rw-r--r-- | test/evp_extra_test.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/test/evp_extra_test.c b/test/evp_extra_test.c index 918c320543..8277f950b1 100644 --- a/test/evp_extra_test.c +++ b/test/evp_extra_test.c @@ -509,6 +509,66 @@ static int test_d2i_AutoPrivateKey(int i) } #ifndef OPENSSL_NO_EC + +static const unsigned char ec_public_sect163k1_validxy[] = { + 0x30, 0x40, 0x30, 0x10, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, + 0x01, 0x06, 0x05, 0x2b, 0x81, 0x04, 0x00, 0x01, 0x03, 0x2c, 0x00, 0x04, + 0x02, 0x84, 0x58, 0xa6, 0xd4, 0xa0, 0x35, 0x2b, 0xae, 0xf0, 0xc0, 0x69, + 0x05, 0xcf, 0x2a, 0x50, 0x33, 0xf9, 0xe3, 0x92, 0x79, 0x02, 0xd1, 0x7b, + 0x9f, 0x22, 0x00, 0xf0, 0x3b, 0x0e, 0x5d, 0x2e, 0xb7, 0x23, 0x24, 0xf3, + 0x6a, 0xd8, 0x17, 0x65, 0x41, 0x2f +}; + +static const unsigned char ec_public_sect163k1_badx[] = { + 0x30, 0x40, 0x30, 0x10, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, + 0x01, 0x06, 0x05, 0x2b, 0x81, 0x04, 0x00, 0x01, 0x03, 0x2c, 0x00, 0x04, + 0x0a, 0x84, 0x58, 0xa6, 0xd4, 0xa0, 0x35, 0x2b, 0xae, 0xf0, 0xc0, 0x69, + 0x05, 0xcf, 0x2a, 0x50, 0x33, 0xf9, 0xe3, 0x92, 0xb0, 0x02, 0xd1, 0x7b, + 0x9f, 0x22, 0x00, 0xf0, 0x3b, 0x0e, 0x5d, 0x2e, 0xb7, 0x23, 0x24, 0xf3, + 0x6a, 0xd8, 0x17, 0x65, 0x41, 0x2f +}; + +static const unsigned char ec_public_sect163k1_bady[] = { + 0x30, 0x40, 0x30, 0x10, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, + 0x01, 0x06, 0x05, 0x2b, 0x81, 0x04, 0x00, 0x01, 0x03, 0x2c, 0x00, 0x04, + 0x02, 0x84, 0x58, 0xa6, 0xd4, 0xa0, 0x35, 0x2b, 0xae, 0xf0, 0xc0, 0x69, + 0x05, 0xcf, 0x2a, 0x50, 0x33, 0xf9, 0xe3, 0x92, 0x79, 0x0a, 0xd1, 0x7b, + 0x9f, 0x22, 0x00, 0xf0, 0x3b, 0x0e, 0x5d, 0x2e, 0xb7, 0x23, 0x24, 0xf3, + 0x6a, 0xd8, 0x17, 0x65, 0x41, 0xe6 +}; + +static struct ec_der_pub_keys_st { + const unsigned char *der; + size_t len; + int valid; +} ec_der_pub_keys[] = { + { ec_public_sect163k1_validxy, sizeof(ec_public_sect163k1_validxy), 1 }, + { ec_public_sect163k1_badx, sizeof(ec_public_sect163k1_badx), 0 }, + { ec_public_sect163k1_bady, sizeof(ec_public_sect163k1_bady), 0 }, +}; + +/* + * Tests the range of the decoded EC char2 public point. + * See ec_GF2m_simple_oct2point(). + */ +static int test_invalide_ec_char2_pub_range_decode(int id) +{ + int ret = 0; + BIO *bio = NULL; + EC_KEY *eckey = NULL; + + if (!TEST_ptr(bio = BIO_new_mem_buf(ec_der_pub_keys[id].der, + ec_der_pub_keys[id].len))) + goto err; + eckey = d2i_EC_PUBKEY_bio(bio, NULL); + ret = (ec_der_pub_keys[id].valid && TEST_ptr(eckey)) + || TEST_ptr_null(eckey); +err: + EC_KEY_free(eckey); + BIO_free(bio); + return ret; +} + /* Tests loading a bad key in PKCS8 format */ static int test_EVP_PKCS82PKEY(void) { @@ -1035,6 +1095,8 @@ int setup_tests(void) ADD_TEST(test_HKDF); #ifndef OPENSSL_NO_EC ADD_TEST(test_X509_PUBKEY_inplace); + ADD_ALL_TESTS(test_invalide_ec_char2_pub_range_decode, + OSSL_NELEM(ec_der_pub_keys)); #endif return 1; } |