/*
- * 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
key = EVP_PKEY_new_CMAC_key(NULL, expected->key, expected->key_len,
EVP_get_cipherbyname(expected->alg));
else
- key = EVP_PKEY_new_private_key(expected->type, NULL, expected->key,
- expected->key_len);
+ key = EVP_PKEY_new_raw_private_key(expected->type, NULL, expected->key,
+ expected->key_len);
if (key == NULL) {
t->err = "MAC_KEY_CREATE_ERROR";
goto err;
/*
* Is the key type an unsupported algorithm?
*/
-static int key_unsupported()
+static int key_unsupported(void)
{
long err = ERR_peek_error();
if (strcmp(pp->key, "PrivateKey") == 0) {
pkey = PEM_read_bio_PrivateKey(t->s.key, NULL, 0, NULL);
if (pkey == NULL && !key_unsupported()) {
+ EVP_PKEY_free(pkey);
TEST_info("Can't read private key %s", pp->value);
TEST_openssl_errors();
return 0;
} else if (strcmp(pp->key, "PublicKey") == 0) {
pkey = PEM_read_bio_PUBKEY(t->s.key, NULL, 0, NULL);
if (pkey == NULL && !key_unsupported()) {
+ EVP_PKEY_free(pkey);
TEST_info("Can't read public key %s", pp->value);
TEST_openssl_errors();
return 0;
return 0;
}
if (klist == &private_keys)
- pkey = EVP_PKEY_new_private_key(nid, NULL, keybin, keylen);
+ pkey = EVP_PKEY_new_raw_private_key(nid, NULL, keybin, keylen);
else
- pkey = EVP_PKEY_new_public_key(nid, NULL, keybin, keylen);
- if (pkey == NULL) {
+ pkey = EVP_PKEY_new_raw_public_key(nid, NULL, keybin, keylen);
+ if (pkey == NULL && !key_unsupported()) {
TEST_info("Can't read %s data", pp->key);
OPENSSL_free(keybin);
TEST_openssl_errors();
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;