modes.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /* $OpenBSD: modes.h,v 1.6 2023/07/08 14:55:36 beck Exp $ */
  2. /* ====================================================================
  3. * Copyright (c) 2008 The OpenSSL Project. All rights reserved.
  4. *
  5. * Rights for redistribution and usage in source and binary
  6. * forms are granted according to the OpenSSL license.
  7. */
  8. #include <stddef.h>
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. typedef void (*block128_f)(const unsigned char in[16],
  13. unsigned char out[16],
  14. 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], unsigned char cmac[16]);
  24. void CRYPTO_cbc128_encrypt(const unsigned char *in, unsigned char *out,
  25. size_t len, const void *key,
  26. unsigned char ivec[16], block128_f block);
  27. void CRYPTO_cbc128_decrypt(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_ctr128_encrypt(const unsigned char *in, unsigned char *out,
  31. size_t len, const void *key,
  32. unsigned char ivec[16], unsigned char ecount_buf[16],
  33. unsigned int *num, 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], unsigned char ecount_buf[16],
  37. unsigned int *num, ctr128_f ctr);
  38. void CRYPTO_ofb128_encrypt(const unsigned char *in, unsigned char *out,
  39. size_t len, const void *key,
  40. unsigned char ivec[16], int *num,
  41. block128_f block);
  42. void CRYPTO_cfb128_encrypt(const unsigned char *in, unsigned char *out,
  43. size_t len, const void *key,
  44. unsigned char ivec[16], int *num,
  45. int enc, block128_f block);
  46. void CRYPTO_cfb128_8_encrypt(const unsigned char *in, unsigned char *out,
  47. size_t length, const void *key,
  48. unsigned char ivec[16], int *num,
  49. int enc, block128_f block);
  50. void CRYPTO_cfb128_1_encrypt(const unsigned char *in, unsigned char *out,
  51. size_t bits, const void *key,
  52. unsigned char ivec[16], int *num,
  53. int enc, block128_f block);
  54. typedef struct gcm128_context GCM128_CONTEXT;
  55. GCM128_CONTEXT *CRYPTO_gcm128_new(void *key, block128_f block);
  56. void CRYPTO_gcm128_init(GCM128_CONTEXT *ctx, void *key, block128_f block);
  57. void CRYPTO_gcm128_setiv(GCM128_CONTEXT *ctx, const unsigned char *iv,
  58. size_t len);
  59. int CRYPTO_gcm128_aad(GCM128_CONTEXT *ctx, const unsigned char *aad,
  60. size_t len);
  61. int CRYPTO_gcm128_encrypt(GCM128_CONTEXT *ctx,
  62. const unsigned char *in, unsigned char *out,
  63. size_t len);
  64. int CRYPTO_gcm128_decrypt(GCM128_CONTEXT *ctx,
  65. const unsigned char *in, unsigned char *out,
  66. size_t len);
  67. int CRYPTO_gcm128_encrypt_ctr32(GCM128_CONTEXT *ctx,
  68. const unsigned char *in, unsigned char *out,
  69. size_t len, ctr128_f stream);
  70. int CRYPTO_gcm128_decrypt_ctr32(GCM128_CONTEXT *ctx,
  71. const unsigned char *in, unsigned char *out,
  72. size_t len, ctr128_f stream);
  73. int CRYPTO_gcm128_finish(GCM128_CONTEXT *ctx, const unsigned char *tag,
  74. size_t len);
  75. void CRYPTO_gcm128_tag(GCM128_CONTEXT *ctx, unsigned char *tag, size_t len);
  76. void CRYPTO_gcm128_release(GCM128_CONTEXT *ctx);
  77. typedef struct ccm128_context CCM128_CONTEXT;
  78. void CRYPTO_ccm128_init(CCM128_CONTEXT *ctx,
  79. unsigned int M, unsigned int L, void *key, block128_f block);
  80. int CRYPTO_ccm128_setiv(CCM128_CONTEXT *ctx,
  81. const unsigned char *nonce, size_t nlen, size_t mlen);
  82. void CRYPTO_ccm128_aad(CCM128_CONTEXT *ctx,
  83. const unsigned char *aad, size_t alen);
  84. int CRYPTO_ccm128_encrypt(CCM128_CONTEXT *ctx,
  85. const unsigned char *inp, unsigned char *out, size_t len);
  86. int CRYPTO_ccm128_decrypt(CCM128_CONTEXT *ctx,
  87. const unsigned char *inp, unsigned char *out, size_t len);
  88. int CRYPTO_ccm128_encrypt_ccm64(CCM128_CONTEXT *ctx,
  89. const unsigned char *inp, unsigned char *out, size_t len,
  90. ccm128_f stream);
  91. int CRYPTO_ccm128_decrypt_ccm64(CCM128_CONTEXT *ctx,
  92. const unsigned char *inp, unsigned char *out, size_t len,
  93. ccm128_f stream);
  94. size_t CRYPTO_ccm128_tag(CCM128_CONTEXT *ctx, unsigned char *tag, size_t len);
  95. typedef struct xts128_context XTS128_CONTEXT;
  96. int CRYPTO_xts128_encrypt(const XTS128_CONTEXT *ctx, const unsigned char iv[16],
  97. const unsigned char *inp, unsigned char *out, size_t len, int enc);
  98. #ifdef __cplusplus
  99. }
  100. #endif