4 * Copyright (C) Cavium, Inc. 2017.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
16 * * Neither the name of Cavium, Inc nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #ifndef _RTE_ARMV8_PMD_PRIVATE_H_
34 #define _RTE_ARMV8_PMD_PRIVATE_H_
36 #define CRYPTODEV_NAME_ARMV8_PMD crypto_armv8
37 /**< ARMv8 Crypto PMD device name */
39 #define ARMV8_CRYPTO_LOG_ERR(fmt, args...) \
40 RTE_LOG(ERR, CRYPTODEV, "[%s] %s() line %u: " fmt "\n", \
41 RTE_STR(CRYPTODEV_NAME_ARMV8_CRYPTO_PMD), \
42 __func__, __LINE__, ## args)
44 #ifdef RTE_LIBRTE_ARMV8_CRYPTO_DEBUG
45 #define ARMV8_CRYPTO_LOG_INFO(fmt, args...) \
46 RTE_LOG(INFO, CRYPTODEV, "[%s] %s() line %u: " fmt "\n", \
47 RTE_STR(CRYPTODEV_NAME_ARMV8_CRYPTO_PMD), \
48 __func__, __LINE__, ## args)
50 #define ARMV8_CRYPTO_LOG_DBG(fmt, args...) \
51 RTE_LOG(DEBUG, CRYPTODEV, "[%s] %s() line %u: " fmt "\n", \
52 RTE_STR(CRYPTODEV_NAME_ARMV8_CRYPTO_PMD), \
53 __func__, __LINE__, ## args)
55 #define ARMV8_CRYPTO_ASSERT(con) \
59 con "condition failed, line %u", __func__); \
64 #define ARMV8_CRYPTO_LOG_INFO(fmt, args...)
65 #define ARMV8_CRYPTO_LOG_DBG(fmt, args...)
66 #define ARMV8_CRYPTO_ASSERT(con)
69 #define NBBY 8 /* Number of bits in a byte */
70 #define BYTE_LENGTH(x) ((x) / NBBY) /* Number of bytes in x (round down) */
72 /* Maximum length for digest (SHA-256 needs 32 bytes) */
73 #define DIGEST_LENGTH_MAX 32
75 /** ARMv8 operation order mode enumerator */
76 enum armv8_crypto_chain_order {
77 ARMV8_CRYPTO_CHAIN_CIPHER_AUTH,
78 ARMV8_CRYPTO_CHAIN_AUTH_CIPHER,
79 ARMV8_CRYPTO_CHAIN_NOT_SUPPORTED,
80 ARMV8_CRYPTO_CHAIN_LIST_END = ARMV8_CRYPTO_CHAIN_NOT_SUPPORTED
83 /** ARMv8 cipher operation enumerator */
84 enum armv8_crypto_cipher_operation {
85 ARMV8_CRYPTO_CIPHER_OP_ENCRYPT = RTE_CRYPTO_CIPHER_OP_ENCRYPT,
86 ARMV8_CRYPTO_CIPHER_OP_DECRYPT = RTE_CRYPTO_CIPHER_OP_DECRYPT,
87 ARMV8_CRYPTO_CIPHER_OP_NOT_SUPPORTED,
88 ARMV8_CRYPTO_CIPHER_OP_LIST_END = ARMV8_CRYPTO_CIPHER_OP_NOT_SUPPORTED
91 enum armv8_crypto_cipher_keylen {
92 ARMV8_CRYPTO_CIPHER_KEYLEN_128,
93 ARMV8_CRYPTO_CIPHER_KEYLEN_192,
94 ARMV8_CRYPTO_CIPHER_KEYLEN_256,
95 ARMV8_CRYPTO_CIPHER_KEYLEN_NOT_SUPPORTED,
96 ARMV8_CRYPTO_CIPHER_KEYLEN_LIST_END =
97 ARMV8_CRYPTO_CIPHER_KEYLEN_NOT_SUPPORTED
100 /** ARMv8 auth mode enumerator */
101 enum armv8_crypto_auth_mode {
102 ARMV8_CRYPTO_AUTH_AS_AUTH,
103 ARMV8_CRYPTO_AUTH_AS_HMAC,
104 ARMV8_CRYPTO_AUTH_AS_CIPHER,
105 ARMV8_CRYPTO_AUTH_NOT_SUPPORTED,
106 ARMV8_CRYPTO_AUTH_LIST_END = ARMV8_CRYPTO_AUTH_NOT_SUPPORTED
109 #define CRYPTO_ORDER_MAX ARMV8_CRYPTO_CHAIN_LIST_END
110 #define CRYPTO_CIPHER_OP_MAX ARMV8_CRYPTO_CIPHER_OP_LIST_END
111 #define CRYPTO_CIPHER_KEYLEN_MAX ARMV8_CRYPTO_CIPHER_KEYLEN_LIST_END
112 #define CRYPTO_CIPHER_MAX RTE_CRYPTO_CIPHER_LIST_END
113 #define CRYPTO_AUTH_MAX RTE_CRYPTO_AUTH_LIST_END
115 #define HMAC_IPAD_VALUE (0x36)
116 #define HMAC_OPAD_VALUE (0x5C)
118 #define SHA256_AUTH_KEY_LENGTH (BYTE_LENGTH(256))
119 #define SHA256_BLOCK_SIZE (BYTE_LENGTH(512))
121 #define SHA1_AUTH_KEY_LENGTH (BYTE_LENGTH(160))
122 #define SHA1_BLOCK_SIZE (BYTE_LENGTH(512))
124 #define SHA_AUTH_KEY_MAX SHA256_AUTH_KEY_LENGTH
125 #define SHA_BLOCK_MAX SHA256_BLOCK_SIZE
127 typedef int (*crypto_func_t)(uint8_t *, uint8_t *, uint64_t,
128 uint8_t *, uint8_t *, uint64_t,
131 typedef void (*crypto_key_sched_t)(uint8_t *, const uint8_t *);
133 /** private data structure for each ARMv8 crypto device */
134 struct armv8_crypto_private {
135 unsigned int max_nb_qpairs;
136 /**< Max number of queue pairs */
137 unsigned int max_nb_sessions;
138 /**< Max number of sessions */
141 /** ARMv8 crypto queue pair */
142 struct armv8_crypto_qp {
144 /**< Queue Pair Identifier */
145 struct rte_ring *processed_ops;
146 /**< Ring for placing process packets */
147 struct rte_mempool *sess_mp;
148 /**< Session Mempool */
149 struct rte_cryptodev_stats stats;
150 /**< Queue pair statistics */
151 char name[RTE_CRYPTODEV_NAME_LEN];
152 /**< Unique Queue Pair Name */
153 uint8_t temp_digest[DIGEST_LENGTH_MAX];
154 /**< Buffer used to store the digest generated
155 * by the driver when verifying a digest provided
156 * by the user (using authentication verify operation)
158 } __rte_cache_aligned;
160 /** ARMv8 crypto private session structure */
161 struct armv8_crypto_session {
162 enum armv8_crypto_chain_order chain_order;
163 /**< chain order mode */
164 crypto_func_t crypto_func;
165 /**< cryptographic function to use for this session */
167 /** Cipher Parameters */
169 enum rte_crypto_cipher_operation direction;
170 /**< cipher operation direction */
171 enum rte_crypto_cipher_algorithm algo;
172 /**< cipher algorithm */
177 /**< IV parameters */
183 /**< key length in bytes */
186 crypto_key_sched_t key_sched;
187 /**< Key schedule function */
190 /** Authentication Parameters */
192 enum rte_crypto_auth_operation operation;
193 /**< auth operation generate or verify */
194 enum armv8_crypto_auth_mode mode;
195 /**< auth operation mode */
199 /* Add data if needed */
203 uint8_t i_key_pad[SHA_BLOCK_MAX]
205 /**< inner pad (max supported block length) */
206 uint8_t o_key_pad[SHA_BLOCK_MAX]
208 /**< outer pad (max supported block length) */
209 uint8_t key[SHA_BLOCK_MAX];
210 /**< HMAC key (max supported block length)*/
213 uint16_t digest_length;
217 } __rte_cache_aligned;
219 /** Set and validate ARMv8 crypto session parameters */
220 extern int armv8_crypto_set_session_parameters(
221 struct armv8_crypto_session *sess,
222 const struct rte_crypto_sym_xform *xform);
224 /** device specific operations function pointer structure */
225 extern struct rte_cryptodev_ops *rte_armv8_crypto_pmd_ops;
227 #endif /* _RTE_ARMV8_PMD_PRIVATE_H_ */