162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (c) 2010-2014, The Linux Foundation. All rights reserved.
462306a36Sopenharmony_ci */
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci#ifndef _COMMON_H_
762306a36Sopenharmony_ci#define _COMMON_H_
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#include <linux/crypto.h>
1062306a36Sopenharmony_ci#include <linux/types.h>
1162306a36Sopenharmony_ci#include <crypto/aes.h>
1262306a36Sopenharmony_ci#include <crypto/hash.h>
1362306a36Sopenharmony_ci#include <crypto/internal/skcipher.h>
1462306a36Sopenharmony_ci#include <crypto/internal/aead.h>
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci/* xts du size */
1762306a36Sopenharmony_ci#define QCE_SECTOR_SIZE			512
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_ci/* key size in bytes */
2062306a36Sopenharmony_ci#define QCE_SHA_HMAC_KEY_SIZE		64
2162306a36Sopenharmony_ci#define QCE_MAX_CIPHER_KEY_SIZE		AES_KEYSIZE_256
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_ci/* IV length in bytes */
2462306a36Sopenharmony_ci#define QCE_AES_IV_LENGTH		AES_BLOCK_SIZE
2562306a36Sopenharmony_ci/* max of AES_BLOCK_SIZE, DES3_EDE_BLOCK_SIZE */
2662306a36Sopenharmony_ci#define QCE_MAX_IV_SIZE			AES_BLOCK_SIZE
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci/* maximum nonce bytes  */
2962306a36Sopenharmony_ci#define QCE_MAX_NONCE			16
3062306a36Sopenharmony_ci#define QCE_MAX_NONCE_WORDS		(QCE_MAX_NONCE / sizeof(u32))
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci/* burst size alignment requirement */
3362306a36Sopenharmony_ci#define QCE_MAX_ALIGN_SIZE		64
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ci/* cipher algorithms */
3662306a36Sopenharmony_ci#define QCE_ALG_DES			BIT(0)
3762306a36Sopenharmony_ci#define QCE_ALG_3DES			BIT(1)
3862306a36Sopenharmony_ci#define QCE_ALG_AES			BIT(2)
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_ci/* hash and hmac algorithms */
4162306a36Sopenharmony_ci#define QCE_HASH_SHA1			BIT(3)
4262306a36Sopenharmony_ci#define QCE_HASH_SHA256			BIT(4)
4362306a36Sopenharmony_ci#define QCE_HASH_SHA1_HMAC		BIT(5)
4462306a36Sopenharmony_ci#define QCE_HASH_SHA256_HMAC		BIT(6)
4562306a36Sopenharmony_ci#define QCE_HASH_AES_CMAC		BIT(7)
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_ci/* cipher modes */
4862306a36Sopenharmony_ci#define QCE_MODE_CBC			BIT(8)
4962306a36Sopenharmony_ci#define QCE_MODE_ECB			BIT(9)
5062306a36Sopenharmony_ci#define QCE_MODE_CTR			BIT(10)
5162306a36Sopenharmony_ci#define QCE_MODE_XTS			BIT(11)
5262306a36Sopenharmony_ci#define QCE_MODE_CCM			BIT(12)
5362306a36Sopenharmony_ci#define QCE_MODE_MASK			GENMASK(12, 8)
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ci#define QCE_MODE_CCM_RFC4309		BIT(13)
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ci/* cipher encryption/decryption operations */
5862306a36Sopenharmony_ci#define QCE_ENCRYPT			BIT(30)
5962306a36Sopenharmony_ci#define QCE_DECRYPT			BIT(31)
6062306a36Sopenharmony_ci
6162306a36Sopenharmony_ci#define IS_DES(flags)			(flags & QCE_ALG_DES)
6262306a36Sopenharmony_ci#define IS_3DES(flags)			(flags & QCE_ALG_3DES)
6362306a36Sopenharmony_ci#define IS_AES(flags)			(flags & QCE_ALG_AES)
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ci#define IS_SHA1(flags)			(flags & QCE_HASH_SHA1)
6662306a36Sopenharmony_ci#define IS_SHA256(flags)		(flags & QCE_HASH_SHA256)
6762306a36Sopenharmony_ci#define IS_SHA1_HMAC(flags)		(flags & QCE_HASH_SHA1_HMAC)
6862306a36Sopenharmony_ci#define IS_SHA256_HMAC(flags)		(flags & QCE_HASH_SHA256_HMAC)
6962306a36Sopenharmony_ci#define IS_CMAC(flags)			(flags & QCE_HASH_AES_CMAC)
7062306a36Sopenharmony_ci#define IS_SHA(flags)			(IS_SHA1(flags) || IS_SHA256(flags))
7162306a36Sopenharmony_ci#define IS_SHA_HMAC(flags)		\
7262306a36Sopenharmony_ci		(IS_SHA1_HMAC(flags) || IS_SHA256_HMAC(flags))
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_ci#define IS_CBC(mode)			(mode & QCE_MODE_CBC)
7562306a36Sopenharmony_ci#define IS_ECB(mode)			(mode & QCE_MODE_ECB)
7662306a36Sopenharmony_ci#define IS_CTR(mode)			(mode & QCE_MODE_CTR)
7762306a36Sopenharmony_ci#define IS_XTS(mode)			(mode & QCE_MODE_XTS)
7862306a36Sopenharmony_ci#define IS_CCM(mode)			(mode & QCE_MODE_CCM)
7962306a36Sopenharmony_ci#define IS_CCM_RFC4309(mode)		((mode) & QCE_MODE_CCM_RFC4309)
8062306a36Sopenharmony_ci
8162306a36Sopenharmony_ci#define IS_ENCRYPT(dir)			(dir & QCE_ENCRYPT)
8262306a36Sopenharmony_ci#define IS_DECRYPT(dir)			(dir & QCE_DECRYPT)
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_cistruct qce_alg_template {
8562306a36Sopenharmony_ci	struct list_head entry;
8662306a36Sopenharmony_ci	u32 crypto_alg_type;
8762306a36Sopenharmony_ci	unsigned long alg_flags;
8862306a36Sopenharmony_ci	const u32 *std_iv;
8962306a36Sopenharmony_ci	union {
9062306a36Sopenharmony_ci		struct skcipher_alg skcipher;
9162306a36Sopenharmony_ci		struct ahash_alg ahash;
9262306a36Sopenharmony_ci		struct aead_alg aead;
9362306a36Sopenharmony_ci	} alg;
9462306a36Sopenharmony_ci	struct qce_device *qce;
9562306a36Sopenharmony_ci	const u8 *hash_zero;
9662306a36Sopenharmony_ci	const u32 digest_size;
9762306a36Sopenharmony_ci};
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_civoid qce_cpu_to_be32p_array(__be32 *dst, const u8 *src, unsigned int len);
10062306a36Sopenharmony_ciint qce_check_status(struct qce_device *qce, u32 *status);
10162306a36Sopenharmony_civoid qce_get_version(struct qce_device *qce, u32 *major, u32 *minor, u32 *step);
10262306a36Sopenharmony_ciint qce_start(struct crypto_async_request *async_req, u32 type);
10362306a36Sopenharmony_ci
10462306a36Sopenharmony_ci#endif /* _COMMON_H_ */
105