Update OpenSSL-1.1.1-pre9-dev
This commit is contained in:
+125
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2017 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2015-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -477,6 +477,127 @@ static int test_EVP_PKCS82PKEY(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef OPENSSL_NO_SM2
|
||||
|
||||
static int test_EVP_SM2(void)
|
||||
{
|
||||
int ret = 0;
|
||||
EVP_PKEY *pkey = NULL;
|
||||
EVP_PKEY *params = NULL;
|
||||
EVP_PKEY_CTX *pctx = NULL;
|
||||
EVP_PKEY_CTX *kctx = NULL;
|
||||
size_t sig_len = 0;
|
||||
unsigned char *sig = NULL;
|
||||
EVP_MD_CTX *md_ctx = NULL;
|
||||
EVP_MD_CTX *md_ctx_verify = NULL;
|
||||
EVP_PKEY_CTX *cctx = NULL;
|
||||
|
||||
uint8_t ciphertext[128];
|
||||
size_t ctext_len = sizeof(ciphertext);
|
||||
|
||||
uint8_t plaintext[8];
|
||||
size_t ptext_len = sizeof(plaintext);
|
||||
|
||||
pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL);
|
||||
if (!TEST_ptr(pctx))
|
||||
goto done;
|
||||
|
||||
if (!TEST_true(EVP_PKEY_paramgen_init(pctx) == 1))
|
||||
goto done;
|
||||
|
||||
if (!TEST_true(EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx, NID_sm2)))
|
||||
goto done;
|
||||
|
||||
if (!TEST_true(EVP_PKEY_paramgen(pctx, ¶ms)))
|
||||
goto done;
|
||||
|
||||
kctx = EVP_PKEY_CTX_new(params, NULL);
|
||||
if (!TEST_ptr(kctx))
|
||||
goto done;
|
||||
|
||||
if (!TEST_true(EVP_PKEY_keygen_init(kctx)))
|
||||
goto done;
|
||||
|
||||
if (!TEST_true(EVP_PKEY_keygen(kctx, &pkey)))
|
||||
goto done;
|
||||
|
||||
if (!TEST_true(EVP_PKEY_set_alias_type(pkey, EVP_PKEY_SM2)))
|
||||
goto done;
|
||||
|
||||
if (!TEST_ptr(md_ctx = EVP_MD_CTX_new()))
|
||||
goto done;
|
||||
|
||||
if (!TEST_ptr(md_ctx_verify = EVP_MD_CTX_new()))
|
||||
goto done;
|
||||
|
||||
if (!TEST_true(EVP_DigestSignInit(md_ctx, NULL, EVP_sm3(), NULL, pkey)))
|
||||
goto done;
|
||||
|
||||
if(!TEST_true(EVP_DigestSignUpdate(md_ctx, kMsg, sizeof(kMsg))))
|
||||
goto done;
|
||||
|
||||
/* Determine the size of the signature. */
|
||||
if (!TEST_true(EVP_DigestSignFinal(md_ctx, NULL, &sig_len)))
|
||||
goto done;
|
||||
|
||||
if (!TEST_size_t_eq(sig_len, (size_t)EVP_PKEY_size(pkey)))
|
||||
goto done;
|
||||
|
||||
if (!TEST_ptr(sig = OPENSSL_malloc(sig_len)))
|
||||
goto done;
|
||||
|
||||
if (!TEST_true(EVP_DigestSignFinal(md_ctx, sig, &sig_len)))
|
||||
goto done;
|
||||
|
||||
/* Ensure that the signature round-trips. */
|
||||
|
||||
if (!TEST_true(EVP_DigestVerifyInit(md_ctx_verify, NULL, EVP_sm3(), NULL, pkey)))
|
||||
goto done;
|
||||
|
||||
if (!TEST_true(EVP_DigestVerifyUpdate(md_ctx_verify, kMsg, sizeof(kMsg))))
|
||||
goto done;
|
||||
|
||||
if (!TEST_true(EVP_DigestVerifyFinal(md_ctx_verify, sig, sig_len)))
|
||||
goto done;
|
||||
|
||||
/* now check encryption/decryption */
|
||||
|
||||
if (!TEST_ptr(cctx = EVP_PKEY_CTX_new(pkey, NULL)))
|
||||
goto done;
|
||||
|
||||
if (!TEST_true(EVP_PKEY_encrypt_init(cctx)))
|
||||
goto done;
|
||||
|
||||
if (!TEST_true(EVP_PKEY_encrypt(cctx, ciphertext, &ctext_len, kMsg, sizeof(kMsg))))
|
||||
goto done;
|
||||
|
||||
if (!TEST_true(EVP_PKEY_decrypt_init(cctx)))
|
||||
goto done;
|
||||
|
||||
if (!TEST_true(EVP_PKEY_decrypt(cctx, plaintext, &ptext_len, ciphertext, ctext_len)))
|
||||
goto done;
|
||||
|
||||
if (!TEST_true(ptext_len == sizeof(kMsg)))
|
||||
goto done;
|
||||
|
||||
if (!TEST_true(memcmp(plaintext, kMsg, sizeof(kMsg)) == 0))
|
||||
goto done;
|
||||
|
||||
ret = 1;
|
||||
done:
|
||||
EVP_PKEY_CTX_free(pctx);
|
||||
EVP_PKEY_CTX_free(kctx);
|
||||
EVP_PKEY_CTX_free(cctx);
|
||||
EVP_PKEY_free(pkey);
|
||||
EVP_PKEY_free(params);
|
||||
EVP_MD_CTX_free(md_ctx);
|
||||
EVP_MD_CTX_free(md_ctx_verify);
|
||||
OPENSSL_free(sig);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static struct keys_st {
|
||||
int type;
|
||||
char *priv;
|
||||
@@ -663,6 +784,9 @@ int setup_tests(void)
|
||||
ADD_ALL_TESTS(test_d2i_AutoPrivateKey, OSSL_NELEM(keydata));
|
||||
#ifndef OPENSSL_NO_EC
|
||||
ADD_TEST(test_EVP_PKCS82PKEY);
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_SM2
|
||||
ADD_TEST(test_EVP_SM2);
|
||||
#endif
|
||||
ADD_ALL_TESTS(test_set_get_raw_keys, OSSL_NELEM(keys));
|
||||
custom_pmeth = EVP_PKEY_meth_new(0xdefaced, 0);
|
||||
|
||||
+11
-21
@@ -2413,23 +2413,6 @@ static char *take_value(PAIR *pp)
|
||||
return p;
|
||||
}
|
||||
|
||||
static int key_disabled(EVP_PKEY *pkey)
|
||||
{
|
||||
#if defined(OPENSSL_NO_SM2) && !defined(OPENSSL_NO_EC)
|
||||
int type = EVP_PKEY_base_id(pkey);
|
||||
|
||||
if (type == EVP_PKEY_EC) {
|
||||
EC_KEY *ec = EVP_PKEY_get0_EC_KEY(pkey);
|
||||
int nid = EC_GROUP_get_curve_name(EC_KEY_get0_group(ec));
|
||||
|
||||
if (nid == NID_sm2)
|
||||
return 1;
|
||||
}
|
||||
#endif /* OPENSSL_NO_SM2 */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Read and parse one test. Return 0 if failure, 1 if okay.
|
||||
*/
|
||||
@@ -2516,10 +2499,6 @@ top:
|
||||
}
|
||||
OPENSSL_free(keybin);
|
||||
}
|
||||
if (pkey != NULL && key_disabled(pkey)) {
|
||||
EVP_PKEY_free(pkey);
|
||||
pkey = NULL;
|
||||
}
|
||||
|
||||
/* If we have a key add to list */
|
||||
if (klist != NULL) {
|
||||
@@ -2530,6 +2509,17 @@ top:
|
||||
if (!TEST_ptr(key = OPENSSL_malloc(sizeof(*key))))
|
||||
return 0;
|
||||
key->name = take_value(pp);
|
||||
|
||||
/* Hack to detect SM2 keys */
|
||||
if(pkey != NULL && strstr(key->name, "SM2") != NULL) {
|
||||
#ifdef OPENSSL_NO_SM2
|
||||
EVP_PKEY_free(pkey);
|
||||
pkey = NULL;
|
||||
#else
|
||||
EVP_PKEY_set_alias_type(pkey, EVP_PKEY_SM2);
|
||||
#endif
|
||||
}
|
||||
|
||||
key->key = pkey;
|
||||
key->next = *klist;
|
||||
*klist = key;
|
||||
|
||||
@@ -17257,6 +17257,35 @@ PeerKey=KAS-ECC-CDH_B-571_C24-Peer-PUBLIC
|
||||
Ctrl=ecdh_cofactor_mode:1
|
||||
SharedSecret=02da266a269bdc8d8b2a0c6bb5762f102fc801c8d5394a9271539136bd81d4b69cfbb7525cd0a983fb7f7e9deec583b8f8e574c6184b2d79831ec770649e484dc006fa35b0bffd0b
|
||||
|
||||
# for cofactor-order points, ECC CDH (co-factor ECDH) should fail. Test that.
|
||||
|
||||
PrivateKey=ALICE_cf_sect283k1
|
||||
-----BEGIN PRIVATE KEY-----
|
||||
MIGQAgEAMBAGByqGSM49AgEGBSuBBAAQBHkwdwIBAQQkAHtPwRfQZ9pWgSctyHdt
|
||||
xt3pd8ESMI3ugVx8MDLkiVB8GkCRoUwDSgAEA+xpY5sDcgM2yYxoWOrzH7WUH+b3
|
||||
n68A32kODgcKu8PXRYEKBH8Xzbr974982ZJW1sGrDs+P81sIFH8tdp45Jkr+OtfM
|
||||
8uKr
|
||||
-----END PRIVATE KEY-----
|
||||
|
||||
PublicKey=ALICE_cf_sect283k1_PUB
|
||||
-----BEGIN PUBLIC KEY-----
|
||||
MF4wEAYHKoZIzj0CAQYFK4EEABADSgAEA+xpY5sDcgM2yYxoWOrzH7WUH+b3n68A
|
||||
32kODgcKu8PXRYEKBH8Xzbr974982ZJW1sGrDs+P81sIFH8tdp45Jkr+OtfM8uKr
|
||||
-----END PUBLIC KEY-----
|
||||
|
||||
PublicKey=BOB_cf_sect283k1_PUB
|
||||
-----BEGIN PUBLIC KEY-----
|
||||
MF4wEAYHKoZIzj0CAQYFK4EEABADSgAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||
AAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB
|
||||
-----END PUBLIC KEY-----
|
||||
|
||||
PrivPubKeyPair = ALICE_cf_sect283k1:ALICE_cf_sect283k1_PUB
|
||||
|
||||
# ECDH Alice with Bob peer
|
||||
Derive=ALICE_cf_sect283k1
|
||||
PeerKey=BOB_cf_sect283k1_PUB
|
||||
Ctrl=ecdh_cofactor_mode:1
|
||||
Result = DERIVE_ERROR
|
||||
|
||||
Title = Test keypair mistmatches
|
||||
|
||||
@@ -18384,6 +18413,16 @@ Ctrl = digest:SM3
|
||||
Input = D7AD397F6FFA5D4F7F11E7217F241607DC30618C236D2C09C1B9EA8FDADEE2E8
|
||||
Output = 3046022100AB1DB64DE7C40EDBDE6651C9B8EBDB804673DB836E5D5C7FE15DCF9ED2725037022100EBA714451FF69B0BB930B379E192E7CD5FA6E3C41C7FBD8303B799AB54A54621
|
||||
|
||||
Verify = SM2_key1
|
||||
Ctrl = digest:SM3
|
||||
Input = B1139602C6ECC9E15E2F3F9C635A1AFE737058BC15387479C1EA0D0B3D90E9E5
|
||||
Output = 3045022100E6E0414EBD3A656C35602AF14AB20287DBF30D57AF75C49A188ED4B42391F22402202F54F277C606F4605E1CE9514947FFDDF94C67A539804A4ED17F852288BDBE2E
|
||||
|
||||
Verify = SM2_key1
|
||||
Ctrl = digest:SHA512
|
||||
Input = 40AA1B203C9D8EE150B21C3C7CDA8261492E5420C5F2B9F7380700E094C303B48E62F319C1DA0E32EB40D113C5F1749CC61AEB499167890AB82F2CC9BB706971
|
||||
Output = 3046022100AE018933B9BA041784380069F2DDF609694DCD299FDBF23D09F4B711FBC103EC0221008440BB1A48C132DE4FB91BE9F43B958142FDD29FB9DABE01B17514023A2F638C
|
||||
|
||||
Decrypt = SM2_key1
|
||||
Input = 30818A0220466BE2EF5C11782EC77864A0055417F407A5AFC11D653C6BCE69E417BB1D05B6022062B572E21FF0DDF5C726BD3F9FF2EAE56E6294713A607E9B9525628965F62CC804203C1B5713B5DB2728EB7BF775E44F4689FC32668BDC564F52EA45B09E8DF2A5F40422084A9D0CC2997092B7D3C404FCE95956EB604D732B2307A8E5B8900ED6608CA5B197
|
||||
Output = "The floofy bunnies hop at midnight"
|
||||
|
||||
@@ -28,6 +28,7 @@ static const RAND_METHOD *saved_rand;
|
||||
|
||||
static uint8_t *fake_rand_bytes = NULL;
|
||||
static size_t fake_rand_bytes_offset = 0;
|
||||
static size_t fake_rand_size = 0;
|
||||
|
||||
static int get_faked_bytes(unsigned char *buf, int num)
|
||||
{
|
||||
@@ -36,6 +37,9 @@ static int get_faked_bytes(unsigned char *buf, int num)
|
||||
if (fake_rand_bytes == NULL)
|
||||
return saved_rand->bytes(buf, num);
|
||||
|
||||
if (!TEST_size_t_le(fake_rand_bytes_offset + num, fake_rand_size))
|
||||
return 0;
|
||||
|
||||
for (i = 0; i != num; ++i)
|
||||
buf[i] = fake_rand_bytes[fake_rand_bytes_offset + i];
|
||||
fake_rand_bytes_offset += num;
|
||||
@@ -54,6 +58,7 @@ static int start_fake_rand(const char *hex_bytes)
|
||||
|
||||
fake_rand_bytes = OPENSSL_hexstr2buf(hex_bytes, NULL);
|
||||
fake_rand_bytes_offset = 0;
|
||||
fake_rand_size = strlen(hex_bytes) / 2;
|
||||
|
||||
/* set new RAND_METHOD */
|
||||
if (!TEST_true(RAND_set_rand_method(&fake_rand)))
|
||||
@@ -170,7 +175,8 @@ static int test_sm2_crypt(const EC_GROUP *group,
|
||||
|
||||
start_fake_rand(k_hex);
|
||||
if (!TEST_true(sm2_encrypt(key, digest, (const uint8_t *)message, msg_len,
|
||||
ctext, &ctext_len))) {
|
||||
ctext, &ctext_len))
|
||||
|| !TEST_size_t_eq(fake_rand_bytes_offset, fake_rand_size)) {
|
||||
restore_rand();
|
||||
goto done;
|
||||
}
|
||||
@@ -222,7 +228,9 @@ static int sm2_crypt_test(void)
|
||||
EVP_sm3(),
|
||||
"1649AB77A00637BD5E2EFE283FBF353534AA7F7CB89463F208DDBC2920BB0DA0",
|
||||
"encryption standard",
|
||||
"004C62EEFD6ECFC2B95B92FD6C3D9575148AFA17425546D49018E5388D49DD7B4F",
|
||||
"004C62EEFD6ECFC2B95B92FD6C3D9575148AFA17425546D49018E5388D49DD7B4F"
|
||||
"0092e8ff62146873c258557548500ab2df2a365e0609ab67640a1f6d57d7b17820"
|
||||
"008349312695a3e1d2f46905f39a766487f2432e95d6be0cb009fe8c69fd8825a7",
|
||||
"307B0220245C26FB68B1DDDDB12C4B6BF9F2B6D5FE60A383B0D18D1C4144ABF1"
|
||||
"7F6252E7022076CB9264C2A7E88E52B19903FDC47378F605E36811F5C07423A2"
|
||||
"4B84400F01B804209C3D7360C30156FAB7C80A0276712DA9D8094A634B766D3A"
|
||||
@@ -235,7 +243,9 @@ static int sm2_crypt_test(void)
|
||||
EVP_sha256(),
|
||||
"1649AB77A00637BD5E2EFE283FBF353534AA7F7CB89463F208DDBC2920BB0DA0",
|
||||
"encryption standard",
|
||||
"004C62EEFD6ECFC2B95B92FD6C3D9575148AFA17425546D49018E5388D49DD7B4F",
|
||||
"004C62EEFD6ECFC2B95B92FD6C3D9575148AFA17425546D49018E5388D49DD7B4F"
|
||||
"003da18008784352192d70f22c26c243174a447ba272fec64163dd4742bae8bc98"
|
||||
"00df17605cf304e9dd1dfeb90c015e93b393a6f046792f790a6fa4228af67d9588",
|
||||
"307B0220245C26FB68B1DDDDB12C4B6BF9F2B6D5FE60A383B0D18D1C4144ABF17F"
|
||||
"6252E7022076CB9264C2A7E88E52B19903FDC47378F605E36811F5C07423A24B84"
|
||||
"400F01B80420BE89139D07853100EFA763F60CBE30099EA3DF7F8F364F9D10A5E9"
|
||||
@@ -285,10 +295,12 @@ static int test_sm2_sign(const EC_GROUP *group,
|
||||
|
||||
start_fake_rand(k_hex);
|
||||
sig = sm2_do_sign(key, EVP_sm3(), userid, (const uint8_t *)message, msg_len);
|
||||
restore_rand();
|
||||
|
||||
if (!TEST_ptr(sig))
|
||||
if (!TEST_ptr(sig)
|
||||
|| !TEST_size_t_eq(fake_rand_bytes_offset, fake_rand_size)) {
|
||||
restore_rand();
|
||||
goto done;
|
||||
}
|
||||
restore_rand();
|
||||
|
||||
ECDSA_SIG_get0(sig, &sig_r, &sig_s);
|
||||
|
||||
@@ -337,7 +349,8 @@ static int sm2_sig_test(void)
|
||||
"ALICE123@YAHOO.COM",
|
||||
"128B2FA8BD433C6C068C8D803DFF79792A519A55171B1B650C23661D15897263",
|
||||
"message digest",
|
||||
"006CB28D99385C175C94F94E934817663FC176D925DD72B727260DBAAE1FB2F96F",
|
||||
"006CB28D99385C175C94F94E934817663FC176D925DD72B727260DBAAE1FB2F96F"
|
||||
"007c47811054c6f99613a578eb8453706ccb96384fe7df5c171671e760bfa8be3a",
|
||||
"40F1EC59F793D9F49E09DCEF49130D4194F79FB1EED2CAA55BACDB49C4E755D1",
|
||||
"6FC6DAC32C5D5CF10C77DFB20F7C2EB667A457872FB09EC56327A67EC7DEEBE7")))
|
||||
goto done;
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-2017 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL licenses, (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -161,6 +161,6 @@ int setup_tests(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
ADD_ALL_TESTS(test_certs, n);
|
||||
ADD_ALL_TESTS(test_certs, (int)n);
|
||||
return 1;
|
||||
}
|
||||
Reference in New Issue
Block a user