EVP_CIPHER_meth_new.pod 9.8 KB

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