2019-05-27 19:52:37 +08:00
|
|
|
/*
|
2021-06-17 20:24:59 +08:00
|
|
|
* Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
|
2019-05-27 19:52:37 +08:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "internal/cryptlib.h"
|
|
|
|
#include <openssl/evp.h>
|
|
|
|
#include <openssl/asn1.h>
|
2020-07-23 22:56:59 +08:00
|
|
|
#include "internal/asn1.h"
|
2019-09-28 06:45:33 +08:00
|
|
|
#include "crypto/asn1.h"
|
2020-07-23 22:56:59 +08:00
|
|
|
#include "crypto/evp.h"
|
2019-05-27 19:52:37 +08:00
|
|
|
|
|
|
|
EVP_PKEY *d2i_KeyParams(int type, EVP_PKEY **a, const unsigned char **pp,
|
|
|
|
long length)
|
|
|
|
{
|
|
|
|
EVP_PKEY *ret = NULL;
|
|
|
|
|
|
|
|
if ((a == NULL) || (*a == NULL)) {
|
|
|
|
if ((ret = EVP_PKEY_new()) == NULL)
|
|
|
|
return NULL;
|
|
|
|
} else
|
|
|
|
ret = *a;
|
|
|
|
|
Rename all getters to use get/get0 in name
For functions that exist in 1.1.1 provide a simple aliases via #define.
Fixes #15236
Functions with OSSL_DECODER_, OSSL_ENCODER_, OSSL_STORE_LOADER_,
EVP_KEYEXCH_, EVP_KEM_, EVP_ASYM_CIPHER_, EVP_SIGNATURE_,
EVP_KEYMGMT_, EVP_RAND_, EVP_MAC_, EVP_KDF_, EVP_PKEY_,
EVP_MD_, and EVP_CIPHER_ prefixes are renamed.
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15405)
2021-05-21 22:58:08 +08:00
|
|
|
if (type != EVP_PKEY_get_id(ret) && !EVP_PKEY_set_type(ret, type))
|
2019-05-27 19:52:37 +08:00
|
|
|
goto err;
|
|
|
|
|
|
|
|
if (ret->ameth == NULL || ret->ameth->param_decode == NULL) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_ASN1, ASN1_R_UNSUPPORTED_TYPE);
|
2019-05-27 19:52:37 +08:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2020-07-23 22:30:38 +08:00
|
|
|
if (!ret->ameth->param_decode(ret, pp, length))
|
2019-05-27 19:52:37 +08:00
|
|
|
goto err;
|
|
|
|
|
|
|
|
if (a != NULL)
|
|
|
|
(*a) = ret;
|
|
|
|
return ret;
|
|
|
|
err:
|
|
|
|
if (a == NULL || *a != ret)
|
|
|
|
EVP_PKEY_free(ret);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
EVP_PKEY *d2i_KeyParams_bio(int type, EVP_PKEY **a, BIO *in)
|
|
|
|
{
|
|
|
|
BUF_MEM *b = NULL;
|
|
|
|
const unsigned char *p;
|
|
|
|
void *ret = NULL;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
len = asn1_d2i_read_bio(in, &b);
|
|
|
|
if (len < 0)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
p = (unsigned char *)b->data;
|
|
|
|
ret = d2i_KeyParams(type, a, &p, len);
|
|
|
|
err:
|
|
|
|
BUF_MEM_free(b);
|
|
|
|
return ret;
|
|
|
|
}
|