modes.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. * Copyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the OpenSSL license (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #ifndef HEADER_MODES_H
  10. # define HEADER_MODES_H
  11. # include <stddef.h>
  12. # ifdef __cplusplus
  13. extern "C" {
  14. # endif
  15. typedef void (*block128_f) (const unsigned char in[16],
  16. unsigned char out[16], const void *key);
  17. typedef void (*cbc128_f) (const unsigned char *in, unsigned char *out,
  18. size_t len, const void *key,
  19. unsigned char ivec[16], int enc);
  20. typedef void (*ctr128_f) (const unsigned char *in, unsigned char *out,
  21. size_t blocks, const void *key,
  22. const unsigned char ivec[16]);
  23. typedef void (*ccm128_f) (const unsigned char *in, unsigned char *out,
  24. size_t blocks, const void *key,
  25. const unsigned char ivec[16],
  26. unsigned char cmac[16]);
  27. void CRYPTO_cbc128_encrypt(const unsigned char *in, unsigned char *out,
  28. size_t len, const void *key,
  29. unsigned char ivec[16], block128_f block);
  30. void CRYPTO_cbc128_decrypt(const unsigned char *in, unsigned char *out,
  31. size_t len, const void *key,
  32. unsigned char ivec[16], block128_f block);
  33. void CRYPTO_ctr128_encrypt(const unsigned char *in, unsigned char *out,
  34. size_t len, const void *key,
  35. unsigned char ivec[16],
  36. unsigned char ecount_buf[16], unsigned int *num,
  37. block128_f block);
  38. void CRYPTO_ctr128_encrypt_ctr32(const unsigned char *in, unsigned char *out,
  39. size_t len, const void *key,
  40. unsigned char ivec[16],
  41. unsigned char ecount_buf[16],
  42. unsigned int *num, ctr128_f ctr);
  43. void CRYPTO_ofb128_encrypt(const unsigned char *in, unsigned char *out,
  44. size_t len, const void *key,
  45. unsigned char ivec[16], int *num,
  46. block128_f block);
  47. void CRYPTO_cfb128_encrypt(const unsigned char *in, unsigned char *out,
  48. size_t len, const void *key,
  49. unsigned char ivec[16], int *num,
  50. int enc, block128_f block);
  51. void CRYPTO_cfb128_8_encrypt(const unsigned char *in, unsigned char *out,
  52. size_t length, const void *key,
  53. unsigned char ivec[16], int *num,
  54. int enc, block128_f block);
  55. void CRYPTO_cfb128_1_encrypt(const unsigned char *in, unsigned char *out,
  56. size_t bits, const void *key,
  57. unsigned char ivec[16], int *num,
  58. int enc, block128_f block);
  59. size_t CRYPTO_cts128_encrypt_block(const unsigned char *in,
  60. unsigned char *out, size_t len,
  61. const void *key, unsigned char ivec[16],
  62. block128_f block);
  63. size_t CRYPTO_cts128_encrypt(const unsigned char *in, unsigned char *out,
  64. size_t len, const void *key,
  65. unsigned char ivec[16], cbc128_f cbc);
  66. size_t CRYPTO_cts128_decrypt_block(const unsigned char *in,
  67. unsigned char *out, size_t len,
  68. const void *key, unsigned char ivec[16],
  69. block128_f block);
  70. size_t CRYPTO_cts128_decrypt(const unsigned char *in, unsigned char *out,
  71. size_t len, const void *key,
  72. unsigned char ivec[16], cbc128_f cbc);
  73. size_t CRYPTO_nistcts128_encrypt_block(const unsigned char *in,
  74. unsigned char *out, size_t len,
  75. const void *key,
  76. unsigned char ivec[16],
  77. block128_f block);
  78. size_t CRYPTO_nistcts128_encrypt(const unsigned char *in, unsigned char *out,
  79. size_t len, const void *key,
  80. unsigned char ivec[16], cbc128_f cbc);
  81. size_t CRYPTO_nistcts128_decrypt_block(const unsigned char *in,
  82. unsigned char *out, size_t len,
  83. const void *key,
  84. unsigned char ivec[16],
  85. block128_f block);
  86. size_t CRYPTO_nistcts128_decrypt(const unsigned char *in, unsigned char *out,
  87. size_t len, const void *key,
  88. unsigned char ivec[16], cbc128_f cbc);
  89. typedef struct gcm128_context GCM128_CONTEXT;
  90. GCM128_CONTEXT *CRYPTO_gcm128_new(void *key, block128_f block);
  91. void CRYPTO_gcm128_init(GCM128_CONTEXT *ctx, void *key, block128_f block);
  92. void CRYPTO_gcm128_setiv(GCM128_CONTEXT *ctx, const unsigned char *iv,
  93. size_t len);
  94. int CRYPTO_gcm128_aad(GCM128_CONTEXT *ctx, const unsigned char *aad,
  95. size_t len);
  96. int CRYPTO_gcm128_encrypt(GCM128_CONTEXT *ctx,
  97. const unsigned char *in, unsigned char *out,
  98. size_t len);
  99. int CRYPTO_gcm128_decrypt(GCM128_CONTEXT *ctx,
  100. const unsigned char *in, unsigned char *out,
  101. size_t len);
  102. int CRYPTO_gcm128_encrypt_ctr32(GCM128_CONTEXT *ctx,
  103. const unsigned char *in, unsigned char *out,
  104. size_t len, ctr128_f stream);
  105. int CRYPTO_gcm128_decrypt_ctr32(GCM128_CONTEXT *ctx,
  106. const unsigned char *in, unsigned char *out,
  107. size_t len, ctr128_f stream);
  108. int CRYPTO_gcm128_finish(GCM128_CONTEXT *ctx, const unsigned char *tag,
  109. size_t len);
  110. void CRYPTO_gcm128_tag(GCM128_CONTEXT *ctx, unsigned char *tag, size_t len);
  111. void CRYPTO_gcm128_release(GCM128_CONTEXT *ctx);
  112. typedef struct ccm128_context CCM128_CONTEXT;
  113. void CRYPTO_ccm128_init(CCM128_CONTEXT *ctx,
  114. unsigned int M, unsigned int L, void *key,
  115. block128_f block);
  116. int CRYPTO_ccm128_setiv(CCM128_CONTEXT *ctx, const unsigned char *nonce,
  117. size_t nlen, size_t mlen);
  118. void CRYPTO_ccm128_aad(CCM128_CONTEXT *ctx, const unsigned char *aad,
  119. size_t alen);
  120. int CRYPTO_ccm128_encrypt(CCM128_CONTEXT *ctx, const unsigned char *inp,
  121. unsigned char *out, size_t len);
  122. int CRYPTO_ccm128_decrypt(CCM128_CONTEXT *ctx, const unsigned char *inp,
  123. unsigned char *out, size_t len);
  124. int CRYPTO_ccm128_encrypt_ccm64(CCM128_CONTEXT *ctx, const unsigned char *inp,
  125. unsigned char *out, size_t len,
  126. ccm128_f stream);
  127. int CRYPTO_ccm128_decrypt_ccm64(CCM128_CONTEXT *ctx, const unsigned char *inp,
  128. unsigned char *out, size_t len,
  129. ccm128_f stream);
  130. size_t CRYPTO_ccm128_tag(CCM128_CONTEXT *ctx, unsigned char *tag, size_t len);
  131. typedef struct xts128_context XTS128_CONTEXT;
  132. int CRYPTO_xts128_encrypt(const XTS128_CONTEXT *ctx,
  133. const unsigned char iv[16],
  134. const unsigned char *inp, unsigned char *out,
  135. size_t len, int enc);
  136. size_t CRYPTO_128_wrap(void *key, const unsigned char *iv,
  137. unsigned char *out,
  138. const unsigned char *in, size_t inlen,
  139. block128_f block);
  140. size_t CRYPTO_128_unwrap(void *key, const unsigned char *iv,
  141. unsigned char *out,
  142. const unsigned char *in, size_t inlen,
  143. block128_f block);
  144. size_t CRYPTO_128_wrap_pad(void *key, const unsigned char *icv,
  145. unsigned char *out, const unsigned char *in,
  146. size_t inlen, block128_f block);
  147. size_t CRYPTO_128_unwrap_pad(void *key, const unsigned char *icv,
  148. unsigned char *out, const unsigned char *in,
  149. size_t inlen, block128_f block);
  150. # ifndef OPENSSL_NO_OCB
  151. typedef struct ocb128_context OCB128_CONTEXT;
  152. typedef void (*ocb128_f) (const unsigned char *in, unsigned char *out,
  153. size_t blocks, const void *key,
  154. size_t start_block_num,
  155. unsigned char offset_i[16],
  156. const unsigned char L_[][16],
  157. unsigned char checksum[16]);
  158. OCB128_CONTEXT *CRYPTO_ocb128_new(void *keyenc, void *keydec,
  159. block128_f encrypt, block128_f decrypt,
  160. ocb128_f stream);
  161. int CRYPTO_ocb128_init(OCB128_CONTEXT *ctx, void *keyenc, void *keydec,
  162. block128_f encrypt, block128_f decrypt,
  163. ocb128_f stream);
  164. int CRYPTO_ocb128_copy_ctx(OCB128_CONTEXT *dest, OCB128_CONTEXT *src,
  165. void *keyenc, void *keydec);
  166. int CRYPTO_ocb128_setiv(OCB128_CONTEXT *ctx, const unsigned char *iv,
  167. size_t len, size_t taglen);
  168. int CRYPTO_ocb128_aad(OCB128_CONTEXT *ctx, const unsigned char *aad,
  169. size_t len);
  170. int CRYPTO_ocb128_encrypt(OCB128_CONTEXT *ctx, const unsigned char *in,
  171. unsigned char *out, size_t len);
  172. int CRYPTO_ocb128_decrypt(OCB128_CONTEXT *ctx, const unsigned char *in,
  173. unsigned char *out, size_t len);
  174. int CRYPTO_ocb128_finish(OCB128_CONTEXT *ctx, const unsigned char *tag,
  175. size_t len);
  176. int CRYPTO_ocb128_tag(OCB128_CONTEXT *ctx, unsigned char *tag, size_t len);
  177. void CRYPTO_ocb128_cleanup(OCB128_CONTEXT *ctx);
  178. # endif /* OPENSSL_NO_OCB */
  179. # ifdef __cplusplus
  180. }
  181. # endif
  182. #endif