1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Cavium, Inc
5 #ifndef _ARMV8_PMD_PRIVATE_H_
6 #define _ARMV8_PMD_PRIVATE_H_
8 #include "AArch64cryptolib.h"
10 #define CRYPTODEV_NAME_ARMV8_PMD crypto_armv8
11 /**< ARMv8 Crypto PMD device name */
13 extern int crypto_armv8_log_type;
15 #define ARMV8_CRYPTO_LOG_ERR(fmt, args...) \
16 rte_log(RTE_LOG_ERR, crypto_armv8_log_type, \
17 "[%s] %s() line %u: " fmt "\n", \
18 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD), \
19 __func__, __LINE__, ## args)
21 #define ARMV8_CRYPTO_LOG_INFO(fmt, args...) \
22 rte_log(RTE_LOG_INFO, crypto_armv8_log_type, \
23 "[%s] %s() line %u: " fmt "\n", \
24 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD), \
25 __func__, __LINE__, ## args)
27 #define ARMV8_CRYPTO_LOG_DBG(fmt, args...) \
28 rte_log(RTE_LOG_DEBUG, crypto_armv8_log_type, \
29 "[%s] %s() line %u: " fmt "\n", \
30 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD), \
31 __func__, __LINE__, ## args)
33 #define NBBY 8 /* Number of bits in a byte */
34 #define BYTE_LENGTH(x) ((x) / NBBY) /* Number of bytes in x (round down) */
36 /* Maximum length for digest (SHA-256 needs 32 bytes) */
37 #define DIGEST_LENGTH_MAX 32
39 /** ARMv8 operation order mode enumerator */
40 enum armv8_crypto_chain_order {
41 ARMV8_CRYPTO_CHAIN_CIPHER_AUTH,
42 ARMV8_CRYPTO_CHAIN_AUTH_CIPHER,
43 ARMV8_CRYPTO_CHAIN_NOT_SUPPORTED,
44 ARMV8_CRYPTO_CHAIN_LIST_END = ARMV8_CRYPTO_CHAIN_NOT_SUPPORTED
47 /** ARMv8 cipher operation enumerator */
48 enum armv8_crypto_cipher_operation {
49 ARMV8_CRYPTO_CIPHER_OP_ENCRYPT = RTE_CRYPTO_CIPHER_OP_ENCRYPT,
50 ARMV8_CRYPTO_CIPHER_OP_DECRYPT = RTE_CRYPTO_CIPHER_OP_DECRYPT,
51 ARMV8_CRYPTO_CIPHER_OP_NOT_SUPPORTED,
52 ARMV8_CRYPTO_CIPHER_OP_LIST_END = ARMV8_CRYPTO_CIPHER_OP_NOT_SUPPORTED
55 enum armv8_crypto_cipher_keylen {
56 ARMV8_CRYPTO_CIPHER_KEYLEN_128,
57 ARMV8_CRYPTO_CIPHER_KEYLEN_192,
58 ARMV8_CRYPTO_CIPHER_KEYLEN_256,
59 ARMV8_CRYPTO_CIPHER_KEYLEN_NOT_SUPPORTED,
60 ARMV8_CRYPTO_CIPHER_KEYLEN_LIST_END =
61 ARMV8_CRYPTO_CIPHER_KEYLEN_NOT_SUPPORTED
64 /** ARMv8 auth mode enumerator */
65 enum armv8_crypto_auth_mode {
66 ARMV8_CRYPTO_AUTH_AS_AUTH,
67 ARMV8_CRYPTO_AUTH_AS_HMAC,
68 ARMV8_CRYPTO_AUTH_AS_CIPHER,
69 ARMV8_CRYPTO_AUTH_NOT_SUPPORTED,
70 ARMV8_CRYPTO_AUTH_LIST_END = ARMV8_CRYPTO_AUTH_NOT_SUPPORTED
73 #define CRYPTO_CIPHER_KEYLEN_MAX ARMV8_CRYPTO_CIPHER_KEYLEN_LIST_END
74 #define CRYPTO_CIPHER_MAX (RTE_CRYPTO_CIPHER_AES_ECB + 1)
75 #define CRYPTO_AUTH_MAX (RTE_CRYPTO_AUTH_SHA512_HMAC + 1)
77 #define HMAC_IPAD_VALUE (0x36)
78 #define HMAC_OPAD_VALUE (0x5C)
80 #define SHA256_AUTH_KEY_LENGTH (BYTE_LENGTH(256))
81 #define SHA256_BLOCK_SIZE (BYTE_LENGTH(512))
83 #define SHA1_AUTH_KEY_LENGTH (BYTE_LENGTH(160))
84 #define SHA1_BLOCK_SIZE (BYTE_LENGTH(512))
86 #define SHA_AUTH_KEY_MAX SHA256_AUTH_KEY_LENGTH
87 #define SHA_BLOCK_MAX SHA256_BLOCK_SIZE
89 typedef int (*crypto_func_t)(uint8_t *, uint8_t *, uint64_t,
90 uint8_t *, uint8_t *, uint64_t,
91 armv8_cipher_digest_t *);
93 typedef void (*crypto_key_sched_t)(uint8_t *, const uint8_t *);
95 /** private data structure for each ARMv8 crypto device */
96 struct armv8_crypto_private {
97 unsigned int max_nb_qpairs;
98 /**< Max number of queue pairs */
101 /** ARMv8 crypto queue pair */
102 struct armv8_crypto_qp {
104 /**< Queue Pair Identifier */
105 struct rte_ring *processed_ops;
106 /**< Ring for placing process packets */
107 struct rte_mempool *sess_mp;
108 /**< Session Mempool */
109 struct rte_mempool *sess_mp_priv;
110 /**< Session Private Data Mempool */
111 struct rte_cryptodev_stats stats;
112 /**< Queue pair statistics */
113 char name[RTE_CRYPTODEV_NAME_MAX_LEN];
114 /**< Unique Queue Pair Name */
115 uint8_t temp_digest[DIGEST_LENGTH_MAX];
116 /**< Buffer used to store the digest generated
117 * by the driver when verifying a digest provided
118 * by the user (using authentication verify operation)
120 } __rte_cache_aligned;
122 /** ARMv8 crypto private session structure */
123 struct armv8_crypto_session {
124 enum armv8_crypto_chain_order chain_order;
125 /**< chain order mode */
126 crypto_func_t crypto_func;
127 /**< cryptographic function to use for this session */
129 /** Cipher Parameters */
131 enum rte_crypto_cipher_operation direction;
132 /**< cipher operation direction */
133 enum rte_crypto_cipher_algorithm algo;
134 /**< cipher algorithm */
139 /**< IV parameters */
145 /**< key length in bytes */
148 crypto_key_sched_t key_sched;
149 /**< Key schedule function */
152 /** Authentication Parameters */
154 enum rte_crypto_auth_operation operation;
155 /**< auth operation generate or verify */
156 enum armv8_crypto_auth_mode mode;
157 /**< auth operation mode */
161 /* Add data if needed */
165 uint8_t i_key_pad[SHA_BLOCK_MAX]
167 /**< inner pad (max supported block length) */
168 uint8_t o_key_pad[SHA_BLOCK_MAX]
170 /**< outer pad (max supported block length) */
171 uint8_t key[SHA_BLOCK_MAX];
172 /**< HMAC key (max supported block length)*/
175 uint16_t digest_length;
179 } __rte_cache_aligned;
181 /** Set and validate ARMv8 crypto session parameters */
182 extern int armv8_crypto_set_session_parameters(
183 struct armv8_crypto_session *sess,
184 const struct rte_crypto_sym_xform *xform);
186 /** device specific operations function pointer structure */
187 extern struct rte_cryptodev_ops *rte_armv8_crypto_pmd_ops;
189 #endif /* _ARMV8_PMD_PRIVATE_H_ */