EVP_PKEY_set1_RSA.pod 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. =pod
  2. =head1 NAME
  3. EVP_PKEY_set1_RSA, EVP_PKEY_set1_DSA, EVP_PKEY_set1_DH, EVP_PKEY_set1_EC_KEY,
  4. EVP_PKEY_get1_RSA, EVP_PKEY_get1_DSA, EVP_PKEY_get1_DH, EVP_PKEY_get1_EC_KEY,
  5. EVP_PKEY_get0_RSA, EVP_PKEY_get0_DSA, EVP_PKEY_get0_DH, EVP_PKEY_get0_EC_KEY,
  6. EVP_PKEY_assign_RSA, EVP_PKEY_assign_DSA, EVP_PKEY_assign_DH,
  7. EVP_PKEY_assign_EC_KEY, EVP_PKEY_get0_hmac, EVP_PKEY_type, EVP_PKEY_id,
  8. EVP_PKEY_base_id, EVP_PKEY_set_alias_type, EVP_PKEY_set1_engine - EVP_PKEY assignment functions
  9. =head1 SYNOPSIS
  10. #include <openssl/evp.h>
  11. int EVP_PKEY_set1_RSA(EVP_PKEY *pkey, RSA *key);
  12. int EVP_PKEY_set1_DSA(EVP_PKEY *pkey, DSA *key);
  13. int EVP_PKEY_set1_DH(EVP_PKEY *pkey, DH *key);
  14. int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey, EC_KEY *key);
  15. RSA *EVP_PKEY_get1_RSA(EVP_PKEY *pkey);
  16. DSA *EVP_PKEY_get1_DSA(EVP_PKEY *pkey);
  17. DH *EVP_PKEY_get1_DH(EVP_PKEY *pkey);
  18. EC_KEY *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey);
  19. const unsigned char *EVP_PKEY_get0_hmac(const EVP_PKEY *pkey, size_t *len);
  20. RSA *EVP_PKEY_get0_RSA(EVP_PKEY *pkey);
  21. DSA *EVP_PKEY_get0_DSA(EVP_PKEY *pkey);
  22. DH *EVP_PKEY_get0_DH(EVP_PKEY *pkey);
  23. EC_KEY *EVP_PKEY_get0_EC_KEY(EVP_PKEY *pkey);
  24. int EVP_PKEY_assign_RSA(EVP_PKEY *pkey, RSA *key);
  25. int EVP_PKEY_assign_DSA(EVP_PKEY *pkey, DSA *key);
  26. int EVP_PKEY_assign_DH(EVP_PKEY *pkey, DH *key);
  27. int EVP_PKEY_assign_EC_KEY(EVP_PKEY *pkey, EC_KEY *key);
  28. int EVP_PKEY_id(const EVP_PKEY *pkey);
  29. int EVP_PKEY_base_id(const EVP_PKEY *pkey);
  30. int EVP_PKEY_type(int type);
  31. int EVP_PKEY_set_alias_type(EVP_PKEY *pkey, int type);
  32. int EVP_PKEY_set1_engine(EVP_PKEY *pkey, ENGINE *engine);
  33. =head1 DESCRIPTION
  34. EVP_PKEY_set1_RSA(), EVP_PKEY_set1_DSA(), EVP_PKEY_set1_DH() and
  35. EVP_PKEY_set1_EC_KEY() set the key referenced by B<pkey> to B<key>.
  36. EVP_PKEY_get1_RSA(), EVP_PKEY_get1_DSA(), EVP_PKEY_get1_DH() and
  37. EVP_PKEY_get1_EC_KEY() return the referenced key in B<pkey> or
  38. B<NULL> if the key is not of the correct type.
  39. EVP_PKEY_get0_hmac(), EVP_PKEY_get0_RSA(), EVP_PKEY_get0_DSA(),
  40. EVP_PKEY_get0_DH() and EVP_PKEY_get0_EC_KEY() also return the
  41. referenced key in B<pkey> or B<NULL> if the key is not of the
  42. correct type but the reference count of the returned key is
  43. B<not> incremented and so must not be freed up after use.
  44. EVP_PKEY_assign_RSA(), EVP_PKEY_assign_DSA(), EVP_PKEY_assign_DH()
  45. and EVP_PKEY_assign_EC_KEY() also set the referenced key to B<key>
  46. however these use the supplied B<key> internally and so B<key>
  47. will be freed when the parent B<pkey> is freed.
  48. EVP_PKEY_base_id() returns the type of B<pkey>. For example
  49. an RSA key will return B<EVP_PKEY_RSA>.
  50. EVP_PKEY_id() returns the actual OID associated with B<pkey>. Historically keys
  51. using the same algorithm could use different OIDs. For example an RSA key could
  52. use the OIDs corresponding to the NIDs B<NID_rsaEncryption> (equivalent to
  53. B<EVP_PKEY_RSA>) or B<NID_rsa> (equivalent to B<EVP_PKEY_RSA2>). The use of
  54. alternative non-standard OIDs is now rare so B<EVP_PKEY_RSA2> et al are not
  55. often seen in practice.
  56. EVP_PKEY_type() returns the underlying type of the NID B<type>. For example
  57. EVP_PKEY_type(EVP_PKEY_RSA2) will return B<EVP_PKEY_RSA>.
  58. EVP_PKEY_set1_engine() sets the ENGINE handling B<pkey> to B<engine>. It
  59. must be called after the key algorithm and components are set up.
  60. If B<engine> does not include an B<EVP_PKEY_METHOD> for B<pkey> an
  61. error occurs.
  62. EVP_PKEY_set_alias_type() allows modifying a EVP_PKEY to use a
  63. different set of algorithms than the default. This is currently used
  64. to support SM2 keys, which use an identical encoding to ECDSA.
  65. =head1 NOTES
  66. In accordance with the OpenSSL naming convention the key obtained
  67. from or assigned to the B<pkey> using the B<1> functions must be
  68. freed as well as B<pkey>.
  69. EVP_PKEY_assign_RSA(), EVP_PKEY_assign_DSA(), EVP_PKEY_assign_DH()
  70. and EVP_PKEY_assign_EC_KEY() are implemented as macros.
  71. Most applications wishing to know a key type will simply call
  72. EVP_PKEY_base_id() and will not care about the actual type:
  73. which will be identical in almost all cases.
  74. Previous versions of this document suggested using EVP_PKEY_type(pkey->type)
  75. to determine the type of a key. Since B<EVP_PKEY> is now opaque this
  76. is no longer possible: the equivalent is EVP_PKEY_base_id(pkey).
  77. EVP_PKEY_set1_engine() is typically used by an ENGINE returning an HSM
  78. key as part of its routine to load a private key.
  79. =head1 EXAMPLES
  80. After loading an ECC key, it is possible to convert it to using SM2
  81. algorithms with EVP_PKEY_set_alias_type:
  82. EVP_PKEY_set_alias_type(pkey, EVP_PKEY_SM2);
  83. =head1 RETURN VALUES
  84. EVP_PKEY_set1_RSA(), EVP_PKEY_set1_DSA(), EVP_PKEY_set1_DH() and
  85. EVP_PKEY_set1_EC_KEY() return 1 for success or 0 for failure.
  86. EVP_PKEY_get1_RSA(), EVP_PKEY_get1_DSA(), EVP_PKEY_get1_DH() and
  87. EVP_PKEY_get1_EC_KEY() return the referenced key or B<NULL> if
  88. an error occurred.
  89. EVP_PKEY_assign_RSA(), EVP_PKEY_assign_DSA(), EVP_PKEY_assign_DH()
  90. and EVP_PKEY_assign_EC_KEY() return 1 for success and 0 for failure.
  91. EVP_PKEY_base_id(), EVP_PKEY_id() and EVP_PKEY_type() return a key
  92. type or B<NID_undef> (equivalently B<EVP_PKEY_NONE>) on error.
  93. EVP_PKEY_set1_engine() returns 1 for success and 0 for failure.
  94. EVP_PKEY_set_alias_type() returns 1 for success and 0 for error.
  95. =head1 SEE ALSO
  96. L<EVP_PKEY_new(3)>
  97. =head1 COPYRIGHT
  98. Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved.
  99. Licensed under the OpenSSL license (the "License"). You may not use
  100. this file except in compliance with the License. You can obtain a copy
  101. in the file LICENSE in the source distribution or at
  102. L<https://www.openssl.org/source/license.html>.
  103. =cut