[dpdk-dev] [PATCH 2/2] app/test: add test cases for AES CTR

2016-05-06 Thread Arek Kusztal
Added tests cases for AES working in counter mode

Signed-off-by: Arek Kusztal 
---
 app/test/test_cryptodev.c  | 254 
 app/test/test_cryptodev_aes_ctr_test_vectors.h | 257 +
 2 files changed, 511 insertions(+)
 create mode 100644 app/test/test_cryptodev_aes_ctr_test_vectors.h

diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c
index 8e8da98..03d6f02 100644
--- a/app/test/test_cryptodev.c
+++ b/app/test/test_cryptodev.c
@@ -42,6 +42,8 @@

 #include "test.h"
 #include "test_cryptodev.h"
+
+#include "test_cryptodev_aes_ctr_test_vectors.h"
 #include "test_cryptodev_snow3g_test_vectors.h"
 #include "test_cryptodev_snow3g_hash_test_vectors.h"
 #include "test_cryptodev_gcm_test_vectors.h"
@@ -1358,6 +1360,245 @@ test_AES_CBC_HMAC_SHA1_decrypt_digest_verify(void)
return TEST_SUCCESS;
 }

+/*  AES counter mode tests  */
+
+static int
+test_AES_CTR_encrypt_digest(const struct aes_ctr_test_data *tdata)
+{
+   struct crypto_testsuite_params *ts_params = _params;
+   struct crypto_unittest_params *ut_params = _params;
+   struct rte_crypto_sym_op *sym_op;
+
+   uint8_t hash_key[tdata->auth_key.len];
+   uint8_t cipher_key[tdata->key.len];
+
+   ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
+   (const char *)tdata->plaintext.data,
+   tdata->plaintext.len, 0);
+
+   /* Setup Cipher Parameters */
+   ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
+   ut_params->cipher_xform.next = _params->auth_xform;
+
+   ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CTR;
+   ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
+
+   rte_memcpy(cipher_key, tdata->key.data, tdata->key.len);
+   ut_params->cipher_xform.cipher.key.data = cipher_key;
+   ut_params->cipher_xform.cipher.key.length =
+   tdata->key.len;
+
+   /* Setup HMAC Parameters */
+   ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
+   ut_params->auth_xform.next = NULL;
+
+   ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
+   ut_params->auth_xform.auth.algo = tdata->auth_key.algo;
+   ut_params->auth_xform.auth.key.length =
+   tdata->auth_key.len;
+   rte_memcpy(hash_key, tdata->auth_key.data, tdata->auth_key.len);
+   ut_params->auth_xform.auth.key.data = hash_key;
+   ut_params->auth_xform.auth.digest_length = tdata->digest.len;
+
+   /* Create Crypto session*/
+   ut_params->sess = rte_cryptodev_sym_session_create(
+   ts_params->valid_devs[0],
+   _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");
+
+   rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
+
+   sym_op = ut_params->op->sym;
+
+   /* set crypto operation source mbuf */
+   sym_op->m_src = ut_params->ibuf;
+
+   /* Set operation cipher parameters */
+   sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
+   sym_op->m_src, tdata->iv.len);
+   sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(sym_op->m_src);
+   sym_op->cipher.iv.length = tdata->iv.len;
+
+   rte_memcpy(sym_op->cipher.iv.data, tdata->iv.data,
+   tdata->iv.len);
+
+   sym_op->cipher.data.offset = tdata->iv.len;
+   sym_op->cipher.data.length = tdata->plaintext.len;
+
+   /* Set operation authentication parameters */
+   sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
+   sym_op->m_src, tdata->digest.len);
+   sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
+   sym_op->m_src,
+   tdata->iv.len + tdata->ciphertext.len);
+   sym_op->auth.digest.length = tdata->digest.len;
+
+   memset(sym_op->auth.digest.data, 0, tdata->digest.len);
+
+   sym_op->auth.data.offset = tdata->iv.len;
+   sym_op->auth.data.length = tdata->plaintext.len;
+
+   /* Process crypto operation */
+   ut_params->op = process_crypto_request(ts_params->valid_devs[0],
+   ut_params->op);
+
+   TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
+   "crypto op processing failed");
+
+   uint8_t *ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
+   uint8_t *, tdata->iv.len);
+
+   TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
+   tdata->ciphertext.data,
+   tdata->ciphertext.len,
+  

[dpdk-dev] [PATCH 2/2] app/test: add test cases for AES CTR

2016-05-05 Thread Arek Kusztal
Added tests cases for AES working in counter mode

Signed-off-by: Arek Kusztal 
---
 app/test/test_cryptodev.c  | 254 
 app/test/test_cryptodev_aes_ctr_test_vectors.h | 257 +
 2 files changed, 511 insertions(+)
 create mode 100644 app/test/test_cryptodev_aes_ctr_test_vectors.h

diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c
index 8e8da98..03d6f02 100644
--- a/app/test/test_cryptodev.c
+++ b/app/test/test_cryptodev.c
@@ -42,6 +42,8 @@

 #include "test.h"
 #include "test_cryptodev.h"
+
+#include "test_cryptodev_aes_ctr_test_vectors.h"
 #include "test_cryptodev_snow3g_test_vectors.h"
 #include "test_cryptodev_snow3g_hash_test_vectors.h"
 #include "test_cryptodev_gcm_test_vectors.h"
@@ -1358,6 +1360,245 @@ test_AES_CBC_HMAC_SHA1_decrypt_digest_verify(void)
return TEST_SUCCESS;
 }

+/*  AES counter mode tests  */
+
+static int
+test_AES_CTR_encrypt_digest(const struct aes_ctr_test_data *tdata)
+{
+   struct crypto_testsuite_params *ts_params = _params;
+   struct crypto_unittest_params *ut_params = _params;
+   struct rte_crypto_sym_op *sym_op;
+
+   uint8_t hash_key[tdata->auth_key.len];
+   uint8_t cipher_key[tdata->key.len];
+
+   ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
+   (const char *)tdata->plaintext.data,
+   tdata->plaintext.len, 0);
+
+   /* Setup Cipher Parameters */
+   ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
+   ut_params->cipher_xform.next = _params->auth_xform;
+
+   ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CTR;
+   ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
+
+   rte_memcpy(cipher_key, tdata->key.data, tdata->key.len);
+   ut_params->cipher_xform.cipher.key.data = cipher_key;
+   ut_params->cipher_xform.cipher.key.length =
+   tdata->key.len;
+
+   /* Setup HMAC Parameters */
+   ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
+   ut_params->auth_xform.next = NULL;
+
+   ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
+   ut_params->auth_xform.auth.algo = tdata->auth_key.algo;
+   ut_params->auth_xform.auth.key.length =
+   tdata->auth_key.len;
+   rte_memcpy(hash_key, tdata->auth_key.data, tdata->auth_key.len);
+   ut_params->auth_xform.auth.key.data = hash_key;
+   ut_params->auth_xform.auth.digest_length = tdata->digest.len;
+
+   /* Create Crypto session*/
+   ut_params->sess = rte_cryptodev_sym_session_create(
+   ts_params->valid_devs[0],
+   _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");
+
+   rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
+
+   sym_op = ut_params->op->sym;
+
+   /* set crypto operation source mbuf */
+   sym_op->m_src = ut_params->ibuf;
+
+   /* Set operation cipher parameters */
+   sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
+   sym_op->m_src, tdata->iv.len);
+   sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(sym_op->m_src);
+   sym_op->cipher.iv.length = tdata->iv.len;
+
+   rte_memcpy(sym_op->cipher.iv.data, tdata->iv.data,
+   tdata->iv.len);
+
+   sym_op->cipher.data.offset = tdata->iv.len;
+   sym_op->cipher.data.length = tdata->plaintext.len;
+
+   /* Set operation authentication parameters */
+   sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
+   sym_op->m_src, tdata->digest.len);
+   sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
+   sym_op->m_src,
+   tdata->iv.len + tdata->ciphertext.len);
+   sym_op->auth.digest.length = tdata->digest.len;
+
+   memset(sym_op->auth.digest.data, 0, tdata->digest.len);
+
+   sym_op->auth.data.offset = tdata->iv.len;
+   sym_op->auth.data.length = tdata->plaintext.len;
+
+   /* Process crypto operation */
+   ut_params->op = process_crypto_request(ts_params->valid_devs[0],
+   ut_params->op);
+
+   TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
+   "crypto op processing failed");
+
+   uint8_t *ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
+   uint8_t *, tdata->iv.len);
+
+   TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
+   tdata->ciphertext.data,
+   tdata->ciphertext.len,
+