NAME
EVP_PKEY_new
,
EVP_PKEY_up_ref
,
EVP_PKEY_free
,
EVP_PKEY_new_raw_private_key
,
EVP_PKEY_new_raw_public_key
,
EVP_PKEY_new_CMAC_key
,
EVP_PKEY_new_mac_key
,
EVP_PKEY_get_raw_private_key
,
EVP_PKEY_get_raw_public_key
—
public and private key allocation and
raw key handling functions
SYNOPSIS
#include
<openssl/evp.h>
EVP_PKEY *
EVP_PKEY_new
(void);
int
EVP_PKEY_up_ref
(EVP_PKEY
*pkey);
void
EVP_PKEY_free
(EVP_PKEY
*pkey);
EVP_PKEY *
EVP_PKEY_new_raw_private_key
(int
type, ENGINE *e, const unsigned
char *rawpriv, size_t rawlen);
EVP_PKEY *
EVP_PKEY_new_raw_public_key
(int
type, ENGINE *e, const unsigned
char *rawpub, size_t rawlen);
EVP_PKEY *
EVP_PKEY_new_CMAC_key
(ENGINE *e,
const unsigned char *rawpriv, size_t
rawlen, const EVP_CIPHER *cipher);
EVP_PKEY *
EVP_PKEY_new_mac_key
(int type,
ENGINE *e, const unsigned char
*rawpriv, int rawlen);
int
EVP_PKEY_get_raw_private_key
(const
EVP_PKEY *pkey, unsigned char *rawpriv,
size_t *rawlen);
int
EVP_PKEY_get_raw_public_key
(const
EVP_PKEY *pkey, unsigned char *rawpub,
size_t *rawlen);
DESCRIPTION
The EVP_PKEY structure is used by various OpenSSL functions which require a general private or public key without reference to any particular algorithm.
The
EVP_PKEY_new
()
function allocates an empty EVP_PKEY structure. The
reference count is set to 1. To add a private or public key to it, use the
functions described in
EVP_PKEY_set1_RSA(3).
EVP_PKEY_up_ref
()
increments the reference count of pkey by 1.
EVP_PKEY_free
()
decrements the reference count of pkey by 1, and if
the reference count reaches zero, frees it up. If pkey
is a NULL
pointer, no action occurs.
EVP_PKEY_new_raw_private_key
()
allocates a new EVP_PKEY. If e
is non-NULL
, the new structure is associated with
the engine e. The NID of a public key algorithm that
supports raw private keys, i.e. EVP_PKEY_HMAC
,
EVP_PKEY_X25519
, or
EVP_PKEY_ED25519
, is provided in the
type argument and rawlen bytes
of raw private key data of that type in rawpriv. The
public key data is automatically derived from the given private key data, if
appropriate for the algorithm type.
EVP_PKEY_new_raw_public_key
()
works in the same way as
EVP_PKEY_new_raw_private_key
() except that
rawpub points to the raw public key data. The
EVP_PKEY structure is initialised without any private
key information. Algorithm types that support raw public keys are
EVP_PKEY_X25519
and
EVP_PKEY_ED25519
.
EVP_PKEY_new_CMAC_key
()
works in the same way as
EVP_PKEY_new_raw_private_key
() except that it only
handles the EVP_PKEY_CMAC
algorithm type. The
additional cipher argument specifies the cipher
algorithm to be used during the creation of the CMAC. It should be a
standard encryption only cipher. For example, AEAD and XTS ciphers should
not be used.
EVP_PKEY_new_mac_key
()
is a deprecated function that works in the same way as
EVP_PKEY_new_raw_private_key
().
EVP_PKEY_get_raw_private_key
()
writes up to *rawlen bytes of raw private key data to
the buffer starting at rawpriv and stores the number
of bytes written in *rawlen. The calling application
is responsible for ensuring that the buffer is large enough to receive the
private key data. If the rawpriv argument is
NULL
, the number of bytes required to hold the key
is stored in *rawlen. This function only works for
algorithms that support raw private keys. Currently these are
EVP_PKEY_HMAC
,
EVP_PKEY_X25519
, and
EVP_PKEY_ED25519
.
EVP_PKEY_get_raw_public_key
()
is similar to EVP_PKEY_get_raw_private_key
() except
that it writes raw public key data. This function only works for algorithms
that support raw public keys. Currently these are
EVP_PKEY_X25519
and
EVP_PKEY_ED25519
.
RETURN VALUES
EVP_PKEY_new
(),
EVP_PKEY_new_raw_private_key
(),
EVP_PKEY_new_raw_public_key
(),
EVP_PKEY_new_CMAC_key
(), and
EVP_PKEY_new_mac_key
() return either the newly
allocated EVP_PKEY structure or
NULL
if an error occurred.
EVP_PKEY_up_ref
(),
EVP_PKEY_get_raw_private_key
(), and
EVP_PKEY_get_raw_public_key
() return 1 for success
or 0 for failure.
SEE ALSO
CMAC_Init(3), d2i_PrivateKey(3), evp(3), EVP_PKCS82PKEY(3), EVP_PKEY_add1_attr(3), EVP_PKEY_asn1_new(3), EVP_PKEY_check(3), EVP_PKEY_cmp(3), EVP_PKEY_CTX_new(3), EVP_PKEY_get_default_digest_nid(3), EVP_PKEY_meth_new(3), EVP_PKEY_print_private(3), EVP_PKEY_set1_RSA(3), EVP_PKEY_size(3), X509_get_pubkey_parameters(3)
HISTORY
EVP_PKEY_new
() and
EVP_PKEY_free
() first appeared in SSLeay 0.6.0 and
have been available since OpenBSD 2.4.
EVP_PKEY_new_CMAC_key
() first appeared in
OpenSSL 1.1.1 and has been available since OpenBSD
6.9.
EVP_PKEY_new_mac_key
() first appeared in
OpenSSL 1.0.0 and has been available since OpenBSD
4.9.
EVP_PKEY_up_ref
() first appeared in
OpenSSL 1.1.0 and has been available since OpenBSD
6.3.
EVP_PKEY_new_raw_private_key
(),
EVP_PKEY_new_raw_public_key
(),
EVP_PKEY_get_raw_private_key
(), and
EVP_PKEY_get_raw_public_key
() first appeared in
OpenSSL 1.1.1 and have been available since OpenBSD
7.3.