2
0

EVP_PKEY_new.pod 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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.
  56. EVP_PKEY_new_mac_key() works in the same way as EVP_PKEY_new_raw_private_key().
  57. New applications should use EVP_PKEY_new_raw_private_key() instead.
  58. EVP_PKEY_get_raw_private_key() fills the buffer provided by B<priv> with raw
  59. private key data. The number of bytes written is populated in B<*len>. If the
  60. buffer B<priv> is NULL then B<*len> is populated with the number of bytes
  61. required to hold the key. The calling application is responsible for ensuring
  62. that the buffer is large enough to receive the private key data. This function
  63. only works for algorithms that support raw private keys. Currently this is:
  64. B<EVP_PKEY_HMAC>, B<EVP_PKEY_POLY1305>, B<EVP_PKEY_SIPHASH>, B<EVP_PKEY_X25519>,
  65. B<EVP_PKEY_ED25519>, B<EVP_PKEY_X448> or B<EVP_PKEY_ED448>.
  66. EVP_PKEY_get_raw_public_key() fills the buffer provided by B<pub> with raw
  67. public key data. The number of bytes written is populated in B<*len>. If the
  68. buffer B<pub> is NULL then B<*len> is populated with the number of bytes
  69. required to hold the key. The calling application is responsible for ensuring
  70. that the buffer is large enough to receive the public key data. This function
  71. only works for algorithms that support raw public keys. Currently this is:
  72. B<EVP_PKEY_X25519>, B<EVP_PKEY_ED25519>, B<EVP_PKEY_X448> or B<EVP_PKEY_ED448>.
  73. =head1 NOTES
  74. The B<EVP_PKEY> structure is used by various OpenSSL functions which require a
  75. general private key without reference to any particular algorithm.
  76. The structure returned by EVP_PKEY_new() is empty. To add a private or public
  77. key to this empty structure use the appropriate functions described in
  78. L<EVP_PKEY_set1_RSA(3)>, L<EVP_PKEY_set1_DSA>, L<EVP_PKEY_set1_DH> or
  79. L<EVP_PKEY_set1_EC_KEY>.
  80. =head1 RETURN VALUES
  81. EVP_PKEY_new(), EVP_PKEY_new_raw_private_key(), EVP_PKEY_new_raw_public_key(),
  82. EVP_PKEY_new_CMAC_key() and EVP_PKEY_new_mac_key() return either the newly
  83. allocated B<EVP_PKEY> structure or B<NULL> if an error occurred.
  84. EVP_PKEY_up_ref(), EVP_PKEY_get_raw_private_key() and
  85. EVP_PKEY_get_raw_public_key() return 1 for success and 0 for failure.
  86. =head1 SEE ALSO
  87. L<EVP_PKEY_set1_RSA(3)>, L<EVP_PKEY_set1_DSA>, L<EVP_PKEY_set1_DH> or
  88. L<EVP_PKEY_set1_EC_KEY>
  89. =head1 HISTORY
  90. EVP_PKEY_new() and EVP_PKEY_free() exist in all versions of OpenSSL.
  91. EVP_PKEY_up_ref() was first added to OpenSSL 1.1.0.
  92. EVP_PKEY_new_raw_private_key(), EVP_PKEY_new_raw_public_key(),
  93. EVP_PKEY_new_CMAC_key(), EVP_PKEY_new_raw_private_key() and
  94. EVP_PKEY_get_raw_public_key() were first added to OpenSSL 1.1.1.
  95. =head1 COPYRIGHT
  96. Copyright 2002-2018 The OpenSSL Project Authors. All Rights Reserved.
  97. Licensed under the OpenSSL license (the "License"). You may not use
  98. this file except in compliance with the License. You can obtain a copy
  99. in the file LICENSE in the source distribution or at
  100. L<https://www.openssl.org/source/license.html>.
  101. =cut