EVP_PKEY_CTX_new.pod 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. =pod
  2. =head1 NAME
  3. EVP_PKEY_CTX_new, EVP_PKEY_CTX_new_id, EVP_PKEY_CTX_new_from_name,
  4. EVP_PKEY_CTX_new_from_pkey, EVP_PKEY_CTX_dup, EVP_PKEY_CTX_free,
  5. EVP_PKEY_CTX_is_a
  6. - public key algorithm context functions
  7. =head1 SYNOPSIS
  8. #include <openssl/evp.h>
  9. EVP_PKEY_CTX *EVP_PKEY_CTX_new(EVP_PKEY *pkey, ENGINE *e);
  10. EVP_PKEY_CTX *EVP_PKEY_CTX_new_id(int id, ENGINE *e);
  11. EVP_PKEY_CTX *EVP_PKEY_CTX_new_from_name(OSSL_LIB_CTX *libctx,
  12. const char *name,
  13. const char *propquery);
  14. EVP_PKEY_CTX *EVP_PKEY_CTX_new_from_pkey(OSSL_LIB_CTX *libctx,
  15. EVP_PKEY *pkey,
  16. const char *propquery);
  17. EVP_PKEY_CTX *EVP_PKEY_CTX_dup(const EVP_PKEY_CTX *ctx);
  18. void EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx);
  19. int EVP_PKEY_CTX_is_a(EVP_PKEY_CTX *ctx, const char *keytype);
  20. =head1 DESCRIPTION
  21. The EVP_PKEY_CTX_new() function allocates public key algorithm context using
  22. the I<pkey> key type and ENGINE I<e>.
  23. The EVP_PKEY_CTX_new_id() function allocates public key algorithm context
  24. using the key type specified by I<id> and ENGINE I<e>.
  25. The EVP_PKEY_CTX_new_from_name() function allocates a public key algorithm
  26. context using the library context I<libctx> (see L<OSSL_LIB_CTX(3)>), the
  27. key type specified by I<name> and the property query I<propquery>. None
  28. of the arguments are duplicated, so they must remain unchanged for the
  29. lifetime of the returned B<EVP_PKEY_CTX> or of any of its duplicates. Read
  30. further about the possible names in L</NOTES> below.
  31. The EVP_PKEY_CTX_new_from_pkey() function allocates a public key algorithm
  32. context using the library context I<libctx> (see L<OSSL_LIB_CTX(3)>) and the
  33. algorithm specified by I<pkey> and the property query I<propquery>. None of the
  34. arguments are duplicated, so they must remain unchanged for the lifetime of the
  35. returned B<EVP_PKEY_CTX> or any of its duplicates.
  36. EVP_PKEY_CTX_new_id() and EVP_PKEY_CTX_new_from_name() are normally
  37. used when no B<EVP_PKEY> structure is associated with the operations,
  38. for example during parameter generation or key generation for some
  39. algorithms.
  40. EVP_PKEY_CTX_dup() duplicates the context I<ctx>.
  41. It is not supported for a keygen operation.
  42. It is however possible to duplicate a context freshly created via any of the
  43. above C<new> functions, provided L<EVP_PKEY_keygen_init(3)> has not yet been
  44. called on the source context, and then use the copy for key generation.
  45. EVP_PKEY_CTX_free() frees up the context I<ctx>.
  46. If I<ctx> is NULL, nothing is done.
  47. EVP_PKEY_is_a() checks if the key type associated with I<ctx> is I<keytype>.
  48. =head1 NOTES
  49. =head2 On B<EVP_PKEY_CTX>
  50. The B<EVP_PKEY_CTX> structure is an opaque public key algorithm context used
  51. by the OpenSSL high-level public key API. Contexts B<MUST NOT> be shared between
  52. threads: that is it is not permissible to use the same context simultaneously
  53. in two threads.
  54. =head2 On Key Types
  55. We mention "key type" in this manual, which is the same
  56. as "algorithm" in most cases, allowing either term to be used
  57. interchangeably. There are algorithms where the I<key type> and the
  58. I<algorithm> of the operations that use the keys are not the same,
  59. such as EC keys being used for ECDSA and ECDH operations.
  60. Key types are given in two different manners:
  61. =over 4
  62. =item Legacy NID or EVP_PKEY type
  63. This is the I<id> used with EVP_PKEY_CTX_new_id().
  64. These are B<EVP_PKEY_RSA>, B<EVP_PKEY_RSA_PSS>, B<EVP_PKEY_DSA>,
  65. B<EVP_PKEY_DH>, B<EVP_PKEY_EC>, B<EVP_PKEY_SM2>, B<EVP_PKEY_X25519>,
  66. B<EVP_PKEY_X448>, and are used by legacy methods.
  67. =item Name strings
  68. This is the I<name> used with EVP_PKEY_CTX_new_from_name().
  69. These are names like "RSA", "DSA", and what's available depends on what
  70. providers are currently accessible.
  71. The OpenSSL providers offer a set of key types available this way, please
  72. see L<OSSL_PROVIDER-FIPS(7)> and L<OSSL_PROVIDER-default(7)> and related
  73. documentation for more information.
  74. =back
  75. =head1 RETURN VALUES
  76. EVP_PKEY_CTX_new(), EVP_PKEY_CTX_new_id() and EVP_PKEY_CTX_dup() return either
  77. the newly allocated B<EVP_PKEY_CTX> structure or B<NULL> if an error occurred.
  78. EVP_PKEY_CTX_free() does not return a value.
  79. EVP_PKEY_CTX_is_a() returns 1 for true and 0 for false.
  80. =head1 SEE ALSO
  81. L<EVP_PKEY_new(3)>
  82. =head1 HISTORY
  83. The EVP_PKEY_CTX_new(), EVP_PKEY_CTX_new_id(), EVP_PKEY_CTX_dup() and
  84. EVP_PKEY_CTX_free() functions were added in OpenSSL 1.0.0.
  85. The EVP_PKEY_CTX_new_from_name() and EVP_PKEY_CTX_new_from_pkey() functions were
  86. added in OpenSSL 3.0.
  87. =head1 COPYRIGHT
  88. Copyright 2006-2025 The OpenSSL Project Authors. All Rights Reserved.
  89. Licensed under the Apache License 2.0 (the "License"). You may not use
  90. this file except in compliance with the License. You can obtain a copy
  91. in the file LICENSE in the source distribution or at
  92. L<https://www.openssl.org/source/license.html>.
  93. =cut