EVP_PKEY_new.pod 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. =pod
  2. =head1 NAME
  3. EVP_PKEY_new,
  4. EVP_PKEY_up_ref,
  5. EVP_PKEY_free,
  6. EVP_PKEY_new_raw_private_key,
  7. EVP_PKEY_new_raw_public_key,
  8. EVP_PKEY_new_CMAC_key,
  9. EVP_PKEY_new_mac_key,
  10. EVP_PKEY_get_raw_private_key,
  11. EVP_PKEY_get_raw_public_key
  12. - public/private key allocation and raw key handling functions
  13. =head1 SYNOPSIS
  14. #include <openssl/evp.h>
  15. EVP_PKEY *EVP_PKEY_new(void);
  16. int EVP_PKEY_up_ref(EVP_PKEY *key);
  17. void EVP_PKEY_free(EVP_PKEY *key);
  18. EVP_PKEY *EVP_PKEY_new_raw_private_key(int type, ENGINE *e,
  19. const unsigned char *key, size_t keylen);
  20. EVP_PKEY *EVP_PKEY_new_raw_public_key(int type, ENGINE *e,
  21. const unsigned char *key, size_t keylen);
  22. EVP_PKEY *EVP_PKEY_new_CMAC_key(ENGINE *e, const unsigned char *priv,
  23. size_t len, const EVP_CIPHER *cipher);
  24. EVP_PKEY *EVP_PKEY_new_mac_key(int type, ENGINE *e, const unsigned char *key,
  25. int keylen);
  26. int EVP_PKEY_get_raw_private_key(const EVP_PKEY *pkey, unsigned char *priv,
  27. size_t *len);
  28. int EVP_PKEY_get_raw_public_key(const EVP_PKEY *pkey, unsigned char *pub,
  29. size_t *len);
  30. =head1 DESCRIPTION
  31. The EVP_PKEY_new() function allocates an empty B<EVP_PKEY> structure which is
  32. used by OpenSSL to store public and private keys. The reference count is set to
  33. B<1>.
  34. EVP_PKEY_up_ref() increments the reference count of B<key>.
  35. EVP_PKEY_free() decrements the reference count of B<key> and, if the reference
  36. count is zero, frees it up. If B<key> is NULL, nothing is done.
  37. EVP_PKEY_new_raw_private_key() allocates a new B<EVP_PKEY>. If B<e> is non-NULL
  38. then the new B<EVP_PKEY> structure is associated with the engine B<e>. The
  39. B<type> argument indicates what kind of key this is. The value should be a NID
  40. for a public key algorithm that supports raw private keys, i.e. one of
  41. B<EVP_PKEY_HMAC>, B<EVP_PKEY_POLY1305>, B<EVP_PKEY_SIPHASH>, B<EVP_PKEY_X25519>,
  42. B<EVP_PKEY_ED25519>, B<EVP_PKEY_X448> or B<EVP_PKEY_ED448>. B<key> points to the
  43. raw private key data for this B<EVP_PKEY> which should be of length B<keylen>.
  44. The length should be appropriate for the type of the key. The public key data
  45. will be automatically derived from the given private key data (if appropriate
  46. for the algorithm type).
  47. EVP_PKEY_new_raw_public_key() works in the same way as
  48. EVP_PKEY_new_raw_private_key() except that B<key> points to the raw public key
  49. data. The B<EVP_PKEY> structure will be initialised without any private key
  50. information. Algorithm types that support raw public keys are
  51. B<EVP_PKEY_X25519>, B<EVP_PKEY_ED25519>, B<EVP_PKEY_X448> or B<EVP_PKEY_ED448>.
  52. EVP_PKEY_new_CMAC_key() works in the same way as EVP_PKEY_new_raw_private_key()
  53. except it is only for the B<EVP_PKEY_CMAC> algorithm type. In addition to the
  54. raw private key data, it also takes a cipher algorithm to be used during
  55. creation of a CMAC in the B<cipher> argument. The cipher should be a standard
  56. encryption only cipher. For example AEAD and XTS ciphers should not be used.
  57. EVP_PKEY_new_mac_key() works in the same way as EVP_PKEY_new_raw_private_key().
  58. New applications should use EVP_PKEY_new_raw_private_key() instead.
  59. EVP_PKEY_get_raw_private_key() fills the buffer provided by B<priv> with raw
  60. private key data. The size of the B<priv> buffer should be in B<*len> on entry
  61. to the function, and on exit B<*len> is updated with the number of bytes
  62. actually written. If the buffer B<priv> is NULL then B<*len> is populated with
  63. the number of bytes required to hold the key. The calling application is
  64. responsible for ensuring that the buffer is large enough to receive the private
  65. key data. This function only works for algorithms that support raw private keys.
  66. Currently this is: B<EVP_PKEY_HMAC>, B<EVP_PKEY_POLY1305>, B<EVP_PKEY_SIPHASH>,
  67. B<EVP_PKEY_X25519>, B<EVP_PKEY_ED25519>, B<EVP_PKEY_X448> or B<EVP_PKEY_ED448>.
  68. EVP_PKEY_get_raw_public_key() fills the buffer provided by B<pub> with raw
  69. public key data. The size of the B<pub> buffer should be in B<*len> on entry
  70. to the function, and on exit B<*len> is updated with the number of bytes
  71. actually written. If the buffer B<pub> is NULL then B<*len> is populated with
  72. the number of bytes required to hold the key. The calling application is
  73. responsible for ensuring that the buffer is large enough to receive the public
  74. key data. This function only works for algorithms that support raw public keys.
  75. Currently this is: B<EVP_PKEY_X25519>, B<EVP_PKEY_ED25519>, B<EVP_PKEY_X448> or
  76. B<EVP_PKEY_ED448>.
  77. =head1 NOTES
  78. The B<EVP_PKEY> structure is used by various OpenSSL functions which require a
  79. general private key without reference to any particular algorithm.
  80. The structure returned by EVP_PKEY_new() is empty. To add a private or public
  81. key to this empty structure use the appropriate functions described in
  82. L<EVP_PKEY_set1_RSA(3)>, L<EVP_PKEY_set1_DSA>, L<EVP_PKEY_set1_DH> or
  83. L<EVP_PKEY_set1_EC_KEY>.
  84. =head1 RETURN VALUES
  85. EVP_PKEY_new(), EVP_PKEY_new_raw_private_key(), EVP_PKEY_new_raw_public_key(),
  86. EVP_PKEY_new_CMAC_key() and EVP_PKEY_new_mac_key() return either the newly
  87. allocated B<EVP_PKEY> structure or B<NULL> if an error occurred.
  88. EVP_PKEY_up_ref(), EVP_PKEY_get_raw_private_key() and
  89. EVP_PKEY_get_raw_public_key() return 1 for success and 0 for failure.
  90. =head1 SEE ALSO
  91. L<EVP_PKEY_set1_RSA(3)>, L<EVP_PKEY_set1_DSA>, L<EVP_PKEY_set1_DH> or
  92. L<EVP_PKEY_set1_EC_KEY>
  93. =head1 HISTORY
  94. The
  95. EVP_PKEY_new() and EVP_PKEY_free() functions exist in all versions of OpenSSL.
  96. The EVP_PKEY_up_ref() function was added in OpenSSL 1.1.0.
  97. The
  98. EVP_PKEY_new_raw_private_key(), EVP_PKEY_new_raw_public_key(),
  99. EVP_PKEY_new_CMAC_key(), EVP_PKEY_new_raw_private_key() and
  100. EVP_PKEY_get_raw_public_key() functions were added in OpenSSL 1.1.1.
  101. =head1 COPYRIGHT
  102. Copyright 2002-2020 The OpenSSL Project Authors. All Rights Reserved.
  103. Licensed under the OpenSSL license (the "License"). You may not use
  104. this file except in compliance with the License. You can obtain a copy
  105. in the file LICENSE in the source distribution or at
  106. L<https://www.openssl.org/source/license.html>.
  107. =cut