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