Snow3G UEA2 support for Intel Quick Assist Devices
cover Snow3G UEA2 support for Intel Quick Assist Devices
This patchset contains support for snow3g UEA2 wireless algorithm for Intel Quick Assist devices. (cipher-only)
QAT PMD previously supported only cipher/hash chaining for AES/SHA. The code has been refactored to also support cipher-only functionality for Snow3g algorithms.
Cipher/hash only functionality is only supported
for Snow3g and not for AES/SHA.
Deepak Kumar JAIN (3):
crypto: add cipher/auth only support
qat: add Snow3G UEA2 support
app/test: add Snow3G UEA2 tests
app/test/test_cryptodev.c | 318 +++++++++++++++++++++- app/test/test_cryptodev.h | 2 +- app/test/test_cryptodev_snow3g_test_vectors.h | 323 +++++++++++++++++++++++ doc/guides/cryptodevs/qat.rst | 5 +- doc/guides/rel_notes/release_2_3.rst | 1 + drivers/crypto/qat/qat_adf/qat_algs.h | 21 +- drivers/crypto/qat/qat_adf/qat_algs_build_desc.c | 218 +++++++++++++-- drivers/crypto/qat/qat_crypto.c | 144 +++++++--- drivers/crypto/qat/qat_crypto.h | 12 +- 9 files changed, 974 insertions(+), 70 deletions(-) create mode 100644 app/test/test_cryptodev_snow3g_test_vectors.h
Signature · 1 line
2.1.0
PATCH 1/3 crypto: add cipher/auth only support
Refactored the existing functionality into
modular form to support the cipher/auth only
functionalities.
--- drivers/crypto/qat/qat_adf/qat_algs.h | 20 ++- drivers/crypto/qat/qat_adf/qat_algs_build_desc.c | 206 ++++++++++++++++++++--- drivers/crypto/qat/qat_crypto.c | 136 +++++++++++---- drivers/crypto/qat/qat_crypto.h | 12 +- 4 files changed, 308 insertions(+), 66 deletions(-)
drivers/crypto/qat/qat_adf/qat_algs.h +13 -7
@@ -3,7 +3,7 @@* redistributing this file, you may do so under either license. * * GPL LICENSE SUMMARY -* Copyright(c) 2015 Intel Corporation. +* Copyright(c) 2015-2016 Intel Corporation. * This program is free software; you can redistribute it and/or modify * it under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation.
@@ -17,7 +17,7 @@* [email protected] * * BSD LICENSE -* Copyright(c) 2015 Intel Corporation. +* Copyright(c) 2015-2016 Intel Corporation. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met:
@@ -104,11 +104,17 @@ struct qat_alg_ablkcipher_cd {int qat_get_inter_state_size (enum icp_qat_hw_auth_algo qat_hash_alg); -int qat_alg_aead_session_create_content_desc (struct qat_session *cd, -uint8_t *enckey,uint32_t enckeylen, -uint8_t *authkey,uint32_t authkeylen, -uint32_t add_auth_data_length, -uint32_t digestsize); +int qat_alg_aead_session_create_content_desc_cipher (struct qat_session *cd, +uint8_t *enckey, +uint32_t enckeylen); + +int qat_alg_aead_session_create_content_desc_auth (struct qat_session *cdesc, +uint8_t *cipherkey, +uint32_t cipherkeylen, +uint8_t *authkey, +uint32_t authkeylen, +uint32_t add_auth_data_length, +uint32_t digestsize);void qat_alg_init_common_hdr (struct icp_qat_fw_comn_req_hdr *header);
drivers/crypto/qat/qat_adf/qat_algs_build_desc.c +181 -25
263 lines not on this page · raw message
drivers/crypto/qat/qat_crypto.c +103 -33
193 lines not on this page · raw message
drivers/crypto/qat/qat_crypto.h +11 -1
@@ -1,7 +1,7 @@/*- * BSD LICENSE * -* Copyright(c) 2010-2015 Intel Corporation. All rights reserved. +* Copyright(c) 2010-2016 Intel Corporation. All rights reserved. * All rights reserved. * * Redistribution and use in source and binary forms, with or without
@@ -107,6 +107,16 @@ qat_crypto_sym_get_session_private_size(struct rte_cryptodev *dev);extern void qat_crypto_sym_session_init (struct rte_mempool *mempool,void *priv_sess); +extern struct qat_session * +qat_crypto_sym_configure_session_cipher (struct rte_cryptodev *dev, +struct rte_crypto_xform *xform, +struct qat_session *session_private); + +extern struct qat_session * +qat_crypto_sym_configure_session_auth (struct rte_cryptodev *dev, +struct rte_crypto_xform *xform, +struct qat_session *session_private); +extern void *qat_crypto_sym_configure_session (struct rte_cryptodev *dev,struct rte_crypto_xform *xform,void *session_private);
Signature · 1 line
2.1.0
PATCH 2/3 qat: add Snow3G UEA2 support
In reply to Deepak Kumar JAINAdded support for wireless Snow3G cipher only,
for the Intel Quick Assist device.
--- doc/guides/cryptodevs/qat.rst | 5 +++-- doc/guides/rel_notes/release_2_3.rst | 1 + drivers/crypto/qat/qat_adf/qat_algs.h | 1 + drivers/crypto/qat/qat_adf/qat_algs_build_desc.c | 12 ++++++++++++ drivers/crypto/qat/qat_crypto.c | 8 ++++++++ 5 files changed, 25 insertions(+), 2 deletions(-)
doc/guides/cryptodevs/qat.rst +3 -2
@@ -1,5 +1,5 @@ .. BSD LICENSE - Copyright(c) 2015 Intel Corporation. All rights reserved. + Copyright(c) 2015-2016 Intel Corporation. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions
@@ -47,6 +47,7 @@ Cipher algorithms: * ``RTE_CRYPTO_SYM_CIPHER_AES128_CBC`` * ``RTE_CRYPTO_SYM_CIPHER_AES192_CBC`` * ``RTE_CRYPTO_SYM_CIPHER_AES256_CBC`` +* ``RTE_CRYPTO_SYM_CIPHER_SNOW3G_UEA2`` Hash algorithms:
@@ -61,7 +62,7 @@ Limitations * Chained mbufs are not supported. * Hash only is not supported. -* Cipher only is not supported. +* Cipher only is not supported except Snow3G UEA2. * Only in-place is currently supported (destination address is the same as source address). * Only supports the session-oriented API implementation (session-less APIs are not supported). * Not performance tuned.
doc/guides/rel_notes/release_2_3.rst +1 -0
@@ -3,6 +3,7 @@ DPDK Release 2.3 New Features ------------ +* **Added the support of Snow3g UEA2 Cipher operation for Intel Quick Assist Devices.* Resolved Issues
drivers/crypto/qat/qat_adf/qat_algs.h +1 -0
@@ -127,5 +127,6 @@ void qat_alg_ablkcipher_init_dec(struct qat_alg_ablkcipher_cd *cd, unsigned int keylen);int qat_alg_validate_aes_key (int key_len,enum icp_qat_hw_cipher_algo *alg); +int qat_alg_validate_snow3g_key (int key_len,enum icp_qat_hw_cipher_algo *alg);#endif
drivers/crypto/qat/qat_adf/qat_algs_build_desc.c +12 -0
@@ -755,3 +755,15 @@ int qat_alg_validate_aes_key(int key_len, enum icp_qat_hw_cipher_algo *alg) }return 0 ; } + +int qat_alg_validate_snow3g_key (int key_len,enum icp_qat_hw_cipher_algo *alg) +{ +switch (key_len) { +case ICP_QAT_HW_SNOW_3G_UEA2_KEY_SZ : + *alg =ICP_QAT_HW_CIPHER_ALGO_SNOW_3G_UEA2 ; +break ; +default : +return -EINVAL ; + } +return 0 ; +}
drivers/crypto/qat/qat_crypto.c +8 -0
@@ -168,6 +168,14 @@ qat_crypto_sym_configure_session_cipher(struct rte_cryptodev *dev, } session->qat_mode =ICP_QAT_HW_CIPHER_CTR_MODE ;break ; +case RTE_CRYPTO_CIPHER_SNOW3G_UEA2 : +if (qat_alg_validate_snow3g_key (cipher_xform->key.length, + &session->qat_cipher_alg) !=0 ) { +PMD_DRV_LOG (ERR ,"Invalid SNOW3G cipher key size" ); + goto error_out; + } + session->qat_mode =ICP_QAT_HW_CIPHER_ECB_MODE ; +break ;case RTE_CRYPTO_CIPHER_NULL :case RTE_CRYPTO_CIPHER_3DES_ECB :case RTE_CRYPTO_CIPHER_3DES_CBC :
Signature · 1 line
2.1.0
PATCH 3/3 app/test: add Snow3G UEA2 tests
In reply to Deepak Kumar JAINAdded encryption and decryption tests with input test vectors from Snow3G UEA2 specifications.
--- app/test/test_cryptodev.c | 318 ++++++++++++++++++++++++- app/test/test_cryptodev.h | 2 +- app/test/test_cryptodev_snow3g_test_vectors.h | 323 ++++++++++++++++++++++++++ 3 files changed, 641 insertions(+), 2 deletions(-) create mode 100644 app/test/test_cryptodev_snow3g_test_vectors.h
app/test/test_cryptodev.c +317 -1
@@ -1,7 +1,7 @@/*- * BSD LICENSE * -* Copyright(c) 2015 Intel Corporation. All rights reserved. +* Copyright(c) 2015-2016 Intel Corporation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions
@@ -43,6 +43,7 @@#include "test.h" #include "test_cryptodev.h" +#include "test_cryptodev_snow3g_test_vectors.h" static enum rte_cryptodev_type gbl_cryptodev_type;
@@ -188,6 +189,23 @@ testsuite_setup(void) } } +/* Create 2 Snow3G devices if required */ +if (gbl_cryptodev_type ==RTE_CRYPTODEV_SNOW3G_PMD ) { + nb_devs =rte_cryptodev_count_devtype (RTE_CRYPTODEV_SNOW3G_PMD ); +if (nb_devs <2 ) { +for (i = nb_devs; i <2 ; i++) { +int dev_id = +rte_eal_vdev_init (CRYPTODEV_NAME_SNOW3G_PMD , +NULL ); + +TEST_ASSERT (dev_id >=0 , +"Failed to create instance %u of" +" pmd : %s" , + i,CRYPTODEV_NAME_SNOW3G_PMD ); + } + } + } + nb_devs =rte_cryptodev_count ();if (nb_devs <1 ) {RTE_LOG (ERR ,USER1 ,"No crypto devices found?" );
@@ -1681,7 +1699,283 @@ test_AES_CBC_HMAC_AES_XCBC_decrypt_digest_verify(void)return TEST_SUCCESS ; } +/* ***** Snow3G Tests ***** */ +static int +create_snow3g_cipher_session (uint8_t dev_id, +enum rte_crypto_cipher_operation op, +const uint8_t *key,const uint8_t key_len) +{ +uint8_t cipher_key[key_len]; + +struct crypto_unittest_params *ut_params = &unittest_params; + +memcpy (cipher_key, key, key_len); + +/* Setup Cipher Parameters */ + ut_params->cipher_xform.type =RTE_CRYPTO_XFORM_CIPHER ; + ut_params->cipher_xform.next =NULL ; + + ut_params->cipher_xform.cipher.algo =RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ; + ut_params->cipher_xform.cipher.op = op; + ut_params->cipher_xform.cipher.key.data = cipher_key; + ut_params->cipher_xform.cipher.key.length = key_len; + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"key:" , key, key_len); +#endif +/* Create Crypto session */ + ut_params->sess =rte_cryptodev_session_create (dev_id, + &ut_params-> + cipher_xform); + +TEST_ASSERT_NOT_NULL (ut_params->sess,"Session creation failed" ); + +return 0 ; +} + +static int +create_snow3g_cipher_operation (const uint8_t *iv,const unsigned iv_len, +const unsigned data_len) +{ +struct crypto_testsuite_params *ts_params = &testsuite_params; +struct crypto_unittest_params *ut_params = &unittest_params; + +unsigned iv_pad_len =0 ; + +/* Generate Crypto op data structure */ + ut_params->ol =rte_pktmbuf_offload_alloc (ts_params->mbuf_ol_pool, +RTE_PKTMBUF_OL_CRYPTO ); +TEST_ASSERT_NOT_NULL (ut_params->ol, +"Failed to allocate pktmbuf offload" ); + + ut_params->op = &ut_params->ol->op.crypto; + +/* iv */ + iv_pad_len =RTE_ALIGN_CEIL (iv_len,16 ); + + ut_params->op->iv.data = + (uint8_t *)rte_pktmbuf_prepend (ut_params->ibuf, iv_pad_len); +TEST_ASSERT_NOT_NULL (ut_params->op->iv.data,"no room to prepend iv" ); + +memset (ut_params->op->iv.data,0 , iv_pad_len); + ut_params->op->iv.phys_addr =rte_pktmbuf_mtophys (ut_params->ibuf); + ut_params->op->iv.length = iv_pad_len; + +rte_memcpy (ut_params->op->iv.data, iv, iv_len); + +rte_hexdump (stdout,"iv:" , ut_params->op->iv.data, iv_pad_len); + ut_params->op->data.to_cipher.length = data_len; + ut_params->op->data.to_cipher.offset = iv_pad_len; +return 0 ; +} + +static int test_snow3g_encryption (const struct snow3g_test_data *tdata) +{ +struct crypto_testsuite_params *ts_params = &testsuite_params; +struct crypto_unittest_params *ut_params = &unittest_params; + +int retval; + +uint8_t *plaintext, *ciphertext; +uint8_t plaintext_pad_len; +uint8_t lastByteValidBits =8 ; +uint8_t lastByteMask =0xFF ; + +/* Create SNOW3G session */ + retval =create_snow3g_cipher_session (ts_params->valid_devs[0 ], +RTE_CRYPTO_CIPHER_OP_ENCRYPT , + tdata->key.data, tdata->key.len); +if (retval <0 ) +return retval; + + 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)); + +/* +* Append data which is padded to a +* multiple of the algorithms block size +*/ + plaintext_pad_len =RTE_ALIGN_CEIL (tdata->plaintext.len,16 ); + + plaintext = (uint8_t *)rte_pktmbuf_append (ut_params->ibuf, + plaintext_pad_len); +memcpy (plaintext, tdata->plaintext.data, tdata->plaintext.len); + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"plaintext:" , plaintext, tdata->plaintext.len); +#endif +/* Create SNOW3G operation */ + retval =create_snow3g_cipher_operation (tdata->iv.data, tdata->iv.len, + tdata->plaintext.len); +if (retval <0 ) +return retval; + +rte_crypto_op_attach_session (ut_params->op, ut_params->sess); + +rte_pktmbuf_offload_attach (ut_params->ibuf, ut_params->ol); + + ut_params->obuf =process_crypto_request (ts_params->valid_devs[0 ], + ut_params->ibuf); +TEST_ASSERT_NOT_NULL (ut_params->obuf,"failed to retrieve obuf" ); + +if (ut_params->op->dst.m) { + ciphertext = rte_pktmbuf_mtod(ut_params->op->dst.m, uint8_t *); + }else { + ciphertext = plaintext; + } + lastByteValidBits = (tdata->validDataLenInBits.len %8 ); +if (lastByteValidBits ==0 ) + lastByteValidBits =8 ; + lastByteMask = lastByteMask << (8 - lastByteValidBits); + (*(ciphertext + tdata->ciphertext.len -1 )) &= lastByteMask; + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"ciphertext:" , ciphertext, tdata->ciphertext.len); +#endif +/* Validate obuf */ +TEST_ASSERT_BUFFERS_ARE_EQUAL (ciphertext, + tdata->ciphertext.data, + tdata->ciphertext.len, +"Snow3G Ciphertext data not as expected" ); +return 0 ; +} + +static int test_snow3g_decryption (const struct snow3g_test_data *tdata) +{ +struct crypto_testsuite_params *ts_params = &testsuite_params; +struct crypto_unittest_params *ut_params = &unittest_params; + +int retval; + +uint8_t *plaintext, *ciphertext; +uint8_t ciphertext_pad_len; +uint8_t lastByteValidBits =8 ; +uint8_t lastByteMask =0xFF ; + +/* Create SNOW3G session */ + retval =create_snow3g_cipher_session (ts_params->valid_devs[0 ], +RTE_CRYPTO_CIPHER_OP_DECRYPT , + tdata->key.data, tdata->key.len); +if (retval <0 ) +return retval; + + 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)); + +/* +* Append data which is padded to a +* multiple of the algorithms block size +*/ + ciphertext_pad_len =RTE_ALIGN_CEIL (tdata->ciphertext.len,16 ); + + ciphertext = (uint8_t *)rte_pktmbuf_append (ut_params->ibuf, + ciphertext_pad_len); +memcpy (ciphertext, tdata->ciphertext.data, tdata->ciphertext.len); + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"ciphertext:" , ciphertext, tdata->ciphertext.len); +#endif +/* Create SNOW3G operation */ + retval =create_snow3g_cipher_operation (tdata->iv.data, tdata->iv.len, + tdata->ciphertext.len); +if (retval <0 ) +return retval; + +rte_crypto_op_attach_session (ut_params->op, ut_params->sess); + +rte_pktmbuf_offload_attach (ut_params->ibuf, ut_params->ol); + + ut_params->obuf =process_crypto_request (ts_params->valid_devs[0 ], + ut_params->ibuf); +TEST_ASSERT_NOT_NULL (ut_params->obuf,"failed to retrieve obuf" ); + +if (ut_params->op->dst.m) { + plaintext = rte_pktmbuf_mtod(ut_params->op->dst.m, uint8_t *); + }else { + plaintext = ciphertext; + } + lastByteValidBits = (tdata->validDataLenInBits.len %8 ); +if (lastByteValidBits ==0 ) + lastByteValidBits =8 ; + lastByteMask = lastByteMask << (8 - lastByteValidBits); + (*(ciphertext + tdata->ciphertext.len -1 )) &= lastByteMask; + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"plaintext:" , plaintext, tdata->plaintext.len); +#endif +/* Validate obuf */ +TEST_ASSERT_BUFFERS_ARE_EQUAL (plaintext, + tdata->plaintext.data, + tdata->plaintext.len, +"Snow3G Plaintext data not as expected" ); +return 0 ; +} + +static int +test_snow3g_encryption_test_case_1 (void ) +{ +return test_snow3g_encryption (&snow3g_test_case_1); +} + +static int +test_snow3g_encryption_test_case_2 (void ) +{ +return test_snow3g_encryption (&snow3g_test_case_2); +} + +static int +test_snow3g_encryption_test_case_3 (void ) +{ +return test_snow3g_encryption (&snow3g_test_case_3); +} + +static int +test_snow3g_encryption_test_case_4 (void ) +{ +return test_snow3g_encryption (&snow3g_test_case_4); +} + +static int +test_snow3g_encryption_test_case_5 (void ) +{ +return test_snow3g_encryption (&snow3g_test_case_5); +} +static int +test_snow3g_decryption_test_case_1 (void ) +{ +return test_snow3g_decryption (&snow3g_test_case_1); +} + +static int +test_snow3g_decryption_test_case_2 (void ) +{ +return test_snow3g_decryption (&snow3g_test_case_2); +} + +static int +test_snow3g_decryption_test_case_3 (void ) +{ +return test_snow3g_decryption (&snow3g_test_case_3); +} + +static int +test_snow3g_decryption_test_case_4 (void ) +{ +return test_snow3g_decryption (&snow3g_test_case_4); +} + +static int +test_snow3g_decryption_test_case_5 (void ) +{ +return test_snow3g_decryption (&snow3g_test_case_5); +}/* ***** AES-GCM Tests ***** */ static int
@@ -1917,8 +2211,30 @@ static struct unit_test_suite cryptodev_qat_testsuite = { TEST_CASE_ST(ut_setup, ut_teardown, test_AES_CBC_HMAC_AES_XCBC_decrypt_digest_verify), +/** Snow3G encrypt only (UEA2) */ + TEST_CASE_ST(ut_setup, ut_teardown, + test_snow3g_encryption_test_case_1), + TEST_CASE_ST(ut_setup, ut_teardown, + test_snow3g_encryption_test_case_2), + TEST_CASE_ST(ut_setup, ut_teardown, + test_snow3g_encryption_test_case_3), + TEST_CASE_ST(ut_setup, ut_teardown, + test_snow3g_encryption_test_case_4), + TEST_CASE_ST(ut_setup, ut_teardown, + test_snow3g_encryption_test_case_5), TEST_CASE_ST(ut_setup, ut_teardown, test_stats), +/** Snow3G decrypt only (UEA2) */ + TEST_CASE_ST(ut_setup, ut_teardown, + test_snow3g_decryption_test_case_1), + TEST_CASE_ST(ut_setup, ut_teardown, + test_snow3g_decryption_test_case_2), + TEST_CASE_ST(ut_setup, ut_teardown, + test_snow3g_decryption_test_case_3), + TEST_CASE_ST(ut_setup, ut_teardown, + test_snow3g_decryption_test_case_4), + TEST_CASE_ST(ut_setup, ut_teardown, + test_snow3g_decryption_test_case_5),TEST_CASES_END ()/**< NULL terminate unit test array */ } };
app/test/test_cryptodev.h +1 -1
@@ -1,7 +1,7 @@/*- * BSD LICENSE * -* Copyright(c) 2015 Intel Corporation. All rights reserved. +* Copyright(c) 2015-2016 Intel Corporation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions
app/test/test_cryptodev_snow3g_test_vectors.h new file +323 -0
323 lines not on this page · raw message
Signature · 1 line
2.1.0
v2 cover Snow3G support for Intel Quick Assist Devices
In reply to Deepak Kumar JAINThis patchset contains fixes and refactoring for Snow3G(UEA2 and UIA2) wireless algorithm for Intel Quick Assist devices.
QAT PMD previously supported only cipher/hash alg-chaining for AES/SHA.
The code has been refactored to also support cipher-only and hash only (for Snow3G only) functionality along with alg-chaining.
Changes from v1:
1) Hash only fix and alg chainging fix
2) Added hash test vectors for snow3g UIA2 functionality.
This patchset depends on
Cryptodev API changes
http://dpdk.org/ml/archives/dev/2016-February/033551.html
Deepak Kumar JAIN (3):
crypto: add cipher/auth only support
qat: add support for Snow3G
app/test: add Snow3G tests
app/test/test_cryptodev.c | 1037 +++++++++++++++++++- app/test/test_cryptodev.h | 3 +- app/test/test_cryptodev_snow3g_hash_test_vectors.h | 415 ++++++++ app/test/test_cryptodev_snow3g_test_vectors.h | 379 +++++++ doc/guides/cryptodevs/qat.rst | 8 +- doc/guides/rel_notes/release_16_04.rst | 4 + drivers/crypto/qat/qat_adf/qat_algs.h | 19 +- drivers/crypto/qat/qat_adf/qat_algs_build_desc.c | 280 +++++- drivers/crypto/qat/qat_crypto.c | 147 ++- drivers/crypto/qat/qat_crypto.h | 10 + 10 files changed, 2228 insertions(+), 74 deletions(-) create mode 100644 app/test/test_cryptodev_snow3g_hash_test_vectors.h create mode 100644 app/test/test_cryptodev_snow3g_test_vectors.h
Signature · 1 line
2.1.0
PATCH v2 1/3 crypto: add cipher/auth only support
Refactored the existing functionality into
modular form to support the cipher/auth only
functionalities.
--- drivers/crypto/qat/qat_adf/qat_algs.h | 18 +- drivers/crypto/qat/qat_adf/qat_algs_build_desc.c | 210 ++++++++++++++++++++--- drivers/crypto/qat/qat_crypto.c | 137 +++++++++++---- drivers/crypto/qat/qat_crypto.h | 10 ++ 4 files changed, 308 insertions(+), 67 deletions(-)
drivers/crypto/qat/qat_adf/qat_algs.h +11 -7
@@ -3,7 +3,7 @@* redistributing this file, you may do so under either license. * * GPL LICENSE SUMMARY -* Copyright(c) 2015 Intel Corporation. +* Copyright(c) 2015-2016 Intel Corporation. * This program is free software; you can redistribute it and/or modify * it under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation.
@@ -17,7 +17,7 @@* [email protected] * * BSD LICENSE -* Copyright(c) 2015 Intel Corporation. +* Copyright(c) 2015-2016 Intel Corporation. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met:
@@ -104,11 +104,15 @@ struct qat_alg_ablkcipher_cd {int qat_get_inter_state_size (enum icp_qat_hw_auth_algo qat_hash_alg); -int qat_alg_aead_session_create_content_desc (struct qat_session *cd, -uint8_t *enckey,uint32_t enckeylen, -uint8_t *authkey,uint32_t authkeylen, -uint32_t add_auth_data_length, -uint32_t digestsize); +int qat_alg_aead_session_create_content_desc_cipher (struct qat_session *cd, +uint8_t *enckey, +uint32_t enckeylen); + +int qat_alg_aead_session_create_content_desc_auth (struct qat_session *cdesc, +uint8_t *authkey, +uint32_t authkeylen, +uint32_t add_auth_data_length, +uint32_t digestsize);void qat_alg_init_common_hdr (struct icp_qat_fw_comn_req_hdr *header);
drivers/crypto/qat/qat_adf/qat_algs_build_desc.c +182 -28
272 lines not on this page · raw message
drivers/crypto/qat/qat_crypto.c +105 -32
177 lines not on this page · raw message
drivers/crypto/qat/qat_crypto.h +10 -0
@@ -111,6 +111,16 @@ extern void * qat_crypto_sym_configure_session(struct rte_cryptodev *dev, struct rte_crypto_sym_xform *xform, void *session_private); +struct qat_session * +qat_crypto_sym_configure_session_auth (struct rte_cryptodev *dev, +struct rte_crypto_sym_xform *xform, +struct qat_session *session_private); + +void * +qat_crypto_sym_configure_session_cipher (struct rte_cryptodev *dev, +struct rte_crypto_sym_xform *xform,void *session_private); + +extern void qat_crypto_sym_clear_session (struct rte_cryptodev *dev,void *session);
Signature · 1 line
2.1.0
PATCH v2 2/3 qat: add support for Snow3G
In reply to Deepak Kumar JAIN--- doc/guides/cryptodevs/qat.rst | 8 ++- doc/guides/rel_notes/release_16_04.rst | 4 ++ drivers/crypto/qat/qat_adf/qat_algs.h | 1 + drivers/crypto/qat/qat_adf/qat_algs_build_desc.c | 86 +++++++++++++++++++++--- drivers/crypto/qat/qat_crypto.c | 10 +++ 5 files changed, 97 insertions(+), 12 deletions(-)
doc/guides/cryptodevs/qat.rst +5 -3
@@ -1,5 +1,5 @@ .. BSD LICENSE - Copyright(c) 2015 Intel Corporation. All rights reserved. + Copyright(c) 2015-2016 Intel Corporation. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions
@@ -47,6 +47,7 @@ Cipher algorithms: * ``RTE_CRYPTO_SYM_CIPHER_AES128_CBC`` * ``RTE_CRYPTO_SYM_CIPHER_AES192_CBC`` * ``RTE_CRYPTO_SYM_CIPHER_AES256_CBC`` +* ``RTE_CRYPTO_SYM_CIPHER_SNOW3G_UEA2`` Hash algorithms:
@@ -54,14 +55,15 @@ Hash algorithms: * ``RTE_CRYPTO_AUTH_SHA256_HMAC`` * ``RTE_CRYPTO_AUTH_SHA512_HMAC`` * ``RTE_CRYPTO_AUTH_AES_XCBC_MAC`` +* ``RTE_CRYPTO_SYM_CIPHER_SNOW3G_UIA2`` Limitations ----------- * Chained mbufs are not supported. -* Hash only is not supported. -* Cipher only is not supported. +* Hash only is not supported except Snow3G UIA2. +* Cipher only is not supported except Snow3G UEA2. * Only in-place is currently supported (destination address is the same as source address). * Only supports the session-oriented API implementation (session-less APIs are not supported). * Not performance tuned.
doc/guides/rel_notes/release_16_04.rst +4 -0
@@ -39,6 +39,10 @@ This section should contain new features added in this release. Sample format: Enabled virtio 1.0 support for virtio pmd driver. +* **Added the support of Snow3g UEA2 Cipher operation for Intel Quick Assist Devices.** + + Enabled support for Snow3g Wireless algorithm for Intel Quick Assist devices. + Support for cipher only, Hash only is also provided laong with alg-chaing operations. Resolved Issues ---------------
drivers/crypto/qat/qat_adf/qat_algs.h +1 -0
@@ -125,5 +125,6 @@ void qat_alg_ablkcipher_init_dec(struct qat_alg_ablkcipher_cd *cd, unsigned int keylen);int qat_alg_validate_aes_key (int key_len,enum icp_qat_hw_cipher_algo *alg); +int qat_alg_validate_snow3g_key (int key_len,enum icp_qat_hw_cipher_algo *alg);#endif
drivers/crypto/qat/qat_adf/qat_algs_build_desc.c +77 -9
165 lines not on this page · raw message
drivers/crypto/qat/qat_crypto.c +10 -0
@@ -169,6 +169,14 @@ qat_crypto_sym_configure_session_cipher(struct rte_cryptodev *dev, } session->qat_mode =ICP_QAT_HW_CIPHER_CTR_MODE ;break ; +case RTE_CRYPTO_CIPHER_SNOW3G_UEA2 : +if (qat_alg_validate_snow3g_key (cipher_xform->key.length, + &session->qat_cipher_alg) !=0 ) { +PMD_DRV_LOG (ERR ,"Invalid SNOW3G cipher key size" ); + goto error_out; + } + session->qat_mode =ICP_QAT_HW_CIPHER_ECB_MODE ; +break ;case RTE_CRYPTO_CIPHER_NULL :case RTE_CRYPTO_CIPHER_3DES_ECB :case RTE_CRYPTO_CIPHER_3DES_CBC :
@@ -303,6 +311,8 @@ qat_crypto_sym_configure_session_auth(struct rte_cryptodev *dev,case RTE_CRYPTO_AUTH_AES_CCM :case RTE_CRYPTO_AUTH_KASUMI_F9 :case RTE_CRYPTO_AUTH_SNOW3G_UIA2 : + session->qat_hash_alg =ICP_QAT_HW_AUTH_ALGO_SNOW_3G_UIA2 ; +break ;case RTE_CRYPTO_AUTH_AES_CMAC :case RTE_CRYPTO_AUTH_AES_CBC_MAC :case RTE_CRYPTO_AUTH_ZUC_EIA3 :
Signature · 1 line
2.1.0
PATCH v2 3/3 app/test: add Snow3G tests
In reply to Deepak Kumar JAIN--- app/test/test_cryptodev.c | 1037 +++++++++++++++++++- app/test/test_cryptodev.h | 3 +- app/test/test_cryptodev_snow3g_hash_test_vectors.h | 415 ++++++++ app/test/test_cryptodev_snow3g_test_vectors.h | 379 +++++++ 4 files changed, 1831 insertions(+), 3 deletions(-) create mode 100644 app/test/test_cryptodev_snow3g_hash_test_vectors.h create mode 100644 app/test/test_cryptodev_snow3g_test_vectors.h
app/test/test_cryptodev.c +1035 -2
@@ -42,7 +42,8 @@#include "test.h" #include "test_cryptodev.h" - +#include "test_cryptodev_snow3g_test_vectors.h" +#include "test_cryptodev_snow3g_hash_test_vectors.h" static enum rte_cryptodev_type gbl_cryptodev_type;struct crypto_testsuite_params {
@@ -68,6 +69,9 @@ struct crypto_unittest_params {uint8_t *digest; }; +#define ALIGN_POW2_ROUNDUP (num, align) \ + (((num) + (align) - 1) & ~((align) - 1)) +/* * Forward declarations. */
@@ -1748,6 +1752,997 @@ test_AES_CBC_HMAC_AES_XCBC_decrypt_digest_verify(void)return TEST_SUCCESS ; } +/* ***** Snow3G Tests ***** */ +static int +create_snow3g_hash_session (uint8_t dev_id, +const uint8_t *key,const uint8_t key_len, +const uint8_t aad_len,const uint8_t auth_len, +enum rte_crypto_auth_operation op) +{ +uint8_t hash_key[key_len]; + +struct crypto_unittest_params *ut_params = &unittest_params; + +memcpy (hash_key, key, key_len); +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"key:" , key, key_len); +#endif +/* Setup Authentication Parameters */ + 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_SNOW3G_UIA2 ; + ut_params->auth_xform.auth.key.length = key_len; + ut_params->auth_xform.auth.key.data = hash_key; + ut_params->auth_xform.auth.digest_length = auth_len; + ut_params->auth_xform.auth.add_auth_data_length = aad_len; + 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_snow3g_cipher_session (uint8_t dev_id, +enum rte_crypto_cipher_operation op, +const uint8_t *key,const uint8_t key_len) +{ +uint8_t cipher_key[key_len]; + +struct crypto_unittest_params *ut_params = &unittest_params; + +memcpy (cipher_key, key, key_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 =RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ; + ut_params->cipher_xform.cipher.op = op; + ut_params->cipher_xform.cipher.key.data = cipher_key; + ut_params->cipher_xform.cipher.key.length = key_len; + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"key:" , key, key_len); +#endif +/* Create Crypto session */ + 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 +create_snow3g_cipher_operation (const uint8_t *iv,const unsigned iv_len, +const unsigned data_len) +{ +struct crypto_testsuite_params *ts_params = &testsuite_params; +struct crypto_unittest_params *ut_params = &unittest_params; +unsigned iv_pad_len =0 ; + +/* 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; + +/* iv */ + iv_pad_len =RTE_ALIGN_CEIL (iv_len,16 ); + 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 = iv_pad_len; + +rte_memcpy (sym_op->cipher.iv.data, iv, iv_len); + sym_op->cipher.data.length = data_len; + sym_op->cipher.data.offset = iv_pad_len; +return 0 ; +} + + +static int +create_snow3g_cipher_auth_session (uint8_t dev_id, +enum rte_crypto_cipher_operation cipher_op, +enum rte_crypto_auth_operation auth_op, +const uint8_t *key,const uint8_t key_len, +const uint8_t aad_len,const uint8_t auth_len) +{ +uint8_t cipher_auth_key[key_len]; + +struct crypto_unittest_params *ut_params = &unittest_params; + +memcpy (cipher_auth_key, key, key_len); + +/* Setup Authentication Parameters */ + ut_params->auth_xform.type =RTE_CRYPTO_SYM_XFORM_AUTH ; + ut_params->auth_xform.next =NULL ; + + ut_params->auth_xform.auth.op = auth_op; + ut_params->auth_xform.auth.algo =RTE_CRYPTO_AUTH_SNOW3G_UIA2 ; + ut_params->auth_xform.auth.key.length = key_len; +/* Hash key = cipher key */ + ut_params->auth_xform.auth.key.data = cipher_auth_key; + ut_params->auth_xform.auth.digest_length = auth_len; + ut_params->auth_xform.auth.add_auth_data_length = aad_len; + +/* 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_SNOW3G_UEA2 ; + ut_params->cipher_xform.cipher.op = cipher_op; + ut_params->cipher_xform.cipher.key.data = cipher_auth_key; + ut_params->cipher_xform.cipher.key.length = key_len; + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"key:" , key, key_len); +#endif +/* Create Crypto session*/ + 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 +create_snow3g_auth_cipher_session (uint8_t dev_id, +enum rte_crypto_cipher_operation cipher_op, +enum rte_crypto_auth_operation auth_op, +const uint8_t *key,const uint8_t key_len, +const uint8_t aad_len,const uint8_t auth_len) + { +uint8_t auth_cipher_key[key_len]; + +struct crypto_unittest_params *ut_params = &unittest_params; + +memcpy (auth_cipher_key, key, 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 =RTE_CRYPTO_AUTH_SNOW3G_UIA2 ; + ut_params->auth_xform.auth.key.length = key_len; + ut_params->auth_xform.auth.key.data = auth_cipher_key; + ut_params->auth_xform.auth.digest_length = auth_len; + ut_params->auth_xform.auth.add_auth_data_length = 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 =RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ; + ut_params->cipher_xform.cipher.op = cipher_op; + ut_params->cipher_xform.cipher.key.data = auth_cipher_key; + ut_params->cipher_xform.cipher.key.length = key_len; + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"key:" , key, key_len); +#endif +/* 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_snow3g_hash_operation (const uint8_t *auth_tag, +const unsigned auth_tag_len, +const uint8_t *aad,const unsigned aad_len, +const unsigned data_len,unsigned data_pad_len, +enum rte_crypto_auth_operation op) +{ +struct crypto_testsuite_params *ts_params = &testsuite_params; + +struct crypto_unittest_params *ut_params = &unittest_params; + +unsigned aad_buffer_len; + +/* 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 */ +/* +* Always allocate the aad up to the block size. +* The cryptodev API calls out - +* - the array must be big enough to hold the AAD, plus any +* space to round this up to the nearest multiple of the +* block size (16 bytes). +*/ + aad_buffer_len =ALIGN_POW2_ROUNDUP (aad_len,16 ); + sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend ( + ut_params->ibuf, aad_buffer_len); +TEST_ASSERT_NOT_NULL (sym_op->auth.aad.data, +"no room to prepend aad" ); + sym_op->auth.aad.phys_addr =rte_pktmbuf_mtophys ( + ut_params->ibuf); + sym_op->auth.aad.length = aad_len; + +memset (sym_op->auth.aad.data,0 , aad_buffer_len); +rte_memcpy (sym_op->auth.aad.data, aad, aad_len); + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"aad:" , + sym_op->auth.aad.data, aad_len); +#endif + +/* digest */ + sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append ( + ut_params->ibuf, auth_tag_len); + +TEST_ASSERT_NOT_NULL (sym_op->auth.digest.data, +"no room to append auth tag" ); + ut_params->digest = sym_op->auth.digest.data; + sym_op->auth.digest.phys_addr =rte_pktmbuf_mtophys_offset ( + ut_params->ibuf, data_pad_len + aad_len); + sym_op->auth.digest.length = auth_tag_len; +if (op ==RTE_CRYPTO_AUTH_OP_GENERATE ) +memset (sym_op->auth.digest.data,0 , auth_tag_len); +else +rte_memcpy (sym_op->auth.digest.data, auth_tag, auth_tag_len); + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"digest:" , + sym_op->auth.digest.data, + sym_op->auth.digest.length); +#endif + + sym_op->auth.data.length = data_len; + sym_op->auth.data.offset = aad_buffer_len; + +return 0 ; +} + +static int +create_snow3g_cipher_hash_operation (const uint8_t *auth_tag, +const unsigned auth_tag_len, +const uint8_t *aad,const unsigned aad_len, +const unsigned data_len,unsigned data_pad_len, +enum rte_crypto_auth_operation op, +const uint8_t *iv,const unsigned iv_len) +{ +struct crypto_testsuite_params *ts_params = &testsuite_params; +struct crypto_unittest_params *ut_params = &unittest_params; + +unsigned iv_pad_len =0 ; +unsigned aad_buffer_len; + +/* 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; + + +/* iv */ + iv_pad_len =RTE_ALIGN_CEIL (iv_len,16 ); + + 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 = iv_pad_len; + +rte_memcpy (sym_op->cipher.iv.data, iv, iv_len); + + sym_op->cipher.data.length = data_len; + sym_op->cipher.data.offset = iv_pad_len; + +/* aad */ +/* +* Always allocate the aad up to the block size. +* The cryptodev API calls out - +* - the array must be big enough to hold the AAD, plus any +* space to round this up to the nearest multiple of the +* block size (16 bytes). +*/ + aad_buffer_len =ALIGN_POW2_ROUNDUP (aad_len,16 ); + + sym_op->auth.aad.data = + (uint8_t *)rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *); +TEST_ASSERT_NOT_NULL (sym_op->auth.aad.data, +"no room to prepend aad" ); + sym_op->auth.aad.phys_addr =rte_pktmbuf_mtophys ( + ut_params->ibuf); + sym_op->auth.aad.length = aad_len; + +memset (sym_op->auth.aad.data,0 , aad_buffer_len); +rte_memcpy (sym_op->auth.aad.data, aad, aad_len); + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"aad:" , + sym_op->auth.aad.data, aad_len); +#endif + +/* digest */ + sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append ( + ut_params->ibuf, auth_tag_len); + +TEST_ASSERT_NOT_NULL (sym_op->auth.digest.data, +"no room to append auth tag" ); + ut_params->digest = sym_op->auth.digest.data; + sym_op->auth.digest.phys_addr =rte_pktmbuf_mtophys_offset ( + ut_params->ibuf, data_pad_len + aad_len); + sym_op->auth.digest.length = auth_tag_len; +if (op ==RTE_CRYPTO_AUTH_OP_GENERATE ) +memset (sym_op->auth.digest.data,0 , auth_tag_len); +else +rte_memcpy (sym_op->auth.digest.data, auth_tag, auth_tag_len); + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"digest:" , + sym_op->auth.digest.data, + sym_op->auth.digest.length); +#endif + + sym_op->auth.data.length = data_len; + sym_op->auth.data.offset = aad_buffer_len; + +return 0 ; +} + +static int +create_snow3g_auth_cipher_operation (const unsigned auth_tag_len, +const uint8_t *iv,const unsigned iv_len, +const uint8_t *aad,const unsigned aad_len, +const unsigned data_len,unsigned data_pad_len) +{ +struct crypto_testsuite_params *ts_params = &testsuite_params; +struct crypto_unittest_params *ut_params = &unittest_params; + +unsigned iv_pad_len =0 ; +unsigned aad_buffer_len =0 ; + +/* 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, auth_tag_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, data_pad_len); + sym_op->auth.digest.length = auth_tag_len; + +memset (sym_op->auth.digest.data,0 , auth_tag_len); + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"digest:" , + sym_op->auth.digest.data, + sym_op->auth.digest.length); +#endif +/* iv */ + iv_pad_len =RTE_ALIGN_CEIL (iv_len,16 ); + + 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 = iv_pad_len; + +rte_memcpy (sym_op->cipher.iv.data, iv, iv_len); + +/* aad */ +/* +* Always allocate the aad up to the block size. +* The cryptodev API calls out - +* - the array must be big enough to hold the AAD, plus any +* space to round this up to the nearest multiple of the +* block size (16 bytes). +*/ + aad_buffer_len =ALIGN_POW2_ROUNDUP (aad_len,16 ); + + sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend ( + ut_params->ibuf, aad_buffer_len); +TEST_ASSERT_NOT_NULL (sym_op->auth.aad.data, +"no room to prepend aad" ); + sym_op->auth.aad.phys_addr =rte_pktmbuf_mtophys ( + ut_params->ibuf); + sym_op->auth.aad.length = aad_len; + +memset (sym_op->auth.aad.data,0 , aad_buffer_len); +rte_memcpy (sym_op->auth.aad.data, aad, aad_len); + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"aad:" , + sym_op->auth.aad.data, aad_len); +#endif + + sym_op->cipher.data.length = data_len; + sym_op->cipher.data.offset = aad_buffer_len + iv_pad_len; + + sym_op->auth.data.length = data_len; + sym_op->auth.data.offset = aad_buffer_len + iv_pad_len; + +return 0 ; +} + +static int +test_snow3g_authentication (const struct snow3g_hash_test_data *tdata) +{ +struct crypto_testsuite_params *ts_params = &testsuite_params; +struct crypto_unittest_params *ut_params = &unittest_params; + +int retval; +unsigned plaintext_pad_len; +uint8_t *plaintext; + +/* Create SNOW3G session */ + retval =create_snow3g_hash_session (ts_params->valid_devs[0 ], + tdata->key.data, tdata->key.len, + tdata->aad.len, tdata->digest.len, +RTE_CRYPTO_AUTH_OP_GENERATE ); +if (retval <0 ) +return retval; + +/* 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)); + +/* Append data which is padded to a multiple of */ +/* the algorithms block size */ + plaintext_pad_len = tdata->plaintext.len; + plaintext = (uint8_t *)rte_pktmbuf_append (ut_params->ibuf, + plaintext_pad_len); +memcpy (plaintext, tdata->plaintext.data, tdata->plaintext.len); + +/* Create SNOW3G opertaion */ + retval =create_snow3g_hash_operation (NULL , tdata->digest.len, + tdata->aad.data, tdata->aad.len, tdata->plaintext.len, + plaintext_pad_len,RTE_CRYPTO_AUTH_OP_GENERATE ); +if (retval <0 ) +return retval; + + ut_params->op =process_crypto_request (ts_params->valid_devs[0 ], + ut_params->op); + ut_params->obuf = ut_params->op->sym->m_src; +TEST_ASSERT_NOT_NULL (ut_params->op,"failed to retrieve obuf" ); + ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) + + plaintext_pad_len + tdata->aad.len; + +/* Validate obuf */ +TEST_ASSERT_BUFFERS_ARE_EQUAL ( + ut_params->digest, + tdata->digest.data, +DIGEST_BYTE_LENGTH_SNOW3G_UIA2 , +"Snow3G Generated auth tag not as expected" ); + +return 0 ; +} + +static int +test_snow3g_authentication_verify (const struct snow3g_hash_test_data *tdata) +{ +struct crypto_testsuite_params *ts_params = &testsuite_params; +struct crypto_unittest_params *ut_params = &unittest_params; + +int retval; +unsigned plaintext_pad_len; +uint8_t *plaintext; + +/* Create SNOW3G session */ + retval =create_snow3g_hash_session (ts_params->valid_devs[0 ], + tdata->key.data, tdata->key.len, + tdata->aad.len, tdata->digest.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); + + memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, +rte_pktmbuf_tailroom (ut_params->ibuf)); + +/* Append data which is padded to a multiple */ +/* of the algorithms block size */ + plaintext_pad_len = tdata->plaintext.len; + plaintext = (uint8_t *)rte_pktmbuf_append (ut_params->ibuf, + plaintext_pad_len); +memcpy (plaintext, tdata->plaintext.data, tdata->plaintext.len); + +/* Create SNOW3G operation */ + retval =create_snow3g_hash_operation (tdata->digest.data, + tdata->digest.len, + tdata->aad.data, tdata->aad.len, + tdata->plaintext.len, plaintext_pad_len, +RTE_CRYPTO_AUTH_OP_VERIFY ); +if (retval <0 ) +return retval; + + ut_params->op =process_crypto_request (ts_params->valid_devs[0 ], + ut_params->op); +TEST_ASSERT_NOT_NULL (ut_params->op,"failed to retrieve obuf" ); + ut_params->obuf = ut_params->op->sym->m_src; + ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) + + plaintext_pad_len + tdata->aad.len; + +/* Validate obuf */ +if (ut_params->op->status ==RTE_CRYPTO_OP_STATUS_SUCCESS ) +return 0 ; +else +return -1 ; + +return 0 ; +} + + +static int +test_snow3g_hash_generate_test_case_1 (void ) +{ +return test_snow3g_authentication (&snow3g_hash_test_case_1); +} + +static int +test_snow3g_hash_generate_test_case_2 (void ) +{ +return test_snow3g_authentication (&snow3g_hash_test_case_2); +} + +static int +test_snow3g_hash_generate_test_case_3 (void ) +{ +return test_snow3g_authentication (&snow3g_hash_test_case_3); +} + +static int +test_snow3g_hash_verify_test_case_1 (void ) +{ +return test_snow3g_authentication_verify (&snow3g_hash_test_case_1); + +} + +static int +test_snow3g_hash_verify_test_case_2 (void ) +{ +return test_snow3g_authentication_verify (&snow3g_hash_test_case_2); +} + +static int +test_snow3g_hash_verify_test_case_3 (void ) +{ +return test_snow3g_authentication_verify (&snow3g_hash_test_case_3); +} + +static int +test_snow3g_encryption (const struct snow3g_test_data *tdata) +{ +struct crypto_testsuite_params *ts_params = &testsuite_params; +struct crypto_unittest_params *ut_params = &unittest_params; + +int retval; + +uint8_t *plaintext, *ciphertext; +uint8_t plaintext_pad_len; +uint8_t lastByteValidBits =8 ; +uint8_t lastByteMask =0xFF ; + +/* Create SNOW3G session */ + retval =create_snow3g_cipher_session (ts_params->valid_devs[0 ], +RTE_CRYPTO_CIPHER_OP_ENCRYPT , + tdata->key.data, tdata->key.len); +if (retval <0 ) +return retval; + + 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)); + +/* +* Append data which is padded to a +* multiple of the algorithms block size +*/ + plaintext_pad_len =RTE_ALIGN_CEIL (tdata->plaintext.len,16 ); + + plaintext = (uint8_t *)rte_pktmbuf_append (ut_params->ibuf, + plaintext_pad_len); +memcpy (plaintext, tdata->plaintext.data, tdata->plaintext.len); + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"plaintext:" , plaintext, tdata->plaintext.len); +#endif +/* Create SNOW3G operation */ + retval =create_snow3g_cipher_operation (tdata->iv.data, tdata->iv.len, + tdata->plaintext.len); +if (retval <0 ) +return retval; + + ut_params->op =process_crypto_request (ts_params->valid_devs[0 ], + ut_params->op); +TEST_ASSERT_NOT_NULL (ut_params->op,"failed to retrieve obuf" ); + + ut_params->obuf = ut_params->op->sym->m_src; +if (ut_params->obuf) + ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) + + tdata->iv.len; +else + ciphertext = plaintext; + + lastByteValidBits = (tdata->validDataLenInBits.len %8 ); +if (lastByteValidBits ==0 ) + lastByteValidBits =8 ; + lastByteMask = lastByteMask << (8 - lastByteValidBits); + (*(ciphertext + tdata->ciphertext.len -1 )) &= lastByteMask; + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"ciphertext:" , ciphertext, tdata->ciphertext.len); +#endif +/* Validate obuf */ +TEST_ASSERT_BUFFERS_ARE_EQUAL ( + ciphertext, + tdata->ciphertext.data, + tdata->ciphertext.len, +"Snow3G Ciphertext data not as expected" ); +return 0 ; +} + +static int test_snow3g_decryption (const struct snow3g_test_data *tdata) +{ +struct crypto_testsuite_params *ts_params = &testsuite_params; +struct crypto_unittest_params *ut_params = &unittest_params; + +int retval; + +uint8_t *plaintext, *ciphertext; +uint8_t ciphertext_pad_len; +uint8_t lastByteValidBits =8 ; +uint8_t lastByteMask =0xFF ; + +/* Create SNOW3G session */ + retval =create_snow3g_cipher_session (ts_params->valid_devs[0 ], +RTE_CRYPTO_CIPHER_OP_DECRYPT , + tdata->key.data, tdata->key.len); +if (retval <0 ) +return retval; + + 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)); + +/* +* Append data which is padded to a +* multiple of the algorithms block size +*/ + ciphertext_pad_len =RTE_ALIGN_CEIL (tdata->ciphertext.len,16 ); + + ciphertext = (uint8_t *)rte_pktmbuf_append (ut_params->ibuf, + ciphertext_pad_len); +memcpy (ciphertext, tdata->ciphertext.data, tdata->ciphertext.len); + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"ciphertext:" , ciphertext, tdata->ciphertext.len); +#endif +/* Create SNOW3G operation */ + retval =create_snow3g_cipher_operation (tdata->iv.data, tdata->iv.len, + tdata->ciphertext.len); +if (retval <0 ) +return retval; + + ut_params->op =process_crypto_request (ts_params->valid_devs[0 ], + ut_params->op); +TEST_ASSERT_NOT_NULL (ut_params->op,"failed to retrieve obuf" ); + ut_params->obuf = ut_params->op->sym->m_src; +if (ut_params->obuf) + plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) + + tdata->iv.len; +else + plaintext = ciphertext; + lastByteValidBits = (tdata->validDataLenInBits.len %8 ); +if (lastByteValidBits ==0 ) + lastByteValidBits =8 ; + lastByteMask = lastByteMask << (8 - lastByteValidBits); + (*(ciphertext + tdata->ciphertext.len -1 )) &= lastByteMask; + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"plaintext:" , plaintext, tdata->plaintext.len); +#endif +/* Validate obuf */ +TEST_ASSERT_BUFFERS_ARE_EQUAL (plaintext, + tdata->plaintext.data, + tdata->plaintext.len, +"Snow3G Plaintext data not as expected" ); +return 0 ; +} + +static int +test_snow3g_authenticated_encryption (const struct snow3g_test_data *tdata) +{ +struct crypto_testsuite_params *ts_params = &testsuite_params; +struct crypto_unittest_params *ut_params = &unittest_params; + +int retval; + +uint8_t *plaintext, *ciphertext; +uint8_t plaintext_pad_len; +uint8_t lastByteValidBits =8 ; +uint8_t lastByteMask =0xFF ; + +/* Create SNOW3G session */ + retval =create_snow3g_cipher_auth_session (ts_params->valid_devs[0 ], +RTE_CRYPTO_CIPHER_OP_ENCRYPT , +RTE_CRYPTO_AUTH_OP_GENERATE , + tdata->key.data, tdata->key.len, + tdata->aad.len, tdata->digest.len); +if (retval <0 ) +return retval; + 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)); + +/* Append data which is padded to a multiple */ +/* of the algorithms block size */ + plaintext_pad_len = tdata->plaintext.len; + + plaintext = (uint8_t *)rte_pktmbuf_append (ut_params->ibuf, + plaintext_pad_len); +memcpy (plaintext, tdata->plaintext.data, tdata->plaintext.len); + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"plaintext:" , plaintext, tdata->plaintext.len); +#endif + +/* Create SNOW3G operation */ + retval =create_snow3g_cipher_hash_operation (tdata->digest.data, + tdata->digest.len, tdata->aad.data, + tdata->aad.len, tdata->plaintext.len, + plaintext_pad_len,RTE_CRYPTO_AUTH_OP_GENERATE , + tdata->iv.data, tdata->iv.len); +if (retval <0 ) +return retval; + + ut_params->op =process_crypto_request (ts_params->valid_devs[0 ], + ut_params->op); +TEST_ASSERT_NOT_NULL (ut_params->op,"failed to retrieve obuf" ); + ut_params->obuf = ut_params->op->sym->m_src; +if (ut_params->obuf) + ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) + + tdata->iv.len; +else + ciphertext = plaintext; + lastByteValidBits = (tdata->validDataLenInBits.len %8 ); +if (lastByteValidBits ==0 ) + lastByteValidBits =8 ; + lastByteMask = lastByteMask << (8 -lastByteValidBits); + (*(ciphertext + tdata->ciphertext.len -1 )) &= lastByteMask; + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"ciphertext:" , ciphertext, tdata->ciphertext.len); +#endif +/* Validate obuf */ +TEST_ASSERT_BUFFERS_ARE_EQUAL ( + ciphertext, + tdata->ciphertext.data, + tdata->ciphertext.len, +"Snow3G Ciphertext data not as expected" ); + + ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) + + plaintext_pad_len + tdata->aad.len; + +/* Validate obuf */ +TEST_ASSERT_BUFFERS_ARE_EQUAL ( + ut_params->digest, + tdata->digest.data, +DIGEST_BYTE_LENGTH_SNOW3G_UIA2 , +"Snow3G Generated auth tag not as expected" ); +return 0 ; +} +static int +test_snow3g_encrypted_authentication (const struct snow3g_test_data *tdata) +{ +struct crypto_testsuite_params *ts_params = &testsuite_params; +struct crypto_unittest_params *ut_params = &unittest_params; + +int retval; + +uint8_t *plaintext, *ciphertext; +uint8_t plaintext_pad_len; +uint8_t lastByteValidBits =8 ; +uint8_t lastByteMask =0xFF ; + +/* Create SNOW3G session */ + retval =create_snow3g_auth_cipher_session (ts_params->valid_devs[0 ], +RTE_CRYPTO_CIPHER_OP_ENCRYPT , +RTE_CRYPTO_AUTH_OP_GENERATE , + tdata->key.data, tdata->key.len, + tdata->aad.len, tdata->digest.len); +if (retval <0 ) +return retval; + + 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)); + +/* Append data which is padded to a multiple */ +/* of the algorithms block size */ + plaintext_pad_len =RTE_ALIGN_CEIL (tdata->plaintext.len,8 ); + + plaintext = (uint8_t *)rte_pktmbuf_append (ut_params->ibuf, + plaintext_pad_len); +memcpy (plaintext, tdata->plaintext.data, tdata->plaintext.len); + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"plaintext:" , plaintext, tdata->plaintext.len); +#endif + +/* Create SNOW3G operation */ + retval =create_snow3g_auth_cipher_operation ( + tdata->digest.len, + tdata->iv.data, tdata->iv.len, + tdata->aad.data, tdata->aad.len, + tdata->plaintext.len, plaintext_pad_len + ); + +if (retval <0 ) +return retval; + + ut_params->op =process_crypto_request (ts_params->valid_devs[0 ], + ut_params->op); +TEST_ASSERT_NOT_NULL (ut_params->op,"failed to retrieve obuf" ); + ut_params->obuf = ut_params->op->sym->m_src; +if (ut_params->obuf) + ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) + + tdata->aad.len + tdata->iv.len; +else + ciphertext = plaintext; + + lastByteValidBits = (tdata->validDataLenInBits.len %8 ); +if (lastByteValidBits ==0 ) + lastByteValidBits =8 ; + lastByteMask = lastByteMask << (8 -lastByteValidBits); + (*(ciphertext + tdata->ciphertext.len -1 )) &= lastByteMask; + ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) + + plaintext_pad_len + tdata->aad.len + tdata->iv.len; + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"ciphertext:" , ciphertext, tdata->ciphertext.len); +#endif +/* Validate obuf */ +TEST_ASSERT_BUFFERS_ARE_EQUAL ( + ciphertext, + tdata->ciphertext.data, + tdata->ciphertext.len, +"Snow3G Ciphertext data not as expected" ); + +/* Validate obuf */ +TEST_ASSERT_BUFFERS_ARE_EQUAL ( + ut_params->digest, + tdata->digest.data, +DIGEST_BYTE_LENGTH_SNOW3G_UIA2 , +"Snow3G Generated auth tag not as expected" ); +return 0 ; +} + +static int +test_snow3g_encryption_test_case_1 (void ) +{ +return test_snow3g_encryption (&snow3g_test_case_1); +} + +static int +test_snow3g_encryption_test_case_2 (void ) +{ +return test_snow3g_encryption (&snow3g_test_case_2); +} + +static int +test_snow3g_encryption_test_case_3 (void ) +{ +return test_snow3g_encryption (&snow3g_test_case_3); +} + +static int +test_snow3g_encryption_test_case_4 (void ) +{ +return test_snow3g_encryption (&snow3g_test_case_4); +} + +static int +test_snow3g_encryption_test_case_5 (void ) +{ +return test_snow3g_encryption (&snow3g_test_case_5); +} + +static int +test_snow3g_decryption_test_case_1 (void ) +{ +return test_snow3g_decryption (&snow3g_test_case_1); +} + +static int +test_snow3g_decryption_test_case_2 (void ) +{ +return test_snow3g_decryption (&snow3g_test_case_2); +} + +static int +test_snow3g_decryption_test_case_3 (void ) +{ +return test_snow3g_decryption (&snow3g_test_case_3); +} + +static int +test_snow3g_decryption_test_case_4 (void ) +{ +return test_snow3g_decryption (&snow3g_test_case_4); +} + +static int +test_snow3g_decryption_test_case_5 (void ) +{ +return test_snow3g_decryption (&snow3g_test_case_5); +} +static int +test_snow3g_authenticated_encryption_test_case_1 (void ) +{ +return test_snow3g_authenticated_encryption (&snow3g_test_case_3); +} + +static int +test_snow3g_encrypted_authentication_test_case_1 (void ) +{ +return test_snow3g_encrypted_authentication (&snow3g_test_case_6); +}/* ***** AES-GCM Tests ***** */
@@ -1983,9 +2978,47 @@ static struct unit_test_suite cryptodev_qat_testsuite = { test_AES_CBC_HMAC_AES_XCBC_encrypt_digest),TEST_CASE_ST (ut_setup ,ut_teardown ,test_AES_CBC_HMAC_AES_XCBC_decrypt_digest_verify ), -TEST_CASE_ST (ut_setup ,ut_teardown ,test_stats ), +/** Snow3G encrypt only (UEA2) */ +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_encryption_test_case_1 ), +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_encryption_test_case_2 ), +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_encryption_test_case_3 ), +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_encryption_test_case_4 ), +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_encryption_test_case_5 ), + +/** Snow3G decrypt only (UEA2) */ +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_decryption_test_case_1 ), +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_decryption_test_case_2 ), +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_decryption_test_case_3 ), +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_decryption_test_case_4 ), +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_decryption_test_case_5 ), +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_hash_generate_test_case_1 ), +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_hash_generate_test_case_2 ), +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_hash_generate_test_case_3 ), +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_hash_verify_test_case_1 ), +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_hash_verify_test_case_2 ), +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_hash_verify_test_case_3 ), +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_authenticated_encryption_test_case_1 ), +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_encrypted_authentication_test_case_1 ),TEST_CASES_END ()/**< NULL terminate unit test array */ } };
app/test/test_cryptodev.h +2 -1
@@ -1,7 +1,7 @@/*- * BSD LICENSE * -* Copyright(c) 2015 Intel Corporation. All rights reserved. +* Copyright(c) 2015-2016 Intel Corporation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions
@@ -58,6 +58,7 @@#define DIGEST_BYTE_LENGTH_SHA384 (BYTE_LENGTH(384))#define DIGEST_BYTE_LENGTH_SHA512 (BYTE_LENGTH(512))#define DIGEST_BYTE_LENGTH_AES_XCBC (BYTE_LENGTH(96)) +#define DIGEST_BYTE_LENGTH_SNOW3G_UIA2 (BYTE_LENGTH(32))#define AES_XCBC_MAC_KEY_SZ (16)#define TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 (12)
app/test/test_cryptodev_snow3g_hash_test_vectors.h new file +415 -0
415 lines not on this page · raw message
app/test/test_cryptodev_snow3g_test_vectors.h new file +379 -0
379 lines not on this page · raw message
Signature · 1 line
2.1.0
v3 cover Snow3G support for Intel Quick Assist Devices
In reply to Deepak Kumar JAINThis patchset contains fixes and refactoring for Snow3G(UEA2 and UIA2) wireless algorithm for Intel Quick Assist devices.
QAT PMD previously supported only cipher/hash alg-chaining for AES/SHA. The code has been refactored to also support cipher-only and hash only (for Snow3G only) functionality along with alg-chaining.
Changes from v2:
1) Rebasing based on below mentioned patchset.
This patchset depends on
cryptodev API changes
http://dpdk.org/ml/archives/dev/2016-February/034212.html
Deepak Kumar JAIN (3):
crypto: add cipher/auth only support
qat: add support for Snow3G
app/test: add Snow3G tests
app/test/test_cryptodev.c | 1037 +++++++++++++++++++- app/test/test_cryptodev.h | 3 +- app/test/test_cryptodev_snow3g_hash_test_vectors.h | 415 ++++++++ app/test/test_cryptodev_snow3g_test_vectors.h | 379 +++++++ doc/guides/cryptodevs/qat.rst | 8 +- doc/guides/rel_notes/release_16_04.rst | 6 + drivers/crypto/qat/qat_adf/qat_algs.h | 19 +- drivers/crypto/qat/qat_adf/qat_algs_build_desc.c | 280 +++++- drivers/crypto/qat/qat_crypto.c | 149 ++- drivers/crypto/qat/qat_crypto.h | 10 + 10 files changed, 2231 insertions(+), 75 deletions(-) create mode 100644 app/test/test_cryptodev_snow3g_hash_test_vectors.h create mode 100644 app/test/test_cryptodev_snow3g_test_vectors.h
Signature · 1 line
2.1.0
PATCH v3 1/3 crypto: add cipher/auth only support
Refactored the existing functionality into
modular form to support the cipher/auth only
functionalities.
--- drivers/crypto/qat/qat_adf/qat_algs.h | 18 +- drivers/crypto/qat/qat_adf/qat_algs_build_desc.c | 210 ++++++++++++++++++++--- drivers/crypto/qat/qat_crypto.c | 137 +++++++++++---- drivers/crypto/qat/qat_crypto.h | 10 ++ 4 files changed, 308 insertions(+), 67 deletions(-)
drivers/crypto/qat/qat_adf/qat_algs.h +11 -7
@@ -3,7 +3,7 @@* redistributing this file, you may do so under either license. * * GPL LICENSE SUMMARY -* Copyright(c) 2015 Intel Corporation. +* Copyright(c) 2015-2016 Intel Corporation. * This program is free software; you can redistribute it and/or modify * it under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation.
@@ -17,7 +17,7 @@* [email protected] * * BSD LICENSE -* Copyright(c) 2015 Intel Corporation. +* Copyright(c) 2015-2016 Intel Corporation. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met:
@@ -104,11 +104,15 @@ struct qat_alg_ablkcipher_cd {int qat_get_inter_state_size (enum icp_qat_hw_auth_algo qat_hash_alg); -int qat_alg_aead_session_create_content_desc (struct qat_session *cd, -uint8_t *enckey,uint32_t enckeylen, -uint8_t *authkey,uint32_t authkeylen, -uint32_t add_auth_data_length, -uint32_t digestsize); +int qat_alg_aead_session_create_content_desc_cipher (struct qat_session *cd, +uint8_t *enckey, +uint32_t enckeylen); + +int qat_alg_aead_session_create_content_desc_auth (struct qat_session *cdesc, +uint8_t *authkey, +uint32_t authkeylen, +uint32_t add_auth_data_length, +uint32_t digestsize);void qat_alg_init_common_hdr (struct icp_qat_fw_comn_req_hdr *header);
drivers/crypto/qat/qat_adf/qat_algs_build_desc.c +182 -28
272 lines not on this page · raw message
drivers/crypto/qat/qat_crypto.c +105 -32
177 lines not on this page · raw message
drivers/crypto/qat/qat_crypto.h +10 -0
@@ -111,6 +111,16 @@ extern void * qat_crypto_sym_configure_session(struct rte_cryptodev *dev, struct rte_crypto_sym_xform *xform, void *session_private); +struct qat_session * +qat_crypto_sym_configure_session_auth (struct rte_cryptodev *dev, +struct rte_crypto_sym_xform *xform, +struct qat_session *session_private); + +void * +qat_crypto_sym_configure_session_cipher (struct rte_cryptodev *dev, +struct rte_crypto_sym_xform *xform,void *session_private); + +extern void qat_crypto_sym_clear_session (struct rte_cryptodev *dev,void *session);
Signature · 1 line
2.1.0
PATCH v3 2/3 qat: add support for Snow3G
In reply to Deepak Kumar JAIN--- doc/guides/cryptodevs/qat.rst | 8 ++- doc/guides/rel_notes/release_16_04.rst | 6 ++ drivers/crypto/qat/qat_adf/qat_algs.h | 1 + drivers/crypto/qat/qat_adf/qat_algs_build_desc.c | 86 +++++++++++++++++++++--- drivers/crypto/qat/qat_crypto.c | 12 +++- 5 files changed, 100 insertions(+), 13 deletions(-)
doc/guides/cryptodevs/qat.rst +5 -3
@@ -1,5 +1,5 @@ .. BSD LICENSE - Copyright(c) 2015 Intel Corporation. All rights reserved. + Copyright(c) 2015-2016 Intel Corporation. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions
@@ -47,6 +47,7 @@ Cipher algorithms: * ``RTE_CRYPTO_SYM_CIPHER_AES128_CBC`` * ``RTE_CRYPTO_SYM_CIPHER_AES192_CBC`` * ``RTE_CRYPTO_SYM_CIPHER_AES256_CBC`` +* ``RTE_CRYPTO_SYM_CIPHER_SNOW3G_UEA2`` Hash algorithms:
@@ -54,14 +55,15 @@ Hash algorithms: * ``RTE_CRYPTO_AUTH_SHA256_HMAC`` * ``RTE_CRYPTO_AUTH_SHA512_HMAC`` * ``RTE_CRYPTO_AUTH_AES_XCBC_MAC`` +* ``RTE_CRYPTO_AUTH_SNOW3G_UIA2`` Limitations ----------- * Chained mbufs are not supported. -* Hash only is not supported. -* Cipher only is not supported. +* Hash only is not supported except Snow3G UIA2. +* Cipher only is not supported except Snow3G UEA2. * Only in-place is currently supported (destination address is the same as source address). * Only supports the session-oriented API implementation (session-less APIs are not supported). * Not performance tuned.
doc/guides/rel_notes/release_16_04.rst +6 -0
@@ -35,6 +35,12 @@ This section should contain new features added in this release. Sample format: Refer to the previous release notes for examples. +* **Added support of Snow3G (UEA2 and UIA2) for Intel Quick Assist Devices.** + + Enabled support for Snow3g Wireless algorithm for Intel Quick Assist devices. + Support for cipher only, Hash only is also provided + along with alg-chaining operations. + * **Enabled bulk allocation of mbufs.** A new function ``rte_pktmbuf_alloc_bulk()`` has been added to allow the user
drivers/crypto/qat/qat_adf/qat_algs.h +1 -0
@@ -125,5 +125,6 @@ void qat_alg_ablkcipher_init_dec(struct qat_alg_ablkcipher_cd *cd, unsigned int keylen);int qat_alg_validate_aes_key (int key_len,enum icp_qat_hw_cipher_algo *alg); +int qat_alg_validate_snow3g_key (int key_len,enum icp_qat_hw_cipher_algo *alg);#endif
drivers/crypto/qat/qat_adf/qat_algs_build_desc.c +77 -9
165 lines not on this page · raw message
drivers/crypto/qat/qat_crypto.c +11 -1
@@ -169,6 +169,14 @@ qat_crypto_sym_configure_session_cipher(struct rte_cryptodev *dev, } session->qat_mode =ICP_QAT_HW_CIPHER_CTR_MODE ;break ; +case RTE_CRYPTO_CIPHER_SNOW3G_UEA2 : +if (qat_alg_validate_snow3g_key (cipher_xform->key.length, + &session->qat_cipher_alg) !=0 ) { +PMD_DRV_LOG (ERR ,"Invalid SNOW3G cipher key size" ); + goto error_out; + } + session->qat_mode =ICP_QAT_HW_CIPHER_ECB_MODE ; +break ;case RTE_CRYPTO_CIPHER_NULL :case RTE_CRYPTO_CIPHER_3DES_ECB :case RTE_CRYPTO_CIPHER_3DES_CBC :
@@ -290,6 +298,9 @@ qat_crypto_sym_configure_session_auth(struct rte_cryptodev *dev,case RTE_CRYPTO_AUTH_AES_GMAC : session->qat_hash_alg =ICP_QAT_HW_AUTH_ALGO_GALOIS_128 ;break ; +case RTE_CRYPTO_AUTH_SNOW3G_UIA2 : + session->qat_hash_alg =ICP_QAT_HW_AUTH_ALGO_SNOW_3G_UIA2 ; +break ;case RTE_CRYPTO_AUTH_NULL :case RTE_CRYPTO_AUTH_SHA1 :case RTE_CRYPTO_AUTH_SHA256 :
@@ -302,7 +313,6 @@ qat_crypto_sym_configure_session_auth(struct rte_cryptodev *dev,case RTE_CRYPTO_AUTH_MD5_HMAC :case RTE_CRYPTO_AUTH_AES_CCM :case RTE_CRYPTO_AUTH_KASUMI_F9 : -case RTE_CRYPTO_AUTH_SNOW3G_UIA2 :case RTE_CRYPTO_AUTH_AES_CMAC :case RTE_CRYPTO_AUTH_AES_CBC_MAC :case RTE_CRYPTO_AUTH_ZUC_EIA3 :
Signature · 1 line
2.1.0
PATCH v3 3/3 app/test: add Snow3G tests
In reply to Deepak Kumar JAIN--- app/test/test_cryptodev.c | 1037 +++++++++++++++++++- app/test/test_cryptodev.h | 3 +- app/test/test_cryptodev_snow3g_hash_test_vectors.h | 415 ++++++++ app/test/test_cryptodev_snow3g_test_vectors.h | 379 +++++++ 4 files changed, 1831 insertions(+), 3 deletions(-) create mode 100644 app/test/test_cryptodev_snow3g_hash_test_vectors.h create mode 100644 app/test/test_cryptodev_snow3g_test_vectors.h
app/test/test_cryptodev.c +1035 -2
@@ -42,7 +42,8 @@#include "test.h" #include "test_cryptodev.h" - +#include "test_cryptodev_snow3g_test_vectors.h" +#include "test_cryptodev_snow3g_hash_test_vectors.h" static enum rte_cryptodev_type gbl_cryptodev_type;struct crypto_testsuite_params {
@@ -68,6 +69,9 @@ struct crypto_unittest_params {uint8_t *digest; }; +#define ALIGN_POW2_ROUNDUP (num, align) \ + (((num) + (align) - 1) & ~((align) - 1)) +/* * Forward declarations. */
@@ -1748,6 +1752,997 @@ test_AES_CBC_HMAC_AES_XCBC_decrypt_digest_verify(void)return TEST_SUCCESS ; } +/* ***** Snow3G Tests ***** */ +static int +create_snow3g_hash_session (uint8_t dev_id, +const uint8_t *key,const uint8_t key_len, +const uint8_t aad_len,const uint8_t auth_len, +enum rte_crypto_auth_operation op) +{ +uint8_t hash_key[key_len]; + +struct crypto_unittest_params *ut_params = &unittest_params; + +memcpy (hash_key, key, key_len); +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"key:" , key, key_len); +#endif +/* Setup Authentication Parameters */ + 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_SNOW3G_UIA2 ; + ut_params->auth_xform.auth.key.length = key_len; + ut_params->auth_xform.auth.key.data = hash_key; + ut_params->auth_xform.auth.digest_length = auth_len; + ut_params->auth_xform.auth.add_auth_data_length = aad_len; + 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_snow3g_cipher_session (uint8_t dev_id, +enum rte_crypto_cipher_operation op, +const uint8_t *key,const uint8_t key_len) +{ +uint8_t cipher_key[key_len]; + +struct crypto_unittest_params *ut_params = &unittest_params; + +memcpy (cipher_key, key, key_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 =RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ; + ut_params->cipher_xform.cipher.op = op; + ut_params->cipher_xform.cipher.key.data = cipher_key; + ut_params->cipher_xform.cipher.key.length = key_len; + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"key:" , key, key_len); +#endif +/* Create Crypto session */ + 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 +create_snow3g_cipher_operation (const uint8_t *iv,const unsigned iv_len, +const unsigned data_len) +{ +struct crypto_testsuite_params *ts_params = &testsuite_params; +struct crypto_unittest_params *ut_params = &unittest_params; +unsigned iv_pad_len =0 ; + +/* 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; + +/* iv */ + iv_pad_len =RTE_ALIGN_CEIL (iv_len,16 ); + 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 = iv_pad_len; + +rte_memcpy (sym_op->cipher.iv.data, iv, iv_len); + sym_op->cipher.data.length = data_len; + sym_op->cipher.data.offset = iv_pad_len; +return 0 ; +} + + +static int +create_snow3g_cipher_auth_session (uint8_t dev_id, +enum rte_crypto_cipher_operation cipher_op, +enum rte_crypto_auth_operation auth_op, +const uint8_t *key,const uint8_t key_len, +const uint8_t aad_len,const uint8_t auth_len) +{ +uint8_t cipher_auth_key[key_len]; + +struct crypto_unittest_params *ut_params = &unittest_params; + +memcpy (cipher_auth_key, key, key_len); + +/* Setup Authentication Parameters */ + ut_params->auth_xform.type =RTE_CRYPTO_SYM_XFORM_AUTH ; + ut_params->auth_xform.next =NULL ; + + ut_params->auth_xform.auth.op = auth_op; + ut_params->auth_xform.auth.algo =RTE_CRYPTO_AUTH_SNOW3G_UIA2 ; + ut_params->auth_xform.auth.key.length = key_len; +/* Hash key = cipher key */ + ut_params->auth_xform.auth.key.data = cipher_auth_key; + ut_params->auth_xform.auth.digest_length = auth_len; + ut_params->auth_xform.auth.add_auth_data_length = aad_len; + +/* 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_SNOW3G_UEA2 ; + ut_params->cipher_xform.cipher.op = cipher_op; + ut_params->cipher_xform.cipher.key.data = cipher_auth_key; + ut_params->cipher_xform.cipher.key.length = key_len; + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"key:" , key, key_len); +#endif +/* Create Crypto session*/ + 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 +create_snow3g_auth_cipher_session (uint8_t dev_id, +enum rte_crypto_cipher_operation cipher_op, +enum rte_crypto_auth_operation auth_op, +const uint8_t *key,const uint8_t key_len, +const uint8_t aad_len,const uint8_t auth_len) + { +uint8_t auth_cipher_key[key_len]; + +struct crypto_unittest_params *ut_params = &unittest_params; + +memcpy (auth_cipher_key, key, 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 =RTE_CRYPTO_AUTH_SNOW3G_UIA2 ; + ut_params->auth_xform.auth.key.length = key_len; + ut_params->auth_xform.auth.key.data = auth_cipher_key; + ut_params->auth_xform.auth.digest_length = auth_len; + ut_params->auth_xform.auth.add_auth_data_length = 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 =RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ; + ut_params->cipher_xform.cipher.op = cipher_op; + ut_params->cipher_xform.cipher.key.data = auth_cipher_key; + ut_params->cipher_xform.cipher.key.length = key_len; + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"key:" , key, key_len); +#endif +/* 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_snow3g_hash_operation (const uint8_t *auth_tag, +const unsigned auth_tag_len, +const uint8_t *aad,const unsigned aad_len, +const unsigned data_len,unsigned data_pad_len, +enum rte_crypto_auth_operation op) +{ +struct crypto_testsuite_params *ts_params = &testsuite_params; + +struct crypto_unittest_params *ut_params = &unittest_params; + +unsigned aad_buffer_len; + +/* 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 */ +/* +* Always allocate the aad up to the block size. +* The cryptodev API calls out - +* - the array must be big enough to hold the AAD, plus any +* space to round this up to the nearest multiple of the +* block size (16 bytes). +*/ + aad_buffer_len =ALIGN_POW2_ROUNDUP (aad_len,16 ); + sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend ( + ut_params->ibuf, aad_buffer_len); +TEST_ASSERT_NOT_NULL (sym_op->auth.aad.data, +"no room to prepend aad" ); + sym_op->auth.aad.phys_addr =rte_pktmbuf_mtophys ( + ut_params->ibuf); + sym_op->auth.aad.length = aad_len; + +memset (sym_op->auth.aad.data,0 , aad_buffer_len); +rte_memcpy (sym_op->auth.aad.data, aad, aad_len); + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"aad:" , + sym_op->auth.aad.data, aad_len); +#endif + +/* digest */ + sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append ( + ut_params->ibuf, auth_tag_len); + +TEST_ASSERT_NOT_NULL (sym_op->auth.digest.data, +"no room to append auth tag" ); + ut_params->digest = sym_op->auth.digest.data; + sym_op->auth.digest.phys_addr =rte_pktmbuf_mtophys_offset ( + ut_params->ibuf, data_pad_len + aad_len); + sym_op->auth.digest.length = auth_tag_len; +if (op ==RTE_CRYPTO_AUTH_OP_GENERATE ) +memset (sym_op->auth.digest.data,0 , auth_tag_len); +else +rte_memcpy (sym_op->auth.digest.data, auth_tag, auth_tag_len); + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"digest:" , + sym_op->auth.digest.data, + sym_op->auth.digest.length); +#endif + + sym_op->auth.data.length = data_len; + sym_op->auth.data.offset = aad_buffer_len; + +return 0 ; +} + +static int +create_snow3g_cipher_hash_operation (const uint8_t *auth_tag, +const unsigned auth_tag_len, +const uint8_t *aad,const unsigned aad_len, +const unsigned data_len,unsigned data_pad_len, +enum rte_crypto_auth_operation op, +const uint8_t *iv,const unsigned iv_len) +{ +struct crypto_testsuite_params *ts_params = &testsuite_params; +struct crypto_unittest_params *ut_params = &unittest_params; + +unsigned iv_pad_len =0 ; +unsigned aad_buffer_len; + +/* 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; + + +/* iv */ + iv_pad_len =RTE_ALIGN_CEIL (iv_len,16 ); + + 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 = iv_pad_len; + +rte_memcpy (sym_op->cipher.iv.data, iv, iv_len); + + sym_op->cipher.data.length = data_len; + sym_op->cipher.data.offset = iv_pad_len; + +/* aad */ +/* +* Always allocate the aad up to the block size. +* The cryptodev API calls out - +* - the array must be big enough to hold the AAD, plus any +* space to round this up to the nearest multiple of the +* block size (16 bytes). +*/ + aad_buffer_len =ALIGN_POW2_ROUNDUP (aad_len,16 ); + + sym_op->auth.aad.data = + (uint8_t *)rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *); +TEST_ASSERT_NOT_NULL (sym_op->auth.aad.data, +"no room to prepend aad" ); + sym_op->auth.aad.phys_addr =rte_pktmbuf_mtophys ( + ut_params->ibuf); + sym_op->auth.aad.length = aad_len; + +memset (sym_op->auth.aad.data,0 , aad_buffer_len); +rte_memcpy (sym_op->auth.aad.data, aad, aad_len); + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"aad:" , + sym_op->auth.aad.data, aad_len); +#endif + +/* digest */ + sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append ( + ut_params->ibuf, auth_tag_len); + +TEST_ASSERT_NOT_NULL (sym_op->auth.digest.data, +"no room to append auth tag" ); + ut_params->digest = sym_op->auth.digest.data; + sym_op->auth.digest.phys_addr =rte_pktmbuf_mtophys_offset ( + ut_params->ibuf, data_pad_len + aad_len); + sym_op->auth.digest.length = auth_tag_len; +if (op ==RTE_CRYPTO_AUTH_OP_GENERATE ) +memset (sym_op->auth.digest.data,0 , auth_tag_len); +else +rte_memcpy (sym_op->auth.digest.data, auth_tag, auth_tag_len); + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"digest:" , + sym_op->auth.digest.data, + sym_op->auth.digest.length); +#endif + + sym_op->auth.data.length = data_len; + sym_op->auth.data.offset = aad_buffer_len; + +return 0 ; +} + +static int +create_snow3g_auth_cipher_operation (const unsigned auth_tag_len, +const uint8_t *iv,const unsigned iv_len, +const uint8_t *aad,const unsigned aad_len, +const unsigned data_len,unsigned data_pad_len) +{ +struct crypto_testsuite_params *ts_params = &testsuite_params; +struct crypto_unittest_params *ut_params = &unittest_params; + +unsigned iv_pad_len =0 ; +unsigned aad_buffer_len =0 ; + +/* 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, auth_tag_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, data_pad_len); + sym_op->auth.digest.length = auth_tag_len; + +memset (sym_op->auth.digest.data,0 , auth_tag_len); + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"digest:" , + sym_op->auth.digest.data, + sym_op->auth.digest.length); +#endif +/* iv */ + iv_pad_len =RTE_ALIGN_CEIL (iv_len,16 ); + + 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 = iv_pad_len; + +rte_memcpy (sym_op->cipher.iv.data, iv, iv_len); + +/* aad */ +/* +* Always allocate the aad up to the block size. +* The cryptodev API calls out - +* - the array must be big enough to hold the AAD, plus any +* space to round this up to the nearest multiple of the +* block size (16 bytes). +*/ + aad_buffer_len =ALIGN_POW2_ROUNDUP (aad_len,16 ); + + sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend ( + ut_params->ibuf, aad_buffer_len); +TEST_ASSERT_NOT_NULL (sym_op->auth.aad.data, +"no room to prepend aad" ); + sym_op->auth.aad.phys_addr =rte_pktmbuf_mtophys ( + ut_params->ibuf); + sym_op->auth.aad.length = aad_len; + +memset (sym_op->auth.aad.data,0 , aad_buffer_len); +rte_memcpy (sym_op->auth.aad.data, aad, aad_len); + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"aad:" , + sym_op->auth.aad.data, aad_len); +#endif + + sym_op->cipher.data.length = data_len; + sym_op->cipher.data.offset = aad_buffer_len + iv_pad_len; + + sym_op->auth.data.length = data_len; + sym_op->auth.data.offset = aad_buffer_len + iv_pad_len; + +return 0 ; +} + +static int +test_snow3g_authentication (const struct snow3g_hash_test_data *tdata) +{ +struct crypto_testsuite_params *ts_params = &testsuite_params; +struct crypto_unittest_params *ut_params = &unittest_params; + +int retval; +unsigned plaintext_pad_len; +uint8_t *plaintext; + +/* Create SNOW3G session */ + retval =create_snow3g_hash_session (ts_params->valid_devs[0 ], + tdata->key.data, tdata->key.len, + tdata->aad.len, tdata->digest.len, +RTE_CRYPTO_AUTH_OP_GENERATE ); +if (retval <0 ) +return retval; + +/* 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)); + +/* Append data which is padded to a multiple of */ +/* the algorithms block size */ + plaintext_pad_len = tdata->plaintext.len; + plaintext = (uint8_t *)rte_pktmbuf_append (ut_params->ibuf, + plaintext_pad_len); +memcpy (plaintext, tdata->plaintext.data, tdata->plaintext.len); + +/* Create SNOW3G opertaion */ + retval =create_snow3g_hash_operation (NULL , tdata->digest.len, + tdata->aad.data, tdata->aad.len, tdata->plaintext.len, + plaintext_pad_len,RTE_CRYPTO_AUTH_OP_GENERATE ); +if (retval <0 ) +return retval; + + ut_params->op =process_crypto_request (ts_params->valid_devs[0 ], + ut_params->op); + ut_params->obuf = ut_params->op->sym->m_src; +TEST_ASSERT_NOT_NULL (ut_params->op,"failed to retrieve obuf" ); + ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) + + plaintext_pad_len + tdata->aad.len; + +/* Validate obuf */ +TEST_ASSERT_BUFFERS_ARE_EQUAL ( + ut_params->digest, + tdata->digest.data, +DIGEST_BYTE_LENGTH_SNOW3G_UIA2 , +"Snow3G Generated auth tag not as expected" ); + +return 0 ; +} + +static int +test_snow3g_authentication_verify (const struct snow3g_hash_test_data *tdata) +{ +struct crypto_testsuite_params *ts_params = &testsuite_params; +struct crypto_unittest_params *ut_params = &unittest_params; + +int retval; +unsigned plaintext_pad_len; +uint8_t *plaintext; + +/* Create SNOW3G session */ + retval =create_snow3g_hash_session (ts_params->valid_devs[0 ], + tdata->key.data, tdata->key.len, + tdata->aad.len, tdata->digest.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); + + memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, +rte_pktmbuf_tailroom (ut_params->ibuf)); + +/* Append data which is padded to a multiple */ +/* of the algorithms block size */ + plaintext_pad_len = tdata->plaintext.len; + plaintext = (uint8_t *)rte_pktmbuf_append (ut_params->ibuf, + plaintext_pad_len); +memcpy (plaintext, tdata->plaintext.data, tdata->plaintext.len); + +/* Create SNOW3G operation */ + retval =create_snow3g_hash_operation (tdata->digest.data, + tdata->digest.len, + tdata->aad.data, tdata->aad.len, + tdata->plaintext.len, plaintext_pad_len, +RTE_CRYPTO_AUTH_OP_VERIFY ); +if (retval <0 ) +return retval; + + ut_params->op =process_crypto_request (ts_params->valid_devs[0 ], + ut_params->op); +TEST_ASSERT_NOT_NULL (ut_params->op,"failed to retrieve obuf" ); + ut_params->obuf = ut_params->op->sym->m_src; + ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) + + plaintext_pad_len + tdata->aad.len; + +/* Validate obuf */ +if (ut_params->op->status ==RTE_CRYPTO_OP_STATUS_SUCCESS ) +return 0 ; +else +return -1 ; + +return 0 ; +} + + +static int +test_snow3g_hash_generate_test_case_1 (void ) +{ +return test_snow3g_authentication (&snow3g_hash_test_case_1); +} + +static int +test_snow3g_hash_generate_test_case_2 (void ) +{ +return test_snow3g_authentication (&snow3g_hash_test_case_2); +} + +static int +test_snow3g_hash_generate_test_case_3 (void ) +{ +return test_snow3g_authentication (&snow3g_hash_test_case_3); +} + +static int +test_snow3g_hash_verify_test_case_1 (void ) +{ +return test_snow3g_authentication_verify (&snow3g_hash_test_case_1); + +} + +static int +test_snow3g_hash_verify_test_case_2 (void ) +{ +return test_snow3g_authentication_verify (&snow3g_hash_test_case_2); +} + +static int +test_snow3g_hash_verify_test_case_3 (void ) +{ +return test_snow3g_authentication_verify (&snow3g_hash_test_case_3); +} + +static int +test_snow3g_encryption (const struct snow3g_test_data *tdata) +{ +struct crypto_testsuite_params *ts_params = &testsuite_params; +struct crypto_unittest_params *ut_params = &unittest_params; + +int retval; + +uint8_t *plaintext, *ciphertext; +uint8_t plaintext_pad_len; +uint8_t lastByteValidBits =8 ; +uint8_t lastByteMask =0xFF ; + +/* Create SNOW3G session */ + retval =create_snow3g_cipher_session (ts_params->valid_devs[0 ], +RTE_CRYPTO_CIPHER_OP_ENCRYPT , + tdata->key.data, tdata->key.len); +if (retval <0 ) +return retval; + + 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)); + +/* +* Append data which is padded to a +* multiple of the algorithms block size +*/ + plaintext_pad_len =RTE_ALIGN_CEIL (tdata->plaintext.len,16 ); + + plaintext = (uint8_t *)rte_pktmbuf_append (ut_params->ibuf, + plaintext_pad_len); +memcpy (plaintext, tdata->plaintext.data, tdata->plaintext.len); + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"plaintext:" , plaintext, tdata->plaintext.len); +#endif +/* Create SNOW3G operation */ + retval =create_snow3g_cipher_operation (tdata->iv.data, tdata->iv.len, + tdata->plaintext.len); +if (retval <0 ) +return retval; + + ut_params->op =process_crypto_request (ts_params->valid_devs[0 ], + ut_params->op); +TEST_ASSERT_NOT_NULL (ut_params->op,"failed to retrieve obuf" ); + + ut_params->obuf = ut_params->op->sym->m_src; +if (ut_params->obuf) + ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) + + tdata->iv.len; +else + ciphertext = plaintext; + + lastByteValidBits = (tdata->validDataLenInBits.len %8 ); +if (lastByteValidBits ==0 ) + lastByteValidBits =8 ; + lastByteMask = lastByteMask << (8 - lastByteValidBits); + (*(ciphertext + tdata->ciphertext.len -1 )) &= lastByteMask; + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"ciphertext:" , ciphertext, tdata->ciphertext.len); +#endif +/* Validate obuf */ +TEST_ASSERT_BUFFERS_ARE_EQUAL ( + ciphertext, + tdata->ciphertext.data, + tdata->ciphertext.len, +"Snow3G Ciphertext data not as expected" ); +return 0 ; +} + +static int test_snow3g_decryption (const struct snow3g_test_data *tdata) +{ +struct crypto_testsuite_params *ts_params = &testsuite_params; +struct crypto_unittest_params *ut_params = &unittest_params; + +int retval; + +uint8_t *plaintext, *ciphertext; +uint8_t ciphertext_pad_len; +uint8_t lastByteValidBits =8 ; +uint8_t lastByteMask =0xFF ; + +/* Create SNOW3G session */ + retval =create_snow3g_cipher_session (ts_params->valid_devs[0 ], +RTE_CRYPTO_CIPHER_OP_DECRYPT , + tdata->key.data, tdata->key.len); +if (retval <0 ) +return retval; + + 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)); + +/* +* Append data which is padded to a +* multiple of the algorithms block size +*/ + ciphertext_pad_len =RTE_ALIGN_CEIL (tdata->ciphertext.len,16 ); + + ciphertext = (uint8_t *)rte_pktmbuf_append (ut_params->ibuf, + ciphertext_pad_len); +memcpy (ciphertext, tdata->ciphertext.data, tdata->ciphertext.len); + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"ciphertext:" , ciphertext, tdata->ciphertext.len); +#endif +/* Create SNOW3G operation */ + retval =create_snow3g_cipher_operation (tdata->iv.data, tdata->iv.len, + tdata->ciphertext.len); +if (retval <0 ) +return retval; + + ut_params->op =process_crypto_request (ts_params->valid_devs[0 ], + ut_params->op); +TEST_ASSERT_NOT_NULL (ut_params->op,"failed to retrieve obuf" ); + ut_params->obuf = ut_params->op->sym->m_src; +if (ut_params->obuf) + plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) + + tdata->iv.len; +else + plaintext = ciphertext; + lastByteValidBits = (tdata->validDataLenInBits.len %8 ); +if (lastByteValidBits ==0 ) + lastByteValidBits =8 ; + lastByteMask = lastByteMask << (8 - lastByteValidBits); + (*(ciphertext + tdata->ciphertext.len -1 )) &= lastByteMask; + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"plaintext:" , plaintext, tdata->plaintext.len); +#endif +/* Validate obuf */ +TEST_ASSERT_BUFFERS_ARE_EQUAL (plaintext, + tdata->plaintext.data, + tdata->plaintext.len, +"Snow3G Plaintext data not as expected" ); +return 0 ; +} + +static int +test_snow3g_authenticated_encryption (const struct snow3g_test_data *tdata) +{ +struct crypto_testsuite_params *ts_params = &testsuite_params; +struct crypto_unittest_params *ut_params = &unittest_params; + +int retval; + +uint8_t *plaintext, *ciphertext; +uint8_t plaintext_pad_len; +uint8_t lastByteValidBits =8 ; +uint8_t lastByteMask =0xFF ; + +/* Create SNOW3G session */ + retval =create_snow3g_cipher_auth_session (ts_params->valid_devs[0 ], +RTE_CRYPTO_CIPHER_OP_ENCRYPT , +RTE_CRYPTO_AUTH_OP_GENERATE , + tdata->key.data, tdata->key.len, + tdata->aad.len, tdata->digest.len); +if (retval <0 ) +return retval; + 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)); + +/* Append data which is padded to a multiple */ +/* of the algorithms block size */ + plaintext_pad_len = tdata->plaintext.len; + + plaintext = (uint8_t *)rte_pktmbuf_append (ut_params->ibuf, + plaintext_pad_len); +memcpy (plaintext, tdata->plaintext.data, tdata->plaintext.len); + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"plaintext:" , plaintext, tdata->plaintext.len); +#endif + +/* Create SNOW3G operation */ + retval =create_snow3g_cipher_hash_operation (tdata->digest.data, + tdata->digest.len, tdata->aad.data, + tdata->aad.len, tdata->plaintext.len, + plaintext_pad_len,RTE_CRYPTO_AUTH_OP_GENERATE , + tdata->iv.data, tdata->iv.len); +if (retval <0 ) +return retval; + + ut_params->op =process_crypto_request (ts_params->valid_devs[0 ], + ut_params->op); +TEST_ASSERT_NOT_NULL (ut_params->op,"failed to retrieve obuf" ); + ut_params->obuf = ut_params->op->sym->m_src; +if (ut_params->obuf) + ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) + + tdata->iv.len; +else + ciphertext = plaintext; + lastByteValidBits = (tdata->validDataLenInBits.len %8 ); +if (lastByteValidBits ==0 ) + lastByteValidBits =8 ; + lastByteMask = lastByteMask << (8 -lastByteValidBits); + (*(ciphertext + tdata->ciphertext.len -1 )) &= lastByteMask; + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"ciphertext:" , ciphertext, tdata->ciphertext.len); +#endif +/* Validate obuf */ +TEST_ASSERT_BUFFERS_ARE_EQUAL ( + ciphertext, + tdata->ciphertext.data, + tdata->ciphertext.len, +"Snow3G Ciphertext data not as expected" ); + + ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) + + plaintext_pad_len + tdata->aad.len; + +/* Validate obuf */ +TEST_ASSERT_BUFFERS_ARE_EQUAL ( + ut_params->digest, + tdata->digest.data, +DIGEST_BYTE_LENGTH_SNOW3G_UIA2 , +"Snow3G Generated auth tag not as expected" ); +return 0 ; +} +static int +test_snow3g_encrypted_authentication (const struct snow3g_test_data *tdata) +{ +struct crypto_testsuite_params *ts_params = &testsuite_params; +struct crypto_unittest_params *ut_params = &unittest_params; + +int retval; + +uint8_t *plaintext, *ciphertext; +uint8_t plaintext_pad_len; +uint8_t lastByteValidBits =8 ; +uint8_t lastByteMask =0xFF ; + +/* Create SNOW3G session */ + retval =create_snow3g_auth_cipher_session (ts_params->valid_devs[0 ], +RTE_CRYPTO_CIPHER_OP_ENCRYPT , +RTE_CRYPTO_AUTH_OP_GENERATE , + tdata->key.data, tdata->key.len, + tdata->aad.len, tdata->digest.len); +if (retval <0 ) +return retval; + + 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)); + +/* Append data which is padded to a multiple */ +/* of the algorithms block size */ + plaintext_pad_len =RTE_ALIGN_CEIL (tdata->plaintext.len,8 ); + + plaintext = (uint8_t *)rte_pktmbuf_append (ut_params->ibuf, + plaintext_pad_len); +memcpy (plaintext, tdata->plaintext.data, tdata->plaintext.len); + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"plaintext:" , plaintext, tdata->plaintext.len); +#endif + +/* Create SNOW3G operation */ + retval =create_snow3g_auth_cipher_operation ( + tdata->digest.len, + tdata->iv.data, tdata->iv.len, + tdata->aad.data, tdata->aad.len, + tdata->plaintext.len, plaintext_pad_len + ); + +if (retval <0 ) +return retval; + + ut_params->op =process_crypto_request (ts_params->valid_devs[0 ], + ut_params->op); +TEST_ASSERT_NOT_NULL (ut_params->op,"failed to retrieve obuf" ); + ut_params->obuf = ut_params->op->sym->m_src; +if (ut_params->obuf) + ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) + + tdata->aad.len + tdata->iv.len; +else + ciphertext = plaintext; + + lastByteValidBits = (tdata->validDataLenInBits.len %8 ); +if (lastByteValidBits ==0 ) + lastByteValidBits =8 ; + lastByteMask = lastByteMask << (8 -lastByteValidBits); + (*(ciphertext + tdata->ciphertext.len -1 )) &= lastByteMask; + ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) + + plaintext_pad_len + tdata->aad.len + tdata->iv.len; + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"ciphertext:" , ciphertext, tdata->ciphertext.len); +#endif +/* Validate obuf */ +TEST_ASSERT_BUFFERS_ARE_EQUAL ( + ciphertext, + tdata->ciphertext.data, + tdata->ciphertext.len, +"Snow3G Ciphertext data not as expected" ); + +/* Validate obuf */ +TEST_ASSERT_BUFFERS_ARE_EQUAL ( + ut_params->digest, + tdata->digest.data, +DIGEST_BYTE_LENGTH_SNOW3G_UIA2 , +"Snow3G Generated auth tag not as expected" ); +return 0 ; +} + +static int +test_snow3g_encryption_test_case_1 (void ) +{ +return test_snow3g_encryption (&snow3g_test_case_1); +} + +static int +test_snow3g_encryption_test_case_2 (void ) +{ +return test_snow3g_encryption (&snow3g_test_case_2); +} + +static int +test_snow3g_encryption_test_case_3 (void ) +{ +return test_snow3g_encryption (&snow3g_test_case_3); +} + +static int +test_snow3g_encryption_test_case_4 (void ) +{ +return test_snow3g_encryption (&snow3g_test_case_4); +} + +static int +test_snow3g_encryption_test_case_5 (void ) +{ +return test_snow3g_encryption (&snow3g_test_case_5); +} + +static int +test_snow3g_decryption_test_case_1 (void ) +{ +return test_snow3g_decryption (&snow3g_test_case_1); +} + +static int +test_snow3g_decryption_test_case_2 (void ) +{ +return test_snow3g_decryption (&snow3g_test_case_2); +} + +static int +test_snow3g_decryption_test_case_3 (void ) +{ +return test_snow3g_decryption (&snow3g_test_case_3); +} + +static int +test_snow3g_decryption_test_case_4 (void ) +{ +return test_snow3g_decryption (&snow3g_test_case_4); +} + +static int +test_snow3g_decryption_test_case_5 (void ) +{ +return test_snow3g_decryption (&snow3g_test_case_5); +} +static int +test_snow3g_authenticated_encryption_test_case_1 (void ) +{ +return test_snow3g_authenticated_encryption (&snow3g_test_case_3); +} + +static int +test_snow3g_encrypted_authentication_test_case_1 (void ) +{ +return test_snow3g_encrypted_authentication (&snow3g_test_case_6); +}/* ***** AES-GCM Tests ***** */
@@ -1999,9 +2994,47 @@ static struct unit_test_suite cryptodev_qat_testsuite = { test_AES_CBC_HMAC_AES_XCBC_encrypt_digest),TEST_CASE_ST (ut_setup ,ut_teardown ,test_AES_CBC_HMAC_AES_XCBC_decrypt_digest_verify ), -TEST_CASE_ST (ut_setup ,ut_teardown ,test_stats ), +/** Snow3G encrypt only (UEA2) */ +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_encryption_test_case_1 ), +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_encryption_test_case_2 ), +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_encryption_test_case_3 ), +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_encryption_test_case_4 ), +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_encryption_test_case_5 ), + +/** Snow3G decrypt only (UEA2) */ +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_decryption_test_case_1 ), +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_decryption_test_case_2 ), +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_decryption_test_case_3 ), +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_decryption_test_case_4 ), +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_decryption_test_case_5 ), +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_hash_generate_test_case_1 ), +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_hash_generate_test_case_2 ), +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_hash_generate_test_case_3 ), +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_hash_verify_test_case_1 ), +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_hash_verify_test_case_2 ), +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_hash_verify_test_case_3 ), +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_authenticated_encryption_test_case_1 ), +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_encrypted_authentication_test_case_1 ),TEST_CASES_END ()/**< NULL terminate unit test array */ } };
app/test/test_cryptodev.h +2 -1
@@ -1,7 +1,7 @@/*- * BSD LICENSE * -* Copyright(c) 2015 Intel Corporation. All rights reserved. +* Copyright(c) 2015-2016 Intel Corporation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions
@@ -58,6 +58,7 @@#define DIGEST_BYTE_LENGTH_SHA384 (BYTE_LENGTH(384))#define DIGEST_BYTE_LENGTH_SHA512 (BYTE_LENGTH(512))#define DIGEST_BYTE_LENGTH_AES_XCBC (BYTE_LENGTH(96)) +#define DIGEST_BYTE_LENGTH_SNOW3G_UIA2 (BYTE_LENGTH(32))#define AES_XCBC_MAC_KEY_SZ (16)#define TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 (12)
app/test/test_cryptodev_snow3g_hash_test_vectors.h new file +415 -0
415 lines not on this page · raw message
app/test/test_cryptodev_snow3g_test_vectors.h new file +379 -0
379 lines not on this page · raw message
Signature · 1 line
2.1.0
Re: [PATCH v3 0/3] Snow3G support for Intel Quick Assist Devices
In reply to Deepak Kumar JAINQuoted 43 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Deepak Kumar JAIN
Sent: Thursday, March 03, 2016 1:01 PM
To: [email protected]
Subject: [dpdk-dev] [PATCH v3 0/3] Snow3G support for Intel Quick Assist DevicesThis patchset contains fixes and refactoring for Snow3G(UEA2 and UIA2) wireless algorithm for Intel Quick Assist devices.
QAT PMD previously supported only cipher/hash alg-chaining for AES/SHA. The code has been refactored to also support cipher-only and hash only (for Snow3G only) functionality along with alg-chaining.
Changes from v2:
1) Rebasing based on below mentioned patchset.
This patchset depends on
cryptodev API changes
http://dpdk.org/ml/archives/dev/2016-February/034212.htmlDeepak Kumar JAIN (3):
crypto: add cipher/auth only support
qat: add support for Snow3G
app/test: add Snow3G testsapp/test/test_cryptodev.c | 1037 +++++++++++++++++++- app/test/test_cryptodev.h | 3 +- app/test/test_cryptodev_snow3g_hash_test_vectors.h | 415 ++++++++ app/test/test_cryptodev_snow3g_test_vectors.h | 379 +++++++ doc/guides/cryptodevs/qat.rst | 8 +- doc/guides/rel_notes/release_16_04.rst | 6 + drivers/crypto/qat/qat_adf/qat_algs.h | 19 +- drivers/crypto/qat/qat_adf/qat_algs_build_desc.c | 280 +++++- drivers/crypto/qat/qat_crypto.c | 149 ++- drivers/crypto/qat/qat_crypto.h | 10 + 10 files changed, 2231 insertions(+), 75 deletions(-) create mode 100644 app/test/test_cryptodev_snow3g_hash_test_vectors.h create mode 100644 app/test/test_cryptodev_snow3g_test_vectors.h
Quoted 2 lines
--
2.1.0
v4 cover Snow3G support for Intel Quick Assist Devices
In reply to Deepak Kumar JAINThis patchset contains fixes and refactoring for Snow3G(UEA2 and UIA2) wireless algorithm for Intel Quick Assist devices.
QAT PMD previously supported only cipher/hash alg-chaining for AES/SHA.
The code has been refactored to also support cipher-only and hash only (for Snow3G only) functionality along with alg-chaining.
Changes from V3:
1) Rebase based on below mentioned patchset.
2) Fixes test failure which happens only after
applying patch 1 only.
Changes from v2:
1) Rebasing based on below mentioned patchset.
This patchset depends on
cryptodev API changes
http://dpdk.org/ml/archives/dev/2016-March/035451.html
Deepak Kumar JAIN (3):
crypto: add cipher/auth only support
qat: add support for Snow3G
app/test: add Snow3G tests
app/test/test_cryptodev.c | 1037 +++++++++++++++++++- app/test/test_cryptodev.h | 3 +- app/test/test_cryptodev_snow3g_hash_test_vectors.h | 415 ++++++++ app/test/test_cryptodev_snow3g_test_vectors.h | 379 +++++++ doc/guides/cryptodevs/qat.rst | 8 +- doc/guides/rel_notes/release_16_04.rst | 6 + drivers/crypto/qat/qat_adf/qat_algs.h | 19 +- drivers/crypto/qat/qat_adf/qat_algs_build_desc.c | 284 +++++- drivers/crypto/qat/qat_crypto.c | 149 ++- drivers/crypto/qat/qat_crypto.h | 10 + 10 files changed, 2236 insertions(+), 74 deletions(-) create mode 100644 app/test/test_cryptodev_snow3g_hash_test_vectors.h create mode 100644 app/test/test_cryptodev_snow3g_test_vectors.h
Signature · 1 line
2.1.0
PATCH v4 1/3 crypto: add cipher/auth only support
Refactored the existing functionality into
modular form to support the cipher/auth only
functionalities.
--- drivers/crypto/qat/qat_adf/qat_algs.h | 18 +- drivers/crypto/qat/qat_adf/qat_algs_build_desc.c | 208 ++++++++++++++++++++--- drivers/crypto/qat/qat_crypto.c | 137 +++++++++++---- drivers/crypto/qat/qat_crypto.h | 10 ++ 4 files changed, 306 insertions(+), 67 deletions(-)
drivers/crypto/qat/qat_adf/qat_algs.h +11 -7
@@ -3,7 +3,7 @@* redistributing this file, you may do so under either license. * * GPL LICENSE SUMMARY -* Copyright(c) 2015 Intel Corporation. +* Copyright(c) 2015-2016 Intel Corporation. * This program is free software; you can redistribute it and/or modify * it under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation.
@@ -17,7 +17,7 @@* [email protected] * * BSD LICENSE -* Copyright(c) 2015 Intel Corporation. +* Copyright(c) 2015-2016 Intel Corporation. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met:
@@ -104,11 +104,15 @@ struct qat_alg_ablkcipher_cd {int qat_get_inter_state_size (enum icp_qat_hw_auth_algo qat_hash_alg); -int qat_alg_aead_session_create_content_desc (struct qat_session *cd, -uint8_t *enckey,uint32_t enckeylen, -uint8_t *authkey,uint32_t authkeylen, -uint32_t add_auth_data_length, -uint32_t digestsize); +int qat_alg_aead_session_create_content_desc_cipher (struct qat_session *cd, +uint8_t *enckey, +uint32_t enckeylen); + +int qat_alg_aead_session_create_content_desc_auth (struct qat_session *cdesc, +uint8_t *authkey, +uint32_t authkeylen, +uint32_t add_auth_data_length, +uint32_t digestsize);void qat_alg_init_common_hdr (struct icp_qat_fw_comn_req_hdr *header);
drivers/crypto/qat/qat_adf/qat_algs_build_desc.c +180 -28
270 lines not on this page · raw message
drivers/crypto/qat/qat_crypto.c +105 -32
177 lines not on this page · raw message
drivers/crypto/qat/qat_crypto.h +10 -0
@@ -111,6 +111,16 @@ extern void * qat_crypto_sym_configure_session(struct rte_cryptodev *dev, struct rte_crypto_sym_xform *xform, void *session_private); +struct qat_session * +qat_crypto_sym_configure_session_auth (struct rte_cryptodev *dev, +struct rte_crypto_sym_xform *xform, +struct qat_session *session_private); + +void * +qat_crypto_sym_configure_session_cipher (struct rte_cryptodev *dev, +struct rte_crypto_sym_xform *xform,void *session_private); + +extern void qat_crypto_sym_clear_session (struct rte_cryptodev *dev,void *session);
Signature · 1 line
2.1.0
PATCH v4 2/3 qat: add support for Snow3G
In reply to Deepak Kumar JAIN--- doc/guides/cryptodevs/qat.rst | 8 ++- doc/guides/rel_notes/release_16_04.rst | 6 ++ drivers/crypto/qat/qat_adf/qat_algs.h | 1 + drivers/crypto/qat/qat_adf/qat_algs_build_desc.c | 86 ++++++++++++++++++++++-- drivers/crypto/qat/qat_crypto.c | 12 +++- 5 files changed, 104 insertions(+), 9 deletions(-)
doc/guides/cryptodevs/qat.rst +5 -3
@@ -1,5 +1,5 @@ .. BSD LICENSE - Copyright(c) 2015 Intel Corporation. All rights reserved. + Copyright(c) 2015-2016 Intel Corporation. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions
@@ -47,6 +47,7 @@ Cipher algorithms: * ``RTE_CRYPTO_SYM_CIPHER_AES128_CBC`` * ``RTE_CRYPTO_SYM_CIPHER_AES192_CBC`` * ``RTE_CRYPTO_SYM_CIPHER_AES256_CBC`` +* ``RTE_CRYPTO_SYM_CIPHER_SNOW3G_UEA2`` Hash algorithms:
@@ -54,14 +55,15 @@ Hash algorithms: * ``RTE_CRYPTO_AUTH_SHA256_HMAC`` * ``RTE_CRYPTO_AUTH_SHA512_HMAC`` * ``RTE_CRYPTO_AUTH_AES_XCBC_MAC`` +* ``RTE_CRYPTO_AUTH_SNOW3G_UIA2`` Limitations ----------- * Chained mbufs are not supported. -* Hash only is not supported. -* Cipher only is not supported. +* Hash only is not supported except Snow3G UIA2. +* Cipher only is not supported except Snow3G UEA2. * Only in-place is currently supported (destination address is the same as source address). * Only supports the session-oriented API implementation (session-less APIs are not supported). * Not performance tuned.
doc/guides/rel_notes/release_16_04.rst +6 -0
@@ -35,6 +35,12 @@ This section should contain new features added in this release. Sample format: Refer to the previous release notes for examples. +* **Added support of Snow3G (UEA2 and UIA2) for Intel Quick Assist Devices.** + + Enabled support for Snow3g Wireless algorithm for Intel Quick Assist devices. + Support for cipher only, Hash only is also provided + along with alg-chaining operations. + * **Added function to check primary process state.** A new function ``rte_eal_primary_proc_alive()`` has been added
drivers/crypto/qat/qat_adf/qat_algs.h +1 -0
@@ -125,5 +125,6 @@ void qat_alg_ablkcipher_init_dec(struct qat_alg_ablkcipher_cd *cd, unsigned int keylen);int qat_alg_validate_aes_key (int key_len,enum icp_qat_hw_cipher_algo *alg); +int qat_alg_validate_snow3g_key (int key_len,enum icp_qat_hw_cipher_algo *alg);#endif
drivers/crypto/qat/qat_adf/qat_algs_build_desc.c +81 -5
170 lines not on this page · raw message
drivers/crypto/qat/qat_crypto.c +11 -1
@@ -169,6 +169,14 @@ qat_crypto_sym_configure_session_cipher(struct rte_cryptodev *dev, } session->qat_mode =ICP_QAT_HW_CIPHER_CTR_MODE ;break ; +case RTE_CRYPTO_CIPHER_SNOW3G_UEA2 : +if (qat_alg_validate_snow3g_key (cipher_xform->key.length, + &session->qat_cipher_alg) !=0 ) { +PMD_DRV_LOG (ERR ,"Invalid SNOW3G cipher key size" ); + goto error_out; + } + session->qat_mode =ICP_QAT_HW_CIPHER_ECB_MODE ; +break ;case RTE_CRYPTO_CIPHER_NULL :case RTE_CRYPTO_CIPHER_3DES_ECB :case RTE_CRYPTO_CIPHER_3DES_CBC :
@@ -290,6 +298,9 @@ qat_crypto_sym_configure_session_auth(struct rte_cryptodev *dev,case RTE_CRYPTO_AUTH_AES_GMAC : session->qat_hash_alg =ICP_QAT_HW_AUTH_ALGO_GALOIS_128 ;break ; +case RTE_CRYPTO_AUTH_SNOW3G_UIA2 : + session->qat_hash_alg =ICP_QAT_HW_AUTH_ALGO_SNOW_3G_UIA2 ; +break ;case RTE_CRYPTO_AUTH_NULL :case RTE_CRYPTO_AUTH_SHA1 :case RTE_CRYPTO_AUTH_SHA256 :
@@ -302,7 +313,6 @@ qat_crypto_sym_configure_session_auth(struct rte_cryptodev *dev,case RTE_CRYPTO_AUTH_MD5_HMAC :case RTE_CRYPTO_AUTH_AES_CCM :case RTE_CRYPTO_AUTH_KASUMI_F9 : -case RTE_CRYPTO_AUTH_SNOW3G_UIA2 :case RTE_CRYPTO_AUTH_AES_CMAC :case RTE_CRYPTO_AUTH_AES_CBC_MAC :case RTE_CRYPTO_AUTH_ZUC_EIA3 :
Signature · 1 line
2.1.0
PATCH v4 3/3 app/test: add Snow3G tests
In reply to Deepak Kumar JAIN--- app/test/test_cryptodev.c | 1037 +++++++++++++++++++- app/test/test_cryptodev.h | 3 +- app/test/test_cryptodev_snow3g_hash_test_vectors.h | 415 ++++++++ app/test/test_cryptodev_snow3g_test_vectors.h | 379 +++++++ 4 files changed, 1831 insertions(+), 3 deletions(-) create mode 100644 app/test/test_cryptodev_snow3g_hash_test_vectors.h create mode 100644 app/test/test_cryptodev_snow3g_test_vectors.h
app/test/test_cryptodev.c +1035 -2
@@ -42,7 +42,8 @@#include "test.h" #include "test_cryptodev.h" - +#include "test_cryptodev_snow3g_test_vectors.h" +#include "test_cryptodev_snow3g_hash_test_vectors.h" static enum rte_cryptodev_type gbl_cryptodev_type;struct crypto_testsuite_params {
@@ -68,6 +69,9 @@ struct crypto_unittest_params {uint8_t *digest; }; +#define ALIGN_POW2_ROUNDUP (num, align) \ + (((num) + (align) - 1) & ~((align) - 1)) +/* * Forward declarations. */
@@ -1747,6 +1751,997 @@ test_AES_CBC_HMAC_AES_XCBC_decrypt_digest_verify(void)return TEST_SUCCESS ; } +/* ***** Snow3G Tests ***** */ +static int +create_snow3g_hash_session (uint8_t dev_id, +const uint8_t *key,const uint8_t key_len, +const uint8_t aad_len,const uint8_t auth_len, +enum rte_crypto_auth_operation op) +{ +uint8_t hash_key[key_len]; + +struct crypto_unittest_params *ut_params = &unittest_params; + +memcpy (hash_key, key, key_len); +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"key:" , key, key_len); +#endif +/* Setup Authentication Parameters */ + 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_SNOW3G_UIA2 ; + ut_params->auth_xform.auth.key.length = key_len; + ut_params->auth_xform.auth.key.data = hash_key; + ut_params->auth_xform.auth.digest_length = auth_len; + ut_params->auth_xform.auth.add_auth_data_length = aad_len; + 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_snow3g_cipher_session (uint8_t dev_id, +enum rte_crypto_cipher_operation op, +const uint8_t *key,const uint8_t key_len) +{ +uint8_t cipher_key[key_len]; + +struct crypto_unittest_params *ut_params = &unittest_params; + +memcpy (cipher_key, key, key_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 =RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ; + ut_params->cipher_xform.cipher.op = op; + ut_params->cipher_xform.cipher.key.data = cipher_key; + ut_params->cipher_xform.cipher.key.length = key_len; + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"key:" , key, key_len); +#endif +/* Create Crypto session */ + 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 +create_snow3g_cipher_operation (const uint8_t *iv,const unsigned iv_len, +const unsigned data_len) +{ +struct crypto_testsuite_params *ts_params = &testsuite_params; +struct crypto_unittest_params *ut_params = &unittest_params; +unsigned iv_pad_len =0 ; + +/* 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; + +/* iv */ + iv_pad_len =RTE_ALIGN_CEIL (iv_len,16 ); + 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 = iv_pad_len; + +rte_memcpy (sym_op->cipher.iv.data, iv, iv_len); + sym_op->cipher.data.length = data_len; + sym_op->cipher.data.offset = iv_pad_len; +return 0 ; +} + + +static int +create_snow3g_cipher_auth_session (uint8_t dev_id, +enum rte_crypto_cipher_operation cipher_op, +enum rte_crypto_auth_operation auth_op, +const uint8_t *key,const uint8_t key_len, +const uint8_t aad_len,const uint8_t auth_len) +{ +uint8_t cipher_auth_key[key_len]; + +struct crypto_unittest_params *ut_params = &unittest_params; + +memcpy (cipher_auth_key, key, key_len); + +/* Setup Authentication Parameters */ + ut_params->auth_xform.type =RTE_CRYPTO_SYM_XFORM_AUTH ; + ut_params->auth_xform.next =NULL ; + + ut_params->auth_xform.auth.op = auth_op; + ut_params->auth_xform.auth.algo =RTE_CRYPTO_AUTH_SNOW3G_UIA2 ; + ut_params->auth_xform.auth.key.length = key_len; +/* Hash key = cipher key */ + ut_params->auth_xform.auth.key.data = cipher_auth_key; + ut_params->auth_xform.auth.digest_length = auth_len; + ut_params->auth_xform.auth.add_auth_data_length = aad_len; + +/* 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_SNOW3G_UEA2 ; + ut_params->cipher_xform.cipher.op = cipher_op; + ut_params->cipher_xform.cipher.key.data = cipher_auth_key; + ut_params->cipher_xform.cipher.key.length = key_len; + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"key:" , key, key_len); +#endif +/* Create Crypto session*/ + 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 +create_snow3g_auth_cipher_session (uint8_t dev_id, +enum rte_crypto_cipher_operation cipher_op, +enum rte_crypto_auth_operation auth_op, +const uint8_t *key,const uint8_t key_len, +const uint8_t aad_len,const uint8_t auth_len) + { +uint8_t auth_cipher_key[key_len]; + +struct crypto_unittest_params *ut_params = &unittest_params; + +memcpy (auth_cipher_key, key, 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 =RTE_CRYPTO_AUTH_SNOW3G_UIA2 ; + ut_params->auth_xform.auth.key.length = key_len; + ut_params->auth_xform.auth.key.data = auth_cipher_key; + ut_params->auth_xform.auth.digest_length = auth_len; + ut_params->auth_xform.auth.add_auth_data_length = 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 =RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ; + ut_params->cipher_xform.cipher.op = cipher_op; + ut_params->cipher_xform.cipher.key.data = auth_cipher_key; + ut_params->cipher_xform.cipher.key.length = key_len; + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"key:" , key, key_len); +#endif +/* 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_snow3g_hash_operation (const uint8_t *auth_tag, +const unsigned auth_tag_len, +const uint8_t *aad,const unsigned aad_len, +const unsigned data_len,unsigned data_pad_len, +enum rte_crypto_auth_operation op) +{ +struct crypto_testsuite_params *ts_params = &testsuite_params; + +struct crypto_unittest_params *ut_params = &unittest_params; + +unsigned aad_buffer_len; + +/* 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 */ +/* +* Always allocate the aad up to the block size. +* The cryptodev API calls out - +* - the array must be big enough to hold the AAD, plus any +* space to round this up to the nearest multiple of the +* block size (16 bytes). +*/ + aad_buffer_len =ALIGN_POW2_ROUNDUP (aad_len,16 ); + sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend ( + ut_params->ibuf, aad_buffer_len); +TEST_ASSERT_NOT_NULL (sym_op->auth.aad.data, +"no room to prepend aad" ); + sym_op->auth.aad.phys_addr =rte_pktmbuf_mtophys ( + ut_params->ibuf); + sym_op->auth.aad.length = aad_len; + +memset (sym_op->auth.aad.data,0 , aad_buffer_len); +rte_memcpy (sym_op->auth.aad.data, aad, aad_len); + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"aad:" , + sym_op->auth.aad.data, aad_len); +#endif + +/* digest */ + sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append ( + ut_params->ibuf, auth_tag_len); + +TEST_ASSERT_NOT_NULL (sym_op->auth.digest.data, +"no room to append auth tag" ); + ut_params->digest = sym_op->auth.digest.data; + sym_op->auth.digest.phys_addr =rte_pktmbuf_mtophys_offset ( + ut_params->ibuf, data_pad_len + aad_len); + sym_op->auth.digest.length = auth_tag_len; +if (op ==RTE_CRYPTO_AUTH_OP_GENERATE ) +memset (sym_op->auth.digest.data,0 , auth_tag_len); +else +rte_memcpy (sym_op->auth.digest.data, auth_tag, auth_tag_len); + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"digest:" , + sym_op->auth.digest.data, + sym_op->auth.digest.length); +#endif + + sym_op->auth.data.length = data_len; + sym_op->auth.data.offset = aad_buffer_len; + +return 0 ; +} + +static int +create_snow3g_cipher_hash_operation (const uint8_t *auth_tag, +const unsigned auth_tag_len, +const uint8_t *aad,const unsigned aad_len, +const unsigned data_len,unsigned data_pad_len, +enum rte_crypto_auth_operation op, +const uint8_t *iv,const unsigned iv_len) +{ +struct crypto_testsuite_params *ts_params = &testsuite_params; +struct crypto_unittest_params *ut_params = &unittest_params; + +unsigned iv_pad_len =0 ; +unsigned aad_buffer_len; + +/* 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; + + +/* iv */ + iv_pad_len =RTE_ALIGN_CEIL (iv_len,16 ); + + 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 = iv_pad_len; + +rte_memcpy (sym_op->cipher.iv.data, iv, iv_len); + + sym_op->cipher.data.length = data_len; + sym_op->cipher.data.offset = iv_pad_len; + +/* aad */ +/* +* Always allocate the aad up to the block size. +* The cryptodev API calls out - +* - the array must be big enough to hold the AAD, plus any +* space to round this up to the nearest multiple of the +* block size (16 bytes). +*/ + aad_buffer_len =ALIGN_POW2_ROUNDUP (aad_len,16 ); + + sym_op->auth.aad.data = + (uint8_t *)rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *); +TEST_ASSERT_NOT_NULL (sym_op->auth.aad.data, +"no room to prepend aad" ); + sym_op->auth.aad.phys_addr =rte_pktmbuf_mtophys ( + ut_params->ibuf); + sym_op->auth.aad.length = aad_len; + +memset (sym_op->auth.aad.data,0 , aad_buffer_len); +rte_memcpy (sym_op->auth.aad.data, aad, aad_len); + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"aad:" , + sym_op->auth.aad.data, aad_len); +#endif + +/* digest */ + sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append ( + ut_params->ibuf, auth_tag_len); + +TEST_ASSERT_NOT_NULL (sym_op->auth.digest.data, +"no room to append auth tag" ); + ut_params->digest = sym_op->auth.digest.data; + sym_op->auth.digest.phys_addr =rte_pktmbuf_mtophys_offset ( + ut_params->ibuf, data_pad_len + aad_len); + sym_op->auth.digest.length = auth_tag_len; +if (op ==RTE_CRYPTO_AUTH_OP_GENERATE ) +memset (sym_op->auth.digest.data,0 , auth_tag_len); +else +rte_memcpy (sym_op->auth.digest.data, auth_tag, auth_tag_len); + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"digest:" , + sym_op->auth.digest.data, + sym_op->auth.digest.length); +#endif + + sym_op->auth.data.length = data_len; + sym_op->auth.data.offset = aad_buffer_len; + +return 0 ; +} + +static int +create_snow3g_auth_cipher_operation (const unsigned auth_tag_len, +const uint8_t *iv,const unsigned iv_len, +const uint8_t *aad,const unsigned aad_len, +const unsigned data_len,unsigned data_pad_len) +{ +struct crypto_testsuite_params *ts_params = &testsuite_params; +struct crypto_unittest_params *ut_params = &unittest_params; + +unsigned iv_pad_len =0 ; +unsigned aad_buffer_len =0 ; + +/* 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, auth_tag_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, data_pad_len); + sym_op->auth.digest.length = auth_tag_len; + +memset (sym_op->auth.digest.data,0 , auth_tag_len); + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"digest:" , + sym_op->auth.digest.data, + sym_op->auth.digest.length); +#endif +/* iv */ + iv_pad_len =RTE_ALIGN_CEIL (iv_len,16 ); + + 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 = iv_pad_len; + +rte_memcpy (sym_op->cipher.iv.data, iv, iv_len); + +/* aad */ +/* +* Always allocate the aad up to the block size. +* The cryptodev API calls out - +* - the array must be big enough to hold the AAD, plus any +* space to round this up to the nearest multiple of the +* block size (16 bytes). +*/ + aad_buffer_len =ALIGN_POW2_ROUNDUP (aad_len,16 ); + + sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend ( + ut_params->ibuf, aad_buffer_len); +TEST_ASSERT_NOT_NULL (sym_op->auth.aad.data, +"no room to prepend aad" ); + sym_op->auth.aad.phys_addr =rte_pktmbuf_mtophys ( + ut_params->ibuf); + sym_op->auth.aad.length = aad_len; + +memset (sym_op->auth.aad.data,0 , aad_buffer_len); +rte_memcpy (sym_op->auth.aad.data, aad, aad_len); + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"aad:" , + sym_op->auth.aad.data, aad_len); +#endif + + sym_op->cipher.data.length = data_len; + sym_op->cipher.data.offset = aad_buffer_len + iv_pad_len; + + sym_op->auth.data.length = data_len; + sym_op->auth.data.offset = aad_buffer_len + iv_pad_len; + +return 0 ; +} + +static int +test_snow3g_authentication (const struct snow3g_hash_test_data *tdata) +{ +struct crypto_testsuite_params *ts_params = &testsuite_params; +struct crypto_unittest_params *ut_params = &unittest_params; + +int retval; +unsigned plaintext_pad_len; +uint8_t *plaintext; + +/* Create SNOW3G session */ + retval =create_snow3g_hash_session (ts_params->valid_devs[0 ], + tdata->key.data, tdata->key.len, + tdata->aad.len, tdata->digest.len, +RTE_CRYPTO_AUTH_OP_GENERATE ); +if (retval <0 ) +return retval; + +/* 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)); + +/* Append data which is padded to a multiple of */ +/* the algorithms block size */ + plaintext_pad_len = tdata->plaintext.len; + plaintext = (uint8_t *)rte_pktmbuf_append (ut_params->ibuf, + plaintext_pad_len); +memcpy (plaintext, tdata->plaintext.data, tdata->plaintext.len); + +/* Create SNOW3G opertaion */ + retval =create_snow3g_hash_operation (NULL , tdata->digest.len, + tdata->aad.data, tdata->aad.len, tdata->plaintext.len, + plaintext_pad_len,RTE_CRYPTO_AUTH_OP_GENERATE ); +if (retval <0 ) +return retval; + + ut_params->op =process_crypto_request (ts_params->valid_devs[0 ], + ut_params->op); + ut_params->obuf = ut_params->op->sym->m_src; +TEST_ASSERT_NOT_NULL (ut_params->op,"failed to retrieve obuf" ); + ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) + + plaintext_pad_len + tdata->aad.len; + +/* Validate obuf */ +TEST_ASSERT_BUFFERS_ARE_EQUAL ( + ut_params->digest, + tdata->digest.data, +DIGEST_BYTE_LENGTH_SNOW3G_UIA2 , +"Snow3G Generated auth tag not as expected" ); + +return 0 ; +} + +static int +test_snow3g_authentication_verify (const struct snow3g_hash_test_data *tdata) +{ +struct crypto_testsuite_params *ts_params = &testsuite_params; +struct crypto_unittest_params *ut_params = &unittest_params; + +int retval; +unsigned plaintext_pad_len; +uint8_t *plaintext; + +/* Create SNOW3G session */ + retval =create_snow3g_hash_session (ts_params->valid_devs[0 ], + tdata->key.data, tdata->key.len, + tdata->aad.len, tdata->digest.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); + + memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, +rte_pktmbuf_tailroom (ut_params->ibuf)); + +/* Append data which is padded to a multiple */ +/* of the algorithms block size */ + plaintext_pad_len = tdata->plaintext.len; + plaintext = (uint8_t *)rte_pktmbuf_append (ut_params->ibuf, + plaintext_pad_len); +memcpy (plaintext, tdata->plaintext.data, tdata->plaintext.len); + +/* Create SNOW3G operation */ + retval =create_snow3g_hash_operation (tdata->digest.data, + tdata->digest.len, + tdata->aad.data, tdata->aad.len, + tdata->plaintext.len, plaintext_pad_len, +RTE_CRYPTO_AUTH_OP_VERIFY ); +if (retval <0 ) +return retval; + + ut_params->op =process_crypto_request (ts_params->valid_devs[0 ], + ut_params->op); +TEST_ASSERT_NOT_NULL (ut_params->op,"failed to retrieve obuf" ); + ut_params->obuf = ut_params->op->sym->m_src; + ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) + + plaintext_pad_len + tdata->aad.len; + +/* Validate obuf */ +if (ut_params->op->status ==RTE_CRYPTO_OP_STATUS_SUCCESS ) +return 0 ; +else +return -1 ; + +return 0 ; +} + + +static int +test_snow3g_hash_generate_test_case_1 (void ) +{ +return test_snow3g_authentication (&snow3g_hash_test_case_1); +} + +static int +test_snow3g_hash_generate_test_case_2 (void ) +{ +return test_snow3g_authentication (&snow3g_hash_test_case_2); +} + +static int +test_snow3g_hash_generate_test_case_3 (void ) +{ +return test_snow3g_authentication (&snow3g_hash_test_case_3); +} + +static int +test_snow3g_hash_verify_test_case_1 (void ) +{ +return test_snow3g_authentication_verify (&snow3g_hash_test_case_1); + +} + +static int +test_snow3g_hash_verify_test_case_2 (void ) +{ +return test_snow3g_authentication_verify (&snow3g_hash_test_case_2); +} + +static int +test_snow3g_hash_verify_test_case_3 (void ) +{ +return test_snow3g_authentication_verify (&snow3g_hash_test_case_3); +} + +static int +test_snow3g_encryption (const struct snow3g_test_data *tdata) +{ +struct crypto_testsuite_params *ts_params = &testsuite_params; +struct crypto_unittest_params *ut_params = &unittest_params; + +int retval; + +uint8_t *plaintext, *ciphertext; +uint8_t plaintext_pad_len; +uint8_t lastByteValidBits =8 ; +uint8_t lastByteMask =0xFF ; + +/* Create SNOW3G session */ + retval =create_snow3g_cipher_session (ts_params->valid_devs[0 ], +RTE_CRYPTO_CIPHER_OP_ENCRYPT , + tdata->key.data, tdata->key.len); +if (retval <0 ) +return retval; + + 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)); + +/* +* Append data which is padded to a +* multiple of the algorithms block size +*/ + plaintext_pad_len =RTE_ALIGN_CEIL (tdata->plaintext.len,16 ); + + plaintext = (uint8_t *)rte_pktmbuf_append (ut_params->ibuf, + plaintext_pad_len); +memcpy (plaintext, tdata->plaintext.data, tdata->plaintext.len); + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"plaintext:" , plaintext, tdata->plaintext.len); +#endif +/* Create SNOW3G operation */ + retval =create_snow3g_cipher_operation (tdata->iv.data, tdata->iv.len, + tdata->plaintext.len); +if (retval <0 ) +return retval; + + ut_params->op =process_crypto_request (ts_params->valid_devs[0 ], + ut_params->op); +TEST_ASSERT_NOT_NULL (ut_params->op,"failed to retrieve obuf" ); + + ut_params->obuf = ut_params->op->sym->m_src; +if (ut_params->obuf) + ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) + + tdata->iv.len; +else + ciphertext = plaintext; + + lastByteValidBits = (tdata->validDataLenInBits.len %8 ); +if (lastByteValidBits ==0 ) + lastByteValidBits =8 ; + lastByteMask = lastByteMask << (8 - lastByteValidBits); + (*(ciphertext + tdata->ciphertext.len -1 )) &= lastByteMask; + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"ciphertext:" , ciphertext, tdata->ciphertext.len); +#endif +/* Validate obuf */ +TEST_ASSERT_BUFFERS_ARE_EQUAL ( + ciphertext, + tdata->ciphertext.data, + tdata->ciphertext.len, +"Snow3G Ciphertext data not as expected" ); +return 0 ; +} + +static int test_snow3g_decryption (const struct snow3g_test_data *tdata) +{ +struct crypto_testsuite_params *ts_params = &testsuite_params; +struct crypto_unittest_params *ut_params = &unittest_params; + +int retval; + +uint8_t *plaintext, *ciphertext; +uint8_t ciphertext_pad_len; +uint8_t lastByteValidBits =8 ; +uint8_t lastByteMask =0xFF ; + +/* Create SNOW3G session */ + retval =create_snow3g_cipher_session (ts_params->valid_devs[0 ], +RTE_CRYPTO_CIPHER_OP_DECRYPT , + tdata->key.data, tdata->key.len); +if (retval <0 ) +return retval; + + 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)); + +/* +* Append data which is padded to a +* multiple of the algorithms block size +*/ + ciphertext_pad_len =RTE_ALIGN_CEIL (tdata->ciphertext.len,16 ); + + ciphertext = (uint8_t *)rte_pktmbuf_append (ut_params->ibuf, + ciphertext_pad_len); +memcpy (ciphertext, tdata->ciphertext.data, tdata->ciphertext.len); + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"ciphertext:" , ciphertext, tdata->ciphertext.len); +#endif +/* Create SNOW3G operation */ + retval =create_snow3g_cipher_operation (tdata->iv.data, tdata->iv.len, + tdata->ciphertext.len); +if (retval <0 ) +return retval; + + ut_params->op =process_crypto_request (ts_params->valid_devs[0 ], + ut_params->op); +TEST_ASSERT_NOT_NULL (ut_params->op,"failed to retrieve obuf" ); + ut_params->obuf = ut_params->op->sym->m_src; +if (ut_params->obuf) + plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) + + tdata->iv.len; +else + plaintext = ciphertext; + lastByteValidBits = (tdata->validDataLenInBits.len %8 ); +if (lastByteValidBits ==0 ) + lastByteValidBits =8 ; + lastByteMask = lastByteMask << (8 - lastByteValidBits); + (*(ciphertext + tdata->ciphertext.len -1 )) &= lastByteMask; + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"plaintext:" , plaintext, tdata->plaintext.len); +#endif +/* Validate obuf */ +TEST_ASSERT_BUFFERS_ARE_EQUAL (plaintext, + tdata->plaintext.data, + tdata->plaintext.len, +"Snow3G Plaintext data not as expected" ); +return 0 ; +} + +static int +test_snow3g_authenticated_encryption (const struct snow3g_test_data *tdata) +{ +struct crypto_testsuite_params *ts_params = &testsuite_params; +struct crypto_unittest_params *ut_params = &unittest_params; + +int retval; + +uint8_t *plaintext, *ciphertext; +uint8_t plaintext_pad_len; +uint8_t lastByteValidBits =8 ; +uint8_t lastByteMask =0xFF ; + +/* Create SNOW3G session */ + retval =create_snow3g_cipher_auth_session (ts_params->valid_devs[0 ], +RTE_CRYPTO_CIPHER_OP_ENCRYPT , +RTE_CRYPTO_AUTH_OP_GENERATE , + tdata->key.data, tdata->key.len, + tdata->aad.len, tdata->digest.len); +if (retval <0 ) +return retval; + 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)); + +/* Append data which is padded to a multiple */ +/* of the algorithms block size */ + plaintext_pad_len = tdata->plaintext.len; + + plaintext = (uint8_t *)rte_pktmbuf_append (ut_params->ibuf, + plaintext_pad_len); +memcpy (plaintext, tdata->plaintext.data, tdata->plaintext.len); + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"plaintext:" , plaintext, tdata->plaintext.len); +#endif + +/* Create SNOW3G operation */ + retval =create_snow3g_cipher_hash_operation (tdata->digest.data, + tdata->digest.len, tdata->aad.data, + tdata->aad.len, tdata->plaintext.len, + plaintext_pad_len,RTE_CRYPTO_AUTH_OP_GENERATE , + tdata->iv.data, tdata->iv.len); +if (retval <0 ) +return retval; + + ut_params->op =process_crypto_request (ts_params->valid_devs[0 ], + ut_params->op); +TEST_ASSERT_NOT_NULL (ut_params->op,"failed to retrieve obuf" ); + ut_params->obuf = ut_params->op->sym->m_src; +if (ut_params->obuf) + ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) + + tdata->iv.len; +else + ciphertext = plaintext; + lastByteValidBits = (tdata->validDataLenInBits.len %8 ); +if (lastByteValidBits ==0 ) + lastByteValidBits =8 ; + lastByteMask = lastByteMask << (8 -lastByteValidBits); + (*(ciphertext + tdata->ciphertext.len -1 )) &= lastByteMask; + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"ciphertext:" , ciphertext, tdata->ciphertext.len); +#endif +/* Validate obuf */ +TEST_ASSERT_BUFFERS_ARE_EQUAL ( + ciphertext, + tdata->ciphertext.data, + tdata->ciphertext.len, +"Snow3G Ciphertext data not as expected" ); + + ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) + + plaintext_pad_len + tdata->aad.len; + +/* Validate obuf */ +TEST_ASSERT_BUFFERS_ARE_EQUAL ( + ut_params->digest, + tdata->digest.data, +DIGEST_BYTE_LENGTH_SNOW3G_UIA2 , +"Snow3G Generated auth tag not as expected" ); +return 0 ; +} +static int +test_snow3g_encrypted_authentication (const struct snow3g_test_data *tdata) +{ +struct crypto_testsuite_params *ts_params = &testsuite_params; +struct crypto_unittest_params *ut_params = &unittest_params; + +int retval; + +uint8_t *plaintext, *ciphertext; +uint8_t plaintext_pad_len; +uint8_t lastByteValidBits =8 ; +uint8_t lastByteMask =0xFF ; + +/* Create SNOW3G session */ + retval =create_snow3g_auth_cipher_session (ts_params->valid_devs[0 ], +RTE_CRYPTO_CIPHER_OP_ENCRYPT , +RTE_CRYPTO_AUTH_OP_GENERATE , + tdata->key.data, tdata->key.len, + tdata->aad.len, tdata->digest.len); +if (retval <0 ) +return retval; + + 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)); + +/* Append data which is padded to a multiple */ +/* of the algorithms block size */ + plaintext_pad_len =RTE_ALIGN_CEIL (tdata->plaintext.len,8 ); + + plaintext = (uint8_t *)rte_pktmbuf_append (ut_params->ibuf, + plaintext_pad_len); +memcpy (plaintext, tdata->plaintext.data, tdata->plaintext.len); + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"plaintext:" , plaintext, tdata->plaintext.len); +#endif + +/* Create SNOW3G operation */ + retval =create_snow3g_auth_cipher_operation ( + tdata->digest.len, + tdata->iv.data, tdata->iv.len, + tdata->aad.data, tdata->aad.len, + tdata->plaintext.len, plaintext_pad_len + ); + +if (retval <0 ) +return retval; + + ut_params->op =process_crypto_request (ts_params->valid_devs[0 ], + ut_params->op); +TEST_ASSERT_NOT_NULL (ut_params->op,"failed to retrieve obuf" ); + ut_params->obuf = ut_params->op->sym->m_src; +if (ut_params->obuf) + ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) + + tdata->aad.len + tdata->iv.len; +else + ciphertext = plaintext; + + lastByteValidBits = (tdata->validDataLenInBits.len %8 ); +if (lastByteValidBits ==0 ) + lastByteValidBits =8 ; + lastByteMask = lastByteMask << (8 -lastByteValidBits); + (*(ciphertext + tdata->ciphertext.len -1 )) &= lastByteMask; + ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) + + plaintext_pad_len + tdata->aad.len + tdata->iv.len; + +#ifdef RTE_APP_TEST_DEBUG +rte_hexdump (stdout,"ciphertext:" , ciphertext, tdata->ciphertext.len); +#endif +/* Validate obuf */ +TEST_ASSERT_BUFFERS_ARE_EQUAL ( + ciphertext, + tdata->ciphertext.data, + tdata->ciphertext.len, +"Snow3G Ciphertext data not as expected" ); + +/* Validate obuf */ +TEST_ASSERT_BUFFERS_ARE_EQUAL ( + ut_params->digest, + tdata->digest.data, +DIGEST_BYTE_LENGTH_SNOW3G_UIA2 , +"Snow3G Generated auth tag not as expected" ); +return 0 ; +} + +static int +test_snow3g_encryption_test_case_1 (void ) +{ +return test_snow3g_encryption (&snow3g_test_case_1); +} + +static int +test_snow3g_encryption_test_case_2 (void ) +{ +return test_snow3g_encryption (&snow3g_test_case_2); +} + +static int +test_snow3g_encryption_test_case_3 (void ) +{ +return test_snow3g_encryption (&snow3g_test_case_3); +} + +static int +test_snow3g_encryption_test_case_4 (void ) +{ +return test_snow3g_encryption (&snow3g_test_case_4); +} + +static int +test_snow3g_encryption_test_case_5 (void ) +{ +return test_snow3g_encryption (&snow3g_test_case_5); +} + +static int +test_snow3g_decryption_test_case_1 (void ) +{ +return test_snow3g_decryption (&snow3g_test_case_1); +} + +static int +test_snow3g_decryption_test_case_2 (void ) +{ +return test_snow3g_decryption (&snow3g_test_case_2); +} + +static int +test_snow3g_decryption_test_case_3 (void ) +{ +return test_snow3g_decryption (&snow3g_test_case_3); +} + +static int +test_snow3g_decryption_test_case_4 (void ) +{ +return test_snow3g_decryption (&snow3g_test_case_4); +} + +static int +test_snow3g_decryption_test_case_5 (void ) +{ +return test_snow3g_decryption (&snow3g_test_case_5); +} +static int +test_snow3g_authenticated_encryption_test_case_1 (void ) +{ +return test_snow3g_authenticated_encryption (&snow3g_test_case_3); +} + +static int +test_snow3g_encrypted_authentication_test_case_1 (void ) +{ +return test_snow3g_encrypted_authentication (&snow3g_test_case_6); +}/* ***** AES-GCM Tests ***** */
@@ -1986,9 +2981,47 @@ static struct unit_test_suite cryptodev_qat_testsuite = { test_AES_CBC_HMAC_AES_XCBC_encrypt_digest),TEST_CASE_ST (ut_setup ,ut_teardown ,test_AES_CBC_HMAC_AES_XCBC_decrypt_digest_verify ), -TEST_CASE_ST (ut_setup ,ut_teardown ,test_stats ), +/** Snow3G encrypt only (UEA2) */ +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_encryption_test_case_1 ), +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_encryption_test_case_2 ), +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_encryption_test_case_3 ), +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_encryption_test_case_4 ), +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_encryption_test_case_5 ), + +/** Snow3G decrypt only (UEA2) */ +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_decryption_test_case_1 ), +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_decryption_test_case_2 ), +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_decryption_test_case_3 ), +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_decryption_test_case_4 ), +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_decryption_test_case_5 ), +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_hash_generate_test_case_1 ), +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_hash_generate_test_case_2 ), +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_hash_generate_test_case_3 ), +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_hash_verify_test_case_1 ), +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_hash_verify_test_case_2 ), +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_hash_verify_test_case_3 ), +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_authenticated_encryption_test_case_1 ), +TEST_CASE_ST (ut_setup ,ut_teardown , +test_snow3g_encrypted_authentication_test_case_1 ),TEST_CASES_END ()/**< NULL terminate unit test array */ } };
app/test/test_cryptodev.h +2 -1
@@ -1,7 +1,7 @@/*- * BSD LICENSE * -* Copyright(c) 2015 Intel Corporation. All rights reserved. +* Copyright(c) 2015-2016 Intel Corporation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions
@@ -60,6 +60,7 @@#define DIGEST_BYTE_LENGTH_SHA384 (BYTE_LENGTH(384))#define DIGEST_BYTE_LENGTH_SHA512 (BYTE_LENGTH(512))#define DIGEST_BYTE_LENGTH_AES_XCBC (BYTE_LENGTH(96)) +#define DIGEST_BYTE_LENGTH_SNOW3G_UIA2 (BYTE_LENGTH(32))#define AES_XCBC_MAC_KEY_SZ (16)#define TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 (12)
app/test/test_cryptodev_snow3g_hash_test_vectors.h new file +415 -0
415 lines not on this page · raw message
app/test/test_cryptodev_snow3g_test_vectors.h new file +379 -0
379 lines not on this page · raw message
Signature · 1 line
2.1.0
Re: [PATCH v4 0/3] Snow3G support for Intel Quick Assist Devices
In reply to Deepak Kumar JAINQuoted 48 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Deepak Kumar JAIN
Sent: Thursday, March 10, 2016 5:13 PM
To: [email protected]
Subject: [dpdk-dev] [PATCH v4 0/3] Snow3G support for Intel Quick Assist DevicesThis patchset contains fixes and refactoring for Snow3G(UEA2 and UIA2) wireless algorithm for Intel Quick Assist devices.
QAT PMD previously supported only cipher/hash alg-chaining for AES/SHA. The code has been refactored to also support cipher-only and hash only
(for Snow3G only) functionality along with alg-chaining.Changes from V3:
1) Rebase based on below mentioned patchset.
2) Fixes test failure which happens only after
applying patch 1 only.Changes from v2:
1) Rebasing based on below mentioned patchset.
This patchset depends on
cryptodev API changes
http://dpdk.org/ml/archives/dev/2016-March/035451.htmlDeepak Kumar JAIN (3):
crypto: add cipher/auth only support
qat: add support for Snow3G
app/test: add Snow3G testsapp/test/test_cryptodev.c | 1037 +++++++++++++++++++- app/test/test_cryptodev.h | 3 +- app/test/test_cryptodev_snow3g_hash_test_vectors.h | 415 ++++++++ app/test/test_cryptodev_snow3g_test_vectors.h | 379 +++++++ doc/guides/cryptodevs/qat.rst | 8 +- doc/guides/rel_notes/release_16_04.rst | 6 + drivers/crypto/qat/qat_adf/qat_algs.h | 19 +- drivers/crypto/qat/qat_adf/qat_algs_build_desc.c | 284 +++++- drivers/crypto/qat/qat_crypto.c | 149 ++- drivers/crypto/qat/qat_crypto.h | 10 + 10 files changed, 2236 insertions(+), 74 deletions(-) create mode 100644 app/test/test_cryptodev_snow3g_hash_test_vectors.h create mode 100644 app/test/test_cryptodev_snow3g_test_vectors.h
Quoted 2 lines
--
2.1.0
Thomas Monjalon
AppliedRe: [PATCH v4 0/3] Snow3G support for Intel Quick Assist Devices
Quoted 6 lines
Quoted 4 lines
Deepak Kumar JAIN (3):
crypto: add cipher/auth only support
qat: add support for Snow3G
app/test: add Snow3G testsSeries-acked-by Pablo de Lara <[email protected]>
Applied, thanks
Re: [PATCH v4 0/3] Snow3G support for Intel Quick Assist Devices
In reply to Deepak Kumar JAIN- Tested Commit: 1b9cb73ecef109593081ab9efbd9d1429607bb99
- OS: Fedora20 3.11.10-301.fc20.x86_64
- GCC: gcc (GCC) 4.8.3
- CPU: Intel(R) Xeon(R) CPU E5-2658 v3 @ 2.20GHz
- NIC: Niantic
- Default x86_64-native-linuxapp-gcc configuration
- Prerequisites:
- Total 42 cases, 42 passed, 0 failed
- test case 1: QAT Unit test
Total 31 cases, 31 passed, 0 failed
- test case 2: AES_NI Unit test
Total 10 cases, 10 passed, 0 failed
- test case 3: l2fwd-crypto
Total 1 cases, 1 passed, 0 failed
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Deepak Kumar JAIN
Sent: Friday, March 11, 2016 1:13 AM
To: [email protected]
Subject: [dpdk-dev] [PATCH v4 0/3] Snow3G support for Intel Quick Assist Devices
This patchset contains fixes and refactoring for Snow3G(UEA2 and UIA2) wireless algorithm for Intel Quick Assist devices.
QAT PMD previously supported only cipher/hash alg-chaining for AES/SHA.
The code has been refactored to also support cipher-only and hash only (for Snow3G only) functionality along with alg-chaining.
Changes from V3:
1) Rebase based on below mentioned patchset.
2) Fixes test failure which happens only after
applying patch 1 only.
Changes from v2:
1) Rebasing based on below mentioned patchset.
This patchset depends on
cryptodev API changes
http://dpdk.org/ml/archives/dev/2016-March/035451.html
Deepak Kumar JAIN (3):
crypto: add cipher/auth only support
qat: add support for Snow3G
app/test: add Snow3G tests
app/test/test_cryptodev.c | 1037 +++++++++++++++++++- app/test/test_cryptodev.h | 3 +- app/test/test_cryptodev_snow3g_hash_test_vectors.h | 415 ++++++++ app/test/test_cryptodev_snow3g_test_vectors.h | 379 +++++++ doc/guides/cryptodevs/qat.rst | 8 +- doc/guides/rel_notes/release_16_04.rst | 6 + drivers/crypto/qat/qat_adf/qat_algs.h | 19 +- drivers/crypto/qat/qat_adf/qat_algs_build_desc.c | 284 +++++- drivers/crypto/qat/qat_crypto.c | 149 ++- drivers/crypto/qat/qat_crypto.h | 10 + 10 files changed, 2236 insertions(+), 74 deletions(-) create mode 100644 app/test/test_cryptodev_snow3g_hash_test_vectors.h create mode 100644 app/test/test_cryptodev_snow3g_test_vectors.h
--
2.1.0
Re: [PATCH v3 0/3] Snow3G support for Intel Quick Assist Devices
In reply to Deepak Kumar JAIN- Tested Commit: 1b9cb73ecef109593081ab9efbd9d1429607bb99
- OS: Fedora20 3.11.10-301.fc20.x86_64
- GCC: gcc (GCC) 4.8.3
- CPU: Intel(R) Xeon(R) CPU E5-2658 v3 @ 2.20GHz
- NIC: Niantic
- Default x86_64-native-linuxapp-gcc configuration
- Prerequisites:
- Total 42 cases, 42 passed, 0 failed
- test case 1: QAT Unit test
Total 31 cases, 31 passed, 0 failed
- test case 2: AES_NI Unit test
Total 10 cases, 10 passed, 0 failed
- test case 3: l2fwd-crypto
Total 1 cases, 1 passed, 0 failed
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Deepak Kumar JAIN
Sent: Thursday, March 03, 2016 9:01 PM
To: [email protected]
Subject: [dpdk-dev] [PATCH v3 0/3] Snow3G support for Intel Quick Assist Devices
This patchset contains fixes and refactoring for Snow3G(UEA2 and UIA2) wireless algorithm for Intel Quick Assist devices.
QAT PMD previously supported only cipher/hash alg-chaining for AES/SHA.
The code has been refactored to also support cipher-only and hash only (for Snow3G only) functionality along with alg-chaining.
Changes from v2:
1) Rebasing based on below mentioned patchset.
This patchset depends on
cryptodev API changes
http://dpdk.org/ml/archives/dev/2016-February/034212.html
Deepak Kumar JAIN (3):
crypto: add cipher/auth only support
qat: add support for Snow3G
app/test: add Snow3G tests
app/test/test_cryptodev.c | 1037 +++++++++++++++++++- app/test/test_cryptodev.h | 3 +- app/test/test_cryptodev_snow3g_hash_test_vectors.h | 415 ++++++++ app/test/test_cryptodev_snow3g_test_vectors.h | 379 +++++++ doc/guides/cryptodevs/qat.rst | 8 +- doc/guides/rel_notes/release_16_04.rst | 6 + drivers/crypto/qat/qat_adf/qat_algs.h | 19 +- drivers/crypto/qat/qat_adf/qat_algs_build_desc.c | 280 +++++- drivers/crypto/qat/qat_crypto.c | 149 ++- drivers/crypto/qat/qat_crypto.h | 10 + 10 files changed, 2231 insertions(+), 75 deletions(-) create mode 100644 app/test/test_cryptodev_snow3g_hash_test_vectors.h create mode 100644 app/test/test_cryptodev_snow3g_test_vectors.h
--
2.1.0
Re: [PATCH v2 0/3] Snow3G support for Intel Quick Assist Devices
In reply to Deepak Kumar JAIN- Tested Commit: 1b9cb73ecef109593081ab9efbd9d1429607bb99
- OS: Fedora20 3.11.10-301.fc20.x86_64
- GCC: gcc (GCC) 4.8.3
- CPU: Intel(R) Xeon(R) CPU E5-2658 v3 @ 2.20GHz
- NIC: Niantic
- Default x86_64-native-linuxapp-gcc configuration
- Prerequisites:
- Total 42 cases, 42 passed, 0 failed
- test case 1: QAT Unit test
Total 31 cases, 31 passed, 0 failed
- test case 2: AES_NI Unit test
Total 10 cases, 10 passed, 0 failed
- test case 3: l2fwd-crypto
Total 1 cases, 1 passed, 0 failed
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Deepak Kumar JAIN
Sent: Tuesday, February 23, 2016 10:03 PM
To: [email protected]
Subject: [dpdk-dev] [PATCH v2 0/3] Snow3G support for Intel Quick Assist Devices
This patchset contains fixes and refactoring for Snow3G(UEA2 and UIA2) wireless algorithm for Intel Quick Assist devices.
QAT PMD previously supported only cipher/hash alg-chaining for AES/SHA.
The code has been refactored to also support cipher-only and hash only (for Snow3G only) functionality along with alg-chaining.
Changes from v1:
1) Hash only fix and alg chainging fix
2) Added hash test vectors for snow3g UIA2 functionality.
This patchset depends on
Cryptodev API changes
http://dpdk.org/ml/archives/dev/2016-February/033551.html
Deepak Kumar JAIN (3):
crypto: add cipher/auth only support
qat: add support for Snow3G
app/test: add Snow3G tests
app/test/test_cryptodev.c | 1037 +++++++++++++++++++- app/test/test_cryptodev.h | 3 +- app/test/test_cryptodev_snow3g_hash_test_vectors.h | 415 ++++++++ app/test/test_cryptodev_snow3g_test_vectors.h | 379 +++++++ doc/guides/cryptodevs/qat.rst | 8 +- doc/guides/rel_notes/release_16_04.rst | 4 + drivers/crypto/qat/qat_adf/qat_algs.h | 19 +- drivers/crypto/qat/qat_adf/qat_algs_build_desc.c | 280 +++++- drivers/crypto/qat/qat_crypto.c | 147 ++- drivers/crypto/qat/qat_crypto.h | 10 + 10 files changed, 2228 insertions(+), 74 deletions(-) create mode 100644 app/test/test_cryptodev_snow3g_hash_test_vectors.h create mode 100644 app/test/test_cryptodev_snow3g_test_vectors.h
--
2.1.0