EVP_CIPHER_meth_new.pod 9.6 KB

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