1e71b7053SJung-uk Kim=pod 2e71b7053SJung-uk Kim 3e71b7053SJung-uk Kim=head1 NAME 4e71b7053SJung-uk Kim 5e71b7053SJung-uk KimEVP_PKEY_new, 6e71b7053SJung-uk KimEVP_PKEY_up_ref, 7e71b7053SJung-uk KimEVP_PKEY_free, 8e71b7053SJung-uk KimEVP_PKEY_new_raw_private_key, 9e71b7053SJung-uk KimEVP_PKEY_new_raw_public_key, 10e71b7053SJung-uk KimEVP_PKEY_new_CMAC_key, 11e71b7053SJung-uk KimEVP_PKEY_new_mac_key, 12e71b7053SJung-uk KimEVP_PKEY_get_raw_private_key, 13e71b7053SJung-uk KimEVP_PKEY_get_raw_public_key 14e71b7053SJung-uk Kim- public/private key allocation and raw key handling functions 15e71b7053SJung-uk Kim 16e71b7053SJung-uk Kim=head1 SYNOPSIS 17e71b7053SJung-uk Kim 18e71b7053SJung-uk Kim #include <openssl/evp.h> 19e71b7053SJung-uk Kim 20e71b7053SJung-uk Kim EVP_PKEY *EVP_PKEY_new(void); 21e71b7053SJung-uk Kim int EVP_PKEY_up_ref(EVP_PKEY *key); 22e71b7053SJung-uk Kim void EVP_PKEY_free(EVP_PKEY *key); 23e71b7053SJung-uk Kim 24e71b7053SJung-uk Kim EVP_PKEY *EVP_PKEY_new_raw_private_key(int type, ENGINE *e, 25e71b7053SJung-uk Kim const unsigned char *key, size_t keylen); 26e71b7053SJung-uk Kim EVP_PKEY *EVP_PKEY_new_raw_public_key(int type, ENGINE *e, 27e71b7053SJung-uk Kim const unsigned char *key, size_t keylen); 28e71b7053SJung-uk Kim EVP_PKEY *EVP_PKEY_new_CMAC_key(ENGINE *e, const unsigned char *priv, 29e71b7053SJung-uk Kim size_t len, const EVP_CIPHER *cipher); 30e71b7053SJung-uk Kim EVP_PKEY *EVP_PKEY_new_mac_key(int type, ENGINE *e, const unsigned char *key, 31e71b7053SJung-uk Kim int keylen); 32e71b7053SJung-uk Kim 33e71b7053SJung-uk Kim int EVP_PKEY_get_raw_private_key(const EVP_PKEY *pkey, unsigned char *priv, 34e71b7053SJung-uk Kim size_t *len); 35e71b7053SJung-uk Kim int EVP_PKEY_get_raw_public_key(const EVP_PKEY *pkey, unsigned char *pub, 36e71b7053SJung-uk Kim size_t *len); 37e71b7053SJung-uk Kim 38e71b7053SJung-uk Kim=head1 DESCRIPTION 39e71b7053SJung-uk Kim 40e71b7053SJung-uk KimThe EVP_PKEY_new() function allocates an empty B<EVP_PKEY> structure which is 41e71b7053SJung-uk Kimused by OpenSSL to store public and private keys. The reference count is set to 42e71b7053SJung-uk KimB<1>. 43e71b7053SJung-uk Kim 44e71b7053SJung-uk KimEVP_PKEY_up_ref() increments the reference count of B<key>. 45e71b7053SJung-uk Kim 46e71b7053SJung-uk KimEVP_PKEY_free() decrements the reference count of B<key> and, if the reference 47e71b7053SJung-uk Kimcount is zero, frees it up. If B<key> is NULL, nothing is done. 48e71b7053SJung-uk Kim 49e71b7053SJung-uk KimEVP_PKEY_new_raw_private_key() allocates a new B<EVP_PKEY>. If B<e> is non-NULL 50e71b7053SJung-uk Kimthen the new B<EVP_PKEY> structure is associated with the engine B<e>. The 51e71b7053SJung-uk KimB<type> argument indicates what kind of key this is. The value should be a NID 52e71b7053SJung-uk Kimfor a public key algorithm that supports raw private keys, i.e. one of 53e71b7053SJung-uk KimB<EVP_PKEY_HMAC>, B<EVP_PKEY_POLY1305>, B<EVP_PKEY_SIPHASH>, B<EVP_PKEY_X25519>, 54e71b7053SJung-uk KimB<EVP_PKEY_ED25519>, B<EVP_PKEY_X448> or B<EVP_PKEY_ED448>. B<key> points to the 55e71b7053SJung-uk Kimraw private key data for this B<EVP_PKEY> which should be of length B<keylen>. 56e71b7053SJung-uk KimThe length should be appropriate for the type of the key. The public key data 57e71b7053SJung-uk Kimwill be automatically derived from the given private key data (if appropriate 58e71b7053SJung-uk Kimfor the algorithm type). 59e71b7053SJung-uk Kim 60e71b7053SJung-uk KimEVP_PKEY_new_raw_public_key() works in the same way as 61e71b7053SJung-uk KimEVP_PKEY_new_raw_private_key() except that B<key> points to the raw public key 62e71b7053SJung-uk Kimdata. The B<EVP_PKEY> structure will be initialised without any private key 63e71b7053SJung-uk Kiminformation. Algorithm types that support raw public keys are 64e71b7053SJung-uk KimB<EVP_PKEY_X25519>, B<EVP_PKEY_ED25519>, B<EVP_PKEY_X448> or B<EVP_PKEY_ED448>. 65e71b7053SJung-uk Kim 66e71b7053SJung-uk KimEVP_PKEY_new_CMAC_key() works in the same way as EVP_PKEY_new_raw_private_key() 67e71b7053SJung-uk Kimexcept it is only for the B<EVP_PKEY_CMAC> algorithm type. In addition to the 68e71b7053SJung-uk Kimraw private key data, it also takes a cipher algorithm to be used during 69e71b7053SJung-uk Kimcreation of a CMAC in the B<cipher> argument. 70e71b7053SJung-uk Kim 71e71b7053SJung-uk KimEVP_PKEY_new_mac_key() works in the same way as EVP_PKEY_new_raw_private_key(). 72e71b7053SJung-uk KimNew applications should use EVP_PKEY_new_raw_private_key() instead. 73e71b7053SJung-uk Kim 74e71b7053SJung-uk KimEVP_PKEY_get_raw_private_key() fills the buffer provided by B<priv> with raw 75e71b7053SJung-uk Kimprivate key data. The number of bytes written is populated in B<*len>. If the 76e71b7053SJung-uk Kimbuffer B<priv> is NULL then B<*len> is populated with the number of bytes 77e71b7053SJung-uk Kimrequired to hold the key. The calling application is responsible for ensuring 78e71b7053SJung-uk Kimthat the buffer is large enough to receive the private key data. This function 79e71b7053SJung-uk Kimonly works for algorithms that support raw private keys. Currently this is: 80e71b7053SJung-uk KimB<EVP_PKEY_HMAC>, B<EVP_PKEY_POLY1305>, B<EVP_PKEY_SIPHASH>, B<EVP_PKEY_X25519>, 81e71b7053SJung-uk KimB<EVP_PKEY_ED25519>, B<EVP_PKEY_X448> or B<EVP_PKEY_ED448>. 82e71b7053SJung-uk Kim 83e71b7053SJung-uk KimEVP_PKEY_get_raw_public_key() fills the buffer provided by B<pub> with raw 84e71b7053SJung-uk Kimpublic key data. The number of bytes written is populated in B<*len>. If the 85e71b7053SJung-uk Kimbuffer B<pub> is NULL then B<*len> is populated with the number of bytes 86e71b7053SJung-uk Kimrequired to hold the key. The calling application is responsible for ensuring 87e71b7053SJung-uk Kimthat the buffer is large enough to receive the public key data. This function 88e71b7053SJung-uk Kimonly works for algorithms that support raw public keys. Currently this is: 89e71b7053SJung-uk KimB<EVP_PKEY_X25519>, B<EVP_PKEY_ED25519>, B<EVP_PKEY_X448> or B<EVP_PKEY_ED448>. 90e71b7053SJung-uk Kim 91e71b7053SJung-uk Kim=head1 NOTES 92e71b7053SJung-uk Kim 93e71b7053SJung-uk KimThe B<EVP_PKEY> structure is used by various OpenSSL functions which require a 94e71b7053SJung-uk Kimgeneral private key without reference to any particular algorithm. 95e71b7053SJung-uk Kim 96e71b7053SJung-uk KimThe structure returned by EVP_PKEY_new() is empty. To add a private or public 97e71b7053SJung-uk Kimkey to this empty structure use the appropriate functions described in 98e71b7053SJung-uk KimL<EVP_PKEY_set1_RSA(3)>, L<EVP_PKEY_set1_DSA>, L<EVP_PKEY_set1_DH> or 99e71b7053SJung-uk KimL<EVP_PKEY_set1_EC_KEY>. 100e71b7053SJung-uk Kim 101e71b7053SJung-uk Kim=head1 RETURN VALUES 102e71b7053SJung-uk Kim 103e71b7053SJung-uk KimEVP_PKEY_new(), EVP_PKEY_new_raw_private_key(), EVP_PKEY_new_raw_public_key(), 104e71b7053SJung-uk KimEVP_PKEY_new_CMAC_key() and EVP_PKEY_new_mac_key() return either the newly 105e71b7053SJung-uk Kimallocated B<EVP_PKEY> structure or B<NULL> if an error occurred. 106e71b7053SJung-uk Kim 107e71b7053SJung-uk KimEVP_PKEY_up_ref(), EVP_PKEY_get_raw_private_key() and 108e71b7053SJung-uk KimEVP_PKEY_get_raw_public_key() return 1 for success and 0 for failure. 109e71b7053SJung-uk Kim 110e71b7053SJung-uk Kim=head1 SEE ALSO 111e71b7053SJung-uk Kim 112e71b7053SJung-uk KimL<EVP_PKEY_set1_RSA(3)>, L<EVP_PKEY_set1_DSA>, L<EVP_PKEY_set1_DH> or 113e71b7053SJung-uk KimL<EVP_PKEY_set1_EC_KEY> 114e71b7053SJung-uk Kim 115e71b7053SJung-uk Kim=head1 HISTORY 116e71b7053SJung-uk Kim 117*6935a639SJung-uk KimThe 118*6935a639SJung-uk KimEVP_PKEY_new() and EVP_PKEY_free() functions exist in all versions of OpenSSL. 119e71b7053SJung-uk Kim 120*6935a639SJung-uk KimThe EVP_PKEY_up_ref() function was added in OpenSSL 1.1.0. 121*6935a639SJung-uk Kim 122*6935a639SJung-uk KimThe 123e71b7053SJung-uk KimEVP_PKEY_new_raw_private_key(), EVP_PKEY_new_raw_public_key(), 124e71b7053SJung-uk KimEVP_PKEY_new_CMAC_key(), EVP_PKEY_new_raw_private_key() and 125*6935a639SJung-uk KimEVP_PKEY_get_raw_public_key() functions were added in OpenSSL 1.1.1. 126e71b7053SJung-uk Kim 127e71b7053SJung-uk Kim=head1 COPYRIGHT 128e71b7053SJung-uk Kim 129e71b7053SJung-uk KimCopyright 2002-2018 The OpenSSL Project Authors. All Rights Reserved. 130e71b7053SJung-uk Kim 131e71b7053SJung-uk KimLicensed under the OpenSSL license (the "License"). You may not use 132e71b7053SJung-uk Kimthis file except in compliance with the License. You can obtain a copy 133e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at 134e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>. 135e71b7053SJung-uk Kim 136e71b7053SJung-uk Kim=cut 137