modes.h 10 KB

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