18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef ASM_X86_CAMELLIA_H
38c2ecf20Sopenharmony_ci#define ASM_X86_CAMELLIA_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#include <crypto/b128ops.h>
68c2ecf20Sopenharmony_ci#include <linux/crypto.h>
78c2ecf20Sopenharmony_ci#include <linux/kernel.h>
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#define CAMELLIA_MIN_KEY_SIZE	16
108c2ecf20Sopenharmony_ci#define CAMELLIA_MAX_KEY_SIZE	32
118c2ecf20Sopenharmony_ci#define CAMELLIA_BLOCK_SIZE	16
128c2ecf20Sopenharmony_ci#define CAMELLIA_TABLE_BYTE_LEN	272
138c2ecf20Sopenharmony_ci#define CAMELLIA_PARALLEL_BLOCKS 2
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_cistruct crypto_skcipher;
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_cistruct camellia_ctx {
188c2ecf20Sopenharmony_ci	u64 key_table[CAMELLIA_TABLE_BYTE_LEN / sizeof(u64)];
198c2ecf20Sopenharmony_ci	u32 key_length;
208c2ecf20Sopenharmony_ci};
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_cistruct camellia_xts_ctx {
238c2ecf20Sopenharmony_ci	struct camellia_ctx tweak_ctx;
248c2ecf20Sopenharmony_ci	struct camellia_ctx crypt_ctx;
258c2ecf20Sopenharmony_ci};
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ciextern int __camellia_setkey(struct camellia_ctx *cctx,
288c2ecf20Sopenharmony_ci			     const unsigned char *key,
298c2ecf20Sopenharmony_ci			     unsigned int key_len);
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ciextern int xts_camellia_setkey(struct crypto_skcipher *tfm, const u8 *key,
328c2ecf20Sopenharmony_ci			       unsigned int keylen);
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci/* regular block cipher functions */
358c2ecf20Sopenharmony_ciasmlinkage void __camellia_enc_blk(const void *ctx, u8 *dst, const u8 *src,
368c2ecf20Sopenharmony_ci				   bool xor);
378c2ecf20Sopenharmony_ciasmlinkage void camellia_dec_blk(const void *ctx, u8 *dst, const u8 *src);
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci/* 2-way parallel cipher functions */
408c2ecf20Sopenharmony_ciasmlinkage void __camellia_enc_blk_2way(const void *ctx, u8 *dst, const u8 *src,
418c2ecf20Sopenharmony_ci					bool xor);
428c2ecf20Sopenharmony_ciasmlinkage void camellia_dec_blk_2way(const void *ctx, u8 *dst, const u8 *src);
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci/* 16-way parallel cipher functions (avx/aes-ni) */
458c2ecf20Sopenharmony_ciasmlinkage void camellia_ecb_enc_16way(const void *ctx, u8 *dst, const u8 *src);
468c2ecf20Sopenharmony_ciasmlinkage void camellia_ecb_dec_16way(const void *ctx, u8 *dst, const u8 *src);
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ciasmlinkage void camellia_cbc_dec_16way(const void *ctx, u8 *dst, const u8 *src);
498c2ecf20Sopenharmony_ciasmlinkage void camellia_ctr_16way(const void *ctx, u8 *dst, const u8 *src,
508c2ecf20Sopenharmony_ci				   le128 *iv);
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ciasmlinkage void camellia_xts_enc_16way(const void *ctx, u8 *dst, const u8 *src,
538c2ecf20Sopenharmony_ci				       le128 *iv);
548c2ecf20Sopenharmony_ciasmlinkage void camellia_xts_dec_16way(const void *ctx, u8 *dst, const u8 *src,
558c2ecf20Sopenharmony_ci				       le128 *iv);
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_cistatic inline void camellia_enc_blk(const void *ctx, u8 *dst, const u8 *src)
588c2ecf20Sopenharmony_ci{
598c2ecf20Sopenharmony_ci	__camellia_enc_blk(ctx, dst, src, false);
608c2ecf20Sopenharmony_ci}
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_cistatic inline void camellia_enc_blk_xor(const void *ctx, u8 *dst, const u8 *src)
638c2ecf20Sopenharmony_ci{
648c2ecf20Sopenharmony_ci	__camellia_enc_blk(ctx, dst, src, true);
658c2ecf20Sopenharmony_ci}
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_cistatic inline void camellia_enc_blk_2way(const void *ctx, u8 *dst,
688c2ecf20Sopenharmony_ci					 const u8 *src)
698c2ecf20Sopenharmony_ci{
708c2ecf20Sopenharmony_ci	__camellia_enc_blk_2way(ctx, dst, src, false);
718c2ecf20Sopenharmony_ci}
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_cistatic inline void camellia_enc_blk_xor_2way(const void *ctx, u8 *dst,
748c2ecf20Sopenharmony_ci					     const u8 *src)
758c2ecf20Sopenharmony_ci{
768c2ecf20Sopenharmony_ci	__camellia_enc_blk_2way(ctx, dst, src, true);
778c2ecf20Sopenharmony_ci}
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci/* glue helpers */
808c2ecf20Sopenharmony_ciextern void camellia_decrypt_cbc_2way(const void *ctx, u8 *dst, const u8 *src);
818c2ecf20Sopenharmony_ciextern void camellia_crypt_ctr(const void *ctx, u8 *dst, const u8 *src,
828c2ecf20Sopenharmony_ci			       le128 *iv);
838c2ecf20Sopenharmony_ciextern void camellia_crypt_ctr_2way(const void *ctx, u8 *dst, const u8 *src,
848c2ecf20Sopenharmony_ci				    le128 *iv);
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ciextern void camellia_xts_enc(const void *ctx, u8 *dst, const u8 *src,
878c2ecf20Sopenharmony_ci			     le128 *iv);
888c2ecf20Sopenharmony_ciextern void camellia_xts_dec(const void *ctx, u8 *dst, const u8 *src,
898c2ecf20Sopenharmony_ci			     le128 *iv);
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci#endif /* ASM_X86_CAMELLIA_H */
92