EVP_CIPHER_meth_new.pod 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. =pod
  2. =head1 NAME
  3. EVP_CIPHER_meth_new, EVP_CIPHER_meth_dup, EVP_CIPHER_meth_free,
  4. EVP_CIPHER_meth_set_iv_length, EVP_CIPHER_meth_set_flags,
  5. EVP_CIPHER_meth_set_impl_ctx_size, EVP_CIPHER_meth_set_init,
  6. EVP_CIPHER_meth_set_do_cipher, EVP_CIPHER_meth_set_cleanup,
  7. EVP_CIPHER_meth_set_set_asn1_params, EVP_CIPHER_meth_set_get_asn1_params,
  8. EVP_CIPHER_meth_set_ctrl, EVP_CIPHER_meth_get_init,
  9. EVP_CIPHER_meth_get_do_cipher, EVP_CIPHER_meth_get_cleanup,
  10. EVP_CIPHER_meth_get_set_asn1_params, EVP_CIPHER_meth_get_get_asn1_params,
  11. EVP_CIPHER_meth_get_ctrl
  12. - Routines to build up EVP_CIPHER methods
  13. =head1 SYNOPSIS
  14. #include <openssl/evp.h>
  15. The following functions have been deprecated since OpenSSL 3.0, and can be
  16. hidden entirely by defining B<OPENSSL_API_COMPAT> with a suitable version value,
  17. see L<openssl_user_macros(7)>:
  18. EVP_CIPHER *EVP_CIPHER_meth_new(int cipher_type, int block_size, int key_len);
  19. EVP_CIPHER *EVP_CIPHER_meth_dup(const EVP_CIPHER *cipher);
  20. void EVP_CIPHER_meth_free(EVP_CIPHER *cipher);
  21. int EVP_CIPHER_meth_set_iv_length(EVP_CIPHER *cipher, int iv_len);
  22. int EVP_CIPHER_meth_set_flags(EVP_CIPHER *cipher, unsigned long flags);
  23. int EVP_CIPHER_meth_set_impl_ctx_size(EVP_CIPHER *cipher, int ctx_size);
  24. int EVP_CIPHER_meth_set_init(EVP_CIPHER *cipher,
  25. int (*init)(EVP_CIPHER_CTX *ctx,
  26. const unsigned char *key,
  27. const unsigned char *iv,
  28. int enc));
  29. int EVP_CIPHER_meth_set_do_cipher(EVP_CIPHER *cipher,
  30. int (*do_cipher)(EVP_CIPHER_CTX *ctx,
  31. unsigned char *out,
  32. const unsigned char *in,
  33. size_t inl));
  34. int EVP_CIPHER_meth_set_cleanup(EVP_CIPHER *cipher,
  35. int (*cleanup)(EVP_CIPHER_CTX *));
  36. int EVP_CIPHER_meth_set_set_asn1_params(EVP_CIPHER *cipher,
  37. int (*set_asn1_parameters)(EVP_CIPHER_CTX *,
  38. ASN1_TYPE *));
  39. int EVP_CIPHER_meth_set_get_asn1_params(EVP_CIPHER *cipher,
  40. int (*get_asn1_parameters)(EVP_CIPHER_CTX *,
  41. ASN1_TYPE *));
  42. int EVP_CIPHER_meth_set_ctrl(EVP_CIPHER *cipher,
  43. int (*ctrl)(EVP_CIPHER_CTX *, int type,
  44. int arg, void *ptr));
  45. int (*EVP_CIPHER_meth_get_init(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *ctx,
  46. const unsigned char *key,
  47. const unsigned char *iv,
  48. int enc);
  49. int (*EVP_CIPHER_meth_get_do_cipher(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *ctx,
  50. unsigned char *out,
  51. const unsigned char *in,
  52. size_t inl);
  53. int (*EVP_CIPHER_meth_get_cleanup(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *);
  54. int (*EVP_CIPHER_meth_get_set_asn1_params(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *,
  55. ASN1_TYPE *);
  56. int (*EVP_CIPHER_meth_get_get_asn1_params(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *,
  57. ASN1_TYPE *);
  58. int (*EVP_CIPHER_meth_get_ctrl(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *,
  59. int type, int arg,
  60. void *ptr);
  61. =head1 DESCRIPTION
  62. All of the functions described on this page are deprecated.
  63. Applications should instead use the OSSL_PROVIDER APIs.
  64. The B<EVP_CIPHER> type is a structure for symmetric cipher method
  65. implementation.
  66. EVP_CIPHER_meth_new() creates a new B<EVP_CIPHER> structure.
  67. EVP_CIPHER_meth_dup() creates a copy of B<cipher>.
  68. EVP_CIPHER_meth_free() destroys a B<EVP_CIPHER> structure.
  69. If the argument is NULL, nothing is done.
  70. EVP_CIPHER_meth_set_iv_length() sets the length of the IV.
  71. This is only needed when the implemented cipher mode requires it.
  72. EVP_CIPHER_meth_set_flags() sets the flags to describe optional
  73. behaviours in the particular B<cipher>.
  74. With the exception of cipher modes, of which only one may be present,
  75. several flags can be or'd together.
  76. The available flags are:
  77. =over 4
  78. =item EVP_CIPH_STREAM_CIPHER, EVP_CIPH_ECB_MODE EVP_CIPH_CBC_MODE,
  79. EVP_CIPH_CFB_MODE, EVP_CIPH_OFB_MODE, EVP_CIPH_CTR_MODE, EVP_CIPH_GCM_MODE,
  80. EVP_CIPH_CCM_MODE, EVP_CIPH_XTS_MODE, EVP_CIPH_WRAP_MODE,
  81. EVP_CIPH_OCB_MODE, EVP_CIPH_SIV_MODE
  82. The cipher mode.
  83. =item EVP_CIPH_VARIABLE_LENGTH
  84. This cipher is of variable length.
  85. =item EVP_CIPH_CUSTOM_IV
  86. Storing and initialising the IV is left entirely to the
  87. implementation.
  88. =item EVP_CIPH_ALWAYS_CALL_INIT
  89. Set this if the implementation's init() function should be called even
  90. if B<key> is B<NULL>.
  91. =item EVP_CIPH_CTRL_INIT
  92. Set this to have the implementation's ctrl() function called with
  93. command code B<EVP_CTRL_INIT> early in its setup.
  94. =item EVP_CIPH_CUSTOM_KEY_LENGTH
  95. Checking and setting the key length after creating the B<EVP_CIPHER>
  96. is left to the implementation.
  97. Whenever someone uses EVP_CIPHER_CTX_set_key_length() on a
  98. B<EVP_CIPHER> with this flag set, the implementation's ctrl() function
  99. will be called with the control code B<EVP_CTRL_SET_KEY_LENGTH> and
  100. the key length in B<arg>.
  101. =item EVP_CIPH_NO_PADDING
  102. Don't use standard block padding.
  103. =item EVP_CIPH_RAND_KEY
  104. Making a key with random content is left to the implementation.
  105. This is done by calling the implementation's ctrl() function with the
  106. control code B<EVP_CTRL_RAND_KEY> and the pointer to the key memory
  107. storage in B<ptr>.
  108. =item EVP_CIPH_CUSTOM_COPY
  109. Set this to have the implementation's ctrl() function called with
  110. command code B<EVP_CTRL_COPY> at the end of EVP_CIPHER_CTX_copy().
  111. The intended use is for further things to deal with after the
  112. implementation specific data block has been copied.
  113. The destination B<EVP_CIPHER_CTX> is passed to the control with the
  114. B<ptr> parameter.
  115. The implementation specific data block is reached with
  116. EVP_CIPHER_CTX_get_cipher_data().
  117. =item EVP_CIPH_FLAG_DEFAULT_ASN1
  118. Use the default EVP routines to pass IV to and from ASN.1.
  119. =item EVP_CIPH_FLAG_LENGTH_BITS
  120. Signals that the length of the input buffer for encryption /
  121. decryption is to be understood as the number of bits instead of
  122. bytes for this implementation.
  123. This is only useful for CFB1 ciphers.
  124. =item EVP_CIPH_FLAG_CTS
  125. Indicates that the cipher uses ciphertext stealing. This is currently
  126. used to indicate that the cipher is a one shot that only allows a single call to
  127. EVP_CipherUpdate().
  128. =item EVP_CIPH_FLAG_CUSTOM_CIPHER
  129. This indicates that the implementation takes care of everything,
  130. including padding, buffering and finalization.
  131. The EVP routines will simply give them control and do nothing more.
  132. =item EVP_CIPH_FLAG_AEAD_CIPHER
  133. This indicates that this is an AEAD cipher implementation.
  134. =item EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK
  135. Allow interleaving of crypto blocks, a particular optimization only applicable
  136. to certain TLS ciphers.
  137. =back
  138. EVP_CIPHER_meth_set_impl_ctx_size() sets the size of the EVP_CIPHER's
  139. implementation context so that it can be automatically allocated.
  140. EVP_CIPHER_meth_set_init() sets the cipher init function for
  141. B<cipher>.
  142. The cipher init function is called by EVP_CipherInit(),
  143. EVP_CipherInit_ex(), EVP_EncryptInit(), EVP_EncryptInit_ex(),
  144. EVP_DecryptInit(), EVP_DecryptInit_ex().
  145. EVP_CIPHER_meth_set_do_cipher() sets the cipher function for
  146. B<cipher>.
  147. The cipher function is called by EVP_CipherUpdate(),
  148. EVP_EncryptUpdate(), EVP_DecryptUpdate(), EVP_CipherFinal(),
  149. EVP_EncryptFinal(), EVP_EncryptFinal_ex(), EVP_DecryptFinal() and
  150. EVP_DecryptFinal_ex().
  151. EVP_CIPHER_meth_set_cleanup() sets the function for B<cipher> to do
  152. extra cleanup before the method's private data structure is cleaned
  153. out and freed.
  154. Note that the cleanup function is passed a B<EVP_CIPHER_CTX *>, the
  155. private data structure is then available with
  156. EVP_CIPHER_CTX_get_cipher_data().
  157. This cleanup function is called by EVP_CIPHER_CTX_reset() and
  158. EVP_CIPHER_CTX_free().
  159. EVP_CIPHER_meth_set_set_asn1_params() sets the function for B<cipher>
  160. to set the AlgorithmIdentifier "parameter" based on the passed cipher.
  161. This function is called by EVP_CIPHER_param_to_asn1().
  162. EVP_CIPHER_meth_set_get_asn1_params() sets the function for B<cipher>
  163. that sets the cipher parameters based on an ASN.1 AlgorithmIdentifier
  164. "parameter".
  165. Both these functions are needed when there is a need for custom data
  166. (more or other than the cipher IV).
  167. They are called by EVP_CIPHER_param_to_asn1() and
  168. EVP_CIPHER_asn1_to_param() respectively if defined.
  169. EVP_CIPHER_meth_set_ctrl() sets the control function for B<cipher>.
  170. EVP_CIPHER_meth_get_init(), EVP_CIPHER_meth_get_do_cipher(),
  171. EVP_CIPHER_meth_get_cleanup(), EVP_CIPHER_meth_get_set_asn1_params(),
  172. EVP_CIPHER_meth_get_get_asn1_params() and EVP_CIPHER_meth_get_ctrl()
  173. are all used to retrieve the method data given with the
  174. EVP_CIPHER_meth_set_*() functions above.
  175. =head1 RETURN VALUES
  176. EVP_CIPHER_meth_new() and EVP_CIPHER_meth_dup() return a pointer to a
  177. newly created B<EVP_CIPHER>, or NULL on failure.
  178. All EVP_CIPHER_meth_set_*() functions return 1.
  179. All EVP_CIPHER_meth_get_*() functions return pointers to their
  180. respective B<cipher> function.
  181. =head1 SEE ALSO
  182. L<EVP_EncryptInit(3)>
  183. =head1 HISTORY
  184. All of these functions were deprecated in OpenSSL 3.0.
  185. The functions described here were added in OpenSSL 1.1.0.
  186. The B<EVP_CIPHER> structure created with these functions became reference
  187. counted in OpenSSL 3.0.
  188. =head1 COPYRIGHT
  189. Copyright 2016-2024 The OpenSSL Project Authors. All Rights Reserved.
  190. Licensed under the Apache License 2.0 (the "License"). You may not use
  191. this file except in compliance with the License. You can obtain a copy
  192. in the file LICENSE in the source distribution or at
  193. L<https://www.openssl.org/source/license.html>.
  194. =cut