1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2015-2021 Intel Corporation
5 #include "pmd_aesni_mb_priv.h"
8 * Calculate the authentication pre-computes
10 * @param one_block_hash Function pointer
11 * to calculate digest on ipad/opad
12 * @param ipad Inner pad output byte array
13 * @param opad Outer pad output byte array
14 * @param hkey Authentication key
15 * @param hkey_len Authentication key length
16 * @param blocksize Block size of selected hash algo
19 calculate_auth_precomputes(hash_one_block_t one_block_hash,
20 uint8_t *ipad, uint8_t *opad,
21 const uint8_t *hkey, uint16_t hkey_len,
26 uint8_t ipad_buf[blocksize] __rte_aligned(16);
27 uint8_t opad_buf[blocksize] __rte_aligned(16);
29 /* Setup inner and outer pads */
30 memset(ipad_buf, HMAC_IPAD_VALUE, blocksize);
31 memset(opad_buf, HMAC_OPAD_VALUE, blocksize);
33 /* XOR hash key with inner and outer pads */
34 length = hkey_len > blocksize ? blocksize : hkey_len;
36 for (i = 0; i < length; i++) {
37 ipad_buf[i] ^= hkey[i];
38 opad_buf[i] ^= hkey[i];
41 /* Compute partial hashes */
42 (*one_block_hash)(ipad_buf, ipad);
43 (*one_block_hash)(opad_buf, opad);
46 memset(ipad_buf, 0, blocksize);
47 memset(opad_buf, 0, blocksize);
51 is_aead_algo(IMB_HASH_ALG hash_alg, IMB_CIPHER_MODE cipher_mode)
53 return (hash_alg == IMB_AUTH_CHACHA20_POLY1305 ||
54 hash_alg == IMB_AUTH_AES_CCM ||
55 (hash_alg == IMB_AUTH_AES_GMAC &&
56 cipher_mode == IMB_CIPHER_GCM));
59 /** Set session authentication parameters */
61 aesni_mb_set_session_auth_parameters(const IMB_MGR *mb_mgr,
62 struct aesni_mb_session *sess,
63 const struct rte_crypto_sym_xform *xform)
65 hash_one_block_t hash_oneblock_fn = NULL;
66 unsigned int key_larger_block_size = 0;
67 uint8_t hashed_key[HMAC_MAX_BLOCK_SIZE] = { 0 };
68 uint32_t auth_precompute = 1;
71 sess->auth.algo = IMB_AUTH_NULL;
75 if (xform->type != RTE_CRYPTO_SYM_XFORM_AUTH) {
76 IPSEC_MB_LOG(ERR, "Crypto xform struct not of type auth");
80 /* Set IV parameters */
81 sess->auth_iv.offset = xform->auth.iv.offset;
82 sess->auth_iv.length = xform->auth.iv.length;
84 /* Set the request digest size */
85 sess->auth.req_digest_len = xform->auth.digest_length;
87 /* Select auth generate/verify */
88 sess->auth.operation = xform->auth.op;
90 /* Set Authentication Parameters */
91 if (xform->auth.algo == RTE_CRYPTO_AUTH_NULL) {
92 sess->auth.algo = IMB_AUTH_NULL;
93 sess->auth.gen_digest_len = 0;
97 if (xform->auth.algo == RTE_CRYPTO_AUTH_AES_XCBC_MAC) {
98 sess->auth.algo = IMB_AUTH_AES_XCBC;
100 uint16_t xcbc_mac_digest_len =
101 get_truncated_digest_byte_length(IMB_AUTH_AES_XCBC);
102 if (sess->auth.req_digest_len != xcbc_mac_digest_len) {
103 IPSEC_MB_LOG(ERR, "Invalid digest size\n");
106 sess->auth.gen_digest_len = sess->auth.req_digest_len;
108 IMB_AES_XCBC_KEYEXP(mb_mgr, xform->auth.key.data,
109 sess->auth.xcbc.k1_expanded,
110 sess->auth.xcbc.k2, sess->auth.xcbc.k3);
114 if (xform->auth.algo == RTE_CRYPTO_AUTH_AES_CMAC) {
117 sess->auth.algo = IMB_AUTH_AES_CMAC;
119 uint16_t cmac_digest_len =
120 get_digest_byte_length(IMB_AUTH_AES_CMAC);
122 if (sess->auth.req_digest_len > cmac_digest_len) {
123 IPSEC_MB_LOG(ERR, "Invalid digest size\n");
127 * Multi-buffer lib supports digest sizes from 4 to 16 bytes
128 * in version 0.50 and sizes of 12 and 16 bytes,
130 * If size requested is different, generate the full digest
131 * (16 bytes) in a temporary location and then memcpy
132 * the requested number of bytes.
134 if (sess->auth.req_digest_len < 4)
135 sess->auth.gen_digest_len = cmac_digest_len;
137 sess->auth.gen_digest_len = sess->auth.req_digest_len;
139 IMB_AES_KEYEXP_128(mb_mgr, xform->auth.key.data,
140 sess->auth.cmac.expkey, dust);
141 IMB_AES_CMAC_SUBKEY_GEN_128(mb_mgr, sess->auth.cmac.expkey,
142 sess->auth.cmac.skey1, sess->auth.cmac.skey2);
146 if (xform->auth.algo == RTE_CRYPTO_AUTH_AES_GMAC) {
147 if (xform->auth.op == RTE_CRYPTO_AUTH_OP_GENERATE) {
148 sess->cipher.direction = IMB_DIR_ENCRYPT;
149 sess->chain_order = IMB_ORDER_CIPHER_HASH;
151 sess->cipher.direction = IMB_DIR_DECRYPT;
153 sess->auth.algo = IMB_AUTH_AES_GMAC;
154 if (sess->auth.req_digest_len >
155 get_digest_byte_length(IMB_AUTH_AES_GMAC)) {
156 IPSEC_MB_LOG(ERR, "Invalid digest size\n");
159 sess->auth.gen_digest_len = sess->auth.req_digest_len;
160 sess->iv.length = xform->auth.iv.length;
161 sess->iv.offset = xform->auth.iv.offset;
163 switch (xform->auth.key.length) {
164 case IMB_KEY_128_BYTES:
165 IMB_AES128_GCM_PRE(mb_mgr, xform->auth.key.data,
166 &sess->cipher.gcm_key);
167 sess->cipher.key_length_in_bytes = IMB_KEY_128_BYTES;
169 case IMB_KEY_192_BYTES:
170 IMB_AES192_GCM_PRE(mb_mgr, xform->auth.key.data,
171 &sess->cipher.gcm_key);
172 sess->cipher.key_length_in_bytes = IMB_KEY_192_BYTES;
174 case IMB_KEY_256_BYTES:
175 IMB_AES256_GCM_PRE(mb_mgr, xform->auth.key.data,
176 &sess->cipher.gcm_key);
177 sess->cipher.key_length_in_bytes = IMB_KEY_256_BYTES;
180 IPSEC_MB_LOG(ERR, "Invalid authentication key length\n");
187 if (xform->auth.algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
188 if (xform->auth.key.length == 16) {
189 sess->auth.algo = IMB_AUTH_ZUC_EIA3_BITLEN;
190 } else if (xform->auth.key.length == 32) {
191 sess->auth.algo = IMB_AUTH_ZUC256_EIA3_BITLEN;
193 IPSEC_MB_LOG(ERR, "Invalid authentication key length\n");
197 uint16_t zuc_eia3_digest_len =
198 get_truncated_digest_byte_length(
199 IMB_AUTH_ZUC_EIA3_BITLEN);
200 if (sess->auth.req_digest_len != zuc_eia3_digest_len) {
201 IPSEC_MB_LOG(ERR, "Invalid digest size\n");
204 sess->auth.gen_digest_len = sess->auth.req_digest_len;
206 memcpy(sess->auth.zuc_auth_key, xform->auth.key.data,
207 xform->auth.key.length);
209 } else if (xform->auth.algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2) {
210 sess->auth.algo = IMB_AUTH_SNOW3G_UIA2_BITLEN;
211 uint16_t snow3g_uia2_digest_len =
212 get_truncated_digest_byte_length(
213 IMB_AUTH_SNOW3G_UIA2_BITLEN);
214 if (sess->auth.req_digest_len != snow3g_uia2_digest_len) {
215 IPSEC_MB_LOG(ERR, "Invalid digest size\n");
218 sess->auth.gen_digest_len = sess->auth.req_digest_len;
220 IMB_SNOW3G_INIT_KEY_SCHED(mb_mgr, xform->auth.key.data,
221 &sess->auth.pKeySched_snow3g_auth);
223 } else if (xform->auth.algo == RTE_CRYPTO_AUTH_KASUMI_F9) {
224 sess->auth.algo = IMB_AUTH_KASUMI_UIA1;
225 uint16_t kasumi_f9_digest_len =
226 get_truncated_digest_byte_length(IMB_AUTH_KASUMI_UIA1);
227 if (sess->auth.req_digest_len != kasumi_f9_digest_len) {
228 IPSEC_MB_LOG(ERR, "Invalid digest size\n");
231 sess->auth.gen_digest_len = sess->auth.req_digest_len;
233 IMB_KASUMI_INIT_F9_KEY_SCHED(mb_mgr, xform->auth.key.data,
234 &sess->auth.pKeySched_kasumi_auth);
238 switch (xform->auth.algo) {
239 case RTE_CRYPTO_AUTH_MD5_HMAC:
240 sess->auth.algo = IMB_AUTH_MD5;
241 hash_oneblock_fn = mb_mgr->md5_one_block;
243 case RTE_CRYPTO_AUTH_SHA1_HMAC:
244 sess->auth.algo = IMB_AUTH_HMAC_SHA_1;
245 hash_oneblock_fn = mb_mgr->sha1_one_block;
246 if (xform->auth.key.length > get_auth_algo_blocksize(
247 IMB_AUTH_HMAC_SHA_1)) {
249 xform->auth.key.data,
250 xform->auth.key.length,
252 key_larger_block_size = 1;
255 case RTE_CRYPTO_AUTH_SHA1:
256 sess->auth.algo = IMB_AUTH_SHA_1;
259 case RTE_CRYPTO_AUTH_SHA224_HMAC:
260 sess->auth.algo = IMB_AUTH_HMAC_SHA_224;
261 hash_oneblock_fn = mb_mgr->sha224_one_block;
262 if (xform->auth.key.length > get_auth_algo_blocksize(
263 IMB_AUTH_HMAC_SHA_224)) {
265 xform->auth.key.data,
266 xform->auth.key.length,
268 key_larger_block_size = 1;
271 case RTE_CRYPTO_AUTH_SHA224:
272 sess->auth.algo = IMB_AUTH_SHA_224;
275 case RTE_CRYPTO_AUTH_SHA256_HMAC:
276 sess->auth.algo = IMB_AUTH_HMAC_SHA_256;
277 hash_oneblock_fn = mb_mgr->sha256_one_block;
278 if (xform->auth.key.length > get_auth_algo_blocksize(
279 IMB_AUTH_HMAC_SHA_256)) {
281 xform->auth.key.data,
282 xform->auth.key.length,
284 key_larger_block_size = 1;
287 case RTE_CRYPTO_AUTH_SHA256:
288 sess->auth.algo = IMB_AUTH_SHA_256;
291 case RTE_CRYPTO_AUTH_SHA384_HMAC:
292 sess->auth.algo = IMB_AUTH_HMAC_SHA_384;
293 hash_oneblock_fn = mb_mgr->sha384_one_block;
294 if (xform->auth.key.length > get_auth_algo_blocksize(
295 IMB_AUTH_HMAC_SHA_384)) {
297 xform->auth.key.data,
298 xform->auth.key.length,
300 key_larger_block_size = 1;
303 case RTE_CRYPTO_AUTH_SHA384:
304 sess->auth.algo = IMB_AUTH_SHA_384;
307 case RTE_CRYPTO_AUTH_SHA512_HMAC:
308 sess->auth.algo = IMB_AUTH_HMAC_SHA_512;
309 hash_oneblock_fn = mb_mgr->sha512_one_block;
310 if (xform->auth.key.length > get_auth_algo_blocksize(
311 IMB_AUTH_HMAC_SHA_512)) {
313 xform->auth.key.data,
314 xform->auth.key.length,
316 key_larger_block_size = 1;
319 case RTE_CRYPTO_AUTH_SHA512:
320 sess->auth.algo = IMB_AUTH_SHA_512;
325 "Unsupported authentication algorithm selection");
328 uint16_t trunc_digest_size =
329 get_truncated_digest_byte_length(sess->auth.algo);
330 uint16_t full_digest_size =
331 get_digest_byte_length(sess->auth.algo);
333 if (sess->auth.req_digest_len > full_digest_size ||
334 sess->auth.req_digest_len == 0) {
335 IPSEC_MB_LOG(ERR, "Invalid digest size\n");
339 if (sess->auth.req_digest_len != trunc_digest_size &&
340 sess->auth.req_digest_len != full_digest_size)
341 sess->auth.gen_digest_len = full_digest_size;
343 sess->auth.gen_digest_len = sess->auth.req_digest_len;
345 /* Plain SHA does not require precompute key */
346 if (auth_precompute == 0)
349 /* Calculate Authentication precomputes */
350 if (key_larger_block_size) {
351 calculate_auth_precomputes(hash_oneblock_fn,
352 sess->auth.pads.inner, sess->auth.pads.outer,
354 xform->auth.key.length,
355 get_auth_algo_blocksize(sess->auth.algo));
357 calculate_auth_precomputes(hash_oneblock_fn,
358 sess->auth.pads.inner, sess->auth.pads.outer,
359 xform->auth.key.data,
360 xform->auth.key.length,
361 get_auth_algo_blocksize(sess->auth.algo));
367 /** Set session cipher parameters */
369 aesni_mb_set_session_cipher_parameters(const IMB_MGR *mb_mgr,
370 struct aesni_mb_session *sess,
371 const struct rte_crypto_sym_xform *xform)
375 uint8_t is_docsis = 0;
377 uint8_t is_snow3g = 0;
378 uint8_t is_kasumi = 0;
381 sess->cipher.mode = IMB_CIPHER_NULL;
385 if (xform->type != RTE_CRYPTO_SYM_XFORM_CIPHER) {
386 IPSEC_MB_LOG(ERR, "Crypto xform struct not of type cipher");
390 /* Select cipher direction */
391 switch (xform->cipher.op) {
392 case RTE_CRYPTO_CIPHER_OP_ENCRYPT:
393 sess->cipher.direction = IMB_DIR_ENCRYPT;
395 case RTE_CRYPTO_CIPHER_OP_DECRYPT:
396 sess->cipher.direction = IMB_DIR_DECRYPT;
399 IPSEC_MB_LOG(ERR, "Invalid cipher operation parameter");
403 /* Select cipher mode */
404 switch (xform->cipher.algo) {
405 case RTE_CRYPTO_CIPHER_AES_CBC:
406 sess->cipher.mode = IMB_CIPHER_CBC;
409 case RTE_CRYPTO_CIPHER_AES_CTR:
410 sess->cipher.mode = IMB_CIPHER_CNTR;
413 case RTE_CRYPTO_CIPHER_AES_DOCSISBPI:
414 sess->cipher.mode = IMB_CIPHER_DOCSIS_SEC_BPI;
417 case RTE_CRYPTO_CIPHER_DES_CBC:
418 sess->cipher.mode = IMB_CIPHER_DES;
420 case RTE_CRYPTO_CIPHER_DES_DOCSISBPI:
421 sess->cipher.mode = IMB_CIPHER_DOCSIS_DES;
423 case RTE_CRYPTO_CIPHER_3DES_CBC:
424 sess->cipher.mode = IMB_CIPHER_DES3;
427 case RTE_CRYPTO_CIPHER_AES_ECB:
428 sess->cipher.mode = IMB_CIPHER_ECB;
431 case RTE_CRYPTO_CIPHER_ZUC_EEA3:
432 sess->cipher.mode = IMB_CIPHER_ZUC_EEA3;
435 case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
436 sess->cipher.mode = IMB_CIPHER_SNOW3G_UEA2_BITLEN;
439 case RTE_CRYPTO_CIPHER_KASUMI_F8:
440 sess->cipher.mode = IMB_CIPHER_KASUMI_UEA1_BITLEN;
443 case RTE_CRYPTO_CIPHER_NULL:
444 sess->cipher.mode = IMB_CIPHER_NULL;
445 sess->cipher.key_length_in_bytes = 0;
446 sess->iv.offset = xform->cipher.iv.offset;
447 sess->iv.length = xform->cipher.iv.length;
450 IPSEC_MB_LOG(ERR, "Unsupported cipher mode parameter");
454 /* Set IV parameters */
455 sess->iv.offset = xform->cipher.iv.offset;
456 sess->iv.length = xform->cipher.iv.length;
458 /* Check key length and choose key expansion function for AES */
460 switch (xform->cipher.key.length) {
461 case IMB_KEY_128_BYTES:
462 sess->cipher.key_length_in_bytes = IMB_KEY_128_BYTES;
463 IMB_AES_KEYEXP_128(mb_mgr, xform->cipher.key.data,
464 sess->cipher.expanded_aes_keys.encode,
465 sess->cipher.expanded_aes_keys.decode);
467 case IMB_KEY_192_BYTES:
468 sess->cipher.key_length_in_bytes = IMB_KEY_192_BYTES;
469 IMB_AES_KEYEXP_192(mb_mgr, xform->cipher.key.data,
470 sess->cipher.expanded_aes_keys.encode,
471 sess->cipher.expanded_aes_keys.decode);
473 case IMB_KEY_256_BYTES:
474 sess->cipher.key_length_in_bytes = IMB_KEY_256_BYTES;
475 IMB_AES_KEYEXP_256(mb_mgr, xform->cipher.key.data,
476 sess->cipher.expanded_aes_keys.encode,
477 sess->cipher.expanded_aes_keys.decode);
480 IPSEC_MB_LOG(ERR, "Invalid cipher key length");
483 } else if (is_docsis) {
484 switch (xform->cipher.key.length) {
485 case IMB_KEY_128_BYTES:
486 sess->cipher.key_length_in_bytes = IMB_KEY_128_BYTES;
487 IMB_AES_KEYEXP_128(mb_mgr, xform->cipher.key.data,
488 sess->cipher.expanded_aes_keys.encode,
489 sess->cipher.expanded_aes_keys.decode);
491 case IMB_KEY_256_BYTES:
492 sess->cipher.key_length_in_bytes = IMB_KEY_256_BYTES;
493 IMB_AES_KEYEXP_256(mb_mgr, xform->cipher.key.data,
494 sess->cipher.expanded_aes_keys.encode,
495 sess->cipher.expanded_aes_keys.decode);
498 IPSEC_MB_LOG(ERR, "Invalid cipher key length");
501 } else if (is_3DES) {
502 uint64_t *keys[3] = {sess->cipher.exp_3des_keys.key[0],
503 sess->cipher.exp_3des_keys.key[1],
504 sess->cipher.exp_3des_keys.key[2]};
506 switch (xform->cipher.key.length) {
508 IMB_DES_KEYSCHED(mb_mgr, keys[0],
509 xform->cipher.key.data);
510 IMB_DES_KEYSCHED(mb_mgr, keys[1],
511 xform->cipher.key.data + 8);
512 IMB_DES_KEYSCHED(mb_mgr, keys[2],
513 xform->cipher.key.data + 16);
515 /* Initialize keys - 24 bytes: [K1-K2-K3] */
516 sess->cipher.exp_3des_keys.ks_ptr[0] = keys[0];
517 sess->cipher.exp_3des_keys.ks_ptr[1] = keys[1];
518 sess->cipher.exp_3des_keys.ks_ptr[2] = keys[2];
521 IMB_DES_KEYSCHED(mb_mgr, keys[0],
522 xform->cipher.key.data);
523 IMB_DES_KEYSCHED(mb_mgr, keys[1],
524 xform->cipher.key.data + 8);
525 /* Initialize keys - 16 bytes: [K1=K1,K2=K2,K3=K1] */
526 sess->cipher.exp_3des_keys.ks_ptr[0] = keys[0];
527 sess->cipher.exp_3des_keys.ks_ptr[1] = keys[1];
528 sess->cipher.exp_3des_keys.ks_ptr[2] = keys[0];
531 IMB_DES_KEYSCHED(mb_mgr, keys[0],
532 xform->cipher.key.data);
534 /* Initialize keys - 8 bytes: [K1 = K2 = K3] */
535 sess->cipher.exp_3des_keys.ks_ptr[0] = keys[0];
536 sess->cipher.exp_3des_keys.ks_ptr[1] = keys[0];
537 sess->cipher.exp_3des_keys.ks_ptr[2] = keys[0];
540 IPSEC_MB_LOG(ERR, "Invalid cipher key length");
544 sess->cipher.key_length_in_bytes = 24;
546 if (xform->cipher.key.length != 16 &&
547 xform->cipher.key.length != 32) {
548 IPSEC_MB_LOG(ERR, "Invalid cipher key length");
551 sess->cipher.key_length_in_bytes = xform->cipher.key.length;
552 memcpy(sess->cipher.zuc_cipher_key, xform->cipher.key.data,
553 xform->cipher.key.length);
554 } else if (is_snow3g) {
555 if (xform->cipher.key.length != 16) {
556 IPSEC_MB_LOG(ERR, "Invalid cipher key length");
559 sess->cipher.key_length_in_bytes = 16;
560 IMB_SNOW3G_INIT_KEY_SCHED(mb_mgr, xform->cipher.key.data,
561 &sess->cipher.pKeySched_snow3g_cipher);
562 } else if (is_kasumi) {
563 if (xform->cipher.key.length != 16) {
564 IPSEC_MB_LOG(ERR, "Invalid cipher key length");
567 sess->cipher.key_length_in_bytes = 16;
568 IMB_KASUMI_INIT_F8_KEY_SCHED(mb_mgr, xform->cipher.key.data,
569 &sess->cipher.pKeySched_kasumi_cipher);
571 if (xform->cipher.key.length != 8) {
572 IPSEC_MB_LOG(ERR, "Invalid cipher key length");
575 sess->cipher.key_length_in_bytes = 8;
577 IMB_DES_KEYSCHED(mb_mgr,
578 (uint64_t *)sess->cipher.expanded_aes_keys.encode,
579 xform->cipher.key.data);
580 IMB_DES_KEYSCHED(mb_mgr,
581 (uint64_t *)sess->cipher.expanded_aes_keys.decode,
582 xform->cipher.key.data);
589 aesni_mb_set_session_aead_parameters(const IMB_MGR *mb_mgr,
590 struct aesni_mb_session *sess,
591 const struct rte_crypto_sym_xform *xform)
593 switch (xform->aead.op) {
594 case RTE_CRYPTO_AEAD_OP_ENCRYPT:
595 sess->cipher.direction = IMB_DIR_ENCRYPT;
596 sess->auth.operation = RTE_CRYPTO_AUTH_OP_GENERATE;
598 case RTE_CRYPTO_AEAD_OP_DECRYPT:
599 sess->cipher.direction = IMB_DIR_DECRYPT;
600 sess->auth.operation = RTE_CRYPTO_AUTH_OP_VERIFY;
603 IPSEC_MB_LOG(ERR, "Invalid aead operation parameter");
607 /* Set IV parameters */
608 sess->iv.offset = xform->aead.iv.offset;
609 sess->iv.length = xform->aead.iv.length;
611 /* Set digest sizes */
612 sess->auth.req_digest_len = xform->aead.digest_length;
613 sess->auth.gen_digest_len = sess->auth.req_digest_len;
615 switch (xform->aead.algo) {
616 case RTE_CRYPTO_AEAD_AES_CCM:
617 sess->cipher.mode = IMB_CIPHER_CCM;
618 sess->auth.algo = IMB_AUTH_AES_CCM;
620 /* Check key length and choose key expansion function for AES */
621 switch (xform->aead.key.length) {
622 case IMB_KEY_128_BYTES:
623 sess->cipher.key_length_in_bytes = IMB_KEY_128_BYTES;
624 IMB_AES_KEYEXP_128(mb_mgr, xform->aead.key.data,
625 sess->cipher.expanded_aes_keys.encode,
626 sess->cipher.expanded_aes_keys.decode);
628 case IMB_KEY_256_BYTES:
629 sess->cipher.key_length_in_bytes = IMB_KEY_256_BYTES;
630 IMB_AES_KEYEXP_256(mb_mgr, xform->aead.key.data,
631 sess->cipher.expanded_aes_keys.encode,
632 sess->cipher.expanded_aes_keys.decode);
635 IPSEC_MB_LOG(ERR, "Invalid cipher key length");
639 /* CCM digests must be between 4 and 16 and an even number */
640 if (sess->auth.req_digest_len < AES_CCM_DIGEST_MIN_LEN ||
641 sess->auth.req_digest_len > AES_CCM_DIGEST_MAX_LEN ||
642 (sess->auth.req_digest_len & 1) == 1) {
643 IPSEC_MB_LOG(ERR, "Invalid digest size\n");
648 case RTE_CRYPTO_AEAD_AES_GCM:
649 sess->cipher.mode = IMB_CIPHER_GCM;
650 sess->auth.algo = IMB_AUTH_AES_GMAC;
652 switch (xform->aead.key.length) {
653 case IMB_KEY_128_BYTES:
654 sess->cipher.key_length_in_bytes = IMB_KEY_128_BYTES;
655 IMB_AES128_GCM_PRE(mb_mgr, xform->aead.key.data,
656 &sess->cipher.gcm_key);
658 case IMB_KEY_192_BYTES:
659 sess->cipher.key_length_in_bytes = IMB_KEY_192_BYTES;
660 IMB_AES192_GCM_PRE(mb_mgr, xform->aead.key.data,
661 &sess->cipher.gcm_key);
663 case IMB_KEY_256_BYTES:
664 sess->cipher.key_length_in_bytes = IMB_KEY_256_BYTES;
665 IMB_AES256_GCM_PRE(mb_mgr, xform->aead.key.data,
666 &sess->cipher.gcm_key);
669 IPSEC_MB_LOG(ERR, "Invalid cipher key length");
673 /* GCM digest size must be between 1 and 16 */
674 if (sess->auth.req_digest_len == 0 ||
675 sess->auth.req_digest_len > 16) {
676 IPSEC_MB_LOG(ERR, "Invalid digest size\n");
681 case RTE_CRYPTO_AEAD_CHACHA20_POLY1305:
682 sess->cipher.mode = IMB_CIPHER_CHACHA20_POLY1305;
683 sess->auth.algo = IMB_AUTH_CHACHA20_POLY1305;
685 if (xform->aead.key.length != 32) {
686 IPSEC_MB_LOG(ERR, "Invalid key length");
689 sess->cipher.key_length_in_bytes = 32;
690 memcpy(sess->cipher.expanded_aes_keys.encode,
691 xform->aead.key.data, 32);
692 if (sess->auth.req_digest_len != 16) {
693 IPSEC_MB_LOG(ERR, "Invalid digest size\n");
698 IPSEC_MB_LOG(ERR, "Unsupported aead mode parameter");
705 /** Configure a aesni multi-buffer session from a crypto xform chain */
707 aesni_mb_session_configure(IMB_MGR *mb_mgr,
709 const struct rte_crypto_sym_xform *xform)
711 const struct rte_crypto_sym_xform *auth_xform = NULL;
712 const struct rte_crypto_sym_xform *cipher_xform = NULL;
713 const struct rte_crypto_sym_xform *aead_xform = NULL;
714 enum ipsec_mb_operation mode;
715 struct aesni_mb_session *sess = (struct aesni_mb_session *) priv_sess;
718 ret = ipsec_mb_parse_xform(xform, &mode, &auth_xform,
719 &cipher_xform, &aead_xform);
723 /* Select Crypto operation - hash then cipher / cipher then hash */
725 case IPSEC_MB_OP_HASH_VERIFY_THEN_DECRYPT:
726 sess->chain_order = IMB_ORDER_HASH_CIPHER;
728 case IPSEC_MB_OP_ENCRYPT_THEN_HASH_GEN:
729 case IPSEC_MB_OP_DECRYPT_THEN_HASH_VERIFY:
730 sess->chain_order = IMB_ORDER_CIPHER_HASH;
732 case IPSEC_MB_OP_HASH_GEN_ONLY:
733 case IPSEC_MB_OP_HASH_VERIFY_ONLY:
734 case IPSEC_MB_OP_HASH_GEN_THEN_ENCRYPT:
735 sess->chain_order = IMB_ORDER_HASH_CIPHER;
738 * Multi buffer library operates only at two modes,
739 * IMB_ORDER_CIPHER_HASH and IMB_ORDER_HASH_CIPHER.
740 * When doing ciphering only, chain order depends
741 * on cipher operation: encryption is always
742 * the first operation and decryption the last one.
744 case IPSEC_MB_OP_ENCRYPT_ONLY:
745 sess->chain_order = IMB_ORDER_CIPHER_HASH;
747 case IPSEC_MB_OP_DECRYPT_ONLY:
748 sess->chain_order = IMB_ORDER_HASH_CIPHER;
750 case IPSEC_MB_OP_AEAD_AUTHENTICATED_ENCRYPT:
751 sess->chain_order = IMB_ORDER_CIPHER_HASH;
752 sess->aead.aad_len = xform->aead.aad_length;
754 case IPSEC_MB_OP_AEAD_AUTHENTICATED_DECRYPT:
755 sess->chain_order = IMB_ORDER_HASH_CIPHER;
756 sess->aead.aad_len = xform->aead.aad_length;
758 case IPSEC_MB_OP_NOT_SUPPORTED:
761 "Unsupported operation chain order parameter");
765 /* Default IV length = 0 */
767 sess->auth_iv.length = 0;
769 ret = aesni_mb_set_session_auth_parameters(mb_mgr, sess, auth_xform);
772 "Invalid/unsupported authentication parameters");
776 ret = aesni_mb_set_session_cipher_parameters(mb_mgr, sess,
779 IPSEC_MB_LOG(ERR, "Invalid/unsupported cipher parameters");
784 ret = aesni_mb_set_session_aead_parameters(mb_mgr, sess,
788 "Invalid/unsupported aead parameters");
796 #ifdef AESNI_MB_DOCSIS_SEC_ENABLED
797 /** Check DOCSIS security session configuration is valid */
799 check_docsis_sec_session(struct rte_security_session_conf *conf)
801 struct rte_crypto_sym_xform *crypto_sym = conf->crypto_xform;
802 struct rte_security_docsis_xform *docsis = &conf->docsis;
804 /* Downlink: CRC generate -> Cipher encrypt */
805 if (docsis->direction == RTE_SECURITY_DOCSIS_DOWNLINK) {
807 if (crypto_sym != NULL &&
808 crypto_sym->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
809 crypto_sym->cipher.op == RTE_CRYPTO_CIPHER_OP_ENCRYPT &&
810 crypto_sym->cipher.algo ==
811 RTE_CRYPTO_CIPHER_AES_DOCSISBPI &&
812 (crypto_sym->cipher.key.length == IMB_KEY_128_BYTES ||
813 crypto_sym->cipher.key.length == IMB_KEY_256_BYTES) &&
814 crypto_sym->cipher.iv.length == IMB_AES_BLOCK_SIZE &&
815 crypto_sym->next == NULL) {
818 /* Uplink: Cipher decrypt -> CRC verify */
819 } else if (docsis->direction == RTE_SECURITY_DOCSIS_UPLINK) {
821 if (crypto_sym != NULL &&
822 crypto_sym->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
823 crypto_sym->cipher.op == RTE_CRYPTO_CIPHER_OP_DECRYPT &&
824 crypto_sym->cipher.algo ==
825 RTE_CRYPTO_CIPHER_AES_DOCSISBPI &&
826 (crypto_sym->cipher.key.length == IMB_KEY_128_BYTES ||
827 crypto_sym->cipher.key.length == IMB_KEY_256_BYTES) &&
828 crypto_sym->cipher.iv.length == IMB_AES_BLOCK_SIZE &&
829 crypto_sym->next == NULL) {
837 /** Set DOCSIS security session auth (CRC) parameters */
839 aesni_mb_set_docsis_sec_session_auth_parameters(struct aesni_mb_session *sess,
840 struct rte_security_docsis_xform *xform)
843 IPSEC_MB_LOG(ERR, "Invalid DOCSIS xform");
847 /* Select CRC generate/verify */
848 if (xform->direction == RTE_SECURITY_DOCSIS_UPLINK) {
849 sess->auth.algo = IMB_AUTH_DOCSIS_CRC32;
850 sess->auth.operation = RTE_CRYPTO_AUTH_OP_VERIFY;
851 } else if (xform->direction == RTE_SECURITY_DOCSIS_DOWNLINK) {
852 sess->auth.algo = IMB_AUTH_DOCSIS_CRC32;
853 sess->auth.operation = RTE_CRYPTO_AUTH_OP_GENERATE;
855 IPSEC_MB_LOG(ERR, "Unsupported DOCSIS direction");
859 sess->auth.req_digest_len = RTE_ETHER_CRC_LEN;
860 sess->auth.gen_digest_len = RTE_ETHER_CRC_LEN;
866 * Parse DOCSIS security session configuration and set private session
870 aesni_mb_set_docsis_sec_session_parameters(
871 __rte_unused struct rte_cryptodev *dev,
872 struct rte_security_session_conf *conf,
875 IMB_MGR *mb_mgr = alloc_init_mb_mgr();
876 struct rte_security_docsis_xform *docsis_xform;
877 struct rte_crypto_sym_xform *cipher_xform;
878 struct aesni_mb_session *ipsec_sess = sess;
884 ret = check_docsis_sec_session(conf);
886 IPSEC_MB_LOG(ERR, "Unsupported DOCSIS security configuration");
890 switch (conf->docsis.direction) {
891 case RTE_SECURITY_DOCSIS_UPLINK:
892 ipsec_sess->chain_order = IMB_ORDER_CIPHER_HASH;
893 docsis_xform = &conf->docsis;
894 cipher_xform = conf->crypto_xform;
896 case RTE_SECURITY_DOCSIS_DOWNLINK:
897 ipsec_sess->chain_order = IMB_ORDER_HASH_CIPHER;
898 cipher_xform = conf->crypto_xform;
899 docsis_xform = &conf->docsis;
902 IPSEC_MB_LOG(ERR, "Unsupported DOCSIS security configuration");
907 /* Default IV length = 0 */
908 ipsec_sess->iv.length = 0;
910 ret = aesni_mb_set_docsis_sec_session_auth_parameters(ipsec_sess,
913 IPSEC_MB_LOG(ERR, "Invalid/unsupported DOCSIS parameters");
917 ret = aesni_mb_set_session_cipher_parameters(mb_mgr,
918 ipsec_sess, cipher_xform);
921 IPSEC_MB_LOG(ERR, "Invalid/unsupported cipher parameters");
931 static inline uint64_t
932 auth_start_offset(struct rte_crypto_op *op, struct aesni_mb_session *session,
933 uint32_t oop, const uint32_t auth_offset,
934 const uint32_t cipher_offset, const uint32_t auth_length,
935 const uint32_t cipher_length)
937 struct rte_mbuf *m_src, *m_dst;
938 uint8_t *p_src, *p_dst;
939 uintptr_t u_src, u_dst;
940 uint32_t cipher_end, auth_end;
942 /* Only cipher then hash needs special calculation. */
943 if (!oop || session->chain_order != IMB_ORDER_CIPHER_HASH)
946 m_src = op->sym->m_src;
947 m_dst = op->sym->m_dst;
949 p_src = rte_pktmbuf_mtod(m_src, uint8_t *);
950 p_dst = rte_pktmbuf_mtod(m_dst, uint8_t *);
951 u_src = (uintptr_t)p_src;
952 u_dst = (uintptr_t)p_dst + auth_offset;
955 * Copy the content between cipher offset and auth offset for generating
958 if (cipher_offset > auth_offset)
959 memcpy(p_dst + auth_offset,
965 * Copy the content between (cipher offset + length) and (auth offset +
966 * length) for generating correct digest
968 cipher_end = cipher_offset + cipher_length;
969 auth_end = auth_offset + auth_length;
970 if (cipher_end < auth_end)
971 memcpy(p_dst + cipher_end, p_src + cipher_end,
972 auth_end - cipher_end);
975 * Since intel-ipsec-mb only supports positive values,
976 * we need to deduct the correct offset between src and dst.
979 return u_src < u_dst ? (u_dst - u_src) :
980 (UINT64_MAX - u_src + u_dst + 1);
984 set_cpu_mb_job_params(IMB_JOB *job, struct aesni_mb_session *session,
985 union rte_crypto_sym_ofs sofs, void *buf, uint32_t len,
986 struct rte_crypto_va_iova_ptr *iv,
987 struct rte_crypto_va_iova_ptr *aad, void *digest, void *udata)
989 /* Set crypto operation */
990 job->chain_order = session->chain_order;
992 /* Set cipher parameters */
993 job->cipher_direction = session->cipher.direction;
994 job->cipher_mode = session->cipher.mode;
996 job->key_len_in_bytes = session->cipher.key_length_in_bytes;
998 /* Set authentication parameters */
999 job->hash_alg = session->auth.algo;
1002 switch (job->hash_alg) {
1003 case IMB_AUTH_AES_XCBC:
1004 job->u.XCBC._k1_expanded = session->auth.xcbc.k1_expanded;
1005 job->u.XCBC._k2 = session->auth.xcbc.k2;
1006 job->u.XCBC._k3 = session->auth.xcbc.k3;
1008 job->enc_keys = session->cipher.expanded_aes_keys.encode;
1009 job->dec_keys = session->cipher.expanded_aes_keys.decode;
1012 case IMB_AUTH_AES_CCM:
1013 job->u.CCM.aad = (uint8_t *)aad->va + 18;
1014 job->u.CCM.aad_len_in_bytes = session->aead.aad_len;
1015 job->enc_keys = session->cipher.expanded_aes_keys.encode;
1016 job->dec_keys = session->cipher.expanded_aes_keys.decode;
1020 case IMB_AUTH_AES_CMAC:
1021 job->u.CMAC._key_expanded = session->auth.cmac.expkey;
1022 job->u.CMAC._skey1 = session->auth.cmac.skey1;
1023 job->u.CMAC._skey2 = session->auth.cmac.skey2;
1024 job->enc_keys = session->cipher.expanded_aes_keys.encode;
1025 job->dec_keys = session->cipher.expanded_aes_keys.decode;
1028 case IMB_AUTH_AES_GMAC:
1029 if (session->cipher.mode == IMB_CIPHER_GCM) {
1030 job->u.GCM.aad = aad->va;
1031 job->u.GCM.aad_len_in_bytes = session->aead.aad_len;
1034 job->u.GCM.aad = buf;
1035 job->u.GCM.aad_len_in_bytes = len;
1036 job->cipher_mode = IMB_CIPHER_GCM;
1038 job->enc_keys = &session->cipher.gcm_key;
1039 job->dec_keys = &session->cipher.gcm_key;
1042 case IMB_AUTH_CHACHA20_POLY1305:
1043 job->u.CHACHA20_POLY1305.aad = aad->va;
1044 job->u.CHACHA20_POLY1305.aad_len_in_bytes =
1045 session->aead.aad_len;
1046 job->enc_keys = session->cipher.expanded_aes_keys.encode;
1047 job->dec_keys = session->cipher.expanded_aes_keys.encode;
1050 job->u.HMAC._hashed_auth_key_xor_ipad =
1051 session->auth.pads.inner;
1052 job->u.HMAC._hashed_auth_key_xor_opad =
1053 session->auth.pads.outer;
1055 if (job->cipher_mode == IMB_CIPHER_DES3) {
1056 job->enc_keys = session->cipher.exp_3des_keys.ks_ptr;
1057 job->dec_keys = session->cipher.exp_3des_keys.ks_ptr;
1059 job->enc_keys = session->cipher.expanded_aes_keys.encode;
1060 job->dec_keys = session->cipher.expanded_aes_keys.decode;
1065 * Multi-buffer library current only support returning a truncated
1066 * digest length as specified in the relevant IPsec RFCs
1069 /* Set digest location and length */
1070 job->auth_tag_output = digest;
1071 job->auth_tag_output_len_in_bytes = session->auth.gen_digest_len;
1073 /* Set IV parameters */
1074 job->iv_len_in_bytes = session->iv.length;
1076 /* Data Parameters */
1078 job->dst = (uint8_t *)buf + sofs.ofs.cipher.head;
1079 job->cipher_start_src_offset_in_bytes = sofs.ofs.cipher.head;
1080 job->hash_start_src_offset_in_bytes = sofs.ofs.auth.head;
1081 if (job->hash_alg == IMB_AUTH_AES_GMAC &&
1082 session->cipher.mode != IMB_CIPHER_GCM) {
1083 job->msg_len_to_hash_in_bytes = 0;
1084 job->msg_len_to_cipher_in_bytes = 0;
1086 job->msg_len_to_hash_in_bytes = len - sofs.ofs.auth.head -
1088 job->msg_len_to_cipher_in_bytes = len - sofs.ofs.cipher.head -
1089 sofs.ofs.cipher.tail;
1092 job->user_data = udata;
1096 * Process a crypto operation and complete a IMB_JOB job structure for
1097 * submission to the multi buffer library for processing.
1099 * @param qp queue pair
1100 * @param job IMB_JOB structure to fill
1101 * @param op crypto op to process
1102 * @param digest_idx ID for digest to use
1105 * - 0 on success, the IMB_JOB will be filled
1106 * - -1 if invalid session, IMB_JOB will not be filled
1109 set_mb_job_params(IMB_JOB *job, struct ipsec_mb_qp *qp,
1110 struct rte_crypto_op *op, uint8_t *digest_idx)
1112 struct rte_mbuf *m_src = op->sym->m_src, *m_dst;
1113 struct aesni_mb_qp_data *qp_data = ipsec_mb_get_qp_private_data(qp);
1114 struct aesni_mb_session *session;
1115 uint32_t m_offset, oop;
1116 uint32_t auth_off_in_bytes;
1117 uint32_t ciph_off_in_bytes;
1118 uint32_t auth_len_in_bytes;
1119 uint32_t ciph_len_in_bytes;
1121 session = ipsec_mb_get_session_private(qp, op);
1122 if (session == NULL) {
1123 op->status = RTE_CRYPTO_OP_STATUS_INVALID_SESSION;
1127 /* Set crypto operation */
1128 job->chain_order = session->chain_order;
1130 /* Set cipher parameters */
1131 job->cipher_direction = session->cipher.direction;
1132 job->cipher_mode = session->cipher.mode;
1134 job->key_len_in_bytes = session->cipher.key_length_in_bytes;
1136 /* Set authentication parameters */
1137 job->hash_alg = session->auth.algo;
1139 const int aead = is_aead_algo(job->hash_alg, job->cipher_mode);
1141 if (job->cipher_mode == IMB_CIPHER_DES3) {
1142 job->enc_keys = session->cipher.exp_3des_keys.ks_ptr;
1143 job->dec_keys = session->cipher.exp_3des_keys.ks_ptr;
1145 job->enc_keys = session->cipher.expanded_aes_keys.encode;
1146 job->dec_keys = session->cipher.expanded_aes_keys.decode;
1149 switch (job->hash_alg) {
1150 case IMB_AUTH_AES_XCBC:
1151 job->u.XCBC._k1_expanded = session->auth.xcbc.k1_expanded;
1152 job->u.XCBC._k2 = session->auth.xcbc.k2;
1153 job->u.XCBC._k3 = session->auth.xcbc.k3;
1155 job->enc_keys = session->cipher.expanded_aes_keys.encode;
1156 job->dec_keys = session->cipher.expanded_aes_keys.decode;
1159 case IMB_AUTH_AES_CCM:
1160 job->u.CCM.aad = op->sym->aead.aad.data + 18;
1161 job->u.CCM.aad_len_in_bytes = session->aead.aad_len;
1162 job->enc_keys = session->cipher.expanded_aes_keys.encode;
1163 job->dec_keys = session->cipher.expanded_aes_keys.decode;
1166 case IMB_AUTH_AES_CMAC:
1167 job->u.CMAC._key_expanded = session->auth.cmac.expkey;
1168 job->u.CMAC._skey1 = session->auth.cmac.skey1;
1169 job->u.CMAC._skey2 = session->auth.cmac.skey2;
1170 job->enc_keys = session->cipher.expanded_aes_keys.encode;
1171 job->dec_keys = session->cipher.expanded_aes_keys.decode;
1174 case IMB_AUTH_AES_GMAC:
1175 if (session->cipher.mode == IMB_CIPHER_GCM) {
1176 job->u.GCM.aad = op->sym->aead.aad.data;
1177 job->u.GCM.aad_len_in_bytes = session->aead.aad_len;
1180 job->u.GCM.aad = rte_pktmbuf_mtod_offset(m_src,
1181 uint8_t *, op->sym->auth.data.offset);
1182 job->u.GCM.aad_len_in_bytes = op->sym->auth.data.length;
1183 job->cipher_mode = IMB_CIPHER_GCM;
1185 job->enc_keys = &session->cipher.gcm_key;
1186 job->dec_keys = &session->cipher.gcm_key;
1188 case IMB_AUTH_ZUC_EIA3_BITLEN:
1189 case IMB_AUTH_ZUC256_EIA3_BITLEN:
1190 job->u.ZUC_EIA3._key = session->auth.zuc_auth_key;
1191 job->u.ZUC_EIA3._iv = rte_crypto_op_ctod_offset(op, uint8_t *,
1192 session->auth_iv.offset);
1194 case IMB_AUTH_SNOW3G_UIA2_BITLEN:
1195 job->u.SNOW3G_UIA2._key = (void *)
1196 &session->auth.pKeySched_snow3g_auth;
1197 job->u.SNOW3G_UIA2._iv =
1198 rte_crypto_op_ctod_offset(op, uint8_t *,
1199 session->auth_iv.offset);
1201 case IMB_AUTH_KASUMI_UIA1:
1202 job->u.KASUMI_UIA1._key = (void *)
1203 &session->auth.pKeySched_kasumi_auth;
1205 case IMB_AUTH_CHACHA20_POLY1305:
1206 job->u.CHACHA20_POLY1305.aad = op->sym->aead.aad.data;
1207 job->u.CHACHA20_POLY1305.aad_len_in_bytes =
1208 session->aead.aad_len;
1209 job->enc_keys = session->cipher.expanded_aes_keys.encode;
1210 job->dec_keys = session->cipher.expanded_aes_keys.encode;
1213 job->u.HMAC._hashed_auth_key_xor_ipad =
1214 session->auth.pads.inner;
1215 job->u.HMAC._hashed_auth_key_xor_opad =
1216 session->auth.pads.outer;
1221 m_offset = op->sym->aead.data.offset;
1223 m_offset = op->sym->cipher.data.offset;
1225 if (job->cipher_mode == IMB_CIPHER_ZUC_EEA3) {
1226 job->enc_keys = session->cipher.zuc_cipher_key;
1227 job->dec_keys = session->cipher.zuc_cipher_key;
1229 } else if (job->cipher_mode == IMB_CIPHER_SNOW3G_UEA2_BITLEN) {
1230 job->enc_keys = &session->cipher.pKeySched_snow3g_cipher;
1232 } else if (job->cipher_mode == IMB_CIPHER_KASUMI_UEA1_BITLEN) {
1233 job->enc_keys = &session->cipher.pKeySched_kasumi_cipher;
1237 if (!op->sym->m_dst) {
1238 /* in-place operation */
1241 } else if (op->sym->m_dst == op->sym->m_src) {
1242 /* in-place operation */
1246 /* out-of-place operation */
1247 m_dst = op->sym->m_dst;
1251 /* Set digest output location */
1252 if (job->hash_alg != IMB_AUTH_NULL &&
1253 session->auth.operation == RTE_CRYPTO_AUTH_OP_VERIFY) {
1254 job->auth_tag_output = qp_data->temp_digests[*digest_idx];
1255 *digest_idx = (*digest_idx + 1) % IMB_MAX_JOBS;
1258 job->auth_tag_output = op->sym->aead.digest.data;
1260 job->auth_tag_output = op->sym->auth.digest.data;
1262 if (session->auth.req_digest_len !=
1263 session->auth.gen_digest_len) {
1264 job->auth_tag_output =
1265 qp_data->temp_digests[*digest_idx];
1266 *digest_idx = (*digest_idx + 1) % IMB_MAX_JOBS;
1270 * Multi-buffer library current only support returning a truncated
1271 * digest length as specified in the relevant IPsec RFCs
1274 /* Set digest length */
1275 job->auth_tag_output_len_in_bytes = session->auth.gen_digest_len;
1277 /* Set IV parameters */
1278 job->iv_len_in_bytes = session->iv.length;
1280 /* Data Parameters */
1281 job->src = rte_pktmbuf_mtod(m_src, uint8_t *);
1282 job->dst = rte_pktmbuf_mtod_offset(m_dst, uint8_t *, m_offset);
1284 switch (job->hash_alg) {
1285 case IMB_AUTH_AES_CCM:
1286 job->hash_start_src_offset_in_bytes = op->sym->aead.data.offset;
1287 job->msg_len_to_hash_in_bytes = op->sym->aead.data.length;
1289 job->iv = rte_crypto_op_ctod_offset(op, uint8_t *,
1290 session->iv.offset + 1);
1293 case IMB_AUTH_AES_GMAC:
1294 if (session->cipher.mode == IMB_CIPHER_GCM) {
1295 job->hash_start_src_offset_in_bytes =
1296 op->sym->aead.data.offset;
1297 job->msg_len_to_hash_in_bytes =
1298 op->sym->aead.data.length;
1300 job->msg_len_to_cipher_in_bytes = 0;
1301 job->msg_len_to_hash_in_bytes = 0;
1304 job->iv = rte_crypto_op_ctod_offset(op, uint8_t *,
1305 session->iv.offset);
1308 case IMB_AUTH_CHACHA20_POLY1305:
1309 job->hash_start_src_offset_in_bytes =
1310 op->sym->aead.data.offset;
1311 job->msg_len_to_hash_in_bytes =
1312 op->sym->aead.data.length;
1314 job->iv = rte_crypto_op_ctod_offset(op, uint8_t *,
1315 session->iv.offset);
1317 /* ZUC and SNOW3G require length in bits and offset in bytes */
1318 case IMB_AUTH_ZUC_EIA3_BITLEN:
1319 case IMB_AUTH_ZUC256_EIA3_BITLEN:
1320 case IMB_AUTH_SNOW3G_UIA2_BITLEN:
1321 auth_off_in_bytes = op->sym->auth.data.offset >> 3;
1322 ciph_off_in_bytes = op->sym->cipher.data.offset >> 3;
1323 auth_len_in_bytes = op->sym->auth.data.length >> 3;
1324 ciph_len_in_bytes = op->sym->cipher.data.length >> 3;
1326 job->hash_start_src_offset_in_bytes = auth_start_offset(op,
1327 session, oop, auth_off_in_bytes,
1328 ciph_off_in_bytes, auth_len_in_bytes,
1330 job->msg_len_to_hash_in_bits = op->sym->auth.data.length;
1332 job->iv = rte_crypto_op_ctod_offset(op, uint8_t *,
1333 session->iv.offset);
1336 /* KASUMI requires lengths and offset in bytes */
1337 case IMB_AUTH_KASUMI_UIA1:
1338 auth_off_in_bytes = op->sym->auth.data.offset >> 3;
1339 ciph_off_in_bytes = op->sym->cipher.data.offset >> 3;
1340 auth_len_in_bytes = op->sym->auth.data.length >> 3;
1341 ciph_len_in_bytes = op->sym->cipher.data.length >> 3;
1343 job->hash_start_src_offset_in_bytes = auth_start_offset(op,
1344 session, oop, auth_off_in_bytes,
1345 ciph_off_in_bytes, auth_len_in_bytes,
1347 job->msg_len_to_hash_in_bytes = auth_len_in_bytes;
1349 job->iv = rte_crypto_op_ctod_offset(op, uint8_t *,
1350 session->iv.offset);
1354 job->hash_start_src_offset_in_bytes = auth_start_offset(op,
1355 session, oop, op->sym->auth.data.offset,
1356 op->sym->cipher.data.offset,
1357 op->sym->auth.data.length,
1358 op->sym->cipher.data.length);
1359 job->msg_len_to_hash_in_bytes = op->sym->auth.data.length;
1361 job->iv = rte_crypto_op_ctod_offset(op, uint8_t *,
1362 session->iv.offset);
1365 switch (job->cipher_mode) {
1366 /* ZUC requires length and offset in bytes */
1367 case IMB_CIPHER_ZUC_EEA3:
1368 job->cipher_start_src_offset_in_bytes =
1369 op->sym->cipher.data.offset >> 3;
1370 job->msg_len_to_cipher_in_bytes =
1371 op->sym->cipher.data.length >> 3;
1373 /* ZUC and SNOW3G require length and offset in bits */
1374 case IMB_CIPHER_SNOW3G_UEA2_BITLEN:
1375 case IMB_CIPHER_KASUMI_UEA1_BITLEN:
1376 job->cipher_start_src_offset_in_bits =
1377 op->sym->cipher.data.offset;
1378 job->msg_len_to_cipher_in_bits =
1379 op->sym->cipher.data.length;
1381 case IMB_CIPHER_CCM:
1382 case IMB_CIPHER_GCM:
1383 case IMB_CIPHER_CHACHA20_POLY1305:
1384 job->cipher_start_src_offset_in_bytes =
1385 op->sym->aead.data.offset;
1386 job->msg_len_to_cipher_in_bytes = op->sym->aead.data.length;
1389 job->cipher_start_src_offset_in_bytes =
1390 op->sym->cipher.data.offset;
1391 job->msg_len_to_cipher_in_bytes = op->sym->cipher.data.length;
1394 if (job->cipher_mode == IMB_CIPHER_NULL && oop) {
1395 memcpy(job->dst + job->cipher_start_src_offset_in_bytes,
1396 job->src + job->cipher_start_src_offset_in_bytes,
1397 job->msg_len_to_cipher_in_bytes);
1400 /* Set user data to be crypto operation data struct */
1401 job->user_data = op;
1406 #ifdef AESNI_MB_DOCSIS_SEC_ENABLED
1408 * Process a crypto operation containing a security op and complete a
1409 * IMB_JOB job structure for submission to the multi buffer library for
1413 set_sec_mb_job_params(IMB_JOB *job, struct ipsec_mb_qp *qp,
1414 struct rte_crypto_op *op, uint8_t *digest_idx)
1416 struct aesni_mb_qp_data *qp_data = ipsec_mb_get_qp_private_data(qp);
1417 struct rte_mbuf *m_src, *m_dst;
1418 struct rte_crypto_sym_op *sym;
1419 struct aesni_mb_session *session = NULL;
1421 if (unlikely(op->sess_type != RTE_CRYPTO_OP_SECURITY_SESSION)) {
1422 op->status = RTE_CRYPTO_OP_STATUS_INVALID_SESSION;
1425 session = (struct aesni_mb_session *)
1426 get_sec_session_private_data(op->sym->sec_session);
1428 if (unlikely(session == NULL)) {
1429 op->status = RTE_CRYPTO_OP_STATUS_INVALID_SESSION;
1432 /* Only DOCSIS protocol operations supported now */
1433 if (session->cipher.mode != IMB_CIPHER_DOCSIS_SEC_BPI ||
1434 session->auth.algo != IMB_AUTH_DOCSIS_CRC32) {
1435 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
1442 if (likely(sym->m_dst == NULL || sym->m_dst == m_src)) {
1443 /* in-place operation */
1446 /* out-of-place operation not supported */
1447 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
1451 /* Set crypto operation */
1452 job->chain_order = session->chain_order;
1454 /* Set cipher parameters */
1455 job->cipher_direction = session->cipher.direction;
1456 job->cipher_mode = session->cipher.mode;
1458 job->key_len_in_bytes = session->cipher.key_length_in_bytes;
1459 job->enc_keys = session->cipher.expanded_aes_keys.encode;
1460 job->dec_keys = session->cipher.expanded_aes_keys.decode;
1462 /* Set IV parameters */
1463 job->iv_len_in_bytes = session->iv.length;
1464 job->iv = (uint8_t *)op + session->iv.offset;
1466 /* Set authentication parameters */
1467 job->hash_alg = session->auth.algo;
1469 /* Set digest output location */
1470 job->auth_tag_output = qp_data->temp_digests[*digest_idx];
1471 *digest_idx = (*digest_idx + 1) % IMB_MAX_JOBS;
1473 /* Set digest length */
1474 job->auth_tag_output_len_in_bytes = session->auth.gen_digest_len;
1476 /* Set data parameters */
1477 job->src = rte_pktmbuf_mtod(m_src, uint8_t *);
1478 job->dst = rte_pktmbuf_mtod_offset(m_dst, uint8_t *,
1479 sym->cipher.data.offset);
1481 job->cipher_start_src_offset_in_bytes = sym->cipher.data.offset;
1482 job->msg_len_to_cipher_in_bytes = sym->cipher.data.length;
1484 job->hash_start_src_offset_in_bytes = sym->auth.data.offset;
1485 job->msg_len_to_hash_in_bytes = sym->auth.data.length;
1487 job->user_data = op;
1493 verify_docsis_sec_crc(IMB_JOB *job, uint8_t *status)
1495 uint16_t crc_offset;
1498 if (!job->msg_len_to_hash_in_bytes)
1501 crc_offset = job->hash_start_src_offset_in_bytes +
1502 job->msg_len_to_hash_in_bytes -
1503 job->cipher_start_src_offset_in_bytes;
1504 crc = job->dst + crc_offset;
1506 /* Verify CRC (at the end of the message) */
1507 if (memcmp(job->auth_tag_output, crc, RTE_ETHER_CRC_LEN) != 0)
1508 *status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
1513 verify_digest(IMB_JOB *job, void *digest, uint16_t len, uint8_t *status)
1515 /* Verify digest if required */
1516 if (memcmp(job->auth_tag_output, digest, len) != 0)
1517 *status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
1521 generate_digest(IMB_JOB *job, struct rte_crypto_op *op,
1522 struct aesni_mb_session *sess)
1524 /* No extra copy needed */
1525 if (likely(sess->auth.req_digest_len == sess->auth.gen_digest_len))
1529 * This can only happen for HMAC, so only digest
1530 * for authentication algos is required
1532 memcpy(op->sym->auth.digest.data, job->auth_tag_output,
1533 sess->auth.req_digest_len);
1537 * Process a completed job and return rte_mbuf which job processed
1539 * @param qp Queue Pair to process
1540 * @param job IMB_JOB job to process
1543 * - Returns processed crypto operation.
1544 * - Returns NULL on invalid job
1546 static inline struct rte_crypto_op *
1547 post_process_mb_job(struct ipsec_mb_qp *qp, IMB_JOB *job)
1549 struct rte_crypto_op *op = (struct rte_crypto_op *)job->user_data;
1550 struct aesni_mb_session *sess = NULL;
1551 uint32_t driver_id = ipsec_mb_get_driver_id(
1552 IPSEC_MB_PMD_TYPE_AESNI_MB);
1554 #ifdef AESNI_MB_DOCSIS_SEC_ENABLED
1555 uint8_t is_docsis_sec = 0;
1557 if (op->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) {
1559 * Assuming at this point that if it's a security type op, that
1560 * this is for DOCSIS
1563 sess = get_sec_session_private_data(op->sym->sec_session);
1567 sess = get_sym_session_private_data(op->sym->session,
1571 if (unlikely(sess == NULL)) {
1572 op->status = RTE_CRYPTO_OP_STATUS_INVALID_SESSION;
1576 if (likely(op->status == RTE_CRYPTO_OP_STATUS_NOT_PROCESSED)) {
1577 switch (job->status) {
1578 case IMB_STATUS_COMPLETED:
1579 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
1581 if (job->hash_alg == IMB_AUTH_NULL)
1584 if (sess->auth.operation == RTE_CRYPTO_AUTH_OP_VERIFY) {
1585 if (is_aead_algo(job->hash_alg,
1588 op->sym->aead.digest.data,
1589 sess->auth.req_digest_len,
1591 #ifdef AESNI_MB_DOCSIS_SEC_ENABLED
1592 else if (is_docsis_sec)
1593 verify_docsis_sec_crc(job,
1598 op->sym->auth.digest.data,
1599 sess->auth.req_digest_len,
1602 generate_digest(job, op, sess);
1605 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
1609 /* Free session if a session-less crypto op */
1610 if (op->sess_type == RTE_CRYPTO_OP_SESSIONLESS) {
1611 memset(sess, 0, sizeof(struct aesni_mb_session));
1612 memset(op->sym->session, 0,
1613 rte_cryptodev_sym_get_existing_header_session_size(
1615 rte_mempool_put(qp->sess_mp_priv, sess);
1616 rte_mempool_put(qp->sess_mp, op->sym->session);
1617 op->sym->session = NULL;
1624 post_process_mb_sync_job(IMB_JOB *job)
1628 st = job->user_data;
1629 st[0] = (job->status == IMB_STATUS_COMPLETED) ? 0 : EBADMSG;
1633 * Process a completed IMB_JOB job and keep processing jobs until
1634 * get_completed_job return NULL
1636 * @param qp Queue Pair to process
1637 * @param mb_mgr IMB_MGR to use
1638 * @param job IMB_JOB job
1639 * @param ops crypto ops to fill
1640 * @param nb_ops number of crypto ops
1643 * - Number of processed jobs
1646 handle_completed_jobs(struct ipsec_mb_qp *qp, IMB_MGR *mb_mgr,
1647 IMB_JOB *job, struct rte_crypto_op **ops,
1650 struct rte_crypto_op *op = NULL;
1651 uint16_t processed_jobs = 0;
1653 while (job != NULL) {
1654 op = post_process_mb_job(qp, job);
1657 ops[processed_jobs++] = op;
1658 qp->stats.dequeued_count++;
1660 qp->stats.dequeue_err_count++;
1663 if (processed_jobs == nb_ops)
1666 job = IMB_GET_COMPLETED_JOB(mb_mgr);
1669 return processed_jobs;
1672 static inline uint32_t
1673 handle_completed_sync_jobs(IMB_JOB *job, IMB_MGR *mb_mgr)
1677 for (i = 0; job != NULL; i++, job = IMB_GET_COMPLETED_JOB(mb_mgr))
1678 post_process_mb_sync_job(job);
1683 static inline uint32_t
1684 flush_mb_sync_mgr(IMB_MGR *mb_mgr)
1688 job = IMB_FLUSH_JOB(mb_mgr);
1689 return handle_completed_sync_jobs(job, mb_mgr);
1692 static inline uint16_t
1693 flush_mb_mgr(struct ipsec_mb_qp *qp, IMB_MGR *mb_mgr,
1694 struct rte_crypto_op **ops, uint16_t nb_ops)
1696 int processed_ops = 0;
1698 /* Flush the remaining jobs */
1699 IMB_JOB *job = IMB_FLUSH_JOB(mb_mgr);
1702 processed_ops += handle_completed_jobs(qp, mb_mgr, job,
1703 &ops[processed_ops], nb_ops - processed_ops);
1705 return processed_ops;
1708 static inline IMB_JOB *
1709 set_job_null_op(IMB_JOB *job, struct rte_crypto_op *op)
1711 job->chain_order = IMB_ORDER_HASH_CIPHER;
1712 job->cipher_mode = IMB_CIPHER_NULL;
1713 job->hash_alg = IMB_AUTH_NULL;
1714 job->cipher_direction = IMB_DIR_DECRYPT;
1716 /* Set user data to be crypto operation data struct */
1717 job->user_data = op;
1723 aesni_mb_dequeue_burst(void *queue_pair, struct rte_crypto_op **ops,
1726 struct ipsec_mb_qp *qp = queue_pair;
1727 IMB_MGR *mb_mgr = qp->mb_mgr;
1728 struct rte_crypto_op *op;
1730 int retval, processed_jobs = 0;
1732 if (unlikely(nb_ops == 0 || mb_mgr == NULL))
1735 uint8_t digest_idx = qp->digest_idx;
1738 /* Get next free mb job struct from mb manager */
1739 job = IMB_GET_NEXT_JOB(mb_mgr);
1740 if (unlikely(job == NULL)) {
1741 /* if no free mb job structs we need to flush mb_mgr */
1742 processed_jobs += flush_mb_mgr(qp, mb_mgr,
1743 &ops[processed_jobs],
1744 nb_ops - processed_jobs);
1746 if (nb_ops == processed_jobs)
1749 job = IMB_GET_NEXT_JOB(mb_mgr);
1753 * Get next operation to process from ingress queue.
1754 * There is no need to return the job to the IMB_MGR
1755 * if there are no more operations to process, since the IMB_MGR
1756 * can use that pointer again in next get_next calls.
1758 retval = rte_ring_dequeue(qp->ingress_queue, (void **)&op);
1762 #ifdef AESNI_MB_DOCSIS_SEC_ENABLED
1763 if (op->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION)
1764 retval = set_sec_mb_job_params(job, qp, op,
1768 retval = set_mb_job_params(job, qp, op,
1771 if (unlikely(retval != 0)) {
1772 qp->stats.dequeue_err_count++;
1773 set_job_null_op(job, op);
1776 /* Submit job to multi-buffer for processing */
1777 #ifdef RTE_LIBRTE_PMD_AESNI_MB_DEBUG
1778 job = IMB_SUBMIT_JOB(mb_mgr);
1780 job = IMB_SUBMIT_JOB_NOCHECK(mb_mgr);
1783 * If submit returns a processed job then handle it,
1784 * before submitting subsequent jobs
1787 processed_jobs += handle_completed_jobs(qp, mb_mgr,
1788 job, &ops[processed_jobs],
1789 nb_ops - processed_jobs);
1791 } while (processed_jobs < nb_ops);
1793 qp->digest_idx = digest_idx;
1795 if (processed_jobs < 1)
1796 processed_jobs += flush_mb_mgr(qp, mb_mgr,
1797 &ops[processed_jobs],
1798 nb_ops - processed_jobs);
1800 return processed_jobs;
1805 ipsec_mb_fill_error_code(struct rte_crypto_sym_vec *vec, int32_t err)
1809 for (i = 0; i != vec->num; ++i)
1810 vec->status[i] = err;
1814 check_crypto_sgl(union rte_crypto_sym_ofs so, const struct rte_crypto_sgl *sgl)
1816 /* no multi-seg support with current AESNI-MB PMD */
1819 else if (so.ofs.cipher.head + so.ofs.cipher.tail > sgl->vec[0].len)
1824 static inline IMB_JOB *
1825 submit_sync_job(IMB_MGR *mb_mgr)
1827 #ifdef RTE_LIBRTE_PMD_AESNI_MB_DEBUG
1828 return IMB_SUBMIT_JOB(mb_mgr);
1830 return IMB_SUBMIT_JOB_NOCHECK(mb_mgr);
1834 static inline uint32_t
1835 generate_sync_dgst(struct rte_crypto_sym_vec *vec,
1836 const uint8_t dgst[][DIGEST_LENGTH_MAX], uint32_t len)
1840 for (i = 0, k = 0; i != vec->num; i++) {
1841 if (vec->status[i] == 0) {
1842 memcpy(vec->digest[i].va, dgst[i], len);
1850 static inline uint32_t
1851 verify_sync_dgst(struct rte_crypto_sym_vec *vec,
1852 const uint8_t dgst[][DIGEST_LENGTH_MAX], uint32_t len)
1856 for (i = 0, k = 0; i != vec->num; i++) {
1857 if (vec->status[i] == 0) {
1858 if (memcmp(vec->digest[i].va, dgst[i], len) != 0)
1859 vec->status[i] = EBADMSG;
1869 aesni_mb_process_bulk(struct rte_cryptodev *dev,
1870 struct rte_cryptodev_sym_session *sess, union rte_crypto_sym_ofs sofs,
1871 struct rte_crypto_sym_vec *vec)
1874 uint32_t i, j, k, len;
1878 struct aesni_mb_session *s;
1879 uint8_t tmp_dgst[vec->num][DIGEST_LENGTH_MAX];
1881 s = get_sym_session_private_data(sess, dev->driver_id);
1883 ipsec_mb_fill_error_code(vec, EINVAL);
1887 /* get per-thread MB MGR, create one if needed */
1888 mb_mgr = get_per_thread_mb_mgr();
1889 if (unlikely(mb_mgr == NULL))
1892 for (i = 0, j = 0, k = 0; i != vec->num; i++) {
1893 ret = check_crypto_sgl(sofs, vec->src_sgl + i);
1895 vec->status[i] = ret;
1899 buf = vec->src_sgl[i].vec[0].base;
1900 len = vec->src_sgl[i].vec[0].len;
1902 job = IMB_GET_NEXT_JOB(mb_mgr);
1904 k += flush_mb_sync_mgr(mb_mgr);
1905 job = IMB_GET_NEXT_JOB(mb_mgr);
1906 RTE_ASSERT(job != NULL);
1909 /* Submit job for processing */
1910 set_cpu_mb_job_params(job, s, sofs, buf, len, &vec->iv[i],
1911 &vec->aad[i], tmp_dgst[i], &vec->status[i]);
1912 job = submit_sync_job(mb_mgr);
1915 /* handle completed jobs */
1916 k += handle_completed_sync_jobs(job, mb_mgr);
1919 /* flush remaining jobs */
1921 k += flush_mb_sync_mgr(mb_mgr);
1923 /* finish processing for successful jobs: check/update digest */
1925 if (s->auth.operation == RTE_CRYPTO_AUTH_OP_VERIFY)
1926 k = verify_sync_dgst(vec,
1927 (const uint8_t (*)[DIGEST_LENGTH_MAX])tmp_dgst,
1928 s->auth.req_digest_len);
1930 k = generate_sync_dgst(vec,
1931 (const uint8_t (*)[DIGEST_LENGTH_MAX])tmp_dgst,
1932 s->auth.req_digest_len);
1938 struct rte_cryptodev_ops aesni_mb_pmd_ops = {
1939 .dev_configure = ipsec_mb_config,
1940 .dev_start = ipsec_mb_start,
1941 .dev_stop = ipsec_mb_stop,
1942 .dev_close = ipsec_mb_close,
1944 .stats_get = ipsec_mb_stats_get,
1945 .stats_reset = ipsec_mb_stats_reset,
1947 .dev_infos_get = ipsec_mb_info_get,
1949 .queue_pair_setup = ipsec_mb_qp_setup,
1950 .queue_pair_release = ipsec_mb_qp_release,
1952 .sym_cpu_process = aesni_mb_process_bulk,
1954 .sym_session_get_size = ipsec_mb_sym_session_get_size,
1955 .sym_session_configure = ipsec_mb_sym_session_configure,
1956 .sym_session_clear = ipsec_mb_sym_session_clear
1959 #ifdef AESNI_MB_DOCSIS_SEC_ENABLED
1961 * Configure a aesni multi-buffer session from a security session
1965 aesni_mb_pmd_sec_sess_create(void *dev, struct rte_security_session_conf *conf,
1966 struct rte_security_session *sess,
1967 struct rte_mempool *mempool)
1969 void *sess_private_data;
1970 struct rte_cryptodev *cdev = (struct rte_cryptodev *)dev;
1973 if (conf->action_type != RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL ||
1974 conf->protocol != RTE_SECURITY_PROTOCOL_DOCSIS) {
1975 IPSEC_MB_LOG(ERR, "Invalid security protocol");
1979 if (rte_mempool_get(mempool, &sess_private_data)) {
1980 IPSEC_MB_LOG(ERR, "Couldn't get object from session mempool");
1984 ret = aesni_mb_set_docsis_sec_session_parameters(cdev, conf,
1988 IPSEC_MB_LOG(ERR, "Failed to configure session parameters");
1990 /* Return session to mempool */
1991 rte_mempool_put(mempool, sess_private_data);
1995 set_sec_session_private_data(sess, sess_private_data);
2000 /** Clear the memory of session so it does not leave key material behind */
2002 aesni_mb_pmd_sec_sess_destroy(void *dev __rte_unused,
2003 struct rte_security_session *sess)
2005 void *sess_priv = get_sec_session_private_data(sess);
2008 struct rte_mempool *sess_mp = rte_mempool_from_obj(sess_priv);
2010 memset(sess_priv, 0, sizeof(struct aesni_mb_session));
2011 set_sec_session_private_data(sess, NULL);
2012 rte_mempool_put(sess_mp, sess_priv);
2017 /** Get security capabilities for aesni multi-buffer */
2018 static const struct rte_security_capability *
2019 aesni_mb_pmd_sec_capa_get(void *device __rte_unused)
2021 return aesni_mb_pmd_security_cap;
2024 static struct rte_security_ops aesni_mb_pmd_sec_ops = {
2025 .session_create = aesni_mb_pmd_sec_sess_create,
2026 .session_update = NULL,
2027 .session_stats_get = NULL,
2028 .session_destroy = aesni_mb_pmd_sec_sess_destroy,
2029 .set_pkt_metadata = NULL,
2030 .capabilities_get = aesni_mb_pmd_sec_capa_get
2033 struct rte_security_ops *rte_aesni_mb_pmd_sec_ops = &aesni_mb_pmd_sec_ops;
2036 aesni_mb_configure_dev(struct rte_cryptodev *dev)
2038 struct rte_security_ctx *security_instance;
2040 security_instance = rte_malloc("aesni_mb_sec",
2041 sizeof(struct rte_security_ctx),
2042 RTE_CACHE_LINE_SIZE);
2043 if (security_instance != NULL) {
2044 security_instance->device = (void *)dev;
2045 security_instance->ops = rte_aesni_mb_pmd_sec_ops;
2046 security_instance->sess_cnt = 0;
2047 dev->security_ctx = security_instance;
2058 aesni_mb_probe(struct rte_vdev_device *vdev)
2060 return ipsec_mb_create(vdev, IPSEC_MB_PMD_TYPE_AESNI_MB);
2063 static struct rte_vdev_driver cryptodev_aesni_mb_pmd_drv = {
2064 .probe = aesni_mb_probe,
2065 .remove = ipsec_mb_remove
2068 static struct cryptodev_driver aesni_mb_crypto_drv;
2070 RTE_PMD_REGISTER_VDEV(CRYPTODEV_NAME_AESNI_MB_PMD,
2071 cryptodev_aesni_mb_pmd_drv);
2072 RTE_PMD_REGISTER_ALIAS(CRYPTODEV_NAME_AESNI_MB_PMD, cryptodev_aesni_mb_pmd);
2073 RTE_PMD_REGISTER_PARAM_STRING(CRYPTODEV_NAME_AESNI_MB_PMD,
2074 "max_nb_queue_pairs=<int> socket_id=<int>");
2075 RTE_PMD_REGISTER_CRYPTO_DRIVER(
2076 aesni_mb_crypto_drv,
2077 cryptodev_aesni_mb_pmd_drv.driver,
2078 pmd_driver_id_aesni_mb);
2080 /* Constructor function to register aesni-mb PMD */
2081 RTE_INIT(ipsec_mb_register_aesni_mb)
2083 struct ipsec_mb_internals *aesni_mb_data =
2084 &ipsec_mb_pmds[IPSEC_MB_PMD_TYPE_AESNI_MB];
2086 aesni_mb_data->caps = aesni_mb_capabilities;
2087 aesni_mb_data->dequeue_burst = aesni_mb_dequeue_burst;
2088 aesni_mb_data->feature_flags = RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO |
2089 RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING |
2090 RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT |
2091 RTE_CRYPTODEV_FF_SYM_CPU_CRYPTO |
2092 RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA |
2093 RTE_CRYPTODEV_FF_SYM_SESSIONLESS;
2095 aesni_mb_data->internals_priv_size = 0;
2096 aesni_mb_data->ops = &aesni_mb_pmd_ops;
2097 aesni_mb_data->qp_priv_size = sizeof(struct aesni_mb_qp_data);
2098 aesni_mb_data->queue_pair_configure = NULL;
2099 #ifdef AESNI_MB_DOCSIS_SEC_ENABLED
2100 aesni_mb_data->security_ops = &aesni_mb_pmd_sec_ops;
2101 aesni_mb_data->dev_config = aesni_mb_configure_dev;
2102 aesni_mb_data->feature_flags |= RTE_CRYPTODEV_FF_SECURITY;
2104 aesni_mb_data->session_configure = aesni_mb_session_configure;
2105 aesni_mb_data->session_priv_size = sizeof(struct aesni_mb_session);