EVP_CIPHER_meth_new.pod 10 KB

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