camellia.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #ifndef ASM_X86_CAMELLIA_H
  2. #define ASM_X86_CAMELLIA_H
  3. #include <linux/kernel.h>
  4. #include <linux/crypto.h>
  5. #define CAMELLIA_MIN_KEY_SIZE 16
  6. #define CAMELLIA_MAX_KEY_SIZE 32
  7. #define CAMELLIA_BLOCK_SIZE 16
  8. #define CAMELLIA_TABLE_BYTE_LEN 272
  9. #define CAMELLIA_PARALLEL_BLOCKS 2
  10. struct camellia_ctx {
  11. u64 key_table[CAMELLIA_TABLE_BYTE_LEN / sizeof(u64)];
  12. u32 key_length;
  13. };
  14. struct camellia_lrw_ctx {
  15. struct lrw_table_ctx lrw_table;
  16. struct camellia_ctx camellia_ctx;
  17. };
  18. struct camellia_xts_ctx {
  19. struct camellia_ctx tweak_ctx;
  20. struct camellia_ctx crypt_ctx;
  21. };
  22. extern int __camellia_setkey(struct camellia_ctx *cctx,
  23. const unsigned char *key,
  24. unsigned int key_len, u32 *flags);
  25. extern int lrw_camellia_setkey(struct crypto_tfm *tfm, const u8 *key,
  26. unsigned int keylen);
  27. extern void lrw_camellia_exit_tfm(struct crypto_tfm *tfm);
  28. extern int xts_camellia_setkey(struct crypto_tfm *tfm, const u8 *key,
  29. unsigned int keylen);
  30. /* regular block cipher functions */
  31. asmlinkage void __camellia_enc_blk(struct camellia_ctx *ctx, u8 *dst,
  32. const u8 *src, bool xor);
  33. asmlinkage void camellia_dec_blk(struct camellia_ctx *ctx, u8 *dst,
  34. const u8 *src);
  35. /* 2-way parallel cipher functions */
  36. asmlinkage void __camellia_enc_blk_2way(struct camellia_ctx *ctx, u8 *dst,
  37. const u8 *src, bool xor);
  38. asmlinkage void camellia_dec_blk_2way(struct camellia_ctx *ctx, u8 *dst,
  39. const u8 *src);
  40. /* 16-way parallel cipher functions (avx/aes-ni) */
  41. asmlinkage void camellia_ecb_enc_16way(struct camellia_ctx *ctx, u8 *dst,
  42. const u8 *src);
  43. asmlinkage void camellia_ecb_dec_16way(struct camellia_ctx *ctx, u8 *dst,
  44. const u8 *src);
  45. asmlinkage void camellia_cbc_dec_16way(struct camellia_ctx *ctx, u8 *dst,
  46. const u8 *src);
  47. asmlinkage void camellia_ctr_16way(struct camellia_ctx *ctx, u8 *dst,
  48. const u8 *src, le128 *iv);
  49. asmlinkage void camellia_xts_enc_16way(struct camellia_ctx *ctx, u8 *dst,
  50. const u8 *src, le128 *iv);
  51. asmlinkage void camellia_xts_dec_16way(struct camellia_ctx *ctx, u8 *dst,
  52. const u8 *src, le128 *iv);
  53. static inline void camellia_enc_blk(struct camellia_ctx *ctx, u8 *dst,
  54. const u8 *src)
  55. {
  56. __camellia_enc_blk(ctx, dst, src, false);
  57. }
  58. static inline void camellia_enc_blk_xor(struct camellia_ctx *ctx, u8 *dst,
  59. const u8 *src)
  60. {
  61. __camellia_enc_blk(ctx, dst, src, true);
  62. }
  63. static inline void camellia_enc_blk_2way(struct camellia_ctx *ctx, u8 *dst,
  64. const u8 *src)
  65. {
  66. __camellia_enc_blk_2way(ctx, dst, src, false);
  67. }
  68. static inline void camellia_enc_blk_xor_2way(struct camellia_ctx *ctx, u8 *dst,
  69. const u8 *src)
  70. {
  71. __camellia_enc_blk_2way(ctx, dst, src, true);
  72. }
  73. /* glue helpers */
  74. extern void camellia_decrypt_cbc_2way(void *ctx, u128 *dst, const u128 *src);
  75. extern void camellia_crypt_ctr(void *ctx, u128 *dst, const u128 *src,
  76. le128 *iv);
  77. extern void camellia_crypt_ctr_2way(void *ctx, u128 *dst, const u128 *src,
  78. le128 *iv);
  79. extern void camellia_xts_enc(void *ctx, u128 *dst, const u128 *src, le128 *iv);
  80. extern void camellia_xts_dec(void *ctx, u128 *dst, const u128 *src, le128 *iv);
  81. #endif /* ASM_X86_CAMELLIA_H */