2
0

EVP_PKEY_CTX_ctrl.pod 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. =pod
  2. =head1 NAME
  3. EVP_PKEY_CTX_ctrl,
  4. EVP_PKEY_CTX_ctrl_str,
  5. EVP_PKEY_CTX_set_signature_md,
  6. EVP_PKEY_CTX_get_signature_md,
  7. EVP_PKEY_CTX_set_mac_key,
  8. EVP_PKEY_CTX_set_rsa_padding,
  9. EVP_PKEY_CTX_set_rsa_pss_saltlen,
  10. EVP_PKEY_CTX_set_rsa_keygen_bits,
  11. EVP_PKEY_CTX_set_rsa_keygen_pubexp,
  12. EVP_PKEY_CTX_set_dsa_paramgen_bits,
  13. EVP_PKEY_CTX_set_dh_paramgen_prime_len,
  14. EVP_PKEY_CTX_set_dh_paramgen_generator,
  15. EVP_PKEY_CTX_set_dh_pad,
  16. EVP_PKEY_CTX_set_dh_nid,
  17. EVP_PKEY_CTX_set_ec_paramgen_curve_nid,
  18. EVP_PKEY_CTX_set_ec_param_enc - algorithm specific control operations
  19. =head1 SYNOPSIS
  20. #include <openssl/evp.h>
  21. int EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX *ctx, int keytype, int optype,
  22. int cmd, int p1, void *p2);
  23. int EVP_PKEY_CTX_ctrl_str(EVP_PKEY_CTX *ctx, const char *type,
  24. const char *value);
  25. int EVP_PKEY_CTX_set_signature_md(EVP_PKEY_CTX *ctx, const EVP_MD *md);
  26. int EVP_PKEY_CTX_get_signature_md(EVP_PKEY_CTX *ctx, const EVP_MD **pmd);
  27. int EVP_PKEY_CTX_set_mac_key(EVP_PKEY_CTX *ctx, unsigned char *key, int len);
  28. #include <openssl/rsa.h>
  29. int EVP_PKEY_CTX_set_rsa_padding(EVP_PKEY_CTX *ctx, int pad);
  30. int EVP_PKEY_CTX_set_rsa_pss_saltlen(EVP_PKEY_CTX *ctx, int len);
  31. int EVP_PKEY_CTX_set_rsa_keygen_bits(EVP_PKEY_CTX *ctx, int mbits);
  32. int EVP_PKEY_CTX_set_rsa_keygen_pubexp(EVP_PKEY_CTX *ctx, BIGNUM *pubexp);
  33. #include <openssl/dsa.h>
  34. int EVP_PKEY_CTX_set_dsa_paramgen_bits(EVP_PKEY_CTX *ctx, int nbits);
  35. #include <openssl/dh.h>
  36. int EVP_PKEY_CTX_set_dh_paramgen_prime_len(EVP_PKEY_CTX *ctx, int len);
  37. int EVP_PKEY_CTX_set_dh_paramgen_generator(EVP_PKEY_CTX *ctx, int gen);
  38. int EVP_PKEY_CTX_set_dh_pad(EVP_PKEY_CTX *ctx, int pad);
  39. int EVP_PKEY_CTX_set_dh_nid(EVP_PKEY_CTX *ctx, int nid);
  40. #include <openssl/ec.h>
  41. int EVP_PKEY_CTX_set_ec_paramgen_curve_nid(EVP_PKEY_CTX *ctx, int nid);
  42. int EVP_PKEY_CTX_set_ec_param_enc(EVP_PKEY_CTX *ctx, int param_enc);
  43. =head1 DESCRIPTION
  44. The function EVP_PKEY_CTX_ctrl() sends a control operation to the context
  45. B<ctx>. The key type used must match B<keytype> if it is not -1. The parameter
  46. B<optype> is a mask indicating which operations the control can be applied to.
  47. The control command is indicated in B<cmd> and any additional arguments in
  48. B<p1> and B<p2>.
  49. For B<cmd> = B<EVP_PKEY_CTRL_SET_MAC_KEY>, B<p1> is the length of the MAC key,
  50. and B<p2> is MAC key. This is used by Poly1305, SipHash, HMAC and CMAC.
  51. Applications will not normally call EVP_PKEY_CTX_ctrl() directly but will
  52. instead call one of the algorithm specific macros below.
  53. The function EVP_PKEY_CTX_ctrl_str() allows an application to send an algorithm
  54. specific control operation to a context B<ctx> in string form. This is
  55. intended to be used for options specified on the command line or in text
  56. files. The commands supported are documented in the openssl utility
  57. command line pages for the option B<-pkeyopt> which is supported by the
  58. B<pkeyutl>, B<genpkey> and B<req> commands.
  59. All the remaining "functions" are implemented as macros.
  60. The EVP_PKEY_CTX_set_signature_md() macro sets the message digest type used
  61. in a signature. It can be used in the RSA, DSA and ECDSA algorithms.
  62. The EVP_PKEY_CTX_get_signature_md() macro gets the message digest type used in a
  63. signature. It can be used in the RSA, DSA and ECDSA algorithms.
  64. Key generation typically involves setting up parameters to be used and
  65. generating the private and public key data. Some algorithm implementations
  66. allow private key data to be set explicitly using the EVP_PKEY_CTX_set_mac_key()
  67. macro. In this case key generation is simply the process of setting up the
  68. parameters for the key and then setting the raw key data to the value explicitly
  69. provided by that macro. Normally applications would call
  70. L<EVP_PKEY_new_raw_private_key(3)> or similar functions instead of this macro.
  71. The EVP_PKEY_CTX_set_mac_key() macro can be used with any of the algorithms
  72. supported by the L<EVP_PKEY_new_raw_private_key(3)> function.
  73. The macro EVP_PKEY_CTX_set_rsa_padding() sets the RSA padding mode for B<ctx>.
  74. The B<pad> parameter can take the value RSA_PKCS1_PADDING for PKCS#1 padding,
  75. RSA_SSLV23_PADDING for SSLv23 padding, RSA_NO_PADDING for no padding,
  76. RSA_PKCS1_OAEP_PADDING for OAEP padding (encrypt and decrypt only),
  77. RSA_X931_PADDING for X9.31 padding (signature operations only) and
  78. RSA_PKCS1_PSS_PADDING (sign and verify only).
  79. Two RSA padding modes behave differently if EVP_PKEY_CTX_set_signature_md()
  80. is used. If this macro is called for PKCS#1 padding the plaintext buffer is
  81. an actual digest value and is encapsulated in a DigestInfo structure according
  82. to PKCS#1 when signing and this structure is expected (and stripped off) when
  83. verifying. If this control is not used with RSA and PKCS#1 padding then the
  84. supplied data is used directly and not encapsulated. In the case of X9.31
  85. padding for RSA the algorithm identifier byte is added or checked and removed
  86. if this control is called. If it is not called then the first byte of the plaintext
  87. buffer is expected to be the algorithm identifier byte.
  88. The EVP_PKEY_CTX_set_rsa_pss_saltlen() macro sets the RSA PSS salt length to
  89. B<len> as its name implies it is only supported for PSS padding. Three special
  90. values are supported: RSA_PSS_SALTLEN_DIGEST sets the salt length to the
  91. digest length, RSA_PSS_SALTLEN_MAX sets the salt length to the maximum
  92. permissible value. When verifying RSA_PSS_SALTLEN_AUTO causes the salt length
  93. to be automatically determined based on the B<PSS> block structure. If this
  94. macro is not called maximum salt length is used when signing and auto detection
  95. when verifying is used by default.
  96. The EVP_PKEY_CTX_set_rsa_keygen_bits() macro sets the RSA key length for
  97. RSA key generation to B<bits>. If not specified 1024 bits is used.
  98. The EVP_PKEY_CTX_set_rsa_keygen_pubexp() macro sets the public exponent value
  99. for RSA key generation to B<pubexp> currently it should be an odd integer. The
  100. B<pubexp> pointer is used internally by this function so it should not be
  101. modified or free after the call. If this macro is not called then 65537 is used.
  102. The macro EVP_PKEY_CTX_set_dsa_paramgen_bits() sets the number of bits used
  103. for DSA parameter generation to B<bits>. If not specified 1024 is used.
  104. The macro EVP_PKEY_CTX_set_dh_paramgen_prime_len() sets the length of the DH
  105. prime parameter B<p> for DH parameter generation. If this macro is not called
  106. then 1024 is used.
  107. The EVP_PKEY_CTX_set_dh_paramgen_generator() macro sets DH generator to B<gen>
  108. for DH parameter generation. If not specified 2 is used.
  109. The EVP_PKEY_CTX_set_dh_pad() macro sets the DH padding mode. If B<pad> is
  110. 1 the shared secret is padded with zeroes up to the size of the DH prime B<p>.
  111. If B<pad> is zero (the default) then no padding is performed.
  112. EVP_PKEY_CTX_set_dh_nid() sets the DH parameters to values corresponding to
  113. B<nid>. The B<nid> parameter must be B<NID_ffdhe2048>, B<NID_ffdhe3072>,
  114. B<NID_ffdhe4096>, B<NID_ffdhe6144> or B<NID_ffdhe8192>. This macro can be
  115. called during parameter or key generation.
  116. The EVP_PKEY_CTX_set_ec_paramgen_curve_nid() sets the EC curve for EC parameter
  117. generation to B<nid>. For EC parameter generation this macro must be called
  118. or an error occurs because there is no default curve.
  119. This function can also be called to set the curve explicitly when
  120. generating an EC key.
  121. The EVP_PKEY_CTX_set_ec_param_enc() sets the EC parameter encoding to
  122. B<param_enc> when generating EC parameters or an EC key. The encoding can be
  123. B<OPENSSL_EC_EXPLICIT_CURVE> for explicit parameters (the default in versions
  124. of OpenSSL before 1.1.0) or B<OPENSSL_EC_NAMED_CURVE> to use named curve form.
  125. For maximum compatibility the named curve form should be used. Note: the
  126. B<OPENSSL_EC_NAMED_CURVE> value was only added to OpenSSL 1.1.0; previous
  127. versions should use 0 instead.
  128. =head1 RETURN VALUES
  129. EVP_PKEY_CTX_ctrl() and its macros return a positive value for success and 0
  130. or a negative value for failure. In particular a return value of -2
  131. indicates the operation is not supported by the public key algorithm.
  132. =head1 SEE ALSO
  133. L<EVP_PKEY_CTX_new(3)>,
  134. L<EVP_PKEY_encrypt(3)>,
  135. L<EVP_PKEY_decrypt(3)>,
  136. L<EVP_PKEY_sign(3)>,
  137. L<EVP_PKEY_verify(3)>,
  138. L<EVP_PKEY_verify_recover(3)>,
  139. L<EVP_PKEY_derive(3)>
  140. L<EVP_PKEY_keygen(3)>
  141. =head1 HISTORY
  142. These functions were first added to OpenSSL 1.0.0.
  143. =head1 COPYRIGHT
  144. Copyright 2006-2018 The OpenSSL Project Authors. All Rights Reserved.
  145. Licensed under the OpenSSL license (the "License"). You may not use
  146. this file except in compliance with the License. You can obtain a copy
  147. in the file LICENSE in the source distribution or at
  148. L<https://www.openssl.org/source/license.html>.
  149. =cut