modes.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /* ====================================================================
  2. * Copyright (c) 2008 The OpenSSL Project. All rights reserved.
  3. *
  4. * Rights for redistribution and usage in source and binary
  5. * forms are granted according to the OpenSSL license.
  6. */
  7. #include <stddef.h>
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. typedef void (*block128_f) (const unsigned char in[16],
  12. unsigned char out[16], const void *key);
  13. typedef void (*cbc128_f) (const unsigned char *in, unsigned char *out,
  14. size_t len, const void *key,
  15. unsigned char ivec[16], int enc);
  16. typedef void (*ctr128_f) (const unsigned char *in, unsigned char *out,
  17. size_t blocks, const void *key,
  18. const unsigned char ivec[16]);
  19. typedef void (*ccm128_f) (const unsigned char *in, unsigned char *out,
  20. size_t blocks, const void *key,
  21. const unsigned char ivec[16],
  22. unsigned char cmac[16]);
  23. void CRYPTO_cbc128_encrypt(const unsigned char *in, unsigned char *out,
  24. size_t len, const void *key,
  25. unsigned char ivec[16], block128_f block);
  26. void CRYPTO_cbc128_decrypt(const unsigned char *in, unsigned char *out,
  27. size_t len, const void *key,
  28. unsigned char ivec[16], block128_f block);
  29. void CRYPTO_ctr128_encrypt(const unsigned char *in, unsigned char *out,
  30. size_t len, const void *key,
  31. unsigned char ivec[16],
  32. unsigned char ecount_buf[16], unsigned int *num,
  33. block128_f block);
  34. void CRYPTO_ctr128_encrypt_ctr32(const unsigned char *in, unsigned char *out,
  35. size_t len, const void *key,
  36. unsigned char ivec[16],
  37. unsigned char ecount_buf[16],
  38. unsigned int *num, ctr128_f ctr);
  39. void CRYPTO_ofb128_encrypt(const unsigned char *in, unsigned char *out,
  40. size_t len, const void *key,
  41. unsigned char ivec[16], int *num,
  42. block128_f block);
  43. void CRYPTO_cfb128_encrypt(const unsigned char *in, unsigned char *out,
  44. size_t len, const void *key,
  45. unsigned char ivec[16], int *num,
  46. int enc, block128_f block);
  47. void CRYPTO_cfb128_8_encrypt(const unsigned char *in, unsigned char *out,
  48. size_t length, const void *key,
  49. unsigned char ivec[16], int *num,
  50. int enc, block128_f block);
  51. void CRYPTO_cfb128_1_encrypt(const unsigned char *in, unsigned char *out,
  52. size_t bits, const void *key,
  53. unsigned char ivec[16], int *num,
  54. int enc, block128_f block);
  55. size_t CRYPTO_cts128_encrypt_block(const unsigned char *in,
  56. unsigned char *out, size_t len,
  57. const void *key, unsigned char ivec[16],
  58. block128_f block);
  59. size_t CRYPTO_cts128_encrypt(const unsigned char *in, unsigned char *out,
  60. size_t len, const void *key,
  61. unsigned char ivec[16], cbc128_f cbc);
  62. size_t CRYPTO_cts128_decrypt_block(const unsigned char *in,
  63. unsigned char *out, size_t len,
  64. const void *key, unsigned char ivec[16],
  65. block128_f block);
  66. size_t CRYPTO_cts128_decrypt(const unsigned char *in, unsigned char *out,
  67. size_t len, const void *key,
  68. unsigned char ivec[16], cbc128_f cbc);
  69. size_t CRYPTO_nistcts128_encrypt_block(const unsigned char *in,
  70. unsigned char *out, size_t len,
  71. const void *key,
  72. unsigned char ivec[16],
  73. block128_f block);
  74. size_t CRYPTO_nistcts128_encrypt(const unsigned char *in, unsigned char *out,
  75. size_t len, const void *key,
  76. unsigned char ivec[16], cbc128_f cbc);
  77. size_t CRYPTO_nistcts128_decrypt_block(const unsigned char *in,
  78. unsigned char *out, size_t len,
  79. const void *key,
  80. unsigned char ivec[16],
  81. block128_f block);
  82. size_t CRYPTO_nistcts128_decrypt(const unsigned char *in, unsigned char *out,
  83. size_t len, const void *key,
  84. unsigned char ivec[16], cbc128_f cbc);
  85. typedef struct gcm128_context GCM128_CONTEXT;
  86. GCM128_CONTEXT *CRYPTO_gcm128_new(void *key, block128_f block);
  87. void CRYPTO_gcm128_init(GCM128_CONTEXT *ctx, void *key, block128_f block);
  88. void CRYPTO_gcm128_setiv(GCM128_CONTEXT *ctx, const unsigned char *iv,
  89. size_t len);
  90. int CRYPTO_gcm128_aad(GCM128_CONTEXT *ctx, const unsigned char *aad,
  91. size_t len);
  92. int CRYPTO_gcm128_encrypt(GCM128_CONTEXT *ctx,
  93. const unsigned char *in, unsigned char *out,
  94. size_t len);
  95. int CRYPTO_gcm128_decrypt(GCM128_CONTEXT *ctx,
  96. const unsigned char *in, unsigned char *out,
  97. size_t len);
  98. int CRYPTO_gcm128_encrypt_ctr32(GCM128_CONTEXT *ctx,
  99. const unsigned char *in, unsigned char *out,
  100. size_t len, ctr128_f stream);
  101. int CRYPTO_gcm128_decrypt_ctr32(GCM128_CONTEXT *ctx,
  102. const unsigned char *in, unsigned char *out,
  103. size_t len, ctr128_f stream);
  104. int CRYPTO_gcm128_finish(GCM128_CONTEXT *ctx, const unsigned char *tag,
  105. size_t len);
  106. void CRYPTO_gcm128_tag(GCM128_CONTEXT *ctx, unsigned char *tag, size_t len);
  107. void CRYPTO_gcm128_release(GCM128_CONTEXT *ctx);
  108. typedef struct ccm128_context CCM128_CONTEXT;
  109. void CRYPTO_ccm128_init(CCM128_CONTEXT *ctx,
  110. unsigned int M, unsigned int L, void *key,
  111. block128_f block);
  112. int CRYPTO_ccm128_setiv(CCM128_CONTEXT *ctx, const unsigned char *nonce,
  113. size_t nlen, size_t mlen);
  114. void CRYPTO_ccm128_aad(CCM128_CONTEXT *ctx, const unsigned char *aad,
  115. size_t alen);
  116. int CRYPTO_ccm128_encrypt(CCM128_CONTEXT *ctx, const unsigned char *inp,
  117. unsigned char *out, size_t len);
  118. int CRYPTO_ccm128_decrypt(CCM128_CONTEXT *ctx, const unsigned char *inp,
  119. unsigned char *out, size_t len);
  120. int CRYPTO_ccm128_encrypt_ccm64(CCM128_CONTEXT *ctx, const unsigned char *inp,
  121. unsigned char *out, size_t len,
  122. ccm128_f stream);
  123. int CRYPTO_ccm128_decrypt_ccm64(CCM128_CONTEXT *ctx, const unsigned char *inp,
  124. unsigned char *out, size_t len,
  125. ccm128_f stream);
  126. size_t CRYPTO_ccm128_tag(CCM128_CONTEXT *ctx, unsigned char *tag, size_t len);
  127. typedef struct xts128_context XTS128_CONTEXT;
  128. int CRYPTO_xts128_encrypt(const XTS128_CONTEXT *ctx,
  129. const unsigned char iv[16],
  130. const unsigned char *inp, unsigned char *out,
  131. size_t len, int enc);
  132. size_t CRYPTO_128_wrap(void *key, const unsigned char *iv,
  133. unsigned char *out,
  134. const unsigned char *in, size_t inlen,
  135. block128_f block);
  136. size_t CRYPTO_128_unwrap(void *key, const unsigned char *iv,
  137. unsigned char *out,
  138. const unsigned char *in, size_t inlen,
  139. block128_f block);
  140. #ifdef __cplusplus
  141. }
  142. #endif