1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2016-2017 Intel Corporation
5 #include <rte_common.h>
6 #include <rte_hexdump.h>
7 #include <rte_cryptodev.h>
8 #include <rte_cryptodev_pmd.h>
9 #include <rte_bus_vdev.h>
10 #include <rte_malloc.h>
11 #include <rte_cpuflags.h>
13 #include <openssl/hmac.h>
14 #include <openssl/evp.h>
16 #include "rte_openssl_pmd_private.h"
18 #define DES_BLOCK_SIZE 8
20 static uint8_t cryptodev_driver_id;
22 #if (OPENSSL_VERSION_NUMBER < 0x10100000L)
23 static HMAC_CTX *HMAC_CTX_new(void)
25 HMAC_CTX *ctx = OPENSSL_malloc(sizeof(*ctx));
32 static void HMAC_CTX_free(HMAC_CTX *ctx)
35 HMAC_CTX_cleanup(ctx);
41 static int cryptodev_openssl_remove(struct rte_vdev_device *vdev);
43 /*----------------------------------------------------------------------------*/
46 * Increment counter by 1
47 * Counter is 64 bit array, big-endian
52 uint64_t *ctr64 = (uint64_t *)ctr;
54 *ctr64 = __builtin_bswap64(*ctr64);
56 *ctr64 = __builtin_bswap64(*ctr64);
60 *------------------------------------------------------------------------------
62 *------------------------------------------------------------------------------
65 /** Get xform chain order */
66 static enum openssl_chain_order
67 openssl_get_chain_order(const struct rte_crypto_sym_xform *xform)
69 enum openssl_chain_order res = OPENSSL_CHAIN_NOT_SUPPORTED;
72 if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
73 if (xform->next == NULL)
74 res = OPENSSL_CHAIN_ONLY_AUTH;
75 else if (xform->next->type ==
76 RTE_CRYPTO_SYM_XFORM_CIPHER)
77 res = OPENSSL_CHAIN_AUTH_CIPHER;
79 if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
80 if (xform->next == NULL)
81 res = OPENSSL_CHAIN_ONLY_CIPHER;
82 else if (xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH)
83 res = OPENSSL_CHAIN_CIPHER_AUTH;
85 if (xform->type == RTE_CRYPTO_SYM_XFORM_AEAD)
86 res = OPENSSL_CHAIN_COMBINED;
92 /** Get session cipher key from input cipher key */
94 get_cipher_key(uint8_t *input_key, int keylen, uint8_t *session_key)
96 memcpy(session_key, input_key, keylen);
99 /** Get key ede 24 bytes standard from input key */
101 get_cipher_key_ede(uint8_t *key, int keylen, uint8_t *key_ede)
105 /* Initialize keys - 24 bytes: [key1-key2-key3] */
108 memcpy(key_ede, key, 24);
112 memcpy(key_ede, key, 16);
113 memcpy(key_ede + 16, key, 8);
116 /* K1 = K2 = K3 (DES compatibility) */
117 memcpy(key_ede, key, 8);
118 memcpy(key_ede + 8, key, 8);
119 memcpy(key_ede + 16, key, 8);
122 OPENSSL_LOG(ERR, "Unsupported key size");
129 /** Get adequate openssl function for input cipher algorithm */
131 get_cipher_algo(enum rte_crypto_cipher_algorithm sess_algo, size_t keylen,
132 const EVP_CIPHER **algo)
138 case RTE_CRYPTO_CIPHER_3DES_CBC:
141 *algo = EVP_des_cbc();
144 *algo = EVP_des_ede_cbc();
147 *algo = EVP_des_ede3_cbc();
153 case RTE_CRYPTO_CIPHER_3DES_CTR:
155 case RTE_CRYPTO_CIPHER_AES_CBC:
158 *algo = EVP_aes_128_cbc();
161 *algo = EVP_aes_192_cbc();
164 *algo = EVP_aes_256_cbc();
170 case RTE_CRYPTO_CIPHER_AES_CTR:
173 *algo = EVP_aes_128_ctr();
176 *algo = EVP_aes_192_ctr();
179 *algo = EVP_aes_256_ctr();
196 /** Get adequate openssl function for input auth algorithm */
198 get_auth_algo(enum rte_crypto_auth_algorithm sessalgo,
205 case RTE_CRYPTO_AUTH_MD5:
206 case RTE_CRYPTO_AUTH_MD5_HMAC:
209 case RTE_CRYPTO_AUTH_SHA1:
210 case RTE_CRYPTO_AUTH_SHA1_HMAC:
213 case RTE_CRYPTO_AUTH_SHA224:
214 case RTE_CRYPTO_AUTH_SHA224_HMAC:
215 *algo = EVP_sha224();
217 case RTE_CRYPTO_AUTH_SHA256:
218 case RTE_CRYPTO_AUTH_SHA256_HMAC:
219 *algo = EVP_sha256();
221 case RTE_CRYPTO_AUTH_SHA384:
222 case RTE_CRYPTO_AUTH_SHA384_HMAC:
223 *algo = EVP_sha384();
225 case RTE_CRYPTO_AUTH_SHA512:
226 case RTE_CRYPTO_AUTH_SHA512_HMAC:
227 *algo = EVP_sha512();
240 /** Get adequate openssl function for input cipher algorithm */
242 get_aead_algo(enum rte_crypto_aead_algorithm sess_algo, size_t keylen,
243 const EVP_CIPHER **algo)
249 case RTE_CRYPTO_AEAD_AES_GCM:
252 *algo = EVP_aes_128_gcm();
255 *algo = EVP_aes_192_gcm();
258 *algo = EVP_aes_256_gcm();
264 case RTE_CRYPTO_AEAD_AES_CCM:
267 *algo = EVP_aes_128_ccm();
270 *algo = EVP_aes_192_ccm();
273 *algo = EVP_aes_256_ccm();
290 /* Set session AEAD encryption parameters */
292 openssl_set_sess_aead_enc_param(struct openssl_session *sess,
293 enum rte_crypto_aead_algorithm algo,
294 uint8_t tag_len, uint8_t *key)
299 sess->cipher.direction = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
300 sess->auth.operation = RTE_CRYPTO_AUTH_OP_GENERATE;
302 /* Select AEAD algo */
304 case RTE_CRYPTO_AEAD_AES_GCM:
305 iv_type = EVP_CTRL_GCM_SET_IVLEN;
310 case RTE_CRYPTO_AEAD_AES_CCM:
311 iv_type = EVP_CTRL_CCM_SET_IVLEN;
312 /* Digest size can be 4, 6, 8, 10, 12, 14 or 16 bytes */
313 if (tag_len < 4 || tag_len > 16 || (tag_len & 1) == 1)
321 sess->cipher.mode = OPENSSL_CIPHER_LIB;
322 sess->cipher.ctx = EVP_CIPHER_CTX_new();
324 if (get_aead_algo(algo, sess->cipher.key.length,
325 &sess->cipher.evp_algo) != 0)
328 get_cipher_key(key, sess->cipher.key.length, sess->cipher.key.data);
330 sess->chain_order = OPENSSL_CHAIN_COMBINED;
332 if (EVP_EncryptInit_ex(sess->cipher.ctx, sess->cipher.evp_algo,
333 NULL, NULL, NULL) <= 0)
336 if (EVP_CIPHER_CTX_ctrl(sess->cipher.ctx, iv_type, sess->iv.length,
341 EVP_CIPHER_CTX_ctrl(sess->cipher.ctx, EVP_CTRL_CCM_SET_TAG,
344 if (EVP_EncryptInit_ex(sess->cipher.ctx, NULL, NULL, key, NULL) <= 0)
350 /* Set session AEAD decryption parameters */
352 openssl_set_sess_aead_dec_param(struct openssl_session *sess,
353 enum rte_crypto_aead_algorithm algo,
354 uint8_t tag_len, uint8_t *key)
357 unsigned int do_ccm = 0;
359 sess->cipher.direction = RTE_CRYPTO_CIPHER_OP_DECRYPT;
360 sess->auth.operation = RTE_CRYPTO_AUTH_OP_VERIFY;
362 /* Select AEAD algo */
364 case RTE_CRYPTO_AEAD_AES_GCM:
365 iv_type = EVP_CTRL_GCM_SET_IVLEN;
369 case RTE_CRYPTO_AEAD_AES_CCM:
370 iv_type = EVP_CTRL_CCM_SET_IVLEN;
371 /* Digest size can be 4, 6, 8, 10, 12, 14 or 16 bytes */
372 if (tag_len < 4 || tag_len > 16 || (tag_len & 1) == 1)
380 sess->cipher.mode = OPENSSL_CIPHER_LIB;
381 sess->cipher.ctx = EVP_CIPHER_CTX_new();
383 if (get_aead_algo(algo, sess->cipher.key.length,
384 &sess->cipher.evp_algo) != 0)
387 get_cipher_key(key, sess->cipher.key.length, sess->cipher.key.data);
389 sess->chain_order = OPENSSL_CHAIN_COMBINED;
391 if (EVP_DecryptInit_ex(sess->cipher.ctx, sess->cipher.evp_algo,
392 NULL, NULL, NULL) <= 0)
395 if (EVP_CIPHER_CTX_ctrl(sess->cipher.ctx, iv_type,
396 sess->iv.length, NULL) <= 0)
400 EVP_CIPHER_CTX_ctrl(sess->cipher.ctx, EVP_CTRL_CCM_SET_TAG,
403 if (EVP_DecryptInit_ex(sess->cipher.ctx, NULL, NULL, key, NULL) <= 0)
409 /** Set session cipher parameters */
411 openssl_set_session_cipher_parameters(struct openssl_session *sess,
412 const struct rte_crypto_sym_xform *xform)
414 /* Select cipher direction */
415 sess->cipher.direction = xform->cipher.op;
416 /* Select cipher key */
417 sess->cipher.key.length = xform->cipher.key.length;
419 /* Set IV parameters */
420 sess->iv.offset = xform->cipher.iv.offset;
421 sess->iv.length = xform->cipher.iv.length;
423 /* Select cipher algo */
424 switch (xform->cipher.algo) {
425 case RTE_CRYPTO_CIPHER_3DES_CBC:
426 case RTE_CRYPTO_CIPHER_AES_CBC:
427 case RTE_CRYPTO_CIPHER_AES_CTR:
428 sess->cipher.mode = OPENSSL_CIPHER_LIB;
429 sess->cipher.algo = xform->cipher.algo;
430 sess->cipher.ctx = EVP_CIPHER_CTX_new();
432 if (get_cipher_algo(sess->cipher.algo, sess->cipher.key.length,
433 &sess->cipher.evp_algo) != 0)
436 get_cipher_key(xform->cipher.key.data, sess->cipher.key.length,
437 sess->cipher.key.data);
438 if (sess->cipher.direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
439 if (EVP_EncryptInit_ex(sess->cipher.ctx,
440 sess->cipher.evp_algo,
441 NULL, xform->cipher.key.data,
445 } else if (sess->cipher.direction ==
446 RTE_CRYPTO_CIPHER_OP_DECRYPT) {
447 if (EVP_DecryptInit_ex(sess->cipher.ctx,
448 sess->cipher.evp_algo,
449 NULL, xform->cipher.key.data,
457 case RTE_CRYPTO_CIPHER_3DES_CTR:
458 sess->cipher.mode = OPENSSL_CIPHER_DES3CTR;
459 sess->cipher.ctx = EVP_CIPHER_CTX_new();
461 if (get_cipher_key_ede(xform->cipher.key.data,
462 sess->cipher.key.length,
463 sess->cipher.key.data) != 0)
467 case RTE_CRYPTO_CIPHER_DES_CBC:
468 sess->cipher.algo = xform->cipher.algo;
469 sess->cipher.ctx = EVP_CIPHER_CTX_new();
470 sess->cipher.evp_algo = EVP_des_cbc();
472 get_cipher_key(xform->cipher.key.data, sess->cipher.key.length,
473 sess->cipher.key.data);
474 if (sess->cipher.direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
475 if (EVP_EncryptInit_ex(sess->cipher.ctx,
476 sess->cipher.evp_algo,
477 NULL, xform->cipher.key.data,
481 } else if (sess->cipher.direction ==
482 RTE_CRYPTO_CIPHER_OP_DECRYPT) {
483 if (EVP_DecryptInit_ex(sess->cipher.ctx,
484 sess->cipher.evp_algo,
485 NULL, xform->cipher.key.data,
493 case RTE_CRYPTO_CIPHER_DES_DOCSISBPI:
494 sess->cipher.algo = xform->cipher.algo;
495 sess->chain_order = OPENSSL_CHAIN_CIPHER_BPI;
496 sess->cipher.ctx = EVP_CIPHER_CTX_new();
497 sess->cipher.evp_algo = EVP_des_cbc();
499 sess->cipher.bpi_ctx = EVP_CIPHER_CTX_new();
500 /* IV will be ECB encrypted whether direction is encrypt or decrypt */
501 if (EVP_EncryptInit_ex(sess->cipher.bpi_ctx, EVP_des_ecb(),
502 NULL, xform->cipher.key.data, 0) != 1)
505 get_cipher_key(xform->cipher.key.data, sess->cipher.key.length,
506 sess->cipher.key.data);
507 if (sess->cipher.direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
508 if (EVP_EncryptInit_ex(sess->cipher.ctx,
509 sess->cipher.evp_algo,
510 NULL, xform->cipher.key.data,
514 } else if (sess->cipher.direction ==
515 RTE_CRYPTO_CIPHER_OP_DECRYPT) {
516 if (EVP_DecryptInit_ex(sess->cipher.ctx,
517 sess->cipher.evp_algo,
518 NULL, xform->cipher.key.data,
526 sess->cipher.algo = RTE_CRYPTO_CIPHER_NULL;
533 /* Set session auth parameters */
535 openssl_set_session_auth_parameters(struct openssl_session *sess,
536 const struct rte_crypto_sym_xform *xform)
538 /* Select auth generate/verify */
539 sess->auth.operation = xform->auth.op;
540 sess->auth.algo = xform->auth.algo;
542 sess->auth.digest_length = xform->auth.digest_length;
544 /* Select auth algo */
545 switch (xform->auth.algo) {
546 case RTE_CRYPTO_AUTH_AES_GMAC:
548 * OpenSSL requires GMAC to be a GCM operation
549 * with no cipher data length
551 sess->cipher.key.length = xform->auth.key.length;
553 /* Set IV parameters */
554 sess->iv.offset = xform->auth.iv.offset;
555 sess->iv.length = xform->auth.iv.length;
557 if (sess->auth.operation == RTE_CRYPTO_AUTH_OP_GENERATE)
558 return openssl_set_sess_aead_enc_param(sess,
559 RTE_CRYPTO_AEAD_AES_GCM,
560 xform->auth.digest_length,
561 xform->auth.key.data);
563 return openssl_set_sess_aead_dec_param(sess,
564 RTE_CRYPTO_AEAD_AES_GCM,
565 xform->auth.digest_length,
566 xform->auth.key.data);
569 case RTE_CRYPTO_AUTH_MD5:
570 case RTE_CRYPTO_AUTH_SHA1:
571 case RTE_CRYPTO_AUTH_SHA224:
572 case RTE_CRYPTO_AUTH_SHA256:
573 case RTE_CRYPTO_AUTH_SHA384:
574 case RTE_CRYPTO_AUTH_SHA512:
575 sess->auth.mode = OPENSSL_AUTH_AS_AUTH;
576 if (get_auth_algo(xform->auth.algo,
577 &sess->auth.auth.evp_algo) != 0)
579 sess->auth.auth.ctx = EVP_MD_CTX_create();
582 case RTE_CRYPTO_AUTH_MD5_HMAC:
583 case RTE_CRYPTO_AUTH_SHA1_HMAC:
584 case RTE_CRYPTO_AUTH_SHA224_HMAC:
585 case RTE_CRYPTO_AUTH_SHA256_HMAC:
586 case RTE_CRYPTO_AUTH_SHA384_HMAC:
587 case RTE_CRYPTO_AUTH_SHA512_HMAC:
588 sess->auth.mode = OPENSSL_AUTH_AS_HMAC;
589 sess->auth.hmac.ctx = HMAC_CTX_new();
590 if (get_auth_algo(xform->auth.algo,
591 &sess->auth.hmac.evp_algo) != 0)
594 if (HMAC_Init_ex(sess->auth.hmac.ctx,
595 xform->auth.key.data,
596 xform->auth.key.length,
597 sess->auth.hmac.evp_algo, NULL) != 1)
608 /* Set session AEAD parameters */
610 openssl_set_session_aead_parameters(struct openssl_session *sess,
611 const struct rte_crypto_sym_xform *xform)
613 /* Select cipher key */
614 sess->cipher.key.length = xform->aead.key.length;
616 /* Set IV parameters */
617 if (xform->aead.algo == RTE_CRYPTO_AEAD_AES_CCM)
619 * For AES-CCM, the actual IV is placed
620 * one byte after the start of the IV field,
621 * according to the API.
623 sess->iv.offset = xform->aead.iv.offset + 1;
625 sess->iv.offset = xform->aead.iv.offset;
627 sess->iv.length = xform->aead.iv.length;
629 sess->auth.aad_length = xform->aead.aad_length;
630 sess->auth.digest_length = xform->aead.digest_length;
632 sess->aead_algo = xform->aead.algo;
633 /* Select cipher direction */
634 if (xform->aead.op == RTE_CRYPTO_AEAD_OP_ENCRYPT)
635 return openssl_set_sess_aead_enc_param(sess, xform->aead.algo,
636 xform->aead.digest_length, xform->aead.key.data);
638 return openssl_set_sess_aead_dec_param(sess, xform->aead.algo,
639 xform->aead.digest_length, xform->aead.key.data);
642 /** Parse crypto xform chain and set private session parameters */
644 openssl_set_session_parameters(struct openssl_session *sess,
645 const struct rte_crypto_sym_xform *xform)
647 const struct rte_crypto_sym_xform *cipher_xform = NULL;
648 const struct rte_crypto_sym_xform *auth_xform = NULL;
649 const struct rte_crypto_sym_xform *aead_xform = NULL;
652 sess->chain_order = openssl_get_chain_order(xform);
653 switch (sess->chain_order) {
654 case OPENSSL_CHAIN_ONLY_CIPHER:
655 cipher_xform = xform;
657 case OPENSSL_CHAIN_ONLY_AUTH:
660 case OPENSSL_CHAIN_CIPHER_AUTH:
661 cipher_xform = xform;
662 auth_xform = xform->next;
664 case OPENSSL_CHAIN_AUTH_CIPHER:
666 cipher_xform = xform->next;
668 case OPENSSL_CHAIN_COMBINED:
675 /* Default IV length = 0 */
678 /* cipher_xform must be check before auth_xform */
680 ret = openssl_set_session_cipher_parameters(
684 "Invalid/unsupported cipher parameters");
690 ret = openssl_set_session_auth_parameters(sess, auth_xform);
693 "Invalid/unsupported auth parameters");
699 ret = openssl_set_session_aead_parameters(sess, aead_xform);
702 "Invalid/unsupported AEAD parameters");
710 /** Reset private session parameters */
712 openssl_reset_session(struct openssl_session *sess)
714 EVP_CIPHER_CTX_free(sess->cipher.ctx);
716 if (sess->chain_order == OPENSSL_CHAIN_CIPHER_BPI)
717 EVP_CIPHER_CTX_free(sess->cipher.bpi_ctx);
719 switch (sess->auth.mode) {
720 case OPENSSL_AUTH_AS_AUTH:
721 EVP_MD_CTX_destroy(sess->auth.auth.ctx);
723 case OPENSSL_AUTH_AS_HMAC:
724 EVP_PKEY_free(sess->auth.hmac.pkey);
725 HMAC_CTX_free(sess->auth.hmac.ctx);
732 /** Provide session for operation */
733 static struct openssl_session *
734 get_session(struct openssl_qp *qp, struct rte_crypto_op *op)
736 struct openssl_session *sess = NULL;
738 if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
739 /* get existing session */
740 if (likely(op->sym->session != NULL))
741 sess = (struct openssl_session *)
742 get_sym_session_private_data(
744 cryptodev_driver_id);
746 /* provide internal session */
748 void *_sess_private_data = NULL;
750 if (rte_mempool_get(qp->sess_mp, (void **)&_sess))
753 if (rte_mempool_get(qp->sess_mp, (void **)&_sess_private_data))
756 sess = (struct openssl_session *)_sess_private_data;
758 if (unlikely(openssl_set_session_parameters(sess,
759 op->sym->xform) != 0)) {
760 rte_mempool_put(qp->sess_mp, _sess);
761 rte_mempool_put(qp->sess_mp, _sess_private_data);
764 op->sym->session = (struct rte_cryptodev_sym_session *)_sess;
765 set_sym_session_private_data(op->sym->session,
766 cryptodev_driver_id, _sess_private_data);
770 op->status = RTE_CRYPTO_OP_STATUS_INVALID_SESSION;
776 *------------------------------------------------------------------------------
778 *------------------------------------------------------------------------------
781 process_openssl_encryption_update(struct rte_mbuf *mbuf_src, int offset,
782 uint8_t **dst, int srclen, EVP_CIPHER_CTX *ctx)
789 for (m = mbuf_src; m != NULL && offset > rte_pktmbuf_data_len(m);
791 offset -= rte_pktmbuf_data_len(m);
796 src = rte_pktmbuf_mtod_offset(m, uint8_t *, offset);
798 l = rte_pktmbuf_data_len(m) - offset;
800 if (EVP_EncryptUpdate(ctx, *dst, &dstlen, src, srclen) <= 0)
806 if (EVP_EncryptUpdate(ctx, *dst, &dstlen, src, l) <= 0)
812 for (m = m->next; (m != NULL) && (n > 0); m = m->next) {
813 src = rte_pktmbuf_mtod(m, uint8_t *);
814 l = rte_pktmbuf_data_len(m) < n ? rte_pktmbuf_data_len(m) : n;
815 if (EVP_EncryptUpdate(ctx, *dst, &dstlen, src, l) <= 0)
825 process_openssl_decryption_update(struct rte_mbuf *mbuf_src, int offset,
826 uint8_t **dst, int srclen, EVP_CIPHER_CTX *ctx)
833 for (m = mbuf_src; m != NULL && offset > rte_pktmbuf_data_len(m);
835 offset -= rte_pktmbuf_data_len(m);
840 src = rte_pktmbuf_mtod_offset(m, uint8_t *, offset);
842 l = rte_pktmbuf_data_len(m) - offset;
844 if (EVP_DecryptUpdate(ctx, *dst, &dstlen, src, srclen) <= 0)
850 if (EVP_DecryptUpdate(ctx, *dst, &dstlen, src, l) <= 0)
856 for (m = m->next; (m != NULL) && (n > 0); m = m->next) {
857 src = rte_pktmbuf_mtod(m, uint8_t *);
858 l = rte_pktmbuf_data_len(m) < n ? rte_pktmbuf_data_len(m) : n;
859 if (EVP_DecryptUpdate(ctx, *dst, &dstlen, src, l) <= 0)
868 /** Process standard openssl cipher encryption */
870 process_openssl_cipher_encrypt(struct rte_mbuf *mbuf_src, uint8_t *dst,
871 int offset, uint8_t *iv, int srclen, EVP_CIPHER_CTX *ctx)
875 if (EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, iv) <= 0)
876 goto process_cipher_encrypt_err;
878 EVP_CIPHER_CTX_set_padding(ctx, 0);
880 if (process_openssl_encryption_update(mbuf_src, offset, &dst,
882 goto process_cipher_encrypt_err;
884 if (EVP_EncryptFinal_ex(ctx, dst, &totlen) <= 0)
885 goto process_cipher_encrypt_err;
889 process_cipher_encrypt_err:
890 OPENSSL_LOG(ERR, "Process openssl cipher encrypt failed");
894 /** Process standard openssl cipher encryption */
896 process_openssl_cipher_bpi_encrypt(uint8_t *src, uint8_t *dst,
897 uint8_t *iv, int srclen,
901 uint8_t encrypted_iv[DES_BLOCK_SIZE];
904 if (EVP_EncryptUpdate(ctx, encrypted_iv, &encrypted_ivlen,
905 iv, DES_BLOCK_SIZE) <= 0)
906 goto process_cipher_encrypt_err;
908 for (i = 0; i < srclen; i++)
909 *(dst + i) = *(src + i) ^ (encrypted_iv[i]);
913 process_cipher_encrypt_err:
914 OPENSSL_LOG(ERR, "Process openssl cipher bpi encrypt failed");
917 /** Process standard openssl cipher decryption */
919 process_openssl_cipher_decrypt(struct rte_mbuf *mbuf_src, uint8_t *dst,
920 int offset, uint8_t *iv, int srclen, EVP_CIPHER_CTX *ctx)
924 if (EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv) <= 0)
925 goto process_cipher_decrypt_err;
927 EVP_CIPHER_CTX_set_padding(ctx, 0);
929 if (process_openssl_decryption_update(mbuf_src, offset, &dst,
931 goto process_cipher_decrypt_err;
933 if (EVP_DecryptFinal_ex(ctx, dst, &totlen) <= 0)
934 goto process_cipher_decrypt_err;
937 process_cipher_decrypt_err:
938 OPENSSL_LOG(ERR, "Process openssl cipher decrypt failed");
942 /** Process cipher des 3 ctr encryption, decryption algorithm */
944 process_openssl_cipher_des3ctr(struct rte_mbuf *mbuf_src, uint8_t *dst,
945 int offset, uint8_t *iv, uint8_t *key, int srclen,
948 uint8_t ebuf[8], ctr[8];
954 for (m = mbuf_src; m != NULL && offset > rte_pktmbuf_data_len(m);
956 offset -= rte_pktmbuf_data_len(m);
959 goto process_cipher_des3ctr_err;
961 src = rte_pktmbuf_mtod_offset(m, uint8_t *, offset);
962 l = rte_pktmbuf_data_len(m) - offset;
964 /* We use 3DES encryption also for decryption.
965 * IV is not important for 3DES ecb
967 if (EVP_EncryptInit_ex(ctx, EVP_des_ede3_ecb(), NULL, key, NULL) <= 0)
968 goto process_cipher_des3ctr_err;
972 for (n = 0; n < srclen; n++) {
974 if (EVP_EncryptUpdate(ctx,
975 (unsigned char *)&ebuf, &unused,
976 (const unsigned char *)&ctr, 8) <= 0)
977 goto process_cipher_des3ctr_err;
980 dst[n] = *(src++) ^ ebuf[n % 8];
986 src = rte_pktmbuf_mtod(m, uint8_t *);
987 l = rte_pktmbuf_data_len(m);
994 process_cipher_des3ctr_err:
995 OPENSSL_LOG(ERR, "Process openssl cipher des 3 ede ctr failed");
999 /** Process AES-GCM encrypt algorithm */
1001 process_openssl_auth_encryption_gcm(struct rte_mbuf *mbuf_src, int offset,
1002 int srclen, uint8_t *aad, int aadlen, uint8_t *iv,
1003 uint8_t *dst, uint8_t *tag, EVP_CIPHER_CTX *ctx)
1005 int len = 0, unused = 0;
1006 uint8_t empty[] = {};
1008 if (EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, iv) <= 0)
1009 goto process_auth_encryption_gcm_err;
1012 if (EVP_EncryptUpdate(ctx, NULL, &len, aad, aadlen) <= 0)
1013 goto process_auth_encryption_gcm_err;
1016 if (process_openssl_encryption_update(mbuf_src, offset, &dst,
1018 goto process_auth_encryption_gcm_err;
1020 /* Workaround open ssl bug in version less then 1.0.1f */
1021 if (EVP_EncryptUpdate(ctx, empty, &unused, empty, 0) <= 0)
1022 goto process_auth_encryption_gcm_err;
1024 if (EVP_EncryptFinal_ex(ctx, dst, &len) <= 0)
1025 goto process_auth_encryption_gcm_err;
1027 if (EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_GET_TAG, 16, tag) <= 0)
1028 goto process_auth_encryption_gcm_err;
1032 process_auth_encryption_gcm_err:
1033 OPENSSL_LOG(ERR, "Process openssl auth encryption gcm failed");
1037 /** Process AES-CCM encrypt algorithm */
1039 process_openssl_auth_encryption_ccm(struct rte_mbuf *mbuf_src, int offset,
1040 int srclen, uint8_t *aad, int aadlen, uint8_t *iv,
1041 uint8_t *dst, uint8_t *tag, uint8_t taglen, EVP_CIPHER_CTX *ctx)
1045 if (EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, iv) <= 0)
1046 goto process_auth_encryption_ccm_err;
1048 if (EVP_EncryptUpdate(ctx, NULL, &len, NULL, srclen) <= 0)
1049 goto process_auth_encryption_ccm_err;
1053 * For AES-CCM, the actual AAD is placed
1054 * 18 bytes after the start of the AAD field,
1055 * according to the API.
1057 if (EVP_EncryptUpdate(ctx, NULL, &len, aad + 18, aadlen) <= 0)
1058 goto process_auth_encryption_ccm_err;
1061 if (process_openssl_encryption_update(mbuf_src, offset, &dst,
1063 goto process_auth_encryption_ccm_err;
1065 if (EVP_EncryptFinal_ex(ctx, dst, &len) <= 0)
1066 goto process_auth_encryption_ccm_err;
1068 if (EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_CCM_GET_TAG, taglen, tag) <= 0)
1069 goto process_auth_encryption_ccm_err;
1073 process_auth_encryption_ccm_err:
1074 OPENSSL_LOG(ERR, "Process openssl auth encryption ccm failed");
1078 /** Process AES-GCM decrypt algorithm */
1080 process_openssl_auth_decryption_gcm(struct rte_mbuf *mbuf_src, int offset,
1081 int srclen, uint8_t *aad, int aadlen, uint8_t *iv,
1082 uint8_t *dst, uint8_t *tag, EVP_CIPHER_CTX *ctx)
1084 int len = 0, unused = 0;
1085 uint8_t empty[] = {};
1087 if (EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_TAG, 16, tag) <= 0)
1088 goto process_auth_decryption_gcm_err;
1090 if (EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv) <= 0)
1091 goto process_auth_decryption_gcm_err;
1094 if (EVP_DecryptUpdate(ctx, NULL, &len, aad, aadlen) <= 0)
1095 goto process_auth_decryption_gcm_err;
1098 if (process_openssl_decryption_update(mbuf_src, offset, &dst,
1100 goto process_auth_decryption_gcm_err;
1102 /* Workaround open ssl bug in version less then 1.0.1f */
1103 if (EVP_DecryptUpdate(ctx, empty, &unused, empty, 0) <= 0)
1104 goto process_auth_decryption_gcm_err;
1106 if (EVP_DecryptFinal_ex(ctx, dst, &len) <= 0)
1111 process_auth_decryption_gcm_err:
1112 OPENSSL_LOG(ERR, "Process openssl auth decryption gcm failed");
1116 /** Process AES-CCM decrypt algorithm */
1118 process_openssl_auth_decryption_ccm(struct rte_mbuf *mbuf_src, int offset,
1119 int srclen, uint8_t *aad, int aadlen, uint8_t *iv,
1120 uint8_t *dst, uint8_t *tag, uint8_t tag_len,
1121 EVP_CIPHER_CTX *ctx)
1125 if (EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_CCM_SET_TAG, tag_len, tag) <= 0)
1126 goto process_auth_decryption_ccm_err;
1128 if (EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv) <= 0)
1129 goto process_auth_decryption_ccm_err;
1131 if (EVP_DecryptUpdate(ctx, NULL, &len, NULL, srclen) <= 0)
1132 goto process_auth_decryption_ccm_err;
1136 * For AES-CCM, the actual AAD is placed
1137 * 18 bytes after the start of the AAD field,
1138 * according to the API.
1140 if (EVP_DecryptUpdate(ctx, NULL, &len, aad + 18, aadlen) <= 0)
1141 goto process_auth_decryption_ccm_err;
1144 if (process_openssl_decryption_update(mbuf_src, offset, &dst,
1150 process_auth_decryption_ccm_err:
1151 OPENSSL_LOG(ERR, "Process openssl auth decryption ccm failed");
1155 /** Process standard openssl auth algorithms */
1157 process_openssl_auth(struct rte_mbuf *mbuf_src, uint8_t *dst, int offset,
1158 __rte_unused uint8_t *iv, __rte_unused EVP_PKEY * pkey,
1159 int srclen, EVP_MD_CTX *ctx, const EVP_MD *algo)
1166 for (m = mbuf_src; m != NULL && offset > rte_pktmbuf_data_len(m);
1168 offset -= rte_pktmbuf_data_len(m);
1171 goto process_auth_err;
1173 if (EVP_DigestInit_ex(ctx, algo, NULL) <= 0)
1174 goto process_auth_err;
1176 src = rte_pktmbuf_mtod_offset(m, uint8_t *, offset);
1178 l = rte_pktmbuf_data_len(m) - offset;
1180 if (EVP_DigestUpdate(ctx, (char *)src, srclen) <= 0)
1181 goto process_auth_err;
1182 goto process_auth_final;
1185 if (EVP_DigestUpdate(ctx, (char *)src, l) <= 0)
1186 goto process_auth_err;
1190 for (m = m->next; (m != NULL) && (n > 0); m = m->next) {
1191 src = rte_pktmbuf_mtod(m, uint8_t *);
1192 l = rte_pktmbuf_data_len(m) < n ? rte_pktmbuf_data_len(m) : n;
1193 if (EVP_DigestUpdate(ctx, (char *)src, l) <= 0)
1194 goto process_auth_err;
1199 if (EVP_DigestFinal_ex(ctx, dst, (unsigned int *)&dstlen) <= 0)
1200 goto process_auth_err;
1204 OPENSSL_LOG(ERR, "Process openssl auth failed");
1208 /** Process standard openssl auth algorithms with hmac */
1210 process_openssl_auth_hmac(struct rte_mbuf *mbuf_src, uint8_t *dst, int offset,
1211 int srclen, HMAC_CTX *ctx)
1213 unsigned int dstlen;
1218 for (m = mbuf_src; m != NULL && offset > rte_pktmbuf_data_len(m);
1220 offset -= rte_pktmbuf_data_len(m);
1223 goto process_auth_err;
1225 src = rte_pktmbuf_mtod_offset(m, uint8_t *, offset);
1227 l = rte_pktmbuf_data_len(m) - offset;
1229 if (HMAC_Update(ctx, (unsigned char *)src, srclen) != 1)
1230 goto process_auth_err;
1231 goto process_auth_final;
1234 if (HMAC_Update(ctx, (unsigned char *)src, l) != 1)
1235 goto process_auth_err;
1239 for (m = m->next; (m != NULL) && (n > 0); m = m->next) {
1240 src = rte_pktmbuf_mtod(m, uint8_t *);
1241 l = rte_pktmbuf_data_len(m) < n ? rte_pktmbuf_data_len(m) : n;
1242 if (HMAC_Update(ctx, (unsigned char *)src, l) != 1)
1243 goto process_auth_err;
1248 if (HMAC_Final(ctx, dst, &dstlen) != 1)
1249 goto process_auth_err;
1251 if (unlikely(HMAC_Init_ex(ctx, NULL, 0, NULL, NULL) != 1))
1252 goto process_auth_err;
1257 OPENSSL_LOG(ERR, "Process openssl auth failed");
1261 /*----------------------------------------------------------------------------*/
1263 /** Process auth/cipher combined operation */
1265 process_openssl_combined_op
1266 (struct rte_crypto_op *op, struct openssl_session *sess,
1267 struct rte_mbuf *mbuf_src, struct rte_mbuf *mbuf_dst)
1270 uint8_t *dst = NULL, *iv, *tag, *aad;
1271 int srclen, aadlen, status = -1;
1276 * Segmented destination buffer is not supported for
1277 * encryption/decryption
1279 if (!rte_pktmbuf_is_contiguous(mbuf_dst)) {
1280 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
1284 iv = rte_crypto_op_ctod_offset(op, uint8_t *,
1286 if (sess->auth.algo == RTE_CRYPTO_AUTH_AES_GMAC) {
1288 offset = op->sym->auth.data.offset;
1289 aadlen = op->sym->auth.data.length;
1290 aad = rte_pktmbuf_mtod_offset(mbuf_src, uint8_t *,
1291 op->sym->auth.data.offset);
1292 tag = op->sym->auth.digest.data;
1294 tag = rte_pktmbuf_mtod_offset(mbuf_dst, uint8_t *,
1297 srclen = op->sym->aead.data.length;
1298 dst = rte_pktmbuf_mtod_offset(mbuf_dst, uint8_t *,
1299 op->sym->aead.data.offset);
1300 offset = op->sym->aead.data.offset;
1301 aad = op->sym->aead.aad.data;
1302 aadlen = sess->auth.aad_length;
1303 tag = op->sym->aead.digest.data;
1305 tag = rte_pktmbuf_mtod_offset(mbuf_dst, uint8_t *,
1309 taglen = sess->auth.digest_length;
1311 if (sess->cipher.direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
1312 if (sess->auth.algo == RTE_CRYPTO_AUTH_AES_GMAC ||
1313 sess->aead_algo == RTE_CRYPTO_AEAD_AES_GCM)
1314 status = process_openssl_auth_encryption_gcm(
1315 mbuf_src, offset, srclen,
1317 dst, tag, sess->cipher.ctx);
1319 status = process_openssl_auth_encryption_ccm(
1320 mbuf_src, offset, srclen,
1322 dst, tag, taglen, sess->cipher.ctx);
1325 if (sess->auth.algo == RTE_CRYPTO_AUTH_AES_GMAC ||
1326 sess->aead_algo == RTE_CRYPTO_AEAD_AES_GCM)
1327 status = process_openssl_auth_decryption_gcm(
1328 mbuf_src, offset, srclen,
1330 dst, tag, sess->cipher.ctx);
1332 status = process_openssl_auth_decryption_ccm(
1333 mbuf_src, offset, srclen,
1335 dst, tag, taglen, sess->cipher.ctx);
1339 if (status == (-EFAULT) &&
1340 sess->auth.operation ==
1341 RTE_CRYPTO_AUTH_OP_VERIFY)
1342 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
1344 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
1348 /** Process cipher operation */
1350 process_openssl_cipher_op
1351 (struct rte_crypto_op *op, struct openssl_session *sess,
1352 struct rte_mbuf *mbuf_src, struct rte_mbuf *mbuf_dst)
1358 * Segmented destination buffer is not supported for
1359 * encryption/decryption
1361 if (!rte_pktmbuf_is_contiguous(mbuf_dst)) {
1362 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
1366 srclen = op->sym->cipher.data.length;
1367 dst = rte_pktmbuf_mtod_offset(mbuf_dst, uint8_t *,
1368 op->sym->cipher.data.offset);
1370 iv = rte_crypto_op_ctod_offset(op, uint8_t *,
1373 if (sess->cipher.mode == OPENSSL_CIPHER_LIB)
1374 if (sess->cipher.direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT)
1375 status = process_openssl_cipher_encrypt(mbuf_src, dst,
1376 op->sym->cipher.data.offset, iv,
1377 srclen, sess->cipher.ctx);
1379 status = process_openssl_cipher_decrypt(mbuf_src, dst,
1380 op->sym->cipher.data.offset, iv,
1381 srclen, sess->cipher.ctx);
1383 status = process_openssl_cipher_des3ctr(mbuf_src, dst,
1384 op->sym->cipher.data.offset, iv,
1385 sess->cipher.key.data, srclen,
1389 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
1392 /** Process cipher operation */
1394 process_openssl_docsis_bpi_op(struct rte_crypto_op *op,
1395 struct openssl_session *sess, struct rte_mbuf *mbuf_src,
1396 struct rte_mbuf *mbuf_dst)
1398 uint8_t *src, *dst, *iv;
1399 uint8_t block_size, last_block_len;
1400 int srclen, status = 0;
1402 srclen = op->sym->cipher.data.length;
1403 src = rte_pktmbuf_mtod_offset(mbuf_src, uint8_t *,
1404 op->sym->cipher.data.offset);
1405 dst = rte_pktmbuf_mtod_offset(mbuf_dst, uint8_t *,
1406 op->sym->cipher.data.offset);
1408 iv = rte_crypto_op_ctod_offset(op, uint8_t *,
1411 block_size = DES_BLOCK_SIZE;
1413 last_block_len = srclen % block_size;
1414 if (sess->cipher.direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
1415 /* Encrypt only with ECB mode XOR IV */
1416 if (srclen < block_size) {
1417 status = process_openssl_cipher_bpi_encrypt(src, dst,
1419 sess->cipher.bpi_ctx);
1421 srclen -= last_block_len;
1422 /* Encrypt with the block aligned stream with CBC mode */
1423 status = process_openssl_cipher_encrypt(mbuf_src, dst,
1424 op->sym->cipher.data.offset, iv,
1425 srclen, sess->cipher.ctx);
1426 if (last_block_len) {
1427 /* Point at last block */
1430 * IV is the last encrypted block from
1431 * the previous operation
1433 iv = dst - block_size;
1435 srclen = last_block_len;
1436 /* Encrypt the last frame with ECB mode */
1437 status |= process_openssl_cipher_bpi_encrypt(src,
1439 srclen, sess->cipher.bpi_ctx);
1443 /* Decrypt only with ECB mode (encrypt, as it is same operation) */
1444 if (srclen < block_size) {
1445 status = process_openssl_cipher_bpi_encrypt(src, dst,
1448 sess->cipher.bpi_ctx);
1450 if (last_block_len) {
1451 /* Point at last block */
1452 dst += srclen - last_block_len;
1453 src += srclen - last_block_len;
1455 * IV is the last full block
1457 iv = src - block_size;
1459 * Decrypt the last frame with ECB mode
1460 * (encrypt, as it is the same operation)
1462 status = process_openssl_cipher_bpi_encrypt(src,
1464 last_block_len, sess->cipher.bpi_ctx);
1465 /* Prepare parameters for CBC mode op */
1466 iv = rte_crypto_op_ctod_offset(op, uint8_t *,
1468 dst += last_block_len - srclen;
1469 srclen -= last_block_len;
1472 /* Decrypt with CBC mode */
1473 status |= process_openssl_cipher_decrypt(mbuf_src, dst,
1474 op->sym->cipher.data.offset, iv,
1475 srclen, sess->cipher.ctx);
1480 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
1483 /** Process auth operation */
1485 process_openssl_auth_op(struct openssl_qp *qp, struct rte_crypto_op *op,
1486 struct openssl_session *sess, struct rte_mbuf *mbuf_src,
1487 struct rte_mbuf *mbuf_dst)
1492 srclen = op->sym->auth.data.length;
1494 if (sess->auth.operation == RTE_CRYPTO_AUTH_OP_VERIFY)
1495 dst = qp->temp_digest;
1497 dst = op->sym->auth.digest.data;
1499 dst = rte_pktmbuf_mtod_offset(mbuf_dst, uint8_t *,
1500 op->sym->auth.data.offset +
1501 op->sym->auth.data.length);
1504 switch (sess->auth.mode) {
1505 case OPENSSL_AUTH_AS_AUTH:
1506 status = process_openssl_auth(mbuf_src, dst,
1507 op->sym->auth.data.offset, NULL, NULL, srclen,
1508 sess->auth.auth.ctx, sess->auth.auth.evp_algo);
1510 case OPENSSL_AUTH_AS_HMAC:
1511 status = process_openssl_auth_hmac(mbuf_src, dst,
1512 op->sym->auth.data.offset, srclen,
1513 sess->auth.hmac.ctx);
1520 if (sess->auth.operation == RTE_CRYPTO_AUTH_OP_VERIFY) {
1521 if (memcmp(dst, op->sym->auth.digest.data,
1522 sess->auth.digest_length) != 0) {
1523 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
1528 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
1531 /** Process crypto operation for mbuf */
1533 process_op(struct openssl_qp *qp, struct rte_crypto_op *op,
1534 struct openssl_session *sess)
1536 struct rte_mbuf *msrc, *mdst;
1539 msrc = op->sym->m_src;
1540 mdst = op->sym->m_dst ? op->sym->m_dst : op->sym->m_src;
1542 op->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
1544 switch (sess->chain_order) {
1545 case OPENSSL_CHAIN_ONLY_CIPHER:
1546 process_openssl_cipher_op(op, sess, msrc, mdst);
1548 case OPENSSL_CHAIN_ONLY_AUTH:
1549 process_openssl_auth_op(qp, op, sess, msrc, mdst);
1551 case OPENSSL_CHAIN_CIPHER_AUTH:
1552 process_openssl_cipher_op(op, sess, msrc, mdst);
1553 process_openssl_auth_op(qp, op, sess, mdst, mdst);
1555 case OPENSSL_CHAIN_AUTH_CIPHER:
1556 process_openssl_auth_op(qp, op, sess, msrc, mdst);
1557 process_openssl_cipher_op(op, sess, msrc, mdst);
1559 case OPENSSL_CHAIN_COMBINED:
1560 process_openssl_combined_op(op, sess, msrc, mdst);
1562 case OPENSSL_CHAIN_CIPHER_BPI:
1563 process_openssl_docsis_bpi_op(op, sess, msrc, mdst);
1566 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
1570 /* Free session if a session-less crypto op */
1571 if (op->sess_type == RTE_CRYPTO_OP_SESSIONLESS) {
1572 openssl_reset_session(sess);
1573 memset(sess, 0, sizeof(struct openssl_session));
1574 memset(op->sym->session, 0,
1575 rte_cryptodev_sym_get_header_session_size());
1576 rte_mempool_put(qp->sess_mp, sess);
1577 rte_mempool_put(qp->sess_mp, op->sym->session);
1578 op->sym->session = NULL;
1581 if (op->status == RTE_CRYPTO_OP_STATUS_NOT_PROCESSED)
1582 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
1584 if (op->status != RTE_CRYPTO_OP_STATUS_ERROR)
1585 retval = rte_ring_enqueue(qp->processed_ops, (void *)op);
1593 *------------------------------------------------------------------------------
1595 *------------------------------------------------------------------------------
1598 /** Enqueue burst */
1600 openssl_pmd_enqueue_burst(void *queue_pair, struct rte_crypto_op **ops,
1603 struct openssl_session *sess;
1604 struct openssl_qp *qp = queue_pair;
1607 for (i = 0; i < nb_ops; i++) {
1608 sess = get_session(qp, ops[i]);
1609 if (unlikely(sess == NULL))
1612 retval = process_op(qp, ops[i], sess);
1613 if (unlikely(retval < 0))
1617 qp->stats.enqueued_count += i;
1621 qp->stats.enqueue_err_count++;
1625 /** Dequeue burst */
1627 openssl_pmd_dequeue_burst(void *queue_pair, struct rte_crypto_op **ops,
1630 struct openssl_qp *qp = queue_pair;
1632 unsigned int nb_dequeued = 0;
1634 nb_dequeued = rte_ring_dequeue_burst(qp->processed_ops,
1635 (void **)ops, nb_ops, NULL);
1636 qp->stats.dequeued_count += nb_dequeued;
1641 /** Create OPENSSL crypto device */
1643 cryptodev_openssl_create(const char *name,
1644 struct rte_vdev_device *vdev,
1645 struct rte_cryptodev_pmd_init_params *init_params)
1647 struct rte_cryptodev *dev;
1648 struct openssl_private *internals;
1650 dev = rte_cryptodev_pmd_create(name, &vdev->device, init_params);
1652 OPENSSL_LOG(ERR, "failed to create cryptodev vdev");
1656 dev->driver_id = cryptodev_driver_id;
1657 dev->dev_ops = rte_openssl_pmd_ops;
1659 /* register rx/tx burst functions for data path */
1660 dev->dequeue_burst = openssl_pmd_dequeue_burst;
1661 dev->enqueue_burst = openssl_pmd_enqueue_burst;
1663 dev->feature_flags = RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO |
1664 RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING |
1665 RTE_CRYPTODEV_FF_CPU_AESNI |
1666 RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT |
1667 RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT;
1669 /* Set vector instructions mode supported */
1670 internals = dev->data->dev_private;
1672 internals->max_nb_qpairs = init_params->max_nb_queue_pairs;
1677 OPENSSL_LOG(ERR, "driver %s: create failed",
1680 cryptodev_openssl_remove(vdev);
1684 /** Initialise OPENSSL crypto device */
1686 cryptodev_openssl_probe(struct rte_vdev_device *vdev)
1688 struct rte_cryptodev_pmd_init_params init_params = {
1690 sizeof(struct openssl_private),
1692 RTE_CRYPTODEV_PMD_DEFAULT_MAX_NB_QUEUE_PAIRS
1695 const char *input_args;
1697 name = rte_vdev_device_name(vdev);
1700 input_args = rte_vdev_device_args(vdev);
1702 rte_cryptodev_pmd_parse_input_args(&init_params, input_args);
1704 return cryptodev_openssl_create(name, vdev, &init_params);
1707 /** Uninitialise OPENSSL crypto device */
1709 cryptodev_openssl_remove(struct rte_vdev_device *vdev)
1711 struct rte_cryptodev *cryptodev;
1714 name = rte_vdev_device_name(vdev);
1718 cryptodev = rte_cryptodev_pmd_get_named_dev(name);
1719 if (cryptodev == NULL)
1722 return rte_cryptodev_pmd_destroy(cryptodev);
1725 static struct rte_vdev_driver cryptodev_openssl_pmd_drv = {
1726 .probe = cryptodev_openssl_probe,
1727 .remove = cryptodev_openssl_remove
1730 static struct cryptodev_driver openssl_crypto_drv;
1732 RTE_PMD_REGISTER_VDEV(CRYPTODEV_NAME_OPENSSL_PMD,
1733 cryptodev_openssl_pmd_drv);
1734 RTE_PMD_REGISTER_PARAM_STRING(CRYPTODEV_NAME_OPENSSL_PMD,
1735 "max_nb_queue_pairs=<int> "
1737 RTE_PMD_REGISTER_CRYPTO_DRIVER(openssl_crypto_drv,
1738 cryptodev_openssl_pmd_drv.driver, cryptodev_driver_id);
1740 RTE_INIT(openssl_init_log)
1742 openssl_logtype_driver = rte_log_register("pmd.crypto.openssl");