From: Deepak Kumar Jain Date: Thu, 10 Mar 2016 17:44:10 +0000 (+0000) Subject: cryptodev: add bit-wise handling for SNOW 3G X-Git-Tag: spdx-start~7500 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=a59ffe7eb952b5777419e880cb4330bb86f8d8ad;p=dpdk.git cryptodev: add bit-wise handling for SNOW 3G Wireless algorithms like Snow3G needs input in bits. In this patch, changes have been made to incorporate this requirement in both QAT and SW PMD. Signed-off-by: Deepak Kumar Jain Acked-by: Pablo de Lara --- diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c index 6c37bf3715..b9db425ec9 100644 --- a/app/test/test_cryptodev.c +++ b/app/test/test_cryptodev.c @@ -1828,7 +1828,8 @@ create_snow3g_cipher_session(uint8_t dev_id, static int create_snow3g_cipher_operation(const uint8_t *iv, const unsigned iv_len, - const unsigned data_len) + const unsigned cipher_len, + const unsigned cipher_offset) { struct crypto_testsuite_params *ts_params = &testsuite_params; struct crypto_unittest_params *ut_params = &unittest_params; @@ -1860,8 +1861,8 @@ create_snow3g_cipher_operation(const uint8_t *iv, const unsigned iv_len, 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; + sym_op->cipher.data.length = cipher_len; + sym_op->cipher.data.offset = cipher_offset; return 0; } @@ -1958,8 +1959,9 @@ 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) + unsigned data_pad_len, + enum rte_crypto_auth_operation op, + const unsigned auth_len, const unsigned auth_offset) { struct crypto_testsuite_params *ts_params = &testsuite_params; @@ -2027,8 +2029,8 @@ create_snow3g_hash_operation(const uint8_t *auth_tag, sym_op->auth.digest.length); #endif - sym_op->auth.data.length = data_len; - sym_op->auth.data.offset = aad_buffer_len; + sym_op->auth.data.length = auth_len; + sym_op->auth.data.offset = auth_offset; return 0; } @@ -2037,9 +2039,11 @@ 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, + unsigned data_pad_len, enum rte_crypto_auth_operation op, - const uint8_t *iv, const unsigned iv_len) + const uint8_t *iv, const unsigned iv_len, + const unsigned cipher_len, const unsigned cipher_offset, + const unsigned auth_len, const unsigned auth_offset) { struct crypto_testsuite_params *ts_params = &testsuite_params; struct crypto_unittest_params *ut_params = &unittest_params; @@ -2074,8 +2078,8 @@ create_snow3g_cipher_hash_operation(const uint8_t *auth_tag, 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; + sym_op->cipher.data.length = cipher_len; + sym_op->cipher.data.offset = cipher_offset; /* aad */ /* @@ -2124,8 +2128,8 @@ create_snow3g_cipher_hash_operation(const uint8_t *auth_tag, sym_op->auth.digest.length); #endif - sym_op->auth.data.length = data_len; - sym_op->auth.data.offset = aad_buffer_len; + sym_op->auth.data.length = auth_len; + sym_op->auth.data.offset = auth_offset; return 0; } @@ -2134,7 +2138,9 @@ 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) + unsigned data_pad_len, + const unsigned cipher_len, const unsigned cipher_offset, + const unsigned auth_len, const unsigned auth_offset) { struct crypto_testsuite_params *ts_params = &testsuite_params; struct crypto_unittest_params *ut_params = &unittest_params; @@ -2213,11 +2219,11 @@ create_snow3g_auth_cipher_operation(const unsigned auth_tag_len, 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->cipher.data.length = cipher_len; + sym_op->cipher.data.offset = auth_offset + cipher_offset; - sym_op->auth.data.length = data_len; - sym_op->auth.data.offset = aad_buffer_len + iv_pad_len; + sym_op->auth.data.length = auth_len; + sym_op->auth.data.offset = auth_offset + cipher_offset; return 0; } @@ -2248,15 +2254,17 @@ test_snow3g_authentication(const struct snow3g_hash_test_data *tdata) /* Append data which is padded to a multiple of */ /* the algorithms block size */ - plaintext_pad_len = tdata->plaintext.len; + plaintext_pad_len = tdata->plaintext.len >> 3; plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, plaintext_pad_len); - memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); + memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3); /* 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); + tdata->aad.data, tdata->aad.len, + plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, + tdata->validAuthLenInBits.len, + tdata->validAuthOffsetLenInBits.len); if (retval < 0) return retval; @@ -2302,17 +2310,19 @@ test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata) /* Append data which is padded to a multiple */ /* of the algorithms block size */ - plaintext_pad_len = tdata->plaintext.len; + plaintext_pad_len = tdata->plaintext.len >> 3; plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, plaintext_pad_len); - memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); + memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3); /* 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); + plaintext_pad_len, + RTE_CRYPTO_AUTH_OP_VERIFY, + tdata->validAuthLenInBits.len, + tdata->validAuthOffsetLenInBits.len); if (retval < 0) return retval; @@ -2400,18 +2410,20 @@ test_snow3g_encryption(const struct snow3g_test_data *tdata) * Append data which is padded to a * multiple of the algorithms block size */ - plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); + /*tdata->plaintext.len = tdata->plaintext.len >> 3;*/ + plaintext_pad_len = RTE_ALIGN_CEIL((tdata->plaintext.len >> 3), 16); plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf, plaintext_pad_len); - memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); + memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3)); #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); + tdata->validCipherLenInBits.len, + tdata->validCipherOffsetLenInBits.len); if (retval < 0) return retval; @@ -2430,7 +2442,7 @@ test_snow3g_encryption(const struct snow3g_test_data *tdata) if (lastByteValidBits == 0) lastByteValidBits = 8; lastByteMask = lastByteMask << (8 - lastByteValidBits); - (*(ciphertext + tdata->ciphertext.len - 1)) &= lastByteMask; + (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask; #ifdef RTE_APP_TEST_DEBUG rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); @@ -2439,7 +2451,7 @@ test_snow3g_encryption(const struct snow3g_test_data *tdata) TEST_ASSERT_BUFFERS_ARE_EQUAL( ciphertext, tdata->ciphertext.data, - tdata->ciphertext.len, + tdata->ciphertext.len >> 3, "Snow3G Ciphertext data not as expected"); return 0; } @@ -2473,18 +2485,19 @@ static int test_snow3g_decryption(const struct snow3g_test_data *tdata) * Append data which is padded to a * multiple of the algorithms block size */ - ciphertext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16); + ciphertext_pad_len = RTE_ALIGN_CEIL((tdata->ciphertext.len >> 3), 16); ciphertext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf, ciphertext_pad_len); - memcpy(ciphertext, tdata->ciphertext.data, tdata->ciphertext.len); + memcpy(ciphertext, tdata->ciphertext.data, tdata->ciphertext.len >> 3); #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); + tdata->validCipherLenInBits.len, + tdata->validCipherOffsetLenInBits.len); if (retval < 0) return retval; @@ -2497,11 +2510,11 @@ static int test_snow3g_decryption(const struct snow3g_test_data *tdata) + tdata->iv.len; else plaintext = ciphertext; - lastByteValidBits = (tdata->validDataLenInBits.len % 8); + lastByteValidBits = (tdata->validDataLenInBits.len % 8); if (lastByteValidBits == 0) lastByteValidBits = 8; lastByteMask = lastByteMask << (8 - lastByteValidBits); - (*(ciphertext + tdata->ciphertext.len - 1)) &= lastByteMask; + (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask; #ifdef RTE_APP_TEST_DEBUG rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len); @@ -2509,7 +2522,7 @@ static int test_snow3g_decryption(const struct snow3g_test_data *tdata) /* Validate obuf */ TEST_ASSERT_BUFFERS_ARE_EQUAL(plaintext, tdata->plaintext.data, - tdata->plaintext.len, + tdata->plaintext.len >> 3, "Snow3G Plaintext data not as expected"); return 0; } @@ -2543,11 +2556,11 @@ test_snow3g_authenticated_encryption(const struct snow3g_test_data *tdata) /* Append data which is padded to a multiple */ /* of the algorithms block size */ - plaintext_pad_len = tdata->plaintext.len; + plaintext_pad_len = tdata->plaintext.len >> 3; plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, plaintext_pad_len); - memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); + memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3); #ifdef RTE_APP_TEST_DEBUG rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len); @@ -2556,9 +2569,13 @@ test_snow3g_authenticated_encryption(const struct snow3g_test_data *tdata) /* Create SNOW3G operation */ retval = create_snow3g_cipher_hash_operation(tdata->digest.data, tdata->digest.len, tdata->aad.data, - tdata->aad.len, tdata->plaintext.len, + tdata->aad.len, /*tdata->plaintext.len,*/ plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, - tdata->iv.data, tdata->iv.len); + tdata->iv.data, tdata->iv.len, + tdata->validCipherLenInBits.len, + tdata->validCipherOffsetLenInBits.len, + tdata->validAuthLenInBits.len, + tdata->validAuthOffsetLenInBits.len); if (retval < 0) return retval; @@ -2575,7 +2592,7 @@ test_snow3g_authenticated_encryption(const struct snow3g_test_data *tdata) if (lastByteValidBits == 0) lastByteValidBits = 8; lastByteMask = lastByteMask << (8-lastByteValidBits); - (*(ciphertext + tdata->ciphertext.len - 1)) &= lastByteMask; + (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask; #ifdef RTE_APP_TEST_DEBUG rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); @@ -2584,7 +2601,7 @@ test_snow3g_authenticated_encryption(const struct snow3g_test_data *tdata) TEST_ASSERT_BUFFERS_ARE_EQUAL( ciphertext, tdata->ciphertext.data, - tdata->ciphertext.len, + tdata->ciphertext.len >> 3, "Snow3G Ciphertext data not as expected"); ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) @@ -2628,11 +2645,11 @@ test_snow3g_encrypted_authentication(const struct snow3g_test_data *tdata) /* Append data which is padded to a multiple */ /* of the algorithms block size */ - plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 8); + plaintext_pad_len = RTE_ALIGN_CEIL((tdata->plaintext.len >> 3), 8); plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, plaintext_pad_len); - memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); + memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3); #ifdef RTE_APP_TEST_DEBUG rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len); @@ -2643,7 +2660,11 @@ test_snow3g_encrypted_authentication(const struct snow3g_test_data *tdata) tdata->digest.len, tdata->iv.data, tdata->iv.len, tdata->aad.data, tdata->aad.len, - tdata->plaintext.len, plaintext_pad_len + plaintext_pad_len, + tdata->validCipherLenInBits.len, + tdata->validCipherOffsetLenInBits.len, + tdata->validAuthLenInBits.len, + tdata->validAuthOffsetLenInBits.len ); if (retval < 0) @@ -2663,10 +2684,9 @@ test_snow3g_encrypted_authentication(const struct snow3g_test_data *tdata) if (lastByteValidBits == 0) lastByteValidBits = 8; lastByteMask = lastByteMask << (8-lastByteValidBits); - (*(ciphertext + tdata->ciphertext.len - 1)) &= lastByteMask; + (*(ciphertext + (tdata->ciphertext.len >> 3) - 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 @@ -2674,7 +2694,7 @@ test_snow3g_encrypted_authentication(const struct snow3g_test_data *tdata) TEST_ASSERT_BUFFERS_ARE_EQUAL( ciphertext, tdata->ciphertext.data, - tdata->ciphertext.len, + tdata->ciphertext.len >> 3, "Snow3G Ciphertext data not as expected"); /* Validate obuf */ diff --git a/app/test/test_cryptodev_snow3g_hash_test_vectors.h b/app/test/test_cryptodev_snow3g_hash_test_vectors.h index f4fa36d7b2..fe4906bc84 100644 --- a/app/test/test_cryptodev_snow3g_hash_test_vectors.h +++ b/app/test/test_cryptodev_snow3g_hash_test_vectors.h @@ -46,9 +46,17 @@ struct snow3g_hash_test_data { struct { uint8_t data[2056]; - unsigned len; + unsigned len; /* length must be in Bits */ } plaintext; + struct { + unsigned len; + } validAuthLenInBits; + + struct { + unsigned len; + } validAuthOffsetLenInBits; + struct { uint8_t data[64]; unsigned len; @@ -79,7 +87,13 @@ struct snow3g_hash_test_data snow3g_hash_test_case_1 = { 0xB2, 0x4A, 0x03, 0x86, 0x65, 0x42, 0x2B, 0x20, 0xA4, 0x99, 0x27, 0x6A, 0x50, 0x42, 0x70, 0x09 }, - .len = 48 + .len = 384 + }, + .validAuthLenInBits = { + .len = 384 + }, + .validAuthOffsetLenInBits = { + .len = 128 }, .digest = { .data = {0x38, 0xB5, 0x54, 0xC0 }, @@ -121,7 +135,13 @@ struct snow3g_hash_test_data snow3g_hash_test_case_2 = { 0x3D, 0x7C, 0xFE, 0xE9, 0x45, 0x85, 0xB5, 0x88, 0x5C, 0xAC, 0x46, 0x06, 0x8B }, - .len = 125 + .len = 1000 + }, + .validAuthLenInBits = { + .len = 1000 + }, + .validAuthOffsetLenInBits = { + .len = 128 }, .digest = { .data = {0x06, 0x17, 0x45, 0xAE}, @@ -404,7 +424,13 @@ struct snow3g_hash_test_data snow3g_hash_test_case_3 = { 0x11, 0x24, 0xBF, 0x1A, 0xD5, 0x4B, 0x79, 0x25, 0x32, 0x98, 0x3D, 0xD6, 0xC3, 0xA8, 0xB7, 0xD0 }, - .len = 2056 + .len = 16448 + }, + .validAuthLenInBits = { + .len = 16448 + }, + .validAuthOffsetLenInBits = { + .len = 128 }, .digest = { .data = {0x17, 0x9F, 0x2F, 0xA6}, diff --git a/app/test/test_cryptodev_snow3g_test_vectors.h b/app/test/test_cryptodev_snow3g_test_vectors.h index 403406d538..51917c14cb 100644 --- a/app/test/test_cryptodev_snow3g_test_vectors.h +++ b/app/test/test_cryptodev_snow3g_test_vectors.h @@ -46,18 +46,34 @@ struct snow3g_test_data { struct { uint8_t data[1024]; - unsigned len; + unsigned len; /* length must be in Bits */ } plaintext; struct { uint8_t data[1024]; - unsigned len; + unsigned len; /* length must be in Bits */ } ciphertext; struct { unsigned len; } validDataLenInBits; + struct { + unsigned len; + } validCipherLenInBits; + + struct { + unsigned len; + } validCipherOffsetLenInBits; + + struct { + unsigned len; + } validAuthLenInBits; + + struct { + unsigned len; + } validAuthOffsetLenInBits; + struct { uint8_t data[64]; unsigned len; @@ -99,7 +115,7 @@ struct snow3g_test_data snow3g_test_case_1 = { 0x39, 0x01, 0xA0, 0x8F, 0x4A, 0xB4, 0x1A, 0xAB, 0x9B, 0x13, 0x48, 0x80 }, - .len = 100 + .len = 800 }, .ciphertext = { .data = { @@ -117,11 +133,17 @@ struct snow3g_test_data snow3g_test_case_1 = { 0x05, 0x3D, 0xB5, 0x5A, 0x88, 0xC4, 0xC4, 0xF9, 0x60, 0x5E, 0x41, 0x40 }, - .len = 100 + .len = 800 }, .validDataLenInBits = { .len = 798 }, + .validCipherLenInBits = { + .len = 800 + }, + .validCipherOffsetLenInBits = { + .len = 128 + }, .aad = { .data = { 0x72, 0xA4, 0xF2, 0x0F, 0x64, 0x00, 0x00, 0x00, @@ -157,7 +179,7 @@ struct snow3g_test_data snow3g_test_case_2 = { 0x1C, 0xF9, 0x3B, 0x15, 0x10, 0x37, 0x6B, 0x02, 0x13, 0x0F, 0x81, 0x2A, 0x9F, 0xA1, 0x69, 0xD8 }, - .len = 64 + .len = 512 }, .ciphertext = { .data = { @@ -170,11 +192,17 @@ struct snow3g_test_data snow3g_test_case_2 = { 0x0D, 0xB0, 0xA9, 0xCD, 0x36, 0xC3, 0x4A, 0xE4, 0x18, 0x14, 0x90, 0xB2, 0x9F, 0x5F, 0xA2, 0xFC }, - .len = 64 + .len = 512 }, .validDataLenInBits = { .len = 510 }, + .validCipherLenInBits = { + .len = 512 + }, + .validCipherOffsetLenInBits = { + .len = 128 + }, .aad = { .data = { 0xE2, 0x8B, 0xCF, 0x7B, 0xC0, 0x00, 0x00, 0x00, @@ -204,18 +232,24 @@ struct snow3g_test_data snow3g_test_case_3 = { 0xAD, 0x9C, 0x44, 0x1F, 0x89, 0x0B, 0x38, 0xC4, 0x57, 0xA4, 0x9D, 0x42, 0x14, 0x07, 0xE8 }, - .len = 15 + .len = 120 }, .ciphertext = { .data = { 0xBA, 0x0F, 0x31, 0x30, 0x03, 0x34, 0xC5, 0x6B, 0x52, 0xA7, 0x49, 0x7C, 0xBA, 0xC0, 0x46 }, - .len = 15 + .len = 120 }, .validDataLenInBits = { .len = 120 }, + .validCipherLenInBits = { + .len = 120 + }, + .validCipherOffsetLenInBits = { + .len = 128 + }, .aad = { .data = { 0xFA, 0x55, 0x6B, 0x26, 0x1C, 0x00, 0x00, 0x00, @@ -226,6 +260,12 @@ struct snow3g_test_data snow3g_test_case_3 = { .digest = { .data = {0xE8, 0x60, 0x5A, 0x3E}, .len = 4 + }, + .validAuthLenInBits = { + .len = 120 + }, + .validAuthOffsetLenInBits = { + .len = 128 } }; @@ -251,7 +291,7 @@ struct snow3g_test_data snow3g_test_case_4 = { 0x8C, 0xE3, 0x3E, 0x2C, 0xC3, 0xC0, 0xB5, 0xFC, 0x1F, 0x3D, 0xE8, 0xA6, 0xDC, 0x66, 0xB1, 0xF0 }, - .len = 32 + .len = 256 }, .ciphertext = { .data = { @@ -260,10 +300,16 @@ struct snow3g_test_data snow3g_test_case_4 = { 0xA5, 0x6C, 0x40, 0xC0, 0xAB, 0x9D, 0x81, 0xF7, 0xA2, 0xA9, 0xBA, 0xC6, 0x0E, 0x11, 0xC4, 0xB0 }, - .len = 32 + .len = 256 }, .validDataLenInBits = { .len = 253 + }, + .validCipherLenInBits = { + .len = 256 + }, + .validCipherOffsetLenInBits = { + .len = 128 } }; @@ -298,7 +344,7 @@ struct snow3g_test_data snow3g_test_case_5 = { 0x98, 0x76, 0x45, 0x98, 0x7A, 0x98, 0x6F, 0x2C, 0xB0 }, - .len = 105 + .len = 840 }, .ciphertext = { .data = { @@ -317,10 +363,16 @@ struct snow3g_test_data snow3g_test_case_5 = { 0x43, 0x24, 0x85, 0x50, 0x92, 0x2A, 0xC1, 0x28, 0x18 }, - .len = 105 + .len = 840 }, .validDataLenInBits = { .len = 837 + }, + .validCipherLenInBits = { + .len = 840 + }, + .validCipherOffsetLenInBits = { + .len = 128 } }; struct snow3g_test_data snow3g_test_case_6 = { @@ -354,7 +406,7 @@ struct snow3g_test_data snow3g_test_case_6 = { 0xB2, 0x4A, 0x03, 0x86, 0x65, 0x42, 0x2B, 0x20, 0xA4, 0x99, 0x27, 0x6A, 0x50, 0x42, 0x70, 0x09 }, - .len = 48 + .len = 384 }, .ciphertext = { .data = { @@ -365,7 +417,7 @@ struct snow3g_test_data snow3g_test_case_6 = { 0xBD, 0x91, 0xAA, 0xB6, 0xA4, 0xDC, 0x64, 0xB4, 0xCB, 0xEB, 0x97, 0x06, 0x4C, 0xF7, 0x02, 0x3D }, - .len = 48 + .len = 384 }, .digest = { .data = {0x38, 0xB5, 0x54, 0xC0 }, @@ -373,6 +425,18 @@ struct snow3g_test_data snow3g_test_case_6 = { }, .validDataLenInBits = { .len = 384 + }, + .validCipherLenInBits = { + .len = 384 + }, + .validCipherOffsetLenInBits = { + .len = 128 + }, + .validAuthLenInBits = { + .len = 384 + }, + .validAuthOffsetLenInBits = { + .len = 128 } }; diff --git a/doc/guides/cryptodevs/qat.rst b/doc/guides/cryptodevs/qat.rst index af52047f2e..8f09d3230a 100644 --- a/doc/guides/cryptodevs/qat.rst +++ b/doc/guides/cryptodevs/qat.rst @@ -67,6 +67,8 @@ Limitations * 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. +* Snow3g(UEA2) supported only if cipher length, cipher offset fields are byte-aligned. +* Snow3g(UIA2) supported only if hash length, hash offset fields are byte-aligned. Installation diff --git a/doc/guides/cryptodevs/snow3g.rst b/doc/guides/cryptodevs/snow3g.rst index ef8ea5d97c..b4c53dcc49 100644 --- a/doc/guides/cryptodevs/snow3g.rst +++ b/doc/guides/cryptodevs/snow3g.rst @@ -51,6 +51,8 @@ Limitations ----------- * Chained mbufs are not supported. +* Snow3g(UEA2) supported only if cipher length, cipher offset fields are byte-aligned. +* Snow3g(UIA2) supported only if hash length, hash offset fields are byte-aligned. Installation ------------ diff --git a/drivers/crypto/qat/qat_crypto.c b/drivers/crypto/qat/qat_crypto.c index e0e506d748..2bd1753e64 100644 --- a/drivers/crypto/qat/qat_crypto.c +++ b/drivers/crypto/qat/qat_crypto.c @@ -66,6 +66,7 @@ #include "qat_crypto.h" #include "adf_transport_access_macros.h" +#define BYTE_LENGTH 8 static inline uint32_t adf_modulo(uint32_t data, uint32_t shift); @@ -506,6 +507,19 @@ qat_write_hw_desc_entry(struct rte_crypto_op *op, uint8_t *out_msg) cipher_param->cipher_length = op->sym->cipher.data.length; cipher_param->cipher_offset = op->sym->cipher.data.offset; + if (ctx->qat_cipher_alg == ICP_QAT_HW_CIPHER_ALGO_SNOW_3G_UEA2) { + if (unlikely((cipher_param->cipher_length % BYTE_LENGTH != 0) || + (cipher_param->cipher_offset + % BYTE_LENGTH != 0))) { + PMD_DRV_LOG(ERR, " For Snow3g, QAT PMD only " + "supports byte aligned values"); + op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS; + return -EINVAL; + } + cipher_param->cipher_length >>= 3; + cipher_param->cipher_offset >>= 3; + } + if (op->sym->cipher.iv.length && (op->sym->cipher.iv.length <= sizeof(cipher_param->u.cipher_IV_array))) { rte_memcpy(cipher_param->u.cipher_IV_array, @@ -525,7 +539,17 @@ qat_write_hw_desc_entry(struct rte_crypto_op *op, uint8_t *out_msg) } auth_param->auth_off = op->sym->auth.data.offset; auth_param->auth_len = op->sym->auth.data.length; - + if (ctx->qat_hash_alg == ICP_QAT_HW_AUTH_ALGO_SNOW_3G_UIA2) { + if (unlikely((auth_param->auth_off % BYTE_LENGTH != 0) || + (auth_param->auth_len % BYTE_LENGTH != 0))) { + PMD_DRV_LOG(ERR, " For Snow3g, QAT PMD only " + "supports byte aligned values"); + op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS; + return -EINVAL; + } + auth_param->auth_off >>= 3; + auth_param->auth_len >>= 3; + } auth_param->u1.aad_adr = op->sym->auth.aad.phys_addr; /* (GCM) aad length(240 max) will be at this location after precompute */ if (ctx->qat_hash_alg == ICP_QAT_HW_AUTH_ALGO_GALOIS_128 || diff --git a/drivers/crypto/snow3g/rte_snow3g_pmd.c b/drivers/crypto/snow3g/rte_snow3g_pmd.c index c35e66e4c9..6f84e5c494 100644 --- a/drivers/crypto/snow3g/rte_snow3g_pmd.c +++ b/drivers/crypto/snow3g/rte_snow3g_pmd.c @@ -43,6 +43,7 @@ #include "rte_snow3g_pmd_private.h" #define SNOW3G_MAX_BURST 8 +#define BYTE_LEN 8 /** * Global static parameter used to create a unique name for each SNOW 3G @@ -203,15 +204,23 @@ process_snow3g_cipher_op(struct rte_crypto_op **ops, break; } + if (((ops[i]->sym->cipher.data.length % BYTE_LEN) != 0) + || ((ops[i]->sym->cipher.data.offset + % BYTE_LEN) != 0)) { + ops[i]->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS; + SNOW3G_LOG_ERR("Data Length or offset"); + break; + } + src[i] = rte_pktmbuf_mtod(ops[i]->sym->m_src, uint8_t *) + - ops[i]->sym->cipher.data.offset; + (ops[i]->sym->cipher.data.offset >> 3); dst[i] = ops[i]->sym->m_dst ? - rte_pktmbuf_mtod(ops[i]->sym->m_dst, uint8_t *) + - ops[i]->sym->cipher.data.offset : - rte_pktmbuf_mtod(ops[i]->sym->m_src, uint8_t *) + - ops[i]->sym->cipher.data.offset; + rte_pktmbuf_mtod(ops[i]->sym->m_dst, uint8_t *) + + (ops[i]->sym->cipher.data.offset >> 3) : + rte_pktmbuf_mtod(ops[i]->sym->m_src, uint8_t *) + + (ops[i]->sym->cipher.data.offset >> 3); IV[i] = ops[i]->sym->cipher.iv.data; - num_bytes[i] = ops[i]->sym->cipher.data.length; + num_bytes[i] = ops[i]->sym->cipher.data.length >> 3; processed_ops++; } @@ -246,10 +255,18 @@ process_snow3g_hash_op(struct rte_crypto_op **ops, break; } - length_in_bits = ops[i]->sym->auth.data.length * 8; + if (((ops[i]->sym->auth.data.length % BYTE_LEN) != 0) + || ((ops[i]->sym->auth.data.offset + % BYTE_LEN) != 0)) { + ops[i]->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS; + SNOW3G_LOG_ERR("Data Length or offset"); + break; + } + + length_in_bits = ops[i]->sym->auth.data.length; src = rte_pktmbuf_mtod(ops[i]->sym->m_src, uint8_t *) + - ops[i]->sym->auth.data.offset; + (ops[i]->sym->auth.data.offset >> 3); if (session->auth_op == RTE_CRYPTO_AUTH_OP_VERIFY) { dst = (uint8_t *)rte_pktmbuf_append(ops[i]->sym->m_src, diff --git a/lib/librte_cryptodev/rte_crypto_sym.h b/lib/librte_cryptodev/rte_crypto_sym.h index 4461fc3d0b..d01287cb85 100644 --- a/lib/librte_cryptodev/rte_crypto_sym.h +++ b/lib/librte_cryptodev/rte_crypto_sym.h @@ -382,6 +382,10 @@ struct rte_crypto_sym_op { * buffer. The result of the cipher operation will be * written back into the output buffer starting at * this location. + * + * @note + * For Snow3G @ RTE_CRYPTO_CIPHER_SNOW3G_UEA2, + * this field should be in bits. */ uint32_t length; @@ -402,6 +406,10 @@ struct rte_crypto_sym_op { * @note * For AES-GMAC @ref RTE_CRYPTO_AUTH_AES_GMAC, this * field should be set to 0. + * + * @note + * For Snow3G @ RTE_CRYPTO_AUTH_SNOW3G_UEA2 + * this field should be in bits. */ } data; /**< Data offsets and length for ciphering */ @@ -470,6 +478,10 @@ struct rte_crypto_sym_op { * @note For AES-GMAC (@ref RTE_CRYPTO_AUTH_AES_GMAC) * mode of operation, this field specifies the start * of the AAD data in the source buffer. + * + * @note + * For Snow3G @ RTE_CRYPTO_AUTH_SNOW3G_UIA2 + * this field should be in bits. */ uint32_t length; @@ -485,6 +497,10 @@ struct rte_crypto_sym_op { * For AES-GMAC @ref RTE_CRYPTO_AUTH_AES_GMAC mode * of operation, this field specifies the length of * the AAD data in the source buffer. + * + * @note + * For Snow3G @ RTE_CRYPTO_AUTH_SNOW3G_UIA2 + * this field should be in bits. */ } data; /**< Data offsets and length for authentication */