From: Pablo de Lara <pablo.de.lara.guarch@intel.com>
To: dev@dpdk.org
Cc: declan.doherty@intel.com, Pablo de Lara <pablo.de.lara.guarch@intel.com>
Subject: [dpdk-dev] [PATCH 8/8] test: add Snow3G UEA2 test with offset
Date: Fri, 6 May 2016 15:03:49 +0100 [thread overview]
Message-ID: <1462543429-26741-9-git-send-email-pablo.de.lara.guarch@intel.com> (raw)
In-Reply-To: <1462543429-26741-1-git-send-email-pablo.de.lara.guarch@intel.com>
With the new libsso library, buffers can be encrypted/decrypted,
providing an offset in bits, so an extra unit test has been
added to cover this case.
Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
---
app/test/test_cryptodev.c | 121 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 121 insertions(+)
diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c
index 679231d..cd4ae43 100644
--- a/app/test/test_cryptodev.c
+++ b/app/test/test_cryptodev.c
@@ -3562,6 +3562,118 @@ test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
return 0;
}
+/* Shift right a buffer by "offset" bits, "offset" < 8 */
+static void
+buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset)
+{
+ uint8_t curr_byte, prev_byte;
+ uint32_t length_in_bytes = ceil_byte_length(length + offset);
+ uint8_t lower_byte_mask = (1 << offset) - 1;
+ unsigned i;
+
+ prev_byte = buffer[0];
+ buffer[0] >>= offset;
+
+ for (i = 1; i < length_in_bytes; i++) {
+ curr_byte = buffer[i];
+ buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) |
+ (curr_byte >> offset);
+ prev_byte = curr_byte;
+ }
+}
+
+static int
+test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata)
+{
+ struct crypto_testsuite_params *ts_params = &testsuite_params;
+ struct crypto_unittest_params *ut_params = &unittest_params;
+ uint8_t *plaintext, *ciphertext;
+ int retval;
+ uint32_t plaintext_len;
+ uint32_t plaintext_pad_len;
+ uint8_t extra_offset = 4;
+ uint8_t *expected_ciphertext_shifted;
+
+ /* 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);
+ ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
+
+ TEST_ASSERT_NOT_NULL(ut_params->ibuf,
+ "Failed to allocate input buffer in mempool");
+ TEST_ASSERT_NOT_NULL(ut_params->obuf,
+ "Failed to allocate output buffer in mempool");
+
+ /* Clear mbuf payload */
+ memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
+ rte_pktmbuf_tailroom(ut_params->ibuf));
+
+ plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset);
+ /*
+ * Append data which is padded to a
+ * multiple of the algorithms block size
+ */
+ plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
+
+ plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
+ plaintext_pad_len);
+
+ rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
+
+ memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
+ buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset);
+
+#ifdef RTE_APP_TEST_DEBUG
+ rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
+#endif
+ /* Create SNOW3G operation */
+ retval = create_snow3g_cipher_operation_oop(tdata->iv.data,
+ tdata->iv.len,
+ tdata->validCipherLenInBits.len,
+ tdata->validCipherOffsetLenInBits.len +
+ extra_offset);
+ 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_dst;
+ if (ut_params->obuf)
+ ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
+ + tdata->iv.len;
+ else
+ ciphertext = plaintext;
+
+#ifdef RTE_APP_TEST_DEBUG
+ rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
+#endif
+
+ expected_ciphertext_shifted = rte_malloc(NULL,
+ ceil_byte_length(plaintext_len + extra_offset), 0);
+
+ TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted,
+ "failed to reserve memory for ciphertext shifted\n");
+
+ memcpy(expected_ciphertext_shifted, tdata->ciphertext.data,
+ ceil_byte_length(tdata->ciphertext.len));
+ buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len,
+ extra_offset);
+ /* Validate obuf */
+ TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
+ ciphertext,
+ expected_ciphertext_shifted,
+ tdata->validDataLenInBits.len,
+ extra_offset,
+ "Snow3G Ciphertext data not as expected");
+ return 0;
+}
static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
{
@@ -3910,6 +4022,12 @@ test_snow3g_encryption_test_case_1_oop(void)
}
static int
+test_snow3g_encryption_test_case_1_offset_oop(void)
+{
+ return test_snow3g_encryption_offset_oop(&snow3g_test_case_1);
+}
+
+static int
test_snow3g_encryption_test_case_2(void)
{
return test_snow3g_encryption(&snow3g_test_case_2);
@@ -5222,6 +5340,9 @@ static struct unit_test_suite cryptodev_sw_snow3g_testsuite = {
TEST_CASE_ST(ut_setup, ut_teardown,
test_snow3g_decryption_test_case_1_oop),
+ TEST_CASE_ST(ut_setup, ut_teardown,
+ test_snow3g_encryption_test_case_1_offset_oop),
+
/** Snow3G decrypt only (UEA2) */
TEST_CASE_ST(ut_setup, ut_teardown,
test_snow3g_decryption_test_case_1),
--
2.5.0
next prev parent reply other threads:[~2016-05-06 13:59 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-06 14:03 [dpdk-dev] [PATCH 0/8] Snow3G bit-level support Pablo de Lara
2016-05-06 14:03 ` [dpdk-dev] [PATCH 1/8] snow3g: rename libsso reference due to library update Pablo de Lara
2016-05-06 14:03 ` [dpdk-dev] [PATCH 2/8] doc: update build instructions for libsso_snow3g Pablo de Lara
2016-06-09 12:07 ` Mcnamara, John
2016-05-06 14:03 ` [dpdk-dev] [PATCH 3/8] snow3g: support bit-level operations Pablo de Lara
2016-05-06 14:03 ` [dpdk-dev] [PATCH 4/8] test: use new bit-level memcmp macro Pablo de Lara
2016-05-06 14:03 ` [dpdk-dev] [PATCH 5/8] test: fix buffer lengths for snow3G tests Pablo de Lara
2016-05-06 14:03 ` [dpdk-dev] [PATCH 6/8] test: add out-of-place crypto op tests for Snow3G PMD Pablo de Lara
2016-05-06 14:03 ` [dpdk-dev] [PATCH 7/8] test: add bit-level Snow3G UIA2 tests Pablo de Lara
2016-05-06 14:03 ` Pablo de Lara [this message]
2016-06-17 11:24 ` [dpdk-dev] [PATCH v2 00/11] Snow3G bit-level support Pablo de Lara
2016-06-17 11:24 ` [dpdk-dev] [PATCH v2 01/11] snow3g: rename libsso reference due to library update Pablo de Lara
2016-06-17 11:24 ` [dpdk-dev] [PATCH v2 02/11] doc: update build instructions for libsso_snow3g Pablo de Lara
2016-06-17 11:24 ` [dpdk-dev] [PATCH v2 03/11] snow3g: define IV/digest length macros Pablo de Lara
2016-06-17 11:24 ` [dpdk-dev] [PATCH v2 04/11] snow3g: support bit-level operations Pablo de Lara
2016-06-17 11:24 ` [dpdk-dev] [PATCH v2 05/11] snow3g: add missing feature flags Pablo de Lara
2016-06-17 11:24 ` [dpdk-dev] [PATCH v2 06/11] test: use new bit-level memcmp macro Pablo de Lara
2016-06-17 11:24 ` [dpdk-dev] [PATCH v2 07/11] test: fix buffer lengths for snow3G tests Pablo de Lara
2016-06-17 11:24 ` [dpdk-dev] [PATCH v2 08/11] test: add out-of-place crypto op tests for Snow3G PMD Pablo de Lara
2016-06-17 11:24 ` [dpdk-dev] [PATCH v2 09/11] test: add bit-level Snow3G UIA2 tests Pablo de Lara
2016-06-17 11:24 ` [dpdk-dev] [PATCH v2 10/11] test: add Snow3G UEA2 test with offset Pablo de Lara
2016-06-17 11:24 ` [dpdk-dev] [PATCH v2 11/11] test: refactor snow3g/kasumi tests Pablo de Lara
2016-06-17 13:41 ` [dpdk-dev] [PATCH v2 00/11] Snow3G bit-level support Jain, Deepak K
2016-06-20 9:27 ` [dpdk-dev] [PATCH v3 " Pablo de Lara
2016-06-20 9:27 ` [dpdk-dev] [PATCH v3 01/11] snow3g: rename libsso reference due to library update Pablo de Lara
2016-06-20 9:27 ` [dpdk-dev] [PATCH v3 02/11] doc: update build instructions for libsso_snow3g Pablo de Lara
2016-06-20 9:27 ` [dpdk-dev] [PATCH v3 03/11] snow3g: define IV/digest length macros Pablo de Lara
2016-06-20 9:27 ` [dpdk-dev] [PATCH v3 04/11] snow3g: support bit-level operations Pablo de Lara
2016-06-20 9:27 ` [dpdk-dev] [PATCH v3 05/11] snow3g: add missing feature flags Pablo de Lara
2016-06-20 9:27 ` [dpdk-dev] [PATCH v3 06/11] test: use new bit-level memcmp macro Pablo de Lara
2016-06-20 9:27 ` [dpdk-dev] [PATCH v3 07/11] test: fix buffer lengths for snow3G tests Pablo de Lara
2016-06-20 9:27 ` [dpdk-dev] [PATCH v3 08/11] test: add out-of-place crypto op tests for Snow3G PMD Pablo de Lara
2016-06-20 9:27 ` [dpdk-dev] [PATCH v3 09/11] test: add bit-level Snow3G UIA2 tests Pablo de Lara
2016-06-20 9:27 ` [dpdk-dev] [PATCH v3 10/11] test: add Snow3G UEA2 test with offset Pablo de Lara
2016-06-20 9:27 ` [dpdk-dev] [PATCH v3 11/11] test: refactor snow3g/kasumi tests Pablo de Lara
2016-06-20 14:44 ` [dpdk-dev] [PATCH v4 00/11] Snow3G bit-level support Pablo de Lara
2016-06-20 14:44 ` [dpdk-dev] [PATCH v4 01/11] snow3g: rename libsso reference due to library update Pablo de Lara
2016-06-20 14:44 ` [dpdk-dev] [PATCH v4 02/11] doc: update build instructions for libsso_snow3g Pablo de Lara
2016-06-20 14:44 ` [dpdk-dev] [PATCH v4 03/11] snow3g: define IV/digest length macros Pablo de Lara
2016-06-20 14:44 ` [dpdk-dev] [PATCH v4 04/11] snow3g: support bit-level operations Pablo de Lara
2016-06-20 14:44 ` [dpdk-dev] [PATCH v4 05/11] snow3g: add missing feature flags Pablo de Lara
2016-06-20 14:44 ` [dpdk-dev] [PATCH v4 06/11] test: use new bit-level memcmp macro Pablo de Lara
2016-06-20 14:44 ` [dpdk-dev] [PATCH v4 07/11] test: fix buffer lengths for snow3G tests Pablo de Lara
2016-06-20 14:44 ` [dpdk-dev] [PATCH v4 08/11] test: add out-of-place crypto op tests for Snow3G PMD Pablo de Lara
2016-06-20 14:45 ` [dpdk-dev] [PATCH v4 09/11] test: add bit-level Snow3G UIA2 tests Pablo de Lara
2016-06-20 14:45 ` [dpdk-dev] [PATCH v4 10/11] test: add Snow3G UEA2 test with offset Pablo de Lara
2016-06-20 14:45 ` [dpdk-dev] [PATCH v4 11/11] test: refactor snow3g/kasumi tests Pablo de Lara
2016-06-20 20:41 ` [dpdk-dev] [PATCH v4 00/11] Snow3G bit-level support Thomas Monjalon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1462543429-26741-9-git-send-email-pablo.de.lara.guarch@intel.com \
--to=pablo.de.lara.guarch@intel.com \
--cc=declan.doherty@intel.com \
--cc=dev@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).