Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Copyright (c) 2010-2014, The Linux Foundation. All rights reserved.
0004  */
0005 
0006 #ifndef _COMMON_H_
0007 #define _COMMON_H_
0008 
0009 #include <linux/crypto.h>
0010 #include <linux/types.h>
0011 #include <crypto/aes.h>
0012 #include <crypto/hash.h>
0013 #include <crypto/internal/skcipher.h>
0014 #include <crypto/internal/aead.h>
0015 
0016 /* xts du size */
0017 #define QCE_SECTOR_SIZE         512
0018 
0019 /* key size in bytes */
0020 #define QCE_SHA_HMAC_KEY_SIZE       64
0021 #define QCE_MAX_CIPHER_KEY_SIZE     AES_KEYSIZE_256
0022 
0023 /* IV length in bytes */
0024 #define QCE_AES_IV_LENGTH       AES_BLOCK_SIZE
0025 /* max of AES_BLOCK_SIZE, DES3_EDE_BLOCK_SIZE */
0026 #define QCE_MAX_IV_SIZE         AES_BLOCK_SIZE
0027 
0028 /* maximum nonce bytes  */
0029 #define QCE_MAX_NONCE           16
0030 #define QCE_MAX_NONCE_WORDS     (QCE_MAX_NONCE / sizeof(u32))
0031 
0032 /* burst size alignment requirement */
0033 #define QCE_MAX_ALIGN_SIZE      64
0034 
0035 /* cipher algorithms */
0036 #define QCE_ALG_DES         BIT(0)
0037 #define QCE_ALG_3DES            BIT(1)
0038 #define QCE_ALG_AES         BIT(2)
0039 
0040 /* hash and hmac algorithms */
0041 #define QCE_HASH_SHA1           BIT(3)
0042 #define QCE_HASH_SHA256         BIT(4)
0043 #define QCE_HASH_SHA1_HMAC      BIT(5)
0044 #define QCE_HASH_SHA256_HMAC        BIT(6)
0045 #define QCE_HASH_AES_CMAC       BIT(7)
0046 
0047 /* cipher modes */
0048 #define QCE_MODE_CBC            BIT(8)
0049 #define QCE_MODE_ECB            BIT(9)
0050 #define QCE_MODE_CTR            BIT(10)
0051 #define QCE_MODE_XTS            BIT(11)
0052 #define QCE_MODE_CCM            BIT(12)
0053 #define QCE_MODE_MASK           GENMASK(12, 8)
0054 
0055 #define QCE_MODE_CCM_RFC4309        BIT(13)
0056 
0057 /* cipher encryption/decryption operations */
0058 #define QCE_ENCRYPT         BIT(30)
0059 #define QCE_DECRYPT         BIT(31)
0060 
0061 #define IS_DES(flags)           (flags & QCE_ALG_DES)
0062 #define IS_3DES(flags)          (flags & QCE_ALG_3DES)
0063 #define IS_AES(flags)           (flags & QCE_ALG_AES)
0064 
0065 #define IS_SHA1(flags)          (flags & QCE_HASH_SHA1)
0066 #define IS_SHA256(flags)        (flags & QCE_HASH_SHA256)
0067 #define IS_SHA1_HMAC(flags)     (flags & QCE_HASH_SHA1_HMAC)
0068 #define IS_SHA256_HMAC(flags)       (flags & QCE_HASH_SHA256_HMAC)
0069 #define IS_CMAC(flags)          (flags & QCE_HASH_AES_CMAC)
0070 #define IS_SHA(flags)           (IS_SHA1(flags) || IS_SHA256(flags))
0071 #define IS_SHA_HMAC(flags)      \
0072         (IS_SHA1_HMAC(flags) || IS_SHA256_HMAC(flags))
0073 
0074 #define IS_CBC(mode)            (mode & QCE_MODE_CBC)
0075 #define IS_ECB(mode)            (mode & QCE_MODE_ECB)
0076 #define IS_CTR(mode)            (mode & QCE_MODE_CTR)
0077 #define IS_XTS(mode)            (mode & QCE_MODE_XTS)
0078 #define IS_CCM(mode)            (mode & QCE_MODE_CCM)
0079 #define IS_CCM_RFC4309(mode)        ((mode) & QCE_MODE_CCM_RFC4309)
0080 
0081 #define IS_ENCRYPT(dir)         (dir & QCE_ENCRYPT)
0082 #define IS_DECRYPT(dir)         (dir & QCE_DECRYPT)
0083 
0084 struct qce_alg_template {
0085     struct list_head entry;
0086     u32 crypto_alg_type;
0087     unsigned long alg_flags;
0088     const u32 *std_iv;
0089     union {
0090         struct skcipher_alg skcipher;
0091         struct ahash_alg ahash;
0092         struct aead_alg aead;
0093     } alg;
0094     struct qce_device *qce;
0095     const u8 *hash_zero;
0096     const u32 digest_size;
0097 };
0098 
0099 void qce_cpu_to_be32p_array(__be32 *dst, const u8 *src, unsigned int len);
0100 int qce_check_status(struct qce_device *qce, u32 *status);
0101 void qce_get_version(struct qce_device *qce, u32 *major, u32 *minor, u32 *step);
0102 int qce_start(struct crypto_async_request *async_req, u32 type);
0103 
0104 #endif /* _COMMON_H_ */