18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (c) 2010-2014, The Linux Foundation. All rights reserved.
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#ifndef _COMMON_H_
78c2ecf20Sopenharmony_ci#define _COMMON_H_
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include <linux/crypto.h>
108c2ecf20Sopenharmony_ci#include <linux/types.h>
118c2ecf20Sopenharmony_ci#include <crypto/aes.h>
128c2ecf20Sopenharmony_ci#include <crypto/hash.h>
138c2ecf20Sopenharmony_ci#include <crypto/internal/skcipher.h>
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci/* xts du size */
168c2ecf20Sopenharmony_ci#define QCE_SECTOR_SIZE			512
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci/* key size in bytes */
198c2ecf20Sopenharmony_ci#define QCE_SHA_HMAC_KEY_SIZE		64
208c2ecf20Sopenharmony_ci#define QCE_MAX_CIPHER_KEY_SIZE		AES_KEYSIZE_256
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci/* IV length in bytes */
238c2ecf20Sopenharmony_ci#define QCE_AES_IV_LENGTH		AES_BLOCK_SIZE
248c2ecf20Sopenharmony_ci/* max of AES_BLOCK_SIZE, DES3_EDE_BLOCK_SIZE */
258c2ecf20Sopenharmony_ci#define QCE_MAX_IV_SIZE			AES_BLOCK_SIZE
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci/* maximum nonce bytes  */
288c2ecf20Sopenharmony_ci#define QCE_MAX_NONCE			16
298c2ecf20Sopenharmony_ci#define QCE_MAX_NONCE_WORDS		(QCE_MAX_NONCE / sizeof(u32))
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci/* burst size alignment requirement */
328c2ecf20Sopenharmony_ci#define QCE_MAX_ALIGN_SIZE		64
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci/* cipher algorithms */
358c2ecf20Sopenharmony_ci#define QCE_ALG_DES			BIT(0)
368c2ecf20Sopenharmony_ci#define QCE_ALG_3DES			BIT(1)
378c2ecf20Sopenharmony_ci#define QCE_ALG_AES			BIT(2)
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci/* hash and hmac algorithms */
408c2ecf20Sopenharmony_ci#define QCE_HASH_SHA1			BIT(3)
418c2ecf20Sopenharmony_ci#define QCE_HASH_SHA256			BIT(4)
428c2ecf20Sopenharmony_ci#define QCE_HASH_SHA1_HMAC		BIT(5)
438c2ecf20Sopenharmony_ci#define QCE_HASH_SHA256_HMAC		BIT(6)
448c2ecf20Sopenharmony_ci#define QCE_HASH_AES_CMAC		BIT(7)
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci/* cipher modes */
478c2ecf20Sopenharmony_ci#define QCE_MODE_CBC			BIT(8)
488c2ecf20Sopenharmony_ci#define QCE_MODE_ECB			BIT(9)
498c2ecf20Sopenharmony_ci#define QCE_MODE_CTR			BIT(10)
508c2ecf20Sopenharmony_ci#define QCE_MODE_XTS			BIT(11)
518c2ecf20Sopenharmony_ci#define QCE_MODE_CCM			BIT(12)
528c2ecf20Sopenharmony_ci#define QCE_MODE_MASK			GENMASK(12, 8)
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci/* cipher encryption/decryption operations */
558c2ecf20Sopenharmony_ci#define QCE_ENCRYPT			BIT(13)
568c2ecf20Sopenharmony_ci#define QCE_DECRYPT			BIT(14)
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci#define IS_DES(flags)			(flags & QCE_ALG_DES)
598c2ecf20Sopenharmony_ci#define IS_3DES(flags)			(flags & QCE_ALG_3DES)
608c2ecf20Sopenharmony_ci#define IS_AES(flags)			(flags & QCE_ALG_AES)
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci#define IS_SHA1(flags)			(flags & QCE_HASH_SHA1)
638c2ecf20Sopenharmony_ci#define IS_SHA256(flags)		(flags & QCE_HASH_SHA256)
648c2ecf20Sopenharmony_ci#define IS_SHA1_HMAC(flags)		(flags & QCE_HASH_SHA1_HMAC)
658c2ecf20Sopenharmony_ci#define IS_SHA256_HMAC(flags)		(flags & QCE_HASH_SHA256_HMAC)
668c2ecf20Sopenharmony_ci#define IS_CMAC(flags)			(flags & QCE_HASH_AES_CMAC)
678c2ecf20Sopenharmony_ci#define IS_SHA(flags)			(IS_SHA1(flags) || IS_SHA256(flags))
688c2ecf20Sopenharmony_ci#define IS_SHA_HMAC(flags)		\
698c2ecf20Sopenharmony_ci		(IS_SHA1_HMAC(flags) || IS_SHA256_HMAC(flags))
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci#define IS_CBC(mode)			(mode & QCE_MODE_CBC)
728c2ecf20Sopenharmony_ci#define IS_ECB(mode)			(mode & QCE_MODE_ECB)
738c2ecf20Sopenharmony_ci#define IS_CTR(mode)			(mode & QCE_MODE_CTR)
748c2ecf20Sopenharmony_ci#define IS_XTS(mode)			(mode & QCE_MODE_XTS)
758c2ecf20Sopenharmony_ci#define IS_CCM(mode)			(mode & QCE_MODE_CCM)
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci#define IS_ENCRYPT(dir)			(dir & QCE_ENCRYPT)
788c2ecf20Sopenharmony_ci#define IS_DECRYPT(dir)			(dir & QCE_DECRYPT)
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_cistruct qce_alg_template {
818c2ecf20Sopenharmony_ci	struct list_head entry;
828c2ecf20Sopenharmony_ci	u32 crypto_alg_type;
838c2ecf20Sopenharmony_ci	unsigned long alg_flags;
848c2ecf20Sopenharmony_ci	const u32 *std_iv;
858c2ecf20Sopenharmony_ci	union {
868c2ecf20Sopenharmony_ci		struct skcipher_alg skcipher;
878c2ecf20Sopenharmony_ci		struct ahash_alg ahash;
888c2ecf20Sopenharmony_ci	} alg;
898c2ecf20Sopenharmony_ci	struct qce_device *qce;
908c2ecf20Sopenharmony_ci	const u8 *hash_zero;
918c2ecf20Sopenharmony_ci	const u32 digest_size;
928c2ecf20Sopenharmony_ci};
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_civoid qce_cpu_to_be32p_array(__be32 *dst, const u8 *src, unsigned int len);
958c2ecf20Sopenharmony_ciint qce_check_status(struct qce_device *qce, u32 *status);
968c2ecf20Sopenharmony_civoid qce_get_version(struct qce_device *qce, u32 *major, u32 *minor, u32 *step);
978c2ecf20Sopenharmony_ciint qce_start(struct crypto_async_request *async_req, u32 type, u32 totallen,
988c2ecf20Sopenharmony_ci	      u32 offset);
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci#endif /* _COMMON_H_ */
101