1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */ 2*4882a593Smuzhiyun /* 3*4882a593Smuzhiyun * Copyright (c) 2010-2014, The Linux Foundation. All rights reserved. 4*4882a593Smuzhiyun */ 5*4882a593Smuzhiyun 6*4882a593Smuzhiyun #ifndef _COMMON_H_ 7*4882a593Smuzhiyun #define _COMMON_H_ 8*4882a593Smuzhiyun 9*4882a593Smuzhiyun #include <linux/crypto.h> 10*4882a593Smuzhiyun #include <linux/types.h> 11*4882a593Smuzhiyun #include <crypto/aes.h> 12*4882a593Smuzhiyun #include <crypto/hash.h> 13*4882a593Smuzhiyun #include <crypto/internal/skcipher.h> 14*4882a593Smuzhiyun 15*4882a593Smuzhiyun /* xts du size */ 16*4882a593Smuzhiyun #define QCE_SECTOR_SIZE 512 17*4882a593Smuzhiyun 18*4882a593Smuzhiyun /* key size in bytes */ 19*4882a593Smuzhiyun #define QCE_SHA_HMAC_KEY_SIZE 64 20*4882a593Smuzhiyun #define QCE_MAX_CIPHER_KEY_SIZE AES_KEYSIZE_256 21*4882a593Smuzhiyun 22*4882a593Smuzhiyun /* IV length in bytes */ 23*4882a593Smuzhiyun #define QCE_AES_IV_LENGTH AES_BLOCK_SIZE 24*4882a593Smuzhiyun /* max of AES_BLOCK_SIZE, DES3_EDE_BLOCK_SIZE */ 25*4882a593Smuzhiyun #define QCE_MAX_IV_SIZE AES_BLOCK_SIZE 26*4882a593Smuzhiyun 27*4882a593Smuzhiyun /* maximum nonce bytes */ 28*4882a593Smuzhiyun #define QCE_MAX_NONCE 16 29*4882a593Smuzhiyun #define QCE_MAX_NONCE_WORDS (QCE_MAX_NONCE / sizeof(u32)) 30*4882a593Smuzhiyun 31*4882a593Smuzhiyun /* burst size alignment requirement */ 32*4882a593Smuzhiyun #define QCE_MAX_ALIGN_SIZE 64 33*4882a593Smuzhiyun 34*4882a593Smuzhiyun /* cipher algorithms */ 35*4882a593Smuzhiyun #define QCE_ALG_DES BIT(0) 36*4882a593Smuzhiyun #define QCE_ALG_3DES BIT(1) 37*4882a593Smuzhiyun #define QCE_ALG_AES BIT(2) 38*4882a593Smuzhiyun 39*4882a593Smuzhiyun /* hash and hmac algorithms */ 40*4882a593Smuzhiyun #define QCE_HASH_SHA1 BIT(3) 41*4882a593Smuzhiyun #define QCE_HASH_SHA256 BIT(4) 42*4882a593Smuzhiyun #define QCE_HASH_SHA1_HMAC BIT(5) 43*4882a593Smuzhiyun #define QCE_HASH_SHA256_HMAC BIT(6) 44*4882a593Smuzhiyun #define QCE_HASH_AES_CMAC BIT(7) 45*4882a593Smuzhiyun 46*4882a593Smuzhiyun /* cipher modes */ 47*4882a593Smuzhiyun #define QCE_MODE_CBC BIT(8) 48*4882a593Smuzhiyun #define QCE_MODE_ECB BIT(9) 49*4882a593Smuzhiyun #define QCE_MODE_CTR BIT(10) 50*4882a593Smuzhiyun #define QCE_MODE_XTS BIT(11) 51*4882a593Smuzhiyun #define QCE_MODE_CCM BIT(12) 52*4882a593Smuzhiyun #define QCE_MODE_MASK GENMASK(12, 8) 53*4882a593Smuzhiyun 54*4882a593Smuzhiyun /* cipher encryption/decryption operations */ 55*4882a593Smuzhiyun #define QCE_ENCRYPT BIT(13) 56*4882a593Smuzhiyun #define QCE_DECRYPT BIT(14) 57*4882a593Smuzhiyun 58*4882a593Smuzhiyun #define IS_DES(flags) (flags & QCE_ALG_DES) 59*4882a593Smuzhiyun #define IS_3DES(flags) (flags & QCE_ALG_3DES) 60*4882a593Smuzhiyun #define IS_AES(flags) (flags & QCE_ALG_AES) 61*4882a593Smuzhiyun 62*4882a593Smuzhiyun #define IS_SHA1(flags) (flags & QCE_HASH_SHA1) 63*4882a593Smuzhiyun #define IS_SHA256(flags) (flags & QCE_HASH_SHA256) 64*4882a593Smuzhiyun #define IS_SHA1_HMAC(flags) (flags & QCE_HASH_SHA1_HMAC) 65*4882a593Smuzhiyun #define IS_SHA256_HMAC(flags) (flags & QCE_HASH_SHA256_HMAC) 66*4882a593Smuzhiyun #define IS_CMAC(flags) (flags & QCE_HASH_AES_CMAC) 67*4882a593Smuzhiyun #define IS_SHA(flags) (IS_SHA1(flags) || IS_SHA256(flags)) 68*4882a593Smuzhiyun #define IS_SHA_HMAC(flags) \ 69*4882a593Smuzhiyun (IS_SHA1_HMAC(flags) || IS_SHA256_HMAC(flags)) 70*4882a593Smuzhiyun 71*4882a593Smuzhiyun #define IS_CBC(mode) (mode & QCE_MODE_CBC) 72*4882a593Smuzhiyun #define IS_ECB(mode) (mode & QCE_MODE_ECB) 73*4882a593Smuzhiyun #define IS_CTR(mode) (mode & QCE_MODE_CTR) 74*4882a593Smuzhiyun #define IS_XTS(mode) (mode & QCE_MODE_XTS) 75*4882a593Smuzhiyun #define IS_CCM(mode) (mode & QCE_MODE_CCM) 76*4882a593Smuzhiyun 77*4882a593Smuzhiyun #define IS_ENCRYPT(dir) (dir & QCE_ENCRYPT) 78*4882a593Smuzhiyun #define IS_DECRYPT(dir) (dir & QCE_DECRYPT) 79*4882a593Smuzhiyun 80*4882a593Smuzhiyun struct qce_alg_template { 81*4882a593Smuzhiyun struct list_head entry; 82*4882a593Smuzhiyun u32 crypto_alg_type; 83*4882a593Smuzhiyun unsigned long alg_flags; 84*4882a593Smuzhiyun const u32 *std_iv; 85*4882a593Smuzhiyun union { 86*4882a593Smuzhiyun struct skcipher_alg skcipher; 87*4882a593Smuzhiyun struct ahash_alg ahash; 88*4882a593Smuzhiyun } alg; 89*4882a593Smuzhiyun struct qce_device *qce; 90*4882a593Smuzhiyun const u8 *hash_zero; 91*4882a593Smuzhiyun const u32 digest_size; 92*4882a593Smuzhiyun }; 93*4882a593Smuzhiyun 94*4882a593Smuzhiyun void qce_cpu_to_be32p_array(__be32 *dst, const u8 *src, unsigned int len); 95*4882a593Smuzhiyun int qce_check_status(struct qce_device *qce, u32 *status); 96*4882a593Smuzhiyun void qce_get_version(struct qce_device *qce, u32 *major, u32 *minor, u32 *step); 97*4882a593Smuzhiyun int qce_start(struct crypto_async_request *async_req, u32 type, u32 totallen, 98*4882a593Smuzhiyun u32 offset); 99*4882a593Smuzhiyun 100*4882a593Smuzhiyun #endif /* _COMMON_H_ */ 101