+ /* clear mbuf payload */
+ memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
+ rte_pktmbuf_tailroom(ut_params->ibuf));
+
+ /* Create GCM operation */
+ retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_ENCRYPT, tdata);
+ if (retval < 0)
+ return retval;
+
+ rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
+
+ ut_params->op->sym->m_src = ut_params->ibuf;
+
+ /* Process crypto operation */
+ TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
+ ut_params->op), "failed to process sym crypto op");
+
+ TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
+ "crypto op processing failed");
+
+ plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
+
+ if (ut_params->op->sym->m_dst) {
+ ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
+ uint8_t *);
+ auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
+ uint8_t *, plaintext_pad_len);
+ } else {
+ ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
+ uint8_t *,
+ ut_params->op->sym->cipher.data.offset);
+ auth_tag = ciphertext + plaintext_pad_len;
+ }
+
+ TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
+ TEST_HEXDUMP(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
+
+ /* Validate obuf */
+ TEST_ASSERT_BUFFERS_ARE_EQUAL(
+ ciphertext,
+ tdata->ciphertext.data,
+ tdata->ciphertext.len,
+ "GCM Ciphertext data not as expected");
+
+ TEST_ASSERT_BUFFERS_ARE_EQUAL(
+ auth_tag,
+ tdata->auth_tag.data,
+ tdata->auth_tag.len,
+ "GCM Generated auth tag not as expected");
+
+ return 0;
+
+}
+
+static int
+test_mb_AES_GCM_authenticated_encryption_test_case_1(void)
+{
+ return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_1);
+}
+
+static int
+test_mb_AES_GCM_authenticated_encryption_test_case_2(void)
+{
+ return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_2);
+}
+
+static int
+test_mb_AES_GCM_authenticated_encryption_test_case_3(void)
+{
+ return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_3);
+}
+
+static int
+test_mb_AES_GCM_authenticated_encryption_test_case_4(void)
+{
+ return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_4);
+}
+
+static int
+test_mb_AES_GCM_authenticated_encryption_test_case_5(void)
+{
+ return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_5);
+}
+
+static int
+test_mb_AES_GCM_authenticated_encryption_test_case_6(void)
+{
+ return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_6);
+}
+
+static int
+test_mb_AES_GCM_authenticated_encryption_test_case_7(void)
+{
+ return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_7);
+}
+
+static int
+test_mb_AES_GCM_auth_encryption_test_case_256_1(void)
+{
+ return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_256_1);
+}
+
+static int
+test_mb_AES_GCM_auth_encryption_test_case_256_2(void)
+{
+ return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_256_2);
+}
+
+static int
+test_mb_AES_GCM_auth_encryption_test_case_256_3(void)
+{
+ return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_256_3);
+}
+
+static int
+test_mb_AES_GCM_auth_encryption_test_case_256_4(void)
+{
+ return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_256_4);
+}
+
+static int
+test_mb_AES_GCM_auth_encryption_test_case_256_5(void)
+{
+ return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_256_5);
+}
+
+static int
+test_mb_AES_GCM_auth_encryption_test_case_256_6(void)
+{
+ return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_256_6);
+}
+
+static int
+test_mb_AES_GCM_auth_encryption_test_case_256_7(void)
+{
+ return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_256_7);
+}
+
+static int
+test_mb_AES_GCM_auth_encryption_test_case_aad_1(void)
+{
+ return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_aad_1);
+}
+
+static int
+test_mb_AES_GCM_auth_encryption_test_case_aad_2(void)
+{
+ return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_aad_2);
+}
+
+static int
+test_mb_AES_GCM_authenticated_decryption(const struct gcm_test_data *tdata)
+{
+ struct crypto_testsuite_params *ts_params = &testsuite_params;
+ struct crypto_unittest_params *ut_params = &unittest_params;
+
+ int retval;
+ uint8_t *plaintext;
+ uint32_t i;
+
+ /* Create GCM session */
+ retval = create_gcm_session(ts_params->valid_devs[0],
+ RTE_CRYPTO_CIPHER_OP_DECRYPT,
+ tdata->key.data, tdata->key.len,
+ tdata->aad.len, tdata->auth_tag.len,
+ RTE_CRYPTO_AUTH_OP_VERIFY);
+ if (retval < 0)
+ return retval;
+
+ /* alloc mbuf and set payload */
+ if (tdata->aad.len > MBUF_SIZE) {
+ ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
+ /* Populate full size of add data */
+ for (i = 32; i < GCM_MAX_AAD_LENGTH; i += 32)
+ memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
+ } else
+ ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
+
+ memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
+ rte_pktmbuf_tailroom(ut_params->ibuf));
+
+ /* Create GCM operation */
+ retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_DECRYPT, tdata);
+ if (retval < 0)
+ return retval;
+
+ rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
+
+ ut_params->op->sym->m_src = ut_params->ibuf;
+
+ /* Process crypto operation */
+ TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
+ ut_params->op), "failed to process sym crypto op");
+
+ TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
+ "crypto op processing failed");
+
+ if (ut_params->op->sym->m_dst)
+ plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
+ uint8_t *);
+ else
+ plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
+ uint8_t *,
+ ut_params->op->sym->cipher.data.offset);
+
+ TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
+
+ /* Validate obuf */
+ TEST_ASSERT_BUFFERS_ARE_EQUAL(
+ plaintext,
+ tdata->plaintext.data,
+ tdata->plaintext.len,
+ "GCM plaintext data not as expected");
+
+ TEST_ASSERT_EQUAL(ut_params->op->status,
+ RTE_CRYPTO_OP_STATUS_SUCCESS,
+ "GCM authentication failed");
+ return 0;
+}
+
+static int
+test_mb_AES_GCM_authenticated_decryption_test_case_1(void)
+{
+ return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_1);
+}
+
+static int
+test_mb_AES_GCM_authenticated_decryption_test_case_2(void)
+{
+ return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_2);
+}
+
+static int
+test_mb_AES_GCM_authenticated_decryption_test_case_3(void)
+{
+ return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_3);
+}
+
+static int
+test_mb_AES_GCM_authenticated_decryption_test_case_4(void)
+{
+ return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_4);
+}
+
+static int
+test_mb_AES_GCM_authenticated_decryption_test_case_5(void)
+{
+ return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_5);
+}
+
+static int
+test_mb_AES_GCM_authenticated_decryption_test_case_6(void)
+{
+ return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_6);
+}
+
+static int
+test_mb_AES_GCM_authenticated_decryption_test_case_7(void)
+{
+ return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_7);
+}
+
+static int
+test_mb_AES_GCM_auth_decryption_test_case_256_1(void)
+{
+ return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_256_1);
+}
+
+static int
+test_mb_AES_GCM_auth_decryption_test_case_256_2(void)
+{
+ return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_256_2);
+}
+
+static int
+test_mb_AES_GCM_auth_decryption_test_case_256_3(void)
+{
+ return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_256_3);
+}
+
+static int
+test_mb_AES_GCM_auth_decryption_test_case_256_4(void)
+{
+ return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_256_4);
+}
+
+static int
+test_mb_AES_GCM_auth_decryption_test_case_256_5(void)
+{
+ return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_256_5);
+}
+
+static int
+test_mb_AES_GCM_auth_decryption_test_case_256_6(void)
+{
+ return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_256_6);
+}
+
+static int
+test_mb_AES_GCM_auth_decryption_test_case_256_7(void)
+{
+ return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_256_7);
+}
+
+static int
+test_mb_AES_GCM_auth_decryption_test_case_aad_1(void)
+{
+ return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_aad_1);
+}
+
+static int
+test_mb_AES_GCM_auth_decryption_test_case_aad_2(void)
+{
+ return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_aad_2);
+}
+
+static int
+test_AES_GCM_authenticated_encryption_oop(const struct gcm_test_data *tdata)
+{
+ struct crypto_testsuite_params *ts_params = &testsuite_params;
+ struct crypto_unittest_params *ut_params = &unittest_params;
+
+ int retval;
+ uint8_t *ciphertext, *auth_tag;
+ uint16_t plaintext_pad_len;
+
+ /* Create GCM session */
+ retval = create_gcm_session(ts_params->valid_devs[0],
+ RTE_CRYPTO_CIPHER_OP_ENCRYPT,
+ tdata->key.data, tdata->key.len,
+ tdata->aad.len, tdata->auth_tag.len,
+ RTE_CRYPTO_AUTH_OP_GENERATE);
+ if (retval < 0)
+ return retval;
+
+ ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
+ ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
+
+ /* clear mbuf payload */
+ memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
+ rte_pktmbuf_tailroom(ut_params->ibuf));
+ memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
+ rte_pktmbuf_tailroom(ut_params->obuf));
+
+ /* Create GCM operation */
+ retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_ENCRYPT, tdata);
+ if (retval < 0)
+ return retval;
+
+ rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
+
+ ut_params->op->sym->m_src = ut_params->ibuf;
+ ut_params->op->sym->m_dst = ut_params->obuf;
+
+ /* Process crypto operation */
+ TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
+ ut_params->op), "failed to process sym crypto op");
+
+ TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
+ "crypto op processing failed");
+
+ plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
+
+ ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
+ ut_params->op->sym->cipher.data.offset);
+ auth_tag = ciphertext + plaintext_pad_len;
+
+ TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
+ TEST_HEXDUMP(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
+
+ /* Validate obuf */
+ TEST_ASSERT_BUFFERS_ARE_EQUAL(
+ ciphertext,
+ tdata->ciphertext.data,
+ tdata->ciphertext.len,
+ "GCM Ciphertext data not as expected");
+
+ TEST_ASSERT_BUFFERS_ARE_EQUAL(
+ auth_tag,
+ tdata->auth_tag.data,
+ tdata->auth_tag.len,
+ "GCM Generated auth tag not as expected");
+
+ return 0;
+
+}
+
+static int
+test_mb_AES_GCM_authenticated_encryption_oop(void)
+{
+ return test_AES_GCM_authenticated_encryption_oop(&gcm_test_case_5);
+}
+
+static int
+test_AES_GCM_authenticated_decryption_oop(const struct gcm_test_data *tdata)
+{
+ struct crypto_testsuite_params *ts_params = &testsuite_params;
+ struct crypto_unittest_params *ut_params = &unittest_params;
+
+ int retval;
+ uint8_t *plaintext;
+
+ /* Create GCM session */
+ retval = create_gcm_session(ts_params->valid_devs[0],
+ RTE_CRYPTO_CIPHER_OP_DECRYPT,
+ tdata->key.data, tdata->key.len,
+ tdata->aad.len, tdata->auth_tag.len,
+ RTE_CRYPTO_AUTH_OP_VERIFY);
+ if (retval < 0)
+ return retval;
+
+ /* alloc mbuf and set payload */
+ ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
+ ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
+
+ memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
+ rte_pktmbuf_tailroom(ut_params->ibuf));
+ memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
+ rte_pktmbuf_tailroom(ut_params->obuf));
+
+ /* Create GCM operation */
+ retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_DECRYPT, tdata);
+ if (retval < 0)
+ return retval;
+
+ rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
+
+ ut_params->op->sym->m_src = ut_params->ibuf;
+ ut_params->op->sym->m_dst = ut_params->obuf;
+
+ /* Process crypto operation */
+ TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
+ ut_params->op), "failed to process sym crypto op");
+
+ TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
+ "crypto op processing failed");
+
+ plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
+ ut_params->op->sym->cipher.data.offset);
+
+ TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
+
+ /* Validate obuf */
+ TEST_ASSERT_BUFFERS_ARE_EQUAL(
+ plaintext,
+ tdata->plaintext.data,
+ tdata->plaintext.len,
+ "GCM plaintext data not as expected");
+
+ TEST_ASSERT_EQUAL(ut_params->op->status,
+ RTE_CRYPTO_OP_STATUS_SUCCESS,
+ "GCM authentication failed");
+ return 0;
+}
+
+static int
+test_mb_AES_GCM_authenticated_decryption_oop(void)
+{
+ return test_AES_GCM_authenticated_decryption_oop(&gcm_test_case_5);
+}
+
+static int
+test_AES_GCM_authenticated_encryption_sessionless(
+ const struct gcm_test_data *tdata)
+{
+ struct crypto_testsuite_params *ts_params = &testsuite_params;
+ struct crypto_unittest_params *ut_params = &unittest_params;
+
+ int retval;
+ uint8_t *ciphertext, *auth_tag;
+ uint16_t plaintext_pad_len;
+ uint8_t key[tdata->key.len + 1];
+
+ ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
+
+ /* clear mbuf payload */
+ memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
+ rte_pktmbuf_tailroom(ut_params->ibuf));
+
+ /* Create GCM operation */
+ retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_ENCRYPT, tdata);
+ if (retval < 0)
+ return retval;
+
+ /* Create GCM xforms */
+ memcpy(key, tdata->key.data, tdata->key.len);
+ retval = create_gcm_xforms(ut_params->op,
+ RTE_CRYPTO_CIPHER_OP_ENCRYPT,
+ key, tdata->key.len,
+ tdata->aad.len, tdata->auth_tag.len,
+ RTE_CRYPTO_AUTH_OP_GENERATE);
+ if (retval < 0)
+ return retval;
+
+ ut_params->op->sym->m_src = ut_params->ibuf;
+
+ TEST_ASSERT_EQUAL(ut_params->op->sym->sess_type,
+ RTE_CRYPTO_SYM_OP_SESSIONLESS,
+ "crypto op session type not sessionless");
+
+ /* Process crypto operation */
+ TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
+ ut_params->op), "failed to process sym crypto op");
+
+ TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
+
+ TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
+ "crypto op status not success");
+
+ plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
+
+ ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
+ ut_params->op->sym->cipher.data.offset);
+ auth_tag = ciphertext + plaintext_pad_len;
+
+ TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
+ TEST_HEXDUMP(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
+
+ /* Validate obuf */
+ TEST_ASSERT_BUFFERS_ARE_EQUAL(
+ ciphertext,
+ tdata->ciphertext.data,
+ tdata->ciphertext.len,
+ "GCM Ciphertext data not as expected");
+
+ TEST_ASSERT_BUFFERS_ARE_EQUAL(
+ auth_tag,
+ tdata->auth_tag.data,
+ tdata->auth_tag.len,
+ "GCM Generated auth tag not as expected");
+
+ return 0;
+
+}
+
+static int
+test_mb_AES_GCM_authenticated_encryption_sessionless(void)
+{
+ return test_AES_GCM_authenticated_encryption_sessionless(
+ &gcm_test_case_5);
+}
+
+static int
+test_AES_GCM_authenticated_decryption_sessionless(
+ const struct gcm_test_data *tdata)
+{
+ struct crypto_testsuite_params *ts_params = &testsuite_params;
+ struct crypto_unittest_params *ut_params = &unittest_params;
+
+ int retval;
+ uint8_t *plaintext;
+ uint8_t key[tdata->key.len + 1];
+
+ /* alloc mbuf and set payload */
+ ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
+
+ memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
+ rte_pktmbuf_tailroom(ut_params->ibuf));
+
+ /* Create GCM operation */
+ retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_DECRYPT, tdata);
+ if (retval < 0)
+ return retval;
+
+ /* Create GCM xforms */
+ memcpy(key, tdata->key.data, tdata->key.len);
+ retval = create_gcm_xforms(ut_params->op,
+ RTE_CRYPTO_CIPHER_OP_DECRYPT,
+ key, tdata->key.len,
+ tdata->aad.len, tdata->auth_tag.len,
+ RTE_CRYPTO_AUTH_OP_VERIFY);
+ if (retval < 0)
+ return retval;
+
+ ut_params->op->sym->m_src = ut_params->ibuf;
+
+ TEST_ASSERT_EQUAL(ut_params->op->sym->sess_type,
+ RTE_CRYPTO_SYM_OP_SESSIONLESS,
+ "crypto op session type not sessionless");
+
+ /* Process crypto operation */
+ TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
+ ut_params->op), "failed to process sym crypto op");
+
+ TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
+
+ TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
+ "crypto op status not success");
+
+ plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
+ ut_params->op->sym->cipher.data.offset);
+
+ TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
+
+ /* Validate obuf */
+ TEST_ASSERT_BUFFERS_ARE_EQUAL(
+ plaintext,
+ tdata->plaintext.data,
+ tdata->plaintext.len,
+ "GCM plaintext data not as expected");
+
+ TEST_ASSERT_EQUAL(ut_params->op->status,
+ RTE_CRYPTO_OP_STATUS_SUCCESS,
+ "GCM authentication failed");
+ return 0;
+}
+
+static int
+test_mb_AES_GCM_authenticated_decryption_sessionless(void)
+{
+ return test_AES_GCM_authenticated_decryption_sessionless(
+ &gcm_test_case_5);
+}
+
+static int
+test_stats(void)
+{
+ struct crypto_testsuite_params *ts_params = &testsuite_params;
+ struct rte_cryptodev_stats stats;
+ struct rte_cryptodev *dev;
+ cryptodev_stats_get_t temp_pfn;
+
+ rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
+ TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
+ &stats) == -ENODEV),
+ "rte_cryptodev_stats_get invalid dev failed");
+ TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
+ "rte_cryptodev_stats_get invalid Param failed");
+ dev = &rte_cryptodevs[ts_params->valid_devs[0]];
+ temp_pfn = dev->dev_ops->stats_get;
+ dev->dev_ops->stats_get = (cryptodev_stats_get_t)0;
+ TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
+ == -ENOTSUP),
+ "rte_cryptodev_stats_get invalid Param failed");
+ dev->dev_ops->stats_get = temp_pfn;
+
+ /* Test expected values */
+ ut_setup();
+ test_AES_CBC_HMAC_SHA1_encrypt_digest();
+ ut_teardown();
+ TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
+ &stats),
+ "rte_cryptodev_stats_get failed");
+ TEST_ASSERT((stats.enqueued_count == 1),
+ "rte_cryptodev_stats_get returned unexpected enqueued stat");
+ TEST_ASSERT((stats.dequeued_count == 1),
+ "rte_cryptodev_stats_get returned unexpected enqueued stat");
+ TEST_ASSERT((stats.enqueue_err_count == 0),
+ "rte_cryptodev_stats_get returned unexpected enqueued stat");
+ TEST_ASSERT((stats.dequeue_err_count == 0),
+ "rte_cryptodev_stats_get returned unexpected enqueued stat");
+
+ /* invalid device but should ignore and not reset device stats*/
+ rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
+ TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
+ &stats),
+ "rte_cryptodev_stats_get failed");
+ TEST_ASSERT((stats.enqueued_count == 1),
+ "rte_cryptodev_stats_get returned unexpected enqueued stat");
+
+ /* check that a valid reset clears stats */
+ rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
+ TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
+ &stats),
+ "rte_cryptodev_stats_get failed");
+ TEST_ASSERT((stats.enqueued_count == 0),
+ "rte_cryptodev_stats_get returned unexpected enqueued stat");
+ TEST_ASSERT((stats.dequeued_count == 0),
+ "rte_cryptodev_stats_get returned unexpected enqueued stat");
+
+ return TEST_SUCCESS;
+}
+
+static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params,
+ struct crypto_unittest_params *ut_params,
+ enum rte_crypto_auth_operation op,
+ const struct HMAC_MD5_vector *test_case)
+{
+ uint8_t key[64];
+
+ memcpy(key, test_case->key.data, test_case->key.len);
+
+ ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
+ ut_params->auth_xform.next = NULL;
+ ut_params->auth_xform.auth.op = op;
+
+ ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC;
+
+ ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN;
+ ut_params->auth_xform.auth.add_auth_data_length = 0;
+ ut_params->auth_xform.auth.key.length = test_case->key.len;
+ ut_params->auth_xform.auth.key.data = key;
+
+ ut_params->sess = rte_cryptodev_sym_session_create(
+ ts_params->valid_devs[0], &ut_params->auth_xform);
+
+ if (ut_params->sess == NULL)
+ return TEST_FAILED;
+
+ ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
+
+ memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
+ rte_pktmbuf_tailroom(ut_params->ibuf));
+
+ return 0;
+}
+
+static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params,
+ const struct HMAC_MD5_vector *test_case,
+ uint8_t **plaintext)
+{
+ uint16_t plaintext_pad_len;
+
+ struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
+
+ plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
+ 16);
+
+ *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
+ plaintext_pad_len);
+ memcpy(*plaintext, test_case->plaintext.data,
+ test_case->plaintext.len);
+
+ sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
+ ut_params->ibuf, MD5_DIGEST_LEN);
+ TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
+ "no room to append digest");
+ sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
+ ut_params->ibuf, plaintext_pad_len);
+ sym_op->auth.digest.length = MD5_DIGEST_LEN;
+
+ if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) {
+ rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data,
+ test_case->auth_tag.len);
+ }
+
+ sym_op->auth.data.offset = 0;
+ sym_op->auth.data.length = test_case->plaintext.len;
+
+ rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
+ ut_params->op->sym->m_src = ut_params->ibuf;
+
+ return 0;
+}
+
+static int
+test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case)
+{
+ uint16_t plaintext_pad_len;
+ uint8_t *plaintext, *auth_tag;
+
+ struct crypto_testsuite_params *ts_params = &testsuite_params;
+ struct crypto_unittest_params *ut_params = &unittest_params;
+
+ if (MD5_HMAC_create_session(ts_params, ut_params,
+ RTE_CRYPTO_AUTH_OP_GENERATE, test_case))
+ return TEST_FAILED;
+
+ /* Generate Crypto op data structure */
+ ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
+ RTE_CRYPTO_OP_TYPE_SYMMETRIC);
+ TEST_ASSERT_NOT_NULL(ut_params->op,
+ "Failed to allocate symmetric crypto operation struct");
+
+ plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
+ 16);
+
+ if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
+ return TEST_FAILED;
+
+ TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
+ ut_params->op), "failed to process sym crypto op");
+
+ TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
+ "crypto op processing failed");
+
+ if (ut_params->op->sym->m_dst) {
+ auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
+ uint8_t *, plaintext_pad_len);
+ } else {
+ auth_tag = plaintext + plaintext_pad_len;
+ }
+
+ TEST_ASSERT_BUFFERS_ARE_EQUAL(
+ auth_tag,
+ test_case->auth_tag.data,
+ test_case->auth_tag.len,
+ "HMAC_MD5 generated tag not as expected");
+
+ return TEST_SUCCESS;
+}
+
+static int
+test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case)
+{
+ uint8_t *plaintext;
+
+ struct crypto_testsuite_params *ts_params = &testsuite_params;
+ struct crypto_unittest_params *ut_params = &unittest_params;
+
+ if (MD5_HMAC_create_session(ts_params, ut_params,
+ RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) {
+ return TEST_FAILED;
+ }
+
+ /* Generate Crypto op data structure */
+ ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
+ RTE_CRYPTO_OP_TYPE_SYMMETRIC);
+ TEST_ASSERT_NOT_NULL(ut_params->op,
+ "Failed to allocate symmetric crypto operation struct");
+
+ if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
+ return TEST_FAILED;
+
+ TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
+ ut_params->op), "failed to process sym crypto op");
+
+ TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
+ "HMAC_MD5 crypto op processing failed");
+
+ return TEST_SUCCESS;
+}
+
+static int
+test_MD5_HMAC_generate_case_1(void)
+{
+ return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1);
+}
+
+static int
+test_MD5_HMAC_verify_case_1(void)
+{
+ return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1);
+}
+
+static int
+test_MD5_HMAC_generate_case_2(void)
+{
+ return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2);
+}
+
+static int
+test_MD5_HMAC_verify_case_2(void)
+{
+ return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2);
+}
+
+static int
+test_multi_session(void)
+{
+ struct crypto_testsuite_params *ts_params = &testsuite_params;
+ struct crypto_unittest_params *ut_params = &unittest_params;
+
+ struct rte_cryptodev_info dev_info;
+ struct rte_cryptodev_sym_session **sessions;
+
+ uint16_t i;
+
+ test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params,
+ aes_cbc_key, hmac_sha512_key);
+
+
+ rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
+
+ sessions = rte_malloc(NULL,
+ (sizeof(struct rte_cryptodev_sym_session *) *
+ dev_info.sym.max_nb_sessions) + 1, 0);
+
+ /* Create multiple crypto sessions*/
+ for (i = 0; i < dev_info.sym.max_nb_sessions; i++) {
+ sessions[i] = rte_cryptodev_sym_session_create(
+ ts_params->valid_devs[0],
+ &ut_params->auth_xform);
+ TEST_ASSERT_NOT_NULL(sessions[i],
+ "Session creation failed at session number %u",
+ i);
+
+ /* Attempt to send a request on each session */
+ TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform(
+ sessions[i],
+ ut_params,
+ ts_params,
+ catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
+ catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
+ aes_cbc_iv),
+ "Failed to perform decrypt on request number %u.", i);
+ /* free crypto operation structure */
+ if (ut_params->op)
+ rte_crypto_op_free(ut_params->op);
+
+ /*
+ * free mbuf - both obuf and ibuf are usually the same,
+ * so check if they point at the same address is necessary,
+ * to avoid freeing the mbuf twice.
+ */
+ if (ut_params->obuf) {
+ rte_pktmbuf_free(ut_params->obuf);
+ if (ut_params->ibuf == ut_params->obuf)
+ ut_params->ibuf = 0;
+ ut_params->obuf = 0;
+ }
+ if (ut_params->ibuf) {
+ rte_pktmbuf_free(ut_params->ibuf);
+ ut_params->ibuf = 0;
+ }
+ }
+
+ /* Next session create should fail */
+ sessions[i] = rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
+ &ut_params->auth_xform);
+ TEST_ASSERT_NULL(sessions[i],
+ "Session creation succeeded unexpectedly!");
+
+ for (i = 0; i < dev_info.sym.max_nb_sessions; i++)
+ rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
+ sessions[i]);
+
+ rte_free(sessions);
+
+ return TEST_SUCCESS;
+}
+
+struct multi_session_params {
+ struct crypto_unittest_params ut_params;
+ uint8_t *cipher_key;
+ uint8_t *hmac_key;
+ const uint8_t *cipher;
+ const uint8_t *digest;
+ uint8_t *iv;
+};
+
+#define MB_SESSION_NUMBER 3
+
+static int
+test_multi_session_random_usage(void)
+{
+ struct crypto_testsuite_params *ts_params = &testsuite_params;
+ struct rte_cryptodev_info dev_info;
+ struct rte_cryptodev_sym_session **sessions;
+ uint32_t i, j;
+ struct multi_session_params ut_paramz[] = {
+
+ {
+ .cipher_key = ms_aes_cbc_key0,
+ .hmac_key = ms_hmac_key0,
+ .cipher = ms_aes_cbc_cipher0,
+ .digest = ms_hmac_digest0,
+ .iv = ms_aes_cbc_iv0
+ },
+ {
+ .cipher_key = ms_aes_cbc_key1,
+ .hmac_key = ms_hmac_key1,
+ .cipher = ms_aes_cbc_cipher1,
+ .digest = ms_hmac_digest1,
+ .iv = ms_aes_cbc_iv1
+ },
+ {
+ .cipher_key = ms_aes_cbc_key2,
+ .hmac_key = ms_hmac_key2,
+ .cipher = ms_aes_cbc_cipher2,
+ .digest = ms_hmac_digest2,
+ .iv = ms_aes_cbc_iv2
+ },
+
+ };
+
+ rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
+
+ sessions = rte_malloc(NULL,
+ (sizeof(struct rte_cryptodev_sym_session *)
+ * dev_info.sym.max_nb_sessions) + 1, 0);
+
+ for (i = 0; i < MB_SESSION_NUMBER; i++) {
+ rte_memcpy(&ut_paramz[i].ut_params, &testsuite_params,
+ sizeof(struct crypto_unittest_params));
+
+ test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
+ &ut_paramz[i].ut_params,
+ ut_paramz[i].cipher_key, ut_paramz[i].hmac_key);
+
+ /* Create multiple crypto sessions*/
+ sessions[i] = rte_cryptodev_sym_session_create(
+ ts_params->valid_devs[0],
+ &ut_paramz[i].ut_params.auth_xform);
+
+ TEST_ASSERT_NOT_NULL(sessions[i],
+ "Session creation failed at session number %u",
+ i);
+
+ }
+
+ srand(time(NULL));
+ for (i = 0; i < 40000; i++) {
+
+ j = rand() % MB_SESSION_NUMBER;
+
+ TEST_ASSERT_SUCCESS(
+ test_AES_CBC_HMAC_SHA512_decrypt_perform(
+ sessions[j],
+ &ut_paramz[j].ut_params,
+ ts_params, ut_paramz[j].cipher,
+ ut_paramz[j].digest,
+ ut_paramz[j].iv),
+ "Failed to perform decrypt on request number %u.", i);
+
+ if (ut_paramz[j].ut_params.op)
+ rte_crypto_op_free(ut_paramz[j].ut_params.op);
+
+ /*
+ * free mbuf - both obuf and ibuf are usually the same,
+ * so check if they point at the same address is necessary,
+ * to avoid freeing the mbuf twice.
+ */
+ if (ut_paramz[j].ut_params.obuf) {
+ rte_pktmbuf_free(ut_paramz[j].ut_params.obuf);
+ if (ut_paramz[j].ut_params.ibuf
+ == ut_paramz[j].ut_params.obuf)
+ ut_paramz[j].ut_params.ibuf = 0;
+ ut_paramz[j].ut_params.obuf = 0;
+ }
+ if (ut_paramz[j].ut_params.ibuf) {
+ rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf);
+ ut_paramz[j].ut_params.ibuf = 0;
+ }
+ }
+
+ for (i = 0; i < MB_SESSION_NUMBER; i++)
+ rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
+ sessions[i]);
+
+ rte_free(sessions);
+
+ return TEST_SUCCESS;
+}
+
+static int
+test_null_cipher_only_operation(void)
+{
+ struct crypto_testsuite_params *ts_params = &testsuite_params;
+ struct crypto_unittest_params *ut_params = &unittest_params;
+
+ /* Generate test mbuf data and space for digest */
+ ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
+ catch_22_quote, QUOTE_512_BYTES, 0);
+
+ /* Setup Cipher Parameters */
+ ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
+ ut_params->cipher_xform.next = NULL;
+
+ ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
+ ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
+
+ /* Create Crypto session*/
+ ut_params->sess = rte_cryptodev_sym_session_create(
+ ts_params->valid_devs[0], &ut_params->cipher_xform);
+ TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
+
+ /* Generate Crypto op data structure */
+ ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
+ RTE_CRYPTO_OP_TYPE_SYMMETRIC);
+ TEST_ASSERT_NOT_NULL(ut_params->op,
+ "Failed to allocate symmetric crypto operation struct");
+
+ /* Set crypto operation data parameters */
+ rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
+
+ struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
+
+ /* set crypto operation source mbuf */
+ sym_op->m_src = ut_params->ibuf;
+
+ sym_op->cipher.data.offset = 0;
+ sym_op->cipher.data.length = QUOTE_512_BYTES;
+
+ /* Process crypto operation */
+ ut_params->op = process_crypto_request(ts_params->valid_devs[0],
+ ut_params->op);
+ TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
+
+ TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
+ "crypto operation processing failed");
+
+ /* Validate obuf */
+ TEST_ASSERT_BUFFERS_ARE_EQUAL(
+ rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
+ catch_22_quote,
+ QUOTE_512_BYTES,
+ "Ciphertext data not as expected");
+
+ return TEST_SUCCESS;
+}
+
+static int
+test_null_auth_only_operation(void)
+{
+ struct crypto_testsuite_params *ts_params = &testsuite_params;
+ struct crypto_unittest_params *ut_params = &unittest_params;
+
+ /* Generate test mbuf data and space for digest */
+ ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
+ catch_22_quote, QUOTE_512_BYTES, 0);
+
+ /* Setup HMAC Parameters */
+ ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
+ ut_params->auth_xform.next = NULL;
+
+ ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
+ ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
+
+ /* Create Crypto session*/
+ ut_params->sess = rte_cryptodev_sym_session_create(
+ ts_params->valid_devs[0], &ut_params->auth_xform);
+ TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
+
+ /* Generate Crypto op data structure */
+ ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
+ RTE_CRYPTO_OP_TYPE_SYMMETRIC);
+ TEST_ASSERT_NOT_NULL(ut_params->op,
+ "Failed to allocate symmetric crypto operation struct");
+
+ /* Set crypto operation data parameters */
+ rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
+
+ struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
+
+ sym_op->m_src = ut_params->ibuf;
+
+ sym_op->auth.data.offset = 0;
+ sym_op->auth.data.length = QUOTE_512_BYTES;
+
+ /* Process crypto operation */
+ ut_params->op = process_crypto_request(ts_params->valid_devs[0],
+ ut_params->op);
+ TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
+
+ TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
+ "crypto operation processing failed");
+
+ return TEST_SUCCESS;
+}
+
+static int
+test_null_cipher_auth_operation(void)
+{
+ struct crypto_testsuite_params *ts_params = &testsuite_params;
+ struct crypto_unittest_params *ut_params = &unittest_params;
+
+ /* Generate test mbuf data and space for digest */
+ ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
+ catch_22_quote, QUOTE_512_BYTES, 0);
+
+ /* Setup Cipher Parameters */
+ ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
+ ut_params->cipher_xform.next = &ut_params->auth_xform;
+
+ ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
+ ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
+
+ /* Setup HMAC Parameters */
+ ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
+ ut_params->auth_xform.next = NULL;
+
+ ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
+ ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
+
+ /* Create Crypto session*/
+ ut_params->sess = rte_cryptodev_sym_session_create(
+ ts_params->valid_devs[0], &ut_params->cipher_xform);
+ TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
+
+ /* Generate Crypto op data structure */
+ ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
+ RTE_CRYPTO_OP_TYPE_SYMMETRIC);
+ TEST_ASSERT_NOT_NULL(ut_params->op,
+ "Failed to allocate symmetric crypto operation struct");
+
+ /* Set crypto operation data parameters */
+ rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
+
+ struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
+
+ sym_op->m_src = ut_params->ibuf;
+
+ sym_op->cipher.data.offset = 0;
+ sym_op->cipher.data.length = QUOTE_512_BYTES;
+
+ sym_op->auth.data.offset = 0;
+ sym_op->auth.data.length = QUOTE_512_BYTES;
+
+ /* Process crypto operation */
+ ut_params->op = process_crypto_request(ts_params->valid_devs[0],
+ ut_params->op);
+ TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
+
+ TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
+ "crypto operation processing failed");
+
+ /* Validate obuf */
+ TEST_ASSERT_BUFFERS_ARE_EQUAL(
+ rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
+ catch_22_quote,
+ QUOTE_512_BYTES,
+ "Ciphertext data not as expected");
+
+ return TEST_SUCCESS;
+}
+
+static int
+test_null_auth_cipher_operation(void)
+{
+ struct crypto_testsuite_params *ts_params = &testsuite_params;
+ struct crypto_unittest_params *ut_params = &unittest_params;
+
+ /* Generate test mbuf data and space for digest */
+ ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
+ catch_22_quote, QUOTE_512_BYTES, 0);
+
+ /* Setup Cipher Parameters */
+ ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
+ ut_params->cipher_xform.next = NULL;
+
+ ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
+ ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
+
+ /* Setup HMAC Parameters */
+ ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
+ ut_params->auth_xform.next = &ut_params->cipher_xform;
+
+ ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
+ ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
+
+ /* Create Crypto session*/
+ ut_params->sess = rte_cryptodev_sym_session_create(
+ ts_params->valid_devs[0], &ut_params->cipher_xform);
+ TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
+
+ /* Generate Crypto op data structure */
+ ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
+ RTE_CRYPTO_OP_TYPE_SYMMETRIC);
+ TEST_ASSERT_NOT_NULL(ut_params->op,
+ "Failed to allocate symmetric crypto operation struct");
+
+ /* Set crypto operation data parameters */
+ rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
+
+ struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
+
+ sym_op->m_src = ut_params->ibuf;
+
+ sym_op->cipher.data.offset = 0;
+ sym_op->cipher.data.length = QUOTE_512_BYTES;
+
+ sym_op->auth.data.offset = 0;
+ sym_op->auth.data.length = QUOTE_512_BYTES;
+
+ /* Process crypto operation */
+ ut_params->op = process_crypto_request(ts_params->valid_devs[0],
+ ut_params->op);
+ TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
+
+ TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
+ "crypto operation processing failed");
+
+ /* Validate obuf */
+ TEST_ASSERT_BUFFERS_ARE_EQUAL(
+ rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
+ catch_22_quote,
+ QUOTE_512_BYTES,
+ "Ciphertext data not as expected");
+
+ return TEST_SUCCESS;
+}
+
+
+static int
+test_null_invalid_operation(void)
+{
+ struct crypto_testsuite_params *ts_params = &testsuite_params;
+ struct crypto_unittest_params *ut_params = &unittest_params;
+
+ /* Setup Cipher Parameters */
+ ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
+ ut_params->cipher_xform.next = NULL;
+
+ ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
+ ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
+
+ /* Create Crypto session*/
+ ut_params->sess = rte_cryptodev_sym_session_create(
+ ts_params->valid_devs[0], &ut_params->cipher_xform);
+ TEST_ASSERT_NULL(ut_params->sess,
+ "Session creation succeeded unexpectedly");
+
+
+ /* Setup HMAC Parameters */
+ ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
+ ut_params->auth_xform.next = NULL;
+
+ ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
+ ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
+
+ /* Create Crypto session*/
+ ut_params->sess = rte_cryptodev_sym_session_create(
+ ts_params->valid_devs[0], &ut_params->auth_xform);
+ TEST_ASSERT_NULL(ut_params->sess,
+ "Session creation succeeded unexpectedly");
+
+ return TEST_SUCCESS;
+}
+
+
+#define NULL_BURST_LENGTH (32)
+
+static int
+test_null_burst_operation(void)
+{
+ struct crypto_testsuite_params *ts_params = &testsuite_params;
+ struct crypto_unittest_params *ut_params = &unittest_params;
+
+ unsigned i, burst_len = NULL_BURST_LENGTH;
+
+ struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
+ struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
+
+ /* Setup Cipher Parameters */
+ ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
+ ut_params->cipher_xform.next = &ut_params->auth_xform;
+
+ ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
+ ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
+
+ /* Setup HMAC Parameters */
+ ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
+ ut_params->auth_xform.next = NULL;
+
+ ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
+ ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
+
+ /* Create Crypto session*/
+ ut_params->sess = rte_cryptodev_sym_session_create(
+ ts_params->valid_devs[0], &ut_params->cipher_xform);
+ TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
+
+ TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
+ RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
+ burst_len, "failed to generate burst of crypto ops");
+
+ /* Generate an operation for each mbuf in burst */
+ for (i = 0; i < burst_len; i++) {
+ struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
+
+ TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
+
+ unsigned *data = (unsigned *)rte_pktmbuf_append(m,
+ sizeof(unsigned));
+ *data = i;
+
+ rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
+
+ burst[i]->sym->m_src = m;
+ }
+
+ /* Process crypto operation */
+ TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
+ 0, burst, burst_len),
+ burst_len,
+ "Error enqueuing burst");
+
+ TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
+ 0, burst_dequeued, burst_len),
+ burst_len,
+ "Error dequeuing burst");
+
+
+ for (i = 0; i < burst_len; i++) {
+ TEST_ASSERT_EQUAL(
+ *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
+ *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
+ uint32_t *),
+ "data not as expected");
+
+ rte_pktmbuf_free(burst[i]->sym->m_src);
+ rte_crypto_op_free(burst[i]);
+ }
+
+ return TEST_SUCCESS;
+}
+
+static void
+generate_gmac_large_plaintext(uint8_t *data)
+{
+ uint16_t i;
+
+ for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32)
+ memcpy(&data[i], &data[0], 32);
+}
+
+static int
+create_gmac_operation(enum rte_crypto_auth_operation op,
+ const struct gmac_test_data *tdata)
+{
+ struct crypto_testsuite_params *ts_params = &testsuite_params;
+ struct crypto_unittest_params *ut_params = &unittest_params;
+ struct rte_crypto_sym_op *sym_op;
+
+ unsigned iv_pad_len;
+ unsigned aad_pad_len;
+
+ iv_pad_len = RTE_ALIGN_CEIL(tdata->iv.len, 16);
+ aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
+
+ /*
+ * Runtime generate the large plain text instead of use hard code
+ * plain text vector. It is done to avoid create huge source file
+ * with the test vector.
+ */
+ if (tdata->aad.len == GMAC_LARGE_PLAINTEXT_LENGTH)
+ generate_gmac_large_plaintext(tdata->aad.data);
+
+ /* Generate Crypto op data structure */
+ ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
+ RTE_CRYPTO_OP_TYPE_SYMMETRIC);
+ TEST_ASSERT_NOT_NULL(ut_params->op,
+ "Failed to allocate symmetric crypto operation struct");
+
+ sym_op = ut_params->op->sym;
+ sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
+ aad_pad_len);
+ TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
+ "no room to append aad");
+
+ sym_op->auth.aad.length = tdata->aad.len;
+ sym_op->auth.aad.phys_addr =
+ rte_pktmbuf_mtophys(ut_params->ibuf);
+ memcpy(sym_op->auth.aad.data, tdata->aad.data, tdata->aad.len);
+
+ sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
+ ut_params->ibuf, tdata->gmac_tag.len);
+ TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
+ "no room to append digest");
+
+ sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
+ ut_params->ibuf, aad_pad_len);
+ sym_op->auth.digest.length = tdata->gmac_tag.len;
+
+ if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
+ rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
+ tdata->gmac_tag.len);
+ TEST_HEXDUMP(stdout, "digest:",
+ sym_op->auth.digest.data,
+ sym_op->auth.digest.length);
+ }
+
+ sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
+ ut_params->ibuf, iv_pad_len);
+ TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
+
+ memset(sym_op->cipher.iv.data, 0, iv_pad_len);
+ sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
+ sym_op->cipher.iv.length = tdata->iv.len;
+
+ rte_memcpy(sym_op->cipher.iv.data, tdata->iv.data, tdata->iv.len);
+
+ TEST_HEXDUMP(stdout, "iv:", sym_op->cipher.iv.data, iv_pad_len);
+
+ sym_op->cipher.data.length = 0;
+ sym_op->cipher.data.offset = 0;
+
+ sym_op->auth.data.offset = 0;
+ sym_op->auth.data.length = 0;
+
+ return 0;
+}
+
+static int create_gmac_session(uint8_t dev_id,
+ enum rte_crypto_cipher_operation op,
+ const struct gmac_test_data *tdata,
+ enum rte_crypto_auth_operation auth_op)
+{
+ uint8_t cipher_key[tdata->key.len];
+
+ struct crypto_unittest_params *ut_params = &unittest_params;
+
+ memcpy(cipher_key, tdata->key.data, tdata->key.len);
+
+ /* For GMAC we setup cipher parameters */
+ ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
+ ut_params->cipher_xform.next = NULL;
+ ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_GCM;
+ ut_params->cipher_xform.cipher.op = op;
+ ut_params->cipher_xform.cipher.key.data = cipher_key;
+ ut_params->cipher_xform.cipher.key.length = tdata->key.len;
+
+ ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
+ ut_params->auth_xform.next = NULL;
+
+ ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC;
+ ut_params->auth_xform.auth.op = auth_op;
+ ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len;
+ ut_params->auth_xform.auth.add_auth_data_length = 0;
+ ut_params->auth_xform.auth.key.length = 0;
+ ut_params->auth_xform.auth.key.data = NULL;
+
+ ut_params->cipher_xform.next = &ut_params->auth_xform;
+
+ ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
+ &ut_params->cipher_xform);
+
+ TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
+
+ return 0;
+}
+
+static int
+test_AES_GMAC_authentication(const struct gmac_test_data *tdata)
+{
+ struct crypto_testsuite_params *ts_params = &testsuite_params;
+ struct crypto_unittest_params *ut_params = &unittest_params;
+
+ int retval;
+
+ uint8_t *auth_tag, *p;
+ uint16_t aad_pad_len;
+
+ TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
+ "No GMAC length in the source data");
+
+ retval = create_gmac_session(ts_params->valid_devs[0],
+ RTE_CRYPTO_CIPHER_OP_ENCRYPT,
+ tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
+
+ if (retval < 0)
+ return retval;
+
+ if (tdata->aad.len > MBUF_SIZE)
+ ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
+ else
+ ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
+ TEST_ASSERT_NOT_NULL(ut_params->ibuf,
+ "Failed to allocate input buffer in mempool");
+
+ memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
+ rte_pktmbuf_tailroom(ut_params->ibuf));
+
+ aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
+
+ p = rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *);
+
+ retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE,
+ tdata);
+
+ if (retval < 0)
+ return retval;
+
+ rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
+
+ ut_params->op->sym->m_src = ut_params->ibuf;
+
+ TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
+ ut_params->op), "failed to process sym crypto op");
+
+ TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
+ "crypto op processing failed");
+
+ if (ut_params->op->sym->m_dst) {
+ auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
+ uint8_t *, aad_pad_len);
+ } else {
+ auth_tag = p + aad_pad_len;
+ }
+
+ TEST_HEXDUMP(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
+
+ TEST_ASSERT_BUFFERS_ARE_EQUAL(
+ auth_tag,
+ tdata->gmac_tag.data,
+ tdata->gmac_tag.len,
+ "GMAC Generated auth tag not as expected");
+
+ return 0;
+}
+
+static int
+test_AES_GMAC_authentication_test_case_1(void)
+{
+ return test_AES_GMAC_authentication(&gmac_test_case_1);
+}
+
+static int
+test_AES_GMAC_authentication_test_case_2(void)
+{
+ return test_AES_GMAC_authentication(&gmac_test_case_2);
+}
+
+static int
+test_AES_GMAC_authentication_test_case_3(void)
+{
+ return test_AES_GMAC_authentication(&gmac_test_case_3);
+}
+
+static int
+test_AES_GMAC_authentication_test_case_4(void)
+{
+ return test_AES_GMAC_authentication(&gmac_test_case_4);
+}
+
+static int
+test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata)
+{
+ struct crypto_testsuite_params *ts_params = &testsuite_params;
+ struct crypto_unittest_params *ut_params = &unittest_params;
+ int retval;
+
+ TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
+ "No GMAC length in the source data");
+
+ retval = create_gmac_session(ts_params->valid_devs[0],
+ RTE_CRYPTO_CIPHER_OP_DECRYPT,
+ tdata, RTE_CRYPTO_AUTH_OP_VERIFY);
+
+ if (retval < 0)
+ return retval;
+
+ if (tdata->aad.len > MBUF_SIZE)
+ ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
+ else
+ ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
+ TEST_ASSERT_NOT_NULL(ut_params->ibuf,
+ "Failed to allocate input buffer in mempool");
+
+ memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
+ rte_pktmbuf_tailroom(ut_params->ibuf));
+
+ retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY,
+ tdata);
+
+ if (retval < 0)
+ return retval;
+
+ rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
+
+ ut_params->op->sym->m_src = ut_params->ibuf;
+
+ TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
+ ut_params->op), "failed to process sym crypto op");
+
+ TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
+ "crypto op processing failed");
+
+ return 0;
+
+}
+
+static int
+test_AES_GMAC_authentication_verify_test_case_1(void)
+{
+ return test_AES_GMAC_authentication_verify(&gmac_test_case_1);
+}
+
+static int
+test_AES_GMAC_authentication_verify_test_case_2(void)
+{
+ return test_AES_GMAC_authentication_verify(&gmac_test_case_2);
+}
+
+static int
+test_AES_GMAC_authentication_verify_test_case_3(void)
+{
+ return test_AES_GMAC_authentication_verify(&gmac_test_case_3);
+}
+
+static int
+test_AES_GMAC_authentication_verify_test_case_4(void)
+{
+ return test_AES_GMAC_authentication_verify(&gmac_test_case_4);
+}
+
+struct test_crypto_vector {
+ enum rte_crypto_cipher_algorithm crypto_algo;
+
+ struct {
+ uint8_t data[64];
+ unsigned int len;
+ } cipher_key;
+
+ struct {
+ uint8_t data[64];
+ unsigned int len;
+ } iv;
+
+ struct {
+ const uint8_t *data;
+ unsigned int len;
+ } plaintext;
+
+ struct {
+ const uint8_t *data;
+ unsigned int len;
+ } ciphertext;
+
+ enum rte_crypto_auth_algorithm auth_algo;
+
+ struct {
+ uint8_t data[128];
+ unsigned int len;
+ } auth_key;
+
+ struct {
+ const uint8_t *data;
+ unsigned int len;
+ } aad;
+
+ struct {
+ uint8_t data[128];
+ unsigned int len;
+ } digest;
+};
+
+static const struct test_crypto_vector
+hmac_sha1_test_crypto_vector = {
+ .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
+ .plaintext = {
+ .data = plaintext_hash,
+ .len = 512
+ },
+ .auth_key = {
+ .data = {
+ 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
+ 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
+ 0xDE, 0xF4, 0xDE, 0xAD
+ },
+ .len = 20
+ },
+ .digest = {
+ .data = {
+ 0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77,
+ 0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17,
+ 0x3F, 0x91, 0x64, 0x59
+ },
+ .len = 20
+ }
+};
+
+static const struct test_crypto_vector
+aes128_gmac_test_vector = {
+ .auth_algo = RTE_CRYPTO_AUTH_AES_GMAC,
+ .crypto_algo = RTE_CRYPTO_CIPHER_AES_GCM,
+ .aad = {
+ .data = plaintext_hash,
+ .len = 512
+ },
+ .iv = {
+ .data = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0A, 0x0B
+ },
+ .len = 12
+ },
+ .cipher_key = {
+ .data = {
+ 0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
+ 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA
+ },
+ .len = 16
+ },
+ .digest = {
+ .data = {
+ 0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56,
+ 0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A
+ },
+ .len = 16
+ }
+};
+
+static const struct test_crypto_vector
+aes128cbc_hmac_sha1_test_vector = {
+ .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
+ .cipher_key = {
+ .data = {
+ 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
+ 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
+ },
+ .len = 16
+ },
+ .iv = {
+ .data = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
+ },
+ .len = 16
+ },
+ .plaintext = {
+ .data = plaintext_hash,
+ .len = 512
+ },
+ .ciphertext = {
+ .data = ciphertext512_aes128cbc,
+ .len = 512
+ },
+ .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
+ .auth_key = {
+ .data = {
+ 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
+ 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
+ 0xDE, 0xF4, 0xDE, 0xAD
+ },
+ .len = 20
+ },
+ .digest = {
+ .data = {
+ 0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60,
+ 0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
+ 0x18, 0x8C, 0x1D, 0x32
+ },
+ .len = 20
+ }
+};
+
+static void
+data_corruption(uint8_t *data)
+{
+ data[0] += 1;
+}
+
+static void
+tag_corruption(uint8_t *data, unsigned int tag_offset)
+{
+ data[tag_offset] += 1;
+}
+
+static int
+create_auth_session(struct crypto_unittest_params *ut_params,
+ uint8_t dev_id,
+ const struct test_crypto_vector *reference,
+ enum rte_crypto_auth_operation auth_op)
+{
+ uint8_t auth_key[reference->auth_key.len + 1];
+
+ memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
+
+ /* Setup Authentication Parameters */
+ ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
+ ut_params->auth_xform.auth.op = auth_op;
+ ut_params->auth_xform.next = NULL;
+ ut_params->auth_xform.auth.algo = reference->auth_algo;
+ ut_params->auth_xform.auth.key.length = reference->auth_key.len;
+ ut_params->auth_xform.auth.key.data = auth_key;
+ ut_params->auth_xform.auth.digest_length = reference->digest.len;
+ ut_params->auth_xform.auth.add_auth_data_length = reference->aad.len;
+
+ /* Create Crypto session*/
+ ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
+ &ut_params->auth_xform);
+
+ TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
+
+ return 0;
+}
+
+static int
+create_auth_cipher_session(struct crypto_unittest_params *ut_params,
+ uint8_t dev_id,
+ const struct test_crypto_vector *reference,
+ enum rte_crypto_auth_operation auth_op,
+ enum rte_crypto_cipher_operation cipher_op)
+{
+ uint8_t cipher_key[reference->cipher_key.len + 1];
+ uint8_t auth_key[reference->auth_key.len + 1];
+
+ memcpy(cipher_key, reference->cipher_key.data,
+ reference->cipher_key.len);
+ memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
+
+ /* Setup Authentication Parameters */
+ ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
+ ut_params->auth_xform.auth.op = auth_op;
+ ut_params->auth_xform.next = &ut_params->cipher_xform;
+ ut_params->auth_xform.auth.algo = reference->auth_algo;
+ ut_params->auth_xform.auth.key.length = reference->auth_key.len;
+ ut_params->auth_xform.auth.key.data = auth_key;
+ ut_params->auth_xform.auth.digest_length = reference->digest.len;
+ ut_params->auth_xform.auth.add_auth_data_length = reference->aad.len;
+
+ /* Setup Cipher Parameters */
+ ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
+ ut_params->cipher_xform.next = NULL;
+ ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
+ ut_params->cipher_xform.cipher.op = cipher_op;
+ ut_params->cipher_xform.cipher.key.data = cipher_key;
+ ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
+
+ /* Create Crypto session*/
+ ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
+ &ut_params->auth_xform);
+
+ TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
+
+ return 0;
+}
+
+static int
+create_auth_operation(struct crypto_testsuite_params *ts_params,
+ struct crypto_unittest_params *ut_params,
+ const struct test_crypto_vector *reference,
+ unsigned int auth_generate)
+{
+ /* Generate Crypto op data structure */
+ ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
+ RTE_CRYPTO_OP_TYPE_SYMMETRIC);
+ TEST_ASSERT_NOT_NULL(ut_params->op,
+ "Failed to allocate pktmbuf offload");
+
+ /* Set crypto operation data parameters */
+ rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
+
+ struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
+
+ /* set crypto operation source mbuf */
+ sym_op->m_src = ut_params->ibuf;
+
+ /* digest */
+ sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
+ ut_params->ibuf, reference->digest.len);
+
+ TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
+ "no room to append auth tag");
+
+ sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
+ ut_params->ibuf, reference->plaintext.len);
+ sym_op->auth.digest.length = reference->digest.len;
+
+ if (auth_generate)
+ memset(sym_op->auth.digest.data, 0, reference->digest.len);
+ else
+ memcpy(sym_op->auth.digest.data,
+ reference->digest.data,
+ reference->digest.len);
+
+ TEST_HEXDUMP(stdout, "digest:",
+ sym_op->auth.digest.data,
+ sym_op->auth.digest.length);
+
+ sym_op->auth.data.length = reference->plaintext.len;
+ sym_op->auth.data.offset = 0;
+
+ return 0;
+}
+
+static int
+create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params,
+ struct crypto_unittest_params *ut_params,
+ const struct test_crypto_vector *reference,
+ unsigned int auth_generate)
+{
+ /* Generate Crypto op data structure */
+ ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
+ RTE_CRYPTO_OP_TYPE_SYMMETRIC);
+ TEST_ASSERT_NOT_NULL(ut_params->op,
+ "Failed to allocate pktmbuf offload");
+
+ /* Set crypto operation data parameters */
+ rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
+
+ struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
+
+ /* set crypto operation source mbuf */
+ sym_op->m_src = ut_params->ibuf;
+
+ /* aad */
+ sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
+ reference->aad.len);
+ TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data, "no room to append AAD");
+ memcpy(sym_op->auth.aad.data, reference->aad.data, reference->aad.len);
+
+ TEST_HEXDUMP(stdout, "AAD:", sym_op->auth.aad.data, reference->aad.len);
+
+ sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
+ sym_op->auth.aad.length = reference->aad.len;
+
+ /* digest */
+ sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
+ ut_params->ibuf, reference->digest.len);
+
+ TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
+ "no room to append auth tag");
+
+ sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
+ ut_params->ibuf, reference->ciphertext.len);
+ sym_op->auth.digest.length = reference->digest.len;
+
+ if (auth_generate)
+ memset(sym_op->auth.digest.data, 0, reference->digest.len);
+ else
+ memcpy(sym_op->auth.digest.data,
+ reference->digest.data,
+ reference->digest.len);
+
+ TEST_HEXDUMP(stdout, "digest:",
+ sym_op->auth.digest.data,
+ sym_op->auth.digest.length);
+
+ sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
+ ut_params->ibuf, reference->iv.len);
+ TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
+
+ sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
+ sym_op->cipher.iv.length = reference->iv.len;
+
+ memcpy(sym_op->cipher.iv.data, reference->iv.data, reference->iv.len);
+
+ sym_op->cipher.data.length = 0;
+ sym_op->cipher.data.offset = 0;
+
+ sym_op->auth.data.length = 0;
+ sym_op->auth.data.offset = 0;
+
+ return 0;
+}
+
+static int
+create_cipher_auth_operation(struct crypto_testsuite_params *ts_params,
+ struct crypto_unittest_params *ut_params,
+ const struct test_crypto_vector *reference,
+ unsigned int auth_generate)
+{
+ /* Generate Crypto op data structure */
+ ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
+ RTE_CRYPTO_OP_TYPE_SYMMETRIC);
+ TEST_ASSERT_NOT_NULL(ut_params->op,
+ "Failed to allocate pktmbuf offload");
+
+ /* Set crypto operation data parameters */
+ rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
+
+ struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
+
+ /* set crypto operation source mbuf */
+ sym_op->m_src = ut_params->ibuf;
+
+ /* digest */
+ sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
+ ut_params->ibuf, reference->digest.len);
+
+ TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
+ "no room to append auth tag");
+
+ sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
+ ut_params->ibuf, reference->ciphertext.len);
+ sym_op->auth.digest.length = reference->digest.len;
+
+ if (auth_generate)
+ memset(sym_op->auth.digest.data, 0, reference->digest.len);
+ else
+ memcpy(sym_op->auth.digest.data,
+ reference->digest.data,
+ reference->digest.len);
+
+ TEST_HEXDUMP(stdout, "digest:",
+ sym_op->auth.digest.data,
+ sym_op->auth.digest.length);
+
+ sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
+ ut_params->ibuf, reference->iv.len);
+ TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
+
+ sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
+ sym_op->cipher.iv.length = reference->iv.len;
+
+ memcpy(sym_op->cipher.iv.data, reference->iv.data, reference->iv.len);