4 * Copyright(c) 2016-2017 Intel Corporation. All rights reserved.
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 Intel Corporation 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 #include <rte_common.h>
34 #include <rte_hexdump.h>
35 #include <rte_cryptodev.h>
36 #include <rte_cryptodev_pmd.h>
37 #include <rte_cryptodev_vdev.h>
39 #include <rte_malloc.h>
40 #include <rte_cpuflags.h>
42 #include <openssl/hmac.h>
43 #include <openssl/evp.h>
45 #include "rte_openssl_pmd_private.h"
47 #define DES_BLOCK_SIZE 8
49 static uint8_t cryptodev_driver_id;
51 #if (OPENSSL_VERSION_NUMBER < 0x10100000L)
52 static HMAC_CTX *HMAC_CTX_new(void)
54 HMAC_CTX *ctx = OPENSSL_malloc(sizeof(*ctx));
61 static void HMAC_CTX_free(HMAC_CTX *ctx)
64 HMAC_CTX_cleanup(ctx);
70 static int cryptodev_openssl_remove(struct rte_vdev_device *vdev);
72 /*----------------------------------------------------------------------------*/
75 * Increment counter by 1
76 * Counter is 64 bit array, big-endian
81 uint64_t *ctr64 = (uint64_t *)ctr;
83 *ctr64 = __builtin_bswap64(*ctr64);
85 *ctr64 = __builtin_bswap64(*ctr64);
89 *------------------------------------------------------------------------------
91 *------------------------------------------------------------------------------
94 /** Get xform chain order */
95 static enum openssl_chain_order
96 openssl_get_chain_order(const struct rte_crypto_sym_xform *xform)
98 enum openssl_chain_order res = OPENSSL_CHAIN_NOT_SUPPORTED;
101 if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
102 if (xform->next == NULL)
103 res = OPENSSL_CHAIN_ONLY_AUTH;
104 else if (xform->next->type ==
105 RTE_CRYPTO_SYM_XFORM_CIPHER)
106 res = OPENSSL_CHAIN_AUTH_CIPHER;
108 if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
109 if (xform->next == NULL)
110 res = OPENSSL_CHAIN_ONLY_CIPHER;
111 else if (xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH)
112 res = OPENSSL_CHAIN_CIPHER_AUTH;
114 if (xform->type == RTE_CRYPTO_SYM_XFORM_AEAD)
115 res = OPENSSL_CHAIN_COMBINED;
121 /** Get session cipher key from input cipher key */
123 get_cipher_key(uint8_t *input_key, int keylen, uint8_t *session_key)
125 memcpy(session_key, input_key, keylen);
128 /** Get key ede 24 bytes standard from input key */
130 get_cipher_key_ede(uint8_t *key, int keylen, uint8_t *key_ede)
134 /* Initialize keys - 24 bytes: [key1-key2-key3] */
137 memcpy(key_ede, key, 24);
141 memcpy(key_ede, key, 16);
142 memcpy(key_ede + 16, key, 8);
145 /* K1 = K2 = K3 (DES compatibility) */
146 memcpy(key_ede, key, 8);
147 memcpy(key_ede + 8, key, 8);
148 memcpy(key_ede + 16, key, 8);
151 OPENSSL_LOG_ERR("Unsupported key size");
158 /** Get adequate openssl function for input cipher algorithm */
160 get_cipher_algo(enum rte_crypto_cipher_algorithm sess_algo, size_t keylen,
161 const EVP_CIPHER **algo)
167 case RTE_CRYPTO_CIPHER_3DES_CBC:
170 *algo = EVP_des_ede_cbc();
173 *algo = EVP_des_ede3_cbc();
179 case RTE_CRYPTO_CIPHER_3DES_CTR:
181 case RTE_CRYPTO_CIPHER_AES_CBC:
184 *algo = EVP_aes_128_cbc();
187 *algo = EVP_aes_192_cbc();
190 *algo = EVP_aes_256_cbc();
196 case RTE_CRYPTO_CIPHER_AES_CTR:
199 *algo = EVP_aes_128_ctr();
202 *algo = EVP_aes_192_ctr();
205 *algo = EVP_aes_256_ctr();
222 /** Get adequate openssl function for input auth algorithm */
224 get_auth_algo(enum rte_crypto_auth_algorithm sessalgo,
231 case RTE_CRYPTO_AUTH_MD5:
232 case RTE_CRYPTO_AUTH_MD5_HMAC:
235 case RTE_CRYPTO_AUTH_SHA1:
236 case RTE_CRYPTO_AUTH_SHA1_HMAC:
239 case RTE_CRYPTO_AUTH_SHA224:
240 case RTE_CRYPTO_AUTH_SHA224_HMAC:
241 *algo = EVP_sha224();
243 case RTE_CRYPTO_AUTH_SHA256:
244 case RTE_CRYPTO_AUTH_SHA256_HMAC:
245 *algo = EVP_sha256();
247 case RTE_CRYPTO_AUTH_SHA384:
248 case RTE_CRYPTO_AUTH_SHA384_HMAC:
249 *algo = EVP_sha384();
251 case RTE_CRYPTO_AUTH_SHA512:
252 case RTE_CRYPTO_AUTH_SHA512_HMAC:
253 *algo = EVP_sha512();
266 /** Get adequate openssl function for input cipher algorithm */
268 get_aead_algo(enum rte_crypto_aead_algorithm sess_algo, size_t keylen,
269 const EVP_CIPHER **algo)
275 case RTE_CRYPTO_AEAD_AES_GCM:
278 *algo = EVP_aes_128_gcm();
281 *algo = EVP_aes_192_gcm();
284 *algo = EVP_aes_256_gcm();
290 case RTE_CRYPTO_AEAD_AES_CCM:
293 *algo = EVP_aes_128_ccm();
296 *algo = EVP_aes_192_ccm();
299 *algo = EVP_aes_256_ccm();
316 /* Set session AEAD encryption parameters */
318 openssl_set_sess_aead_enc_param(struct openssl_session *sess,
319 enum rte_crypto_aead_algorithm algo,
320 uint8_t tag_len, uint8_t *key)
325 sess->cipher.direction = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
326 sess->auth.operation = RTE_CRYPTO_AUTH_OP_GENERATE;
328 /* Select AEAD algo */
330 case RTE_CRYPTO_AEAD_AES_GCM:
331 iv_type = EVP_CTRL_GCM_SET_IVLEN;
336 case RTE_CRYPTO_AEAD_AES_CCM:
337 iv_type = EVP_CTRL_CCM_SET_IVLEN;
338 /* Digest size can be 4, 6, 8, 10, 12, 14 or 16 bytes */
339 if (tag_len < 4 || tag_len > 16 || (tag_len & 1) == 1)
347 sess->cipher.mode = OPENSSL_CIPHER_LIB;
348 sess->cipher.ctx = EVP_CIPHER_CTX_new();
350 if (get_aead_algo(algo, sess->cipher.key.length,
351 &sess->cipher.evp_algo) != 0)
354 get_cipher_key(key, sess->cipher.key.length, sess->cipher.key.data);
356 sess->chain_order = OPENSSL_CHAIN_COMBINED;
358 if (EVP_EncryptInit_ex(sess->cipher.ctx, sess->cipher.evp_algo,
359 NULL, NULL, NULL) <= 0)
362 if (EVP_CIPHER_CTX_ctrl(sess->cipher.ctx, iv_type, sess->iv.length,
367 EVP_CIPHER_CTX_ctrl(sess->cipher.ctx, EVP_CTRL_CCM_SET_TAG,
370 if (EVP_EncryptInit_ex(sess->cipher.ctx, NULL, NULL, key, NULL) <= 0)
376 /* Set session AEAD decryption parameters */
378 openssl_set_sess_aead_dec_param(struct openssl_session *sess,
379 enum rte_crypto_aead_algorithm algo,
380 uint8_t tag_len, uint8_t *key)
383 unsigned int do_ccm = 0;
385 sess->cipher.direction = RTE_CRYPTO_CIPHER_OP_DECRYPT;
386 sess->auth.operation = RTE_CRYPTO_AUTH_OP_VERIFY;
388 /* Select AEAD algo */
390 case RTE_CRYPTO_AEAD_AES_GCM:
391 iv_type = EVP_CTRL_GCM_SET_IVLEN;
395 case RTE_CRYPTO_AEAD_AES_CCM:
396 iv_type = EVP_CTRL_CCM_SET_IVLEN;
397 /* Digest size can be 4, 6, 8, 10, 12, 14 or 16 bytes */
398 if (tag_len < 4 || tag_len > 16 || (tag_len & 1) == 1)
406 sess->cipher.mode = OPENSSL_CIPHER_LIB;
407 sess->cipher.ctx = EVP_CIPHER_CTX_new();
409 if (get_aead_algo(algo, sess->cipher.key.length,
410 &sess->cipher.evp_algo) != 0)
413 get_cipher_key(key, sess->cipher.key.length, sess->cipher.key.data);
415 sess->chain_order = OPENSSL_CHAIN_COMBINED;
417 if (EVP_DecryptInit_ex(sess->cipher.ctx, sess->cipher.evp_algo,
418 NULL, NULL, NULL) <= 0)
421 if (EVP_CIPHER_CTX_ctrl(sess->cipher.ctx, iv_type,
422 sess->iv.length, NULL) <= 0)
426 EVP_CIPHER_CTX_ctrl(sess->cipher.ctx, EVP_CTRL_CCM_SET_TAG,
429 if (EVP_DecryptInit_ex(sess->cipher.ctx, NULL, NULL, key, NULL) <= 0)
435 /** Set session cipher parameters */
437 openssl_set_session_cipher_parameters(struct openssl_session *sess,
438 const struct rte_crypto_sym_xform *xform)
440 /* Select cipher direction */
441 sess->cipher.direction = xform->cipher.op;
442 /* Select cipher key */
443 sess->cipher.key.length = xform->cipher.key.length;
445 /* Set IV parameters */
446 sess->iv.offset = xform->cipher.iv.offset;
447 sess->iv.length = xform->cipher.iv.length;
449 /* Select cipher algo */
450 switch (xform->cipher.algo) {
451 case RTE_CRYPTO_CIPHER_3DES_CBC:
452 case RTE_CRYPTO_CIPHER_AES_CBC:
453 case RTE_CRYPTO_CIPHER_AES_CTR:
454 sess->cipher.mode = OPENSSL_CIPHER_LIB;
455 sess->cipher.algo = xform->cipher.algo;
456 sess->cipher.ctx = EVP_CIPHER_CTX_new();
458 if (get_cipher_algo(sess->cipher.algo, sess->cipher.key.length,
459 &sess->cipher.evp_algo) != 0)
462 get_cipher_key(xform->cipher.key.data, sess->cipher.key.length,
463 sess->cipher.key.data);
464 if (sess->cipher.direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
465 if (EVP_EncryptInit_ex(sess->cipher.ctx,
466 sess->cipher.evp_algo,
467 NULL, xform->cipher.key.data,
471 } else if (sess->cipher.direction ==
472 RTE_CRYPTO_CIPHER_OP_DECRYPT) {
473 if (EVP_DecryptInit_ex(sess->cipher.ctx,
474 sess->cipher.evp_algo,
475 NULL, xform->cipher.key.data,
483 case RTE_CRYPTO_CIPHER_3DES_CTR:
484 sess->cipher.mode = OPENSSL_CIPHER_DES3CTR;
485 sess->cipher.ctx = EVP_CIPHER_CTX_new();
487 if (get_cipher_key_ede(xform->cipher.key.data,
488 sess->cipher.key.length,
489 sess->cipher.key.data) != 0)
493 case RTE_CRYPTO_CIPHER_DES_CBC:
494 sess->cipher.algo = xform->cipher.algo;
495 sess->cipher.ctx = EVP_CIPHER_CTX_new();
496 sess->cipher.evp_algo = EVP_des_cbc();
498 get_cipher_key(xform->cipher.key.data, sess->cipher.key.length,
499 sess->cipher.key.data);
500 if (sess->cipher.direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
501 if (EVP_EncryptInit_ex(sess->cipher.ctx,
502 sess->cipher.evp_algo,
503 NULL, xform->cipher.key.data,
507 } else if (sess->cipher.direction ==
508 RTE_CRYPTO_CIPHER_OP_DECRYPT) {
509 if (EVP_DecryptInit_ex(sess->cipher.ctx,
510 sess->cipher.evp_algo,
511 NULL, xform->cipher.key.data,
519 case RTE_CRYPTO_CIPHER_DES_DOCSISBPI:
520 sess->cipher.algo = xform->cipher.algo;
521 sess->chain_order = OPENSSL_CHAIN_CIPHER_BPI;
522 sess->cipher.ctx = EVP_CIPHER_CTX_new();
523 sess->cipher.evp_algo = EVP_des_cbc();
525 sess->cipher.bpi_ctx = EVP_CIPHER_CTX_new();
526 /* IV will be ECB encrypted whether direction is encrypt or decrypt */
527 if (EVP_EncryptInit_ex(sess->cipher.bpi_ctx, EVP_des_ecb(),
528 NULL, xform->cipher.key.data, 0) != 1)
531 get_cipher_key(xform->cipher.key.data, sess->cipher.key.length,
532 sess->cipher.key.data);
533 if (sess->cipher.direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
534 if (EVP_EncryptInit_ex(sess->cipher.ctx,
535 sess->cipher.evp_algo,
536 NULL, xform->cipher.key.data,
540 } else if (sess->cipher.direction ==
541 RTE_CRYPTO_CIPHER_OP_DECRYPT) {
542 if (EVP_DecryptInit_ex(sess->cipher.ctx,
543 sess->cipher.evp_algo,
544 NULL, xform->cipher.key.data,
552 sess->cipher.algo = RTE_CRYPTO_CIPHER_NULL;
559 /* Set session auth parameters */
561 openssl_set_session_auth_parameters(struct openssl_session *sess,
562 const struct rte_crypto_sym_xform *xform)
564 /* Select auth generate/verify */
565 sess->auth.operation = xform->auth.op;
566 sess->auth.algo = xform->auth.algo;
568 sess->auth.digest_length = xform->auth.digest_length;
570 /* Select auth algo */
571 switch (xform->auth.algo) {
572 case RTE_CRYPTO_AUTH_AES_GMAC:
574 * OpenSSL requires GMAC to be a GCM operation
575 * with no cipher data length
577 sess->cipher.key.length = xform->auth.key.length;
579 /* Set IV parameters */
580 sess->iv.offset = xform->auth.iv.offset;
581 sess->iv.length = xform->auth.iv.length;
583 if (sess->auth.operation == RTE_CRYPTO_AUTH_OP_GENERATE)
584 return openssl_set_sess_aead_enc_param(sess,
585 RTE_CRYPTO_AEAD_AES_GCM,
586 xform->auth.digest_length,
587 xform->auth.key.data);
589 return openssl_set_sess_aead_dec_param(sess,
590 RTE_CRYPTO_AEAD_AES_GCM,
591 xform->auth.digest_length,
592 xform->auth.key.data);
595 case RTE_CRYPTO_AUTH_MD5:
596 case RTE_CRYPTO_AUTH_SHA1:
597 case RTE_CRYPTO_AUTH_SHA224:
598 case RTE_CRYPTO_AUTH_SHA256:
599 case RTE_CRYPTO_AUTH_SHA384:
600 case RTE_CRYPTO_AUTH_SHA512:
601 sess->auth.mode = OPENSSL_AUTH_AS_AUTH;
602 if (get_auth_algo(xform->auth.algo,
603 &sess->auth.auth.evp_algo) != 0)
605 sess->auth.auth.ctx = EVP_MD_CTX_create();
608 case RTE_CRYPTO_AUTH_MD5_HMAC:
609 case RTE_CRYPTO_AUTH_SHA1_HMAC:
610 case RTE_CRYPTO_AUTH_SHA224_HMAC:
611 case RTE_CRYPTO_AUTH_SHA256_HMAC:
612 case RTE_CRYPTO_AUTH_SHA384_HMAC:
613 case RTE_CRYPTO_AUTH_SHA512_HMAC:
614 sess->auth.mode = OPENSSL_AUTH_AS_HMAC;
615 sess->auth.hmac.ctx = HMAC_CTX_new();
616 if (get_auth_algo(xform->auth.algo,
617 &sess->auth.hmac.evp_algo) != 0)
620 if (HMAC_Init_ex(sess->auth.hmac.ctx,
621 xform->auth.key.data,
622 xform->auth.key.length,
623 sess->auth.hmac.evp_algo, NULL) != 1)
634 /* Set session AEAD parameters */
636 openssl_set_session_aead_parameters(struct openssl_session *sess,
637 const struct rte_crypto_sym_xform *xform)
639 /* Select cipher key */
640 sess->cipher.key.length = xform->aead.key.length;
642 /* Set IV parameters */
643 if (xform->aead.algo == RTE_CRYPTO_AEAD_AES_CCM)
645 * For AES-CCM, the actual IV is placed
646 * one byte after the start of the IV field,
647 * according to the API.
649 sess->iv.offset = xform->aead.iv.offset + 1;
651 sess->iv.offset = xform->aead.iv.offset;
653 sess->iv.length = xform->aead.iv.length;
655 sess->auth.aad_length = xform->aead.aad_length;
656 sess->auth.digest_length = xform->aead.digest_length;
658 sess->aead_algo = xform->aead.algo;
659 /* Select cipher direction */
660 if (xform->aead.op == RTE_CRYPTO_AEAD_OP_ENCRYPT)
661 return openssl_set_sess_aead_enc_param(sess, xform->aead.algo,
662 xform->aead.digest_length, xform->aead.key.data);
664 return openssl_set_sess_aead_dec_param(sess, xform->aead.algo,
665 xform->aead.digest_length, xform->aead.key.data);
668 /** Parse crypto xform chain and set private session parameters */
670 openssl_set_session_parameters(struct openssl_session *sess,
671 const struct rte_crypto_sym_xform *xform)
673 const struct rte_crypto_sym_xform *cipher_xform = NULL;
674 const struct rte_crypto_sym_xform *auth_xform = NULL;
675 const struct rte_crypto_sym_xform *aead_xform = NULL;
678 sess->chain_order = openssl_get_chain_order(xform);
679 switch (sess->chain_order) {
680 case OPENSSL_CHAIN_ONLY_CIPHER:
681 cipher_xform = xform;
683 case OPENSSL_CHAIN_ONLY_AUTH:
686 case OPENSSL_CHAIN_CIPHER_AUTH:
687 cipher_xform = xform;
688 auth_xform = xform->next;
690 case OPENSSL_CHAIN_AUTH_CIPHER:
692 cipher_xform = xform->next;
694 case OPENSSL_CHAIN_COMBINED:
701 /* Default IV length = 0 */
704 /* cipher_xform must be check before auth_xform */
706 ret = openssl_set_session_cipher_parameters(
710 "Invalid/unsupported cipher parameters");
716 ret = openssl_set_session_auth_parameters(sess, auth_xform);
719 "Invalid/unsupported auth parameters");
725 ret = openssl_set_session_aead_parameters(sess, aead_xform);
728 "Invalid/unsupported AEAD parameters");
736 /** Reset private session parameters */
738 openssl_reset_session(struct openssl_session *sess)
740 EVP_CIPHER_CTX_free(sess->cipher.ctx);
742 if (sess->chain_order == OPENSSL_CHAIN_CIPHER_BPI)
743 EVP_CIPHER_CTX_free(sess->cipher.bpi_ctx);
745 switch (sess->auth.mode) {
746 case OPENSSL_AUTH_AS_AUTH:
747 EVP_MD_CTX_destroy(sess->auth.auth.ctx);
749 case OPENSSL_AUTH_AS_HMAC:
750 EVP_PKEY_free(sess->auth.hmac.pkey);
751 HMAC_CTX_free(sess->auth.hmac.ctx);
758 /** Provide session for operation */
759 static struct openssl_session *
760 get_session(struct openssl_qp *qp, struct rte_crypto_op *op)
762 struct openssl_session *sess = NULL;
764 if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
765 /* get existing session */
766 if (likely(op->sym->session != NULL))
767 sess = (struct openssl_session *)
768 get_session_private_data(
770 cryptodev_driver_id);
772 /* provide internal session */
774 void *_sess_private_data = NULL;
776 if (rte_mempool_get(qp->sess_mp, (void **)&_sess))
779 if (rte_mempool_get(qp->sess_mp, (void **)&_sess_private_data))
782 sess = (struct openssl_session *)_sess_private_data;
784 if (unlikely(openssl_set_session_parameters(sess,
785 op->sym->xform) != 0)) {
786 rte_mempool_put(qp->sess_mp, _sess);
787 rte_mempool_put(qp->sess_mp, _sess_private_data);
790 op->sym->session = (struct rte_cryptodev_sym_session *)_sess;
791 set_session_private_data(op->sym->session, cryptodev_driver_id,
796 op->status = RTE_CRYPTO_OP_STATUS_INVALID_SESSION;
802 *------------------------------------------------------------------------------
804 *------------------------------------------------------------------------------
807 process_openssl_encryption_update(struct rte_mbuf *mbuf_src, int offset,
808 uint8_t **dst, int srclen, EVP_CIPHER_CTX *ctx)
815 for (m = mbuf_src; m != NULL && offset > rte_pktmbuf_data_len(m);
817 offset -= rte_pktmbuf_data_len(m);
822 src = rte_pktmbuf_mtod_offset(m, uint8_t *, offset);
824 l = rte_pktmbuf_data_len(m) - offset;
826 if (EVP_EncryptUpdate(ctx, *dst, &dstlen, src, srclen) <= 0)
832 if (EVP_EncryptUpdate(ctx, *dst, &dstlen, src, l) <= 0)
838 for (m = m->next; (m != NULL) && (n > 0); m = m->next) {
839 src = rte_pktmbuf_mtod(m, uint8_t *);
840 l = rte_pktmbuf_data_len(m) < n ? rte_pktmbuf_data_len(m) : n;
841 if (EVP_EncryptUpdate(ctx, *dst, &dstlen, src, l) <= 0)
851 process_openssl_decryption_update(struct rte_mbuf *mbuf_src, int offset,
852 uint8_t **dst, int srclen, EVP_CIPHER_CTX *ctx)
859 for (m = mbuf_src; m != NULL && offset > rte_pktmbuf_data_len(m);
861 offset -= rte_pktmbuf_data_len(m);
866 src = rte_pktmbuf_mtod_offset(m, uint8_t *, offset);
868 l = rte_pktmbuf_data_len(m) - offset;
870 if (EVP_DecryptUpdate(ctx, *dst, &dstlen, src, srclen) <= 0)
876 if (EVP_DecryptUpdate(ctx, *dst, &dstlen, src, l) <= 0)
882 for (m = m->next; (m != NULL) && (n > 0); m = m->next) {
883 src = rte_pktmbuf_mtod(m, uint8_t *);
884 l = rte_pktmbuf_data_len(m) < n ? rte_pktmbuf_data_len(m) : n;
885 if (EVP_DecryptUpdate(ctx, *dst, &dstlen, src, l) <= 0)
894 /** Process standard openssl cipher encryption */
896 process_openssl_cipher_encrypt(struct rte_mbuf *mbuf_src, uint8_t *dst,
897 int offset, uint8_t *iv, int srclen, EVP_CIPHER_CTX *ctx)
901 if (EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, iv) <= 0)
902 goto process_cipher_encrypt_err;
904 EVP_CIPHER_CTX_set_padding(ctx, 0);
906 if (process_openssl_encryption_update(mbuf_src, offset, &dst,
908 goto process_cipher_encrypt_err;
910 if (EVP_EncryptFinal_ex(ctx, dst, &totlen) <= 0)
911 goto process_cipher_encrypt_err;
915 process_cipher_encrypt_err:
916 OPENSSL_LOG_ERR("Process openssl cipher encrypt failed");
920 /** Process standard openssl cipher encryption */
922 process_openssl_cipher_bpi_encrypt(uint8_t *src, uint8_t *dst,
923 uint8_t *iv, int srclen,
927 uint8_t encrypted_iv[DES_BLOCK_SIZE];
930 if (EVP_EncryptUpdate(ctx, encrypted_iv, &encrypted_ivlen,
931 iv, DES_BLOCK_SIZE) <= 0)
932 goto process_cipher_encrypt_err;
934 for (i = 0; i < srclen; i++)
935 *(dst + i) = *(src + i) ^ (encrypted_iv[i]);
939 process_cipher_encrypt_err:
940 OPENSSL_LOG_ERR("Process openssl cipher bpi encrypt failed");
943 /** Process standard openssl cipher decryption */
945 process_openssl_cipher_decrypt(struct rte_mbuf *mbuf_src, uint8_t *dst,
946 int offset, uint8_t *iv, int srclen, EVP_CIPHER_CTX *ctx)
950 if (EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv) <= 0)
951 goto process_cipher_decrypt_err;
953 EVP_CIPHER_CTX_set_padding(ctx, 0);
955 if (process_openssl_decryption_update(mbuf_src, offset, &dst,
957 goto process_cipher_decrypt_err;
959 if (EVP_DecryptFinal_ex(ctx, dst, &totlen) <= 0)
960 goto process_cipher_decrypt_err;
963 process_cipher_decrypt_err:
964 OPENSSL_LOG_ERR("Process openssl cipher decrypt failed");
968 /** Process cipher des 3 ctr encryption, decryption algorithm */
970 process_openssl_cipher_des3ctr(struct rte_mbuf *mbuf_src, uint8_t *dst,
971 int offset, uint8_t *iv, uint8_t *key, int srclen,
974 uint8_t ebuf[8], ctr[8];
980 for (m = mbuf_src; m != NULL && offset > rte_pktmbuf_data_len(m);
982 offset -= rte_pktmbuf_data_len(m);
985 goto process_cipher_des3ctr_err;
987 src = rte_pktmbuf_mtod_offset(m, uint8_t *, offset);
988 l = rte_pktmbuf_data_len(m) - offset;
990 /* We use 3DES encryption also for decryption.
991 * IV is not important for 3DES ecb
993 if (EVP_EncryptInit_ex(ctx, EVP_des_ede3_ecb(), NULL, key, NULL) <= 0)
994 goto process_cipher_des3ctr_err;
998 for (n = 0; n < srclen; n++) {
1000 if (EVP_EncryptUpdate(ctx,
1001 (unsigned char *)&ebuf, &unused,
1002 (const unsigned char *)&ctr, 8) <= 0)
1003 goto process_cipher_des3ctr_err;
1006 dst[n] = *(src++) ^ ebuf[n % 8];
1012 src = rte_pktmbuf_mtod(m, uint8_t *);
1013 l = rte_pktmbuf_data_len(m);
1020 process_cipher_des3ctr_err:
1021 OPENSSL_LOG_ERR("Process openssl cipher des 3 ede ctr failed");
1025 /** Process AES-GCM encrypt algorithm */
1027 process_openssl_auth_encryption_gcm(struct rte_mbuf *mbuf_src, int offset,
1028 int srclen, uint8_t *aad, int aadlen, uint8_t *iv,
1029 uint8_t *dst, uint8_t *tag, EVP_CIPHER_CTX *ctx)
1031 int len = 0, unused = 0;
1032 uint8_t empty[] = {};
1034 if (EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, iv) <= 0)
1035 goto process_auth_encryption_gcm_err;
1038 if (EVP_EncryptUpdate(ctx, NULL, &len, aad, aadlen) <= 0)
1039 goto process_auth_encryption_gcm_err;
1042 if (process_openssl_encryption_update(mbuf_src, offset, &dst,
1044 goto process_auth_encryption_gcm_err;
1046 /* Workaround open ssl bug in version less then 1.0.1f */
1047 if (EVP_EncryptUpdate(ctx, empty, &unused, empty, 0) <= 0)
1048 goto process_auth_encryption_gcm_err;
1050 if (EVP_EncryptFinal_ex(ctx, dst, &len) <= 0)
1051 goto process_auth_encryption_gcm_err;
1053 if (EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_GET_TAG, 16, tag) <= 0)
1054 goto process_auth_encryption_gcm_err;
1058 process_auth_encryption_gcm_err:
1059 OPENSSL_LOG_ERR("Process openssl auth encryption gcm failed");
1063 /** Process AES-CCM encrypt algorithm */
1065 process_openssl_auth_encryption_ccm(struct rte_mbuf *mbuf_src, int offset,
1066 int srclen, uint8_t *aad, int aadlen, uint8_t *iv,
1067 uint8_t *dst, uint8_t *tag, uint8_t taglen, EVP_CIPHER_CTX *ctx)
1071 if (EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, iv) <= 0)
1072 goto process_auth_encryption_ccm_err;
1074 if (EVP_EncryptUpdate(ctx, NULL, &len, NULL, srclen) <= 0)
1075 goto process_auth_encryption_ccm_err;
1079 * For AES-CCM, the actual AAD is placed
1080 * 18 bytes after the start of the AAD field,
1081 * according to the API.
1083 if (EVP_EncryptUpdate(ctx, NULL, &len, aad + 18, aadlen) <= 0)
1084 goto process_auth_encryption_ccm_err;
1087 if (process_openssl_encryption_update(mbuf_src, offset, &dst,
1089 goto process_auth_encryption_ccm_err;
1091 if (EVP_EncryptFinal_ex(ctx, dst, &len) <= 0)
1092 goto process_auth_encryption_ccm_err;
1094 if (EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_CCM_GET_TAG, taglen, tag) <= 0)
1095 goto process_auth_encryption_ccm_err;
1099 process_auth_encryption_ccm_err:
1100 OPENSSL_LOG_ERR("Process openssl auth encryption ccm failed");
1104 /** Process AES-GCM decrypt algorithm */
1106 process_openssl_auth_decryption_gcm(struct rte_mbuf *mbuf_src, int offset,
1107 int srclen, uint8_t *aad, int aadlen, uint8_t *iv,
1108 uint8_t *dst, uint8_t *tag, EVP_CIPHER_CTX *ctx)
1110 int len = 0, unused = 0;
1111 uint8_t empty[] = {};
1113 if (EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_TAG, 16, tag) <= 0)
1114 goto process_auth_decryption_gcm_err;
1116 if (EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv) <= 0)
1117 goto process_auth_decryption_gcm_err;
1120 if (EVP_DecryptUpdate(ctx, NULL, &len, aad, aadlen) <= 0)
1121 goto process_auth_decryption_gcm_err;
1124 if (process_openssl_decryption_update(mbuf_src, offset, &dst,
1126 goto process_auth_decryption_gcm_err;
1128 /* Workaround open ssl bug in version less then 1.0.1f */
1129 if (EVP_DecryptUpdate(ctx, empty, &unused, empty, 0) <= 0)
1130 goto process_auth_decryption_gcm_err;
1132 if (EVP_DecryptFinal_ex(ctx, dst, &len) <= 0)
1137 process_auth_decryption_gcm_err:
1138 OPENSSL_LOG_ERR("Process openssl auth decryption gcm failed");
1142 /** Process AES-CCM decrypt algorithm */
1144 process_openssl_auth_decryption_ccm(struct rte_mbuf *mbuf_src, int offset,
1145 int srclen, uint8_t *aad, int aadlen, uint8_t *iv,
1146 uint8_t *dst, uint8_t *tag, uint8_t tag_len,
1147 EVP_CIPHER_CTX *ctx)
1151 if (EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_CCM_SET_TAG, tag_len, tag) <= 0)
1152 goto process_auth_decryption_ccm_err;
1154 if (EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv) <= 0)
1155 goto process_auth_decryption_ccm_err;
1157 if (EVP_DecryptUpdate(ctx, NULL, &len, NULL, srclen) <= 0)
1158 goto process_auth_decryption_ccm_err;
1162 * For AES-CCM, the actual AAD is placed
1163 * 18 bytes after the start of the AAD field,
1164 * according to the API.
1166 if (EVP_DecryptUpdate(ctx, NULL, &len, aad + 18, aadlen) <= 0)
1167 goto process_auth_decryption_ccm_err;
1170 if (process_openssl_decryption_update(mbuf_src, offset, &dst,
1176 process_auth_decryption_ccm_err:
1177 OPENSSL_LOG_ERR("Process openssl auth decryption ccm failed");
1181 /** Process standard openssl auth algorithms */
1183 process_openssl_auth(struct rte_mbuf *mbuf_src, uint8_t *dst, int offset,
1184 __rte_unused uint8_t *iv, __rte_unused EVP_PKEY * pkey,
1185 int srclen, EVP_MD_CTX *ctx, const EVP_MD *algo)
1192 for (m = mbuf_src; m != NULL && offset > rte_pktmbuf_data_len(m);
1194 offset -= rte_pktmbuf_data_len(m);
1197 goto process_auth_err;
1199 if (EVP_DigestInit_ex(ctx, algo, NULL) <= 0)
1200 goto process_auth_err;
1202 src = rte_pktmbuf_mtod_offset(m, uint8_t *, offset);
1204 l = rte_pktmbuf_data_len(m) - offset;
1206 if (EVP_DigestUpdate(ctx, (char *)src, srclen) <= 0)
1207 goto process_auth_err;
1208 goto process_auth_final;
1211 if (EVP_DigestUpdate(ctx, (char *)src, l) <= 0)
1212 goto process_auth_err;
1216 for (m = m->next; (m != NULL) && (n > 0); m = m->next) {
1217 src = rte_pktmbuf_mtod(m, uint8_t *);
1218 l = rte_pktmbuf_data_len(m) < n ? rte_pktmbuf_data_len(m) : n;
1219 if (EVP_DigestUpdate(ctx, (char *)src, l) <= 0)
1220 goto process_auth_err;
1225 if (EVP_DigestFinal_ex(ctx, dst, (unsigned int *)&dstlen) <= 0)
1226 goto process_auth_err;
1230 OPENSSL_LOG_ERR("Process openssl auth failed");
1234 /** Process standard openssl auth algorithms with hmac */
1236 process_openssl_auth_hmac(struct rte_mbuf *mbuf_src, uint8_t *dst, int offset,
1237 int srclen, HMAC_CTX *ctx)
1239 unsigned int dstlen;
1244 for (m = mbuf_src; m != NULL && offset > rte_pktmbuf_data_len(m);
1246 offset -= rte_pktmbuf_data_len(m);
1249 goto process_auth_err;
1251 src = rte_pktmbuf_mtod_offset(m, uint8_t *, offset);
1253 l = rte_pktmbuf_data_len(m) - offset;
1255 if (HMAC_Update(ctx, (unsigned char *)src, srclen) != 1)
1256 goto process_auth_err;
1257 goto process_auth_final;
1260 if (HMAC_Update(ctx, (unsigned char *)src, l) != 1)
1261 goto process_auth_err;
1265 for (m = m->next; (m != NULL) && (n > 0); m = m->next) {
1266 src = rte_pktmbuf_mtod(m, uint8_t *);
1267 l = rte_pktmbuf_data_len(m) < n ? rte_pktmbuf_data_len(m) : n;
1268 if (HMAC_Update(ctx, (unsigned char *)src, l) != 1)
1269 goto process_auth_err;
1274 if (HMAC_Final(ctx, dst, &dstlen) != 1)
1275 goto process_auth_err;
1277 if (unlikely(HMAC_Init_ex(ctx, NULL, 0, NULL, NULL) != 1))
1278 goto process_auth_err;
1283 OPENSSL_LOG_ERR("Process openssl auth failed");
1287 /*----------------------------------------------------------------------------*/
1289 /** Process auth/cipher combined operation */
1291 process_openssl_combined_op
1292 (struct rte_crypto_op *op, struct openssl_session *sess,
1293 struct rte_mbuf *mbuf_src, struct rte_mbuf *mbuf_dst)
1296 uint8_t *dst = NULL, *iv, *tag, *aad;
1297 int srclen, aadlen, status = -1;
1302 * Segmented destination buffer is not supported for
1303 * encryption/decryption
1305 if (!rte_pktmbuf_is_contiguous(mbuf_dst)) {
1306 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
1310 iv = rte_crypto_op_ctod_offset(op, uint8_t *,
1312 if (sess->auth.algo == RTE_CRYPTO_AUTH_AES_GMAC) {
1314 offset = op->sym->auth.data.offset;
1315 aadlen = op->sym->auth.data.length;
1316 aad = rte_pktmbuf_mtod_offset(mbuf_src, uint8_t *,
1317 op->sym->auth.data.offset);
1318 tag = op->sym->auth.digest.data;
1320 tag = rte_pktmbuf_mtod_offset(mbuf_dst, uint8_t *,
1323 srclen = op->sym->aead.data.length;
1324 dst = rte_pktmbuf_mtod_offset(mbuf_dst, uint8_t *,
1325 op->sym->aead.data.offset);
1326 offset = op->sym->aead.data.offset;
1327 aad = op->sym->aead.aad.data;
1328 aadlen = sess->auth.aad_length;
1329 tag = op->sym->aead.digest.data;
1331 tag = rte_pktmbuf_mtod_offset(mbuf_dst, uint8_t *,
1335 taglen = sess->auth.digest_length;
1337 if (sess->cipher.direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
1338 if (sess->auth.algo == RTE_CRYPTO_AUTH_AES_GMAC ||
1339 sess->aead_algo == RTE_CRYPTO_AEAD_AES_GCM)
1340 status = process_openssl_auth_encryption_gcm(
1341 mbuf_src, offset, srclen,
1343 dst, tag, sess->cipher.ctx);
1345 status = process_openssl_auth_encryption_ccm(
1346 mbuf_src, offset, srclen,
1348 dst, tag, taglen, sess->cipher.ctx);
1351 if (sess->auth.algo == RTE_CRYPTO_AUTH_AES_GMAC ||
1352 sess->aead_algo == RTE_CRYPTO_AEAD_AES_GCM)
1353 status = process_openssl_auth_decryption_gcm(
1354 mbuf_src, offset, srclen,
1356 dst, tag, sess->cipher.ctx);
1358 status = process_openssl_auth_decryption_ccm(
1359 mbuf_src, offset, srclen,
1361 dst, tag, taglen, sess->cipher.ctx);
1365 if (status == (-EFAULT) &&
1366 sess->auth.operation ==
1367 RTE_CRYPTO_AUTH_OP_VERIFY)
1368 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
1370 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
1374 /** Process cipher operation */
1376 process_openssl_cipher_op
1377 (struct rte_crypto_op *op, struct openssl_session *sess,
1378 struct rte_mbuf *mbuf_src, struct rte_mbuf *mbuf_dst)
1384 * Segmented destination buffer is not supported for
1385 * encryption/decryption
1387 if (!rte_pktmbuf_is_contiguous(mbuf_dst)) {
1388 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
1392 srclen = op->sym->cipher.data.length;
1393 dst = rte_pktmbuf_mtod_offset(mbuf_dst, uint8_t *,
1394 op->sym->cipher.data.offset);
1396 iv = rte_crypto_op_ctod_offset(op, uint8_t *,
1399 if (sess->cipher.mode == OPENSSL_CIPHER_LIB)
1400 if (sess->cipher.direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT)
1401 status = process_openssl_cipher_encrypt(mbuf_src, dst,
1402 op->sym->cipher.data.offset, iv,
1403 srclen, sess->cipher.ctx);
1405 status = process_openssl_cipher_decrypt(mbuf_src, dst,
1406 op->sym->cipher.data.offset, iv,
1407 srclen, sess->cipher.ctx);
1409 status = process_openssl_cipher_des3ctr(mbuf_src, dst,
1410 op->sym->cipher.data.offset, iv,
1411 sess->cipher.key.data, srclen,
1415 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
1418 /** Process cipher operation */
1420 process_openssl_docsis_bpi_op(struct rte_crypto_op *op,
1421 struct openssl_session *sess, struct rte_mbuf *mbuf_src,
1422 struct rte_mbuf *mbuf_dst)
1424 uint8_t *src, *dst, *iv;
1425 uint8_t block_size, last_block_len;
1426 int srclen, status = 0;
1428 srclen = op->sym->cipher.data.length;
1429 src = rte_pktmbuf_mtod_offset(mbuf_src, uint8_t *,
1430 op->sym->cipher.data.offset);
1431 dst = rte_pktmbuf_mtod_offset(mbuf_dst, uint8_t *,
1432 op->sym->cipher.data.offset);
1434 iv = rte_crypto_op_ctod_offset(op, uint8_t *,
1437 block_size = DES_BLOCK_SIZE;
1439 last_block_len = srclen % block_size;
1440 if (sess->cipher.direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
1441 /* Encrypt only with ECB mode XOR IV */
1442 if (srclen < block_size) {
1443 status = process_openssl_cipher_bpi_encrypt(src, dst,
1445 sess->cipher.bpi_ctx);
1447 srclen -= last_block_len;
1448 /* Encrypt with the block aligned stream with CBC mode */
1449 status = process_openssl_cipher_encrypt(mbuf_src, dst,
1450 op->sym->cipher.data.offset, iv,
1451 srclen, sess->cipher.ctx);
1452 if (last_block_len) {
1453 /* Point at last block */
1456 * IV is the last encrypted block from
1457 * the previous operation
1459 iv = dst - block_size;
1461 srclen = last_block_len;
1462 /* Encrypt the last frame with ECB mode */
1463 status |= process_openssl_cipher_bpi_encrypt(src,
1465 srclen, sess->cipher.bpi_ctx);
1469 /* Decrypt only with ECB mode (encrypt, as it is same operation) */
1470 if (srclen < block_size) {
1471 status = process_openssl_cipher_bpi_encrypt(src, dst,
1474 sess->cipher.bpi_ctx);
1476 if (last_block_len) {
1477 /* Point at last block */
1478 dst += srclen - last_block_len;
1479 src += srclen - last_block_len;
1481 * IV is the last full block
1483 iv = src - block_size;
1485 * Decrypt the last frame with ECB mode
1486 * (encrypt, as it is the same operation)
1488 status = process_openssl_cipher_bpi_encrypt(src,
1490 last_block_len, sess->cipher.bpi_ctx);
1491 /* Prepare parameters for CBC mode op */
1492 iv = rte_crypto_op_ctod_offset(op, uint8_t *,
1494 dst += last_block_len - srclen;
1495 srclen -= last_block_len;
1498 /* Decrypt with CBC mode */
1499 status |= process_openssl_cipher_decrypt(mbuf_src, dst,
1500 op->sym->cipher.data.offset, iv,
1501 srclen, sess->cipher.ctx);
1506 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
1509 /** Process auth operation */
1511 process_openssl_auth_op(struct openssl_qp *qp, struct rte_crypto_op *op,
1512 struct openssl_session *sess, struct rte_mbuf *mbuf_src,
1513 struct rte_mbuf *mbuf_dst)
1518 srclen = op->sym->auth.data.length;
1520 if (sess->auth.operation == RTE_CRYPTO_AUTH_OP_VERIFY)
1521 dst = qp->temp_digest;
1523 dst = op->sym->auth.digest.data;
1525 dst = rte_pktmbuf_mtod_offset(mbuf_dst, uint8_t *,
1526 op->sym->auth.data.offset +
1527 op->sym->auth.data.length);
1530 switch (sess->auth.mode) {
1531 case OPENSSL_AUTH_AS_AUTH:
1532 status = process_openssl_auth(mbuf_src, dst,
1533 op->sym->auth.data.offset, NULL, NULL, srclen,
1534 sess->auth.auth.ctx, sess->auth.auth.evp_algo);
1536 case OPENSSL_AUTH_AS_HMAC:
1537 status = process_openssl_auth_hmac(mbuf_src, dst,
1538 op->sym->auth.data.offset, srclen,
1539 sess->auth.hmac.ctx);
1546 if (sess->auth.operation == RTE_CRYPTO_AUTH_OP_VERIFY) {
1547 if (memcmp(dst, op->sym->auth.digest.data,
1548 sess->auth.digest_length) != 0) {
1549 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
1554 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
1557 /** Process crypto operation for mbuf */
1559 process_op(struct openssl_qp *qp, struct rte_crypto_op *op,
1560 struct openssl_session *sess)
1562 struct rte_mbuf *msrc, *mdst;
1565 msrc = op->sym->m_src;
1566 mdst = op->sym->m_dst ? op->sym->m_dst : op->sym->m_src;
1568 op->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
1570 switch (sess->chain_order) {
1571 case OPENSSL_CHAIN_ONLY_CIPHER:
1572 process_openssl_cipher_op(op, sess, msrc, mdst);
1574 case OPENSSL_CHAIN_ONLY_AUTH:
1575 process_openssl_auth_op(qp, op, sess, msrc, mdst);
1577 case OPENSSL_CHAIN_CIPHER_AUTH:
1578 process_openssl_cipher_op(op, sess, msrc, mdst);
1579 process_openssl_auth_op(qp, op, sess, mdst, mdst);
1581 case OPENSSL_CHAIN_AUTH_CIPHER:
1582 process_openssl_auth_op(qp, op, sess, msrc, mdst);
1583 process_openssl_cipher_op(op, sess, msrc, mdst);
1585 case OPENSSL_CHAIN_COMBINED:
1586 process_openssl_combined_op(op, sess, msrc, mdst);
1588 case OPENSSL_CHAIN_CIPHER_BPI:
1589 process_openssl_docsis_bpi_op(op, sess, msrc, mdst);
1592 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
1596 /* Free session if a session-less crypto op */
1597 if (op->sess_type == RTE_CRYPTO_OP_SESSIONLESS) {
1598 openssl_reset_session(sess);
1599 memset(sess, 0, sizeof(struct openssl_session));
1600 memset(op->sym->session, 0,
1601 rte_cryptodev_get_header_session_size());
1602 rte_mempool_put(qp->sess_mp, sess);
1603 rte_mempool_put(qp->sess_mp, op->sym->session);
1604 op->sym->session = NULL;
1607 if (op->status == RTE_CRYPTO_OP_STATUS_NOT_PROCESSED)
1608 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
1610 if (op->status != RTE_CRYPTO_OP_STATUS_ERROR)
1611 retval = rte_ring_enqueue(qp->processed_ops, (void *)op);
1619 *------------------------------------------------------------------------------
1621 *------------------------------------------------------------------------------
1624 /** Enqueue burst */
1626 openssl_pmd_enqueue_burst(void *queue_pair, struct rte_crypto_op **ops,
1629 struct openssl_session *sess;
1630 struct openssl_qp *qp = queue_pair;
1633 for (i = 0; i < nb_ops; i++) {
1634 sess = get_session(qp, ops[i]);
1635 if (unlikely(sess == NULL))
1638 retval = process_op(qp, ops[i], sess);
1639 if (unlikely(retval < 0))
1643 qp->stats.enqueued_count += i;
1647 qp->stats.enqueue_err_count++;
1651 /** Dequeue burst */
1653 openssl_pmd_dequeue_burst(void *queue_pair, struct rte_crypto_op **ops,
1656 struct openssl_qp *qp = queue_pair;
1658 unsigned int nb_dequeued = 0;
1660 nb_dequeued = rte_ring_dequeue_burst(qp->processed_ops,
1661 (void **)ops, nb_ops, NULL);
1662 qp->stats.dequeued_count += nb_dequeued;
1667 /** Create OPENSSL crypto device */
1669 cryptodev_openssl_create(const char *name,
1670 struct rte_vdev_device *vdev,
1671 struct rte_crypto_vdev_init_params *init_params)
1673 struct rte_cryptodev *dev;
1674 struct openssl_private *internals;
1676 if (init_params->name[0] == '\0')
1677 snprintf(init_params->name, sizeof(init_params->name),
1680 dev = rte_cryptodev_vdev_pmd_init(init_params->name,
1681 sizeof(struct openssl_private),
1682 init_params->socket_id,
1685 OPENSSL_LOG_ERR("failed to create cryptodev vdev");
1689 dev->driver_id = cryptodev_driver_id;
1690 dev->dev_ops = rte_openssl_pmd_ops;
1692 /* register rx/tx burst functions for data path */
1693 dev->dequeue_burst = openssl_pmd_dequeue_burst;
1694 dev->enqueue_burst = openssl_pmd_enqueue_burst;
1696 dev->feature_flags = RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO |
1697 RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING |
1698 RTE_CRYPTODEV_FF_CPU_AESNI |
1699 RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER;
1701 /* Set vector instructions mode supported */
1702 internals = dev->data->dev_private;
1704 internals->max_nb_qpairs = init_params->max_nb_queue_pairs;
1705 internals->max_nb_sessions = init_params->max_nb_sessions;
1710 OPENSSL_LOG_ERR("driver %s: cryptodev_openssl_create failed",
1713 cryptodev_openssl_remove(vdev);
1717 /** Initialise OPENSSL crypto device */
1719 cryptodev_openssl_probe(struct rte_vdev_device *vdev)
1721 struct rte_crypto_vdev_init_params init_params = {
1722 RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_QUEUE_PAIRS,
1723 RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_SESSIONS,
1728 const char *input_args;
1730 name = rte_vdev_device_name(vdev);
1733 input_args = rte_vdev_device_args(vdev);
1735 rte_cryptodev_vdev_parse_init_params(&init_params, input_args);
1737 RTE_LOG(INFO, PMD, "Initialising %s on NUMA node %d\n", name,
1738 init_params.socket_id);
1739 if (init_params.name[0] != '\0')
1740 RTE_LOG(INFO, PMD, " User defined name = %s\n",
1742 RTE_LOG(INFO, PMD, " Max number of queue pairs = %d\n",
1743 init_params.max_nb_queue_pairs);
1744 RTE_LOG(INFO, PMD, " Max number of sessions = %d\n",
1745 init_params.max_nb_sessions);
1747 return cryptodev_openssl_create(name, vdev, &init_params);
1750 /** Uninitialise OPENSSL crypto device */
1752 cryptodev_openssl_remove(struct rte_vdev_device *vdev)
1756 name = rte_vdev_device_name(vdev);
1761 "Closing OPENSSL crypto device %s on numa socket %u\n",
1762 name, rte_socket_id());
1767 static struct rte_vdev_driver cryptodev_openssl_pmd_drv = {
1768 .probe = cryptodev_openssl_probe,
1769 .remove = cryptodev_openssl_remove
1772 static struct cryptodev_driver openssl_crypto_drv;
1774 RTE_PMD_REGISTER_VDEV(CRYPTODEV_NAME_OPENSSL_PMD,
1775 cryptodev_openssl_pmd_drv);
1776 RTE_PMD_REGISTER_PARAM_STRING(CRYPTODEV_NAME_OPENSSL_PMD,
1777 "max_nb_queue_pairs=<int> "
1778 "max_nb_sessions=<int> "
1780 RTE_PMD_REGISTER_CRYPTO_DRIVER(openssl_crypto_drv, cryptodev_openssl_pmd_drv,
1781 cryptodev_driver_id);