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 #define ARMV8_CRYPTO_LOG_ERR(fmt, args...) \
14 RTE_LOG(ERR, CRYPTODEV, "[%s] %s() line %u: " fmt "\n", \
15 RTE_STR(CRYPTODEV_NAME_ARMV8_CRYPTO_PMD), \
16 __func__, __LINE__, ## args)
18 #ifdef RTE_LIBRTE_ARMV8_CRYPTO_DEBUG
19 #define ARMV8_CRYPTO_LOG_INFO(fmt, args...) \
20 RTE_LOG(INFO, CRYPTODEV, "[%s] %s() line %u: " fmt "\n", \
21 RTE_STR(CRYPTODEV_NAME_ARMV8_CRYPTO_PMD), \
22 __func__, __LINE__, ## args)
24 #define ARMV8_CRYPTO_LOG_DBG(fmt, args...) \
25 RTE_LOG(DEBUG, CRYPTODEV, "[%s] %s() line %u: " fmt "\n", \
26 RTE_STR(CRYPTODEV_NAME_ARMV8_CRYPTO_PMD), \
27 __func__, __LINE__, ## args)
29 #define ARMV8_CRYPTO_ASSERT(con) \
33 con "condition failed, line %u", __func__); \
38 #define ARMV8_CRYPTO_LOG_INFO(fmt, args...)
39 #define ARMV8_CRYPTO_LOG_DBG(fmt, args...)
40 #define ARMV8_CRYPTO_ASSERT(con)
43 #define NBBY 8 /* Number of bits in a byte */
44 #define BYTE_LENGTH(x) ((x) / NBBY) /* Number of bytes in x (round down) */
46 /* Maximum length for digest (SHA-256 needs 32 bytes) */
47 #define DIGEST_LENGTH_MAX 32
49 /** ARMv8 operation order mode enumerator */
50 enum armv8_crypto_chain_order {
51 ARMV8_CRYPTO_CHAIN_CIPHER_AUTH,
52 ARMV8_CRYPTO_CHAIN_AUTH_CIPHER,
53 ARMV8_CRYPTO_CHAIN_NOT_SUPPORTED,
54 ARMV8_CRYPTO_CHAIN_LIST_END = ARMV8_CRYPTO_CHAIN_NOT_SUPPORTED
57 /** ARMv8 cipher operation enumerator */
58 enum armv8_crypto_cipher_operation {
59 ARMV8_CRYPTO_CIPHER_OP_ENCRYPT = RTE_CRYPTO_CIPHER_OP_ENCRYPT,
60 ARMV8_CRYPTO_CIPHER_OP_DECRYPT = RTE_CRYPTO_CIPHER_OP_DECRYPT,
61 ARMV8_CRYPTO_CIPHER_OP_NOT_SUPPORTED,
62 ARMV8_CRYPTO_CIPHER_OP_LIST_END = ARMV8_CRYPTO_CIPHER_OP_NOT_SUPPORTED
65 enum armv8_crypto_cipher_keylen {
66 ARMV8_CRYPTO_CIPHER_KEYLEN_128,
67 ARMV8_CRYPTO_CIPHER_KEYLEN_192,
68 ARMV8_CRYPTO_CIPHER_KEYLEN_256,
69 ARMV8_CRYPTO_CIPHER_KEYLEN_NOT_SUPPORTED,
70 ARMV8_CRYPTO_CIPHER_KEYLEN_LIST_END =
71 ARMV8_CRYPTO_CIPHER_KEYLEN_NOT_SUPPORTED
74 /** ARMv8 auth mode enumerator */
75 enum armv8_crypto_auth_mode {
76 ARMV8_CRYPTO_AUTH_AS_AUTH,
77 ARMV8_CRYPTO_AUTH_AS_HMAC,
78 ARMV8_CRYPTO_AUTH_AS_CIPHER,
79 ARMV8_CRYPTO_AUTH_NOT_SUPPORTED,
80 ARMV8_CRYPTO_AUTH_LIST_END = ARMV8_CRYPTO_AUTH_NOT_SUPPORTED
83 #define CRYPTO_ORDER_MAX ARMV8_CRYPTO_CHAIN_LIST_END
84 #define CRYPTO_CIPHER_OP_MAX ARMV8_CRYPTO_CIPHER_OP_LIST_END
85 #define CRYPTO_CIPHER_KEYLEN_MAX ARMV8_CRYPTO_CIPHER_KEYLEN_LIST_END
86 #define CRYPTO_CIPHER_MAX RTE_CRYPTO_CIPHER_LIST_END
87 #define CRYPTO_AUTH_MAX RTE_CRYPTO_AUTH_LIST_END
89 #define HMAC_IPAD_VALUE (0x36)
90 #define HMAC_OPAD_VALUE (0x5C)
92 #define SHA256_AUTH_KEY_LENGTH (BYTE_LENGTH(256))
93 #define SHA256_BLOCK_SIZE (BYTE_LENGTH(512))
95 #define SHA1_AUTH_KEY_LENGTH (BYTE_LENGTH(160))
96 #define SHA1_BLOCK_SIZE (BYTE_LENGTH(512))
98 #define SHA_AUTH_KEY_MAX SHA256_AUTH_KEY_LENGTH
99 #define SHA_BLOCK_MAX SHA256_BLOCK_SIZE
101 typedef int (*crypto_func_t)(uint8_t *, uint8_t *, uint64_t,
102 uint8_t *, uint8_t *, uint64_t,
103 armv8_cipher_digest_t *);
105 typedef void (*crypto_key_sched_t)(uint8_t *, const uint8_t *);
107 /** private data structure for each ARMv8 crypto device */
108 struct armv8_crypto_private {
109 unsigned int max_nb_qpairs;
110 /**< Max number of queue pairs */
113 /** ARMv8 crypto queue pair */
114 struct armv8_crypto_qp {
116 /**< Queue Pair Identifier */
117 struct rte_ring *processed_ops;
118 /**< Ring for placing process packets */
119 struct rte_mempool *sess_mp;
120 /**< Session Mempool */
121 struct rte_mempool *sess_mp_priv;
122 /**< Session Private Data Mempool */
123 struct rte_cryptodev_stats stats;
124 /**< Queue pair statistics */
125 char name[RTE_CRYPTODEV_NAME_MAX_LEN];
126 /**< Unique Queue Pair Name */
127 uint8_t temp_digest[DIGEST_LENGTH_MAX];
128 /**< Buffer used to store the digest generated
129 * by the driver when verifying a digest provided
130 * by the user (using authentication verify operation)
132 } __rte_cache_aligned;
134 /** ARMv8 crypto private session structure */
135 struct armv8_crypto_session {
136 enum armv8_crypto_chain_order chain_order;
137 /**< chain order mode */
138 crypto_func_t crypto_func;
139 /**< cryptographic function to use for this session */
141 /** Cipher Parameters */
143 enum rte_crypto_cipher_operation direction;
144 /**< cipher operation direction */
145 enum rte_crypto_cipher_algorithm algo;
146 /**< cipher algorithm */
151 /**< IV parameters */
157 /**< key length in bytes */
160 crypto_key_sched_t key_sched;
161 /**< Key schedule function */
164 /** Authentication Parameters */
166 enum rte_crypto_auth_operation operation;
167 /**< auth operation generate or verify */
168 enum armv8_crypto_auth_mode mode;
169 /**< auth operation mode */
173 /* Add data if needed */
177 uint8_t i_key_pad[SHA_BLOCK_MAX]
179 /**< inner pad (max supported block length) */
180 uint8_t o_key_pad[SHA_BLOCK_MAX]
182 /**< outer pad (max supported block length) */
183 uint8_t key[SHA_BLOCK_MAX];
184 /**< HMAC key (max supported block length)*/
187 uint16_t digest_length;
191 } __rte_cache_aligned;
193 /** Set and validate ARMv8 crypto session parameters */
194 extern int armv8_crypto_set_session_parameters(
195 struct armv8_crypto_session *sess,
196 const struct rte_crypto_sym_xform *xform);
198 /** device specific operations function pointer structure */
199 extern struct rte_cryptodev_ops *rte_armv8_crypto_pmd_ops;
201 #endif /* _ARMV8_PMD_PRIVATE_H_ */