EVP_PKEY_new.pod 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. - public/private key allocation functions
  11. =head1 SYNOPSIS
  12. #include <openssl/evp.h>
  13. EVP_PKEY *EVP_PKEY_new(void);
  14. int EVP_PKEY_up_ref(EVP_PKEY *key);
  15. void EVP_PKEY_free(EVP_PKEY *key);
  16. EVP_PKEY *EVP_PKEY_new_raw_private_key(int type, ENGINE *e,
  17. const unsigned char *key, size_t keylen);
  18. EVP_PKEY *EVP_PKEY_new_raw_public_key(int type, ENGINE *e,
  19. const unsigned char *key, size_t keylen);
  20. EVP_PKEY *EVP_PKEY_new_CMAC_key(ENGINE *e, const unsigned char *priv,
  21. size_t len, const EVP_CIPHER *cipher);
  22. EVP_PKEY *EVP_PKEY_new_mac_key(int type, ENGINE *e, const unsigned char *key,
  23. int keylen);
  24. =head1 DESCRIPTION
  25. The EVP_PKEY_new() function allocates an empty B<EVP_PKEY> structure which is
  26. used by OpenSSL to store private keys. The reference count is set to B<1>.
  27. EVP_PKEY_up_ref() increments the reference count of B<key>.
  28. EVP_PKEY_free() decrements the reference count of B<key> and, if the reference
  29. count is zero, frees it up. If B<key> is NULL, nothing is done.
  30. EVP_PKEY_new_raw_private_key() allocates a new B<EVP_PKEY>. If B<e> is non-NULL
  31. then the new B<EVP_PKEY> structure is associated with the engine B<e>. The
  32. B<type> argument indicates what kind of key this is. The value should be a NID
  33. for a public key algorithm that supports raw private keys, i.e. one of
  34. B<EVP_PKEY_HMAC>, B<EVP_PKEY_POLY1305>, B<EVP_PKEY_SIPHASH>, B<EVP_PKEY_X25519>,
  35. B<EVP_PKEY_ED25519>, B<EVP_PKEY_X448> or B<EVP_PKEY_ED448>. B<key> points to the
  36. raw private key data for this B<EVP_PKEY> which should be of length B<keylen>.
  37. The length should be appropriate for the type of the key. The public key data
  38. will be automatically derived from the given private key data (if appropriate
  39. for the algorithm type).
  40. EVP_PKEY_new_raw_public_key() works in the same way as
  41. EVP_PKEY_new_raw_private_key() except that B<key> points to the raw public key
  42. data. The B<EVP_PKEY> structure will be initialised without any private key
  43. information. Algorithm types that support raw public keys are
  44. B<EVP_PKEY_X25519>, B<EVP_PKEY_ED25519>, B<EVP_PKEY_X448> or B<EVP_PKEY_ED448>.
  45. EVP_PKEY_new_CMAC_key() works in the same way as EVP_PKEY_new_raw_private_key()
  46. except it is only for the B<EVP_PKEY_CMAC> algorithm type. In addition to the
  47. raw private key data, it also takes a cipher algorithm to be used during
  48. creation of a CMAC in the B<cipher> argument.
  49. EVP_PKEY_new_mac_key() works in the same way as EVP_PKEY_new_raw_private_key().
  50. New applications should use EVP_PKEY_new_raw_private_key() instead.
  51. =head1 NOTES
  52. The B<EVP_PKEY> structure is used by various OpenSSL functions which require a
  53. general private key without reference to any particular algorithm.
  54. The structure returned by EVP_PKEY_new() is empty. To add a private key to this
  55. empty structure the functions described in L<EVP_PKEY_set1_RSA(3)> should be
  56. used.
  57. =head1 RETURN VALUES
  58. EVP_PKEY_new(), EVP_PKEY_new_raw_private_key(), EVP_PKEY_new_raw_public_key(),
  59. EVP_PKEY_new_CMAC_key() and EVP_PKEY_new_mac_key() return either the newly
  60. allocated B<EVP_PKEY> structure or B<NULL> if an error occurred.
  61. EVP_PKEY_up_ref() returns 1 for success and 0 for failure.
  62. =head1 SEE ALSO
  63. L<EVP_PKEY_set1_RSA(3)>
  64. =head1 HISTORY
  65. EVP_PKEY_new() and EVP_PKEY_free() exist in all versions of OpenSSL.
  66. EVP_PKEY_up_ref() was first added to OpenSSL 1.1.0.
  67. EVP_PKEY_new_raw_private_key(), EVP_PKEY_new_raw_public_key() and
  68. EVP_PKEY_new_CMAC_key() were first added to OpenSSL 1.1.1.
  69. =head1 COPYRIGHT
  70. Copyright 2002-2018 The OpenSSL Project Authors. All Rights Reserved.
  71. Licensed under the OpenSSL license (the "License"). You may not use
  72. this file except in compliance with the License. You can obtain a copy
  73. in the file LICENSE in the source distribution or at
  74. L<https://www.openssl.org/source/license.html>.
  75. =cut