This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "".
The branch, master has been updated via 9bdd6ed64a1603f15c869be637093abb88f196a8 (commit) via 5ea522cca3ef536ad9075129215f1836af34ed73 (commit) via 0ca2df3d74f89b47a3cdcf3088eee831761dd9be (commit) via 500e4176107db9e9797c6decc249d34c9d906abe (commit) via 619499a4a0bd99989c90260678cc9dbe3948c870 (commit) via ff879d5fa8c3ed9ba52cb44d9a4501e66531672d (commit) via 9fc4a95a6c7807a24d1595bd2c8c7884e6ce12a2 (commit) via 373baab2f1c03f0ff3c47527c93bed713a0e403c (commit) via 141d0310e97c91be0802670730fd178d0b81152b (commit) via 20944653d0d8640cdc3a7beca6855bc0213b814a (commit) via 8dd36d8d001ae74dd4758b3abe45f49bf752a5f7 (commit) via fe8b4bcae94c5795885f5ded211d5ebf85abcab5 (commit) via 60268b670beb5ed89528f498caa932b8eb9d2564 (commit) via e7fac06c87efeef4dc9aaef67e20a25e1bc50af2 (commit) via f86fa1a7aa137814e023f2fd2783f6abc78e797c (commit) via a7492121cbf3a30cf5219744dc5774177f3d9496 (commit) via 72c3f81f56169ac6f1bd7d7f1c1f0b18ab2e1fdb (commit) via 8a662a3e7566994bac18113c2d4ea5ed3047bc62 (commit) via 27e79f97b32df3426f7bc13fd0b1b3bff2cbf835 (commit) via be29376373fe098955f4bb1d24f76157dae82065 (commit) via 7f6413db99c5e7172ae255116bdbdfd53c2171b7 (commit) via 181118b438f3abb6bc0b4f6df6b4656215e12158 (commit) via 44cde88d44b123d5726351599e8a043c38920762 (commit) via c0e82fab2c677480bf4774eb4c854e0ed31d893c (commit) via 21bf585ca33eea0073c41f4d5115dcc8765bd122 (commit) via 2cb1bd572c9cc17f39742a46884a147ebf6f2302 (commit) via 067f57be454ce360fedb7501c51e5f1ef2824b7e (commit) via 379bbf144141d41ee31df11d8a8d3a0758c1db06 (commit) from 7f79421ba6204559fc33d960f9c58ee4bd2ca064 (commit)
Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below.
- Log ----------------------------------------------------------------- commit 9bdd6ed64a1603f15c869be637093abb88f196a8 Author: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Date: Tue May 14 11:21:43 2019 +0300
configure.ac: bump ODP API version
Bump ODP API minor version, as API changes are backwards compatible.
Signed-off-by: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Reviewed-by: Petri Savolainen petri.savolainen@nokia.com
diff --git a/configure.ac b/configure.ac index 4cd00cc5e..83765d9c9 100644 --- a/configure.ac +++ b/configure.ac @@ -4,7 +4,7 @@ AC_PREREQ([2.5]) ########################################################################## m4_define([odpapi_generation_version], [1]) m4_define([odpapi_major_version], [21]) -m4_define([odpapi_minor_version], [4]) +m4_define([odpapi_minor_version], [5]) m4_define([odpapi_point_version], [0]) m4_define([odpapi_version], [odpapi_generation_version.odpapi_major_version.odpapi_minor_version.odpapi_point_version])
commit 5ea522cca3ef536ad9075129215f1836af34ed73 Author: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Date: Tue May 21 18:21:37 2019 +0300
api: crypto: clarify IV format for 3GPP algorithms
Clarify IV data format and point to proper documents for 3GPP algorithms.
Signed-off-by: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Reviewed-by: Petri Savolainen petri.savolainen@nokia.com
diff --git a/include/odp/api/spec/crypto.h b/include/odp/api/spec/crypto.h index e796ddbfb..8d8f24bbf 100644 --- a/include/odp/api/spec/crypto.h +++ b/include/odp/api/spec/crypto.h @@ -125,24 +125,42 @@ typedef enum { /** Confidentiality F8 algorithm (UEA1) * * KASUMI-based F8 algorithm (also known as UEA1). + * + * IV should be formatted according to the 3GPP TS 35.201: + * COUNT || BEARER || DIRECTION || 0...0 */ ODP_CIPHER_ALG_KASUMI_F8,
/** Confidentiality UEA2 algorithm (128-EEA1) * * SNOW 3G-based UEA2 algorithm (also known as 128-EEA1). + * + * IV (128 bit) should be formatted according to the ETSI/SAGE + * UEA2 & UIA2 specification: + * COUNT || BEARER || DIRECTION || 0...0 || + * COUNT || BEARER || DIRECTION || 0...0 || */ ODP_CIPHER_ALG_SNOW3G_UEA2,
/** Confidentiality 128-EEA2 algorithm * * AES-CTR-based 128-EEA2 algorithm. + * + * IV (128 bit) should be formatted according to the ETSI/SAGE + * 128-EA2 & 128-EIA2 specification: + * COUNT || BEARER || + * DIRECTION || 0....0 */ ODP_CIPHER_ALG_AES_EEA2,
/** Confidentiality 128-EEA3 algorithm * * ZUC-based 128-EEA3 algorithm. + * + * IV (128 bit) should be formatted according to the ETSI/SAGE + * 128-EEA3 & 128-EIA3 specification: + * COUNT || BEARER || DIRECTION || 0...0 || + * COUNT || BEARER || DIRECTION || 0...0 || */ ODP_CIPHER_ALG_ZUC_EEA3,
@@ -262,24 +280,42 @@ typedef enum { * * IV (9 bytes) is a concatenation of COUNT (32b), FRESH (32b) and * DIRECTION (LSB-aligned, 1b). + * IV (8 bytes) is a concatenation of COUNT (32b) and FRESH (32b) + * DIRECTION (1b) and padding should come at the end of message. */ ODP_AUTH_ALG_KASUMI_F9,
/** Integrity UIA2 algorithm (128-EIA1) * * SNOW 3G-based UIA2 algorithm (also known as 128-EIA1). + * IV (128 bit) should be formatted according to the ETSI/SAGE + * UEA2 & UIA2 specification: + * COUNT || FRESH || + * DIRECTION XOR COUNT0 || COUNT1 .. COUNT31 || + * FRESH0 .. FRESH15 || FRESH16 XOR DIRECTION || FRESH17 .. FRESH31 */ ODP_AUTH_ALG_SNOW3G_UIA2,
/** Integrity 128-EIA2 algorithm * * AES_CMAC-based 128-EIA2 algorithm. + * + * IV (128 bit) should be formatted according to the ETSI/SAGE + * 128-EA2 & 128-EIA2 specification: + * COUNT || BEARER || + * DIRECTION || 0....0 */ ODP_AUTH_ALG_AES_EIA2,
/** Integrity 128-EIA3 algorithm * * ZUC-based 128-EIA3 algorithm. + * + * IV (128 bit) should be formatted according to the ETSI/SAGE + * 128-EA3 & 128-EIA2 specification: + * COUNT || BEARER || + * DIRECTION XOR COUNT0 || COUNT1 .. COUNT31 || + * BEARER || 0...0 || DIRECTION || 0...0 */ ODP_AUTH_ALG_ZUC_EIA3,
commit 0ca2df3d74f89b47a3cdcf3088eee831761dd9be Author: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Date: Mon May 13 16:12:11 2019 +0300
linux-gen: crypto: fix support for OpenSSL 1.0.x
Provide implementation of new EVP_MD_CTX API which is missing in OpenSSL 1.0.x.
Signed-off-by: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Reviewed-by: Petri Savolainen petri.savolainen@nokia.com
diff --git a/platform/linux-generic/odp_crypto_openssl.c b/platform/linux-generic/odp_crypto_openssl.c index 08c8262c8..3f03b63fa 100644 --- a/platform/linux-generic/odp_crypto_openssl.c +++ b/platform/linux-generic/odp_crypto_openssl.c @@ -332,6 +332,20 @@ static void HMAC_CTX_free(HMAC_CTX *ctx) HMAC_CTX_cleanup(ctx); free(ctx); } + +static EVP_MD_CTX *EVP_MD_CTX_new(void) +{ + EVP_MD_CTX *ctx = malloc(sizeof(*ctx)); + + EVP_MD_CTX_init(ctx); + return ctx; +} + +static void EVP_MD_CTX_free(EVP_MD_CTX *ctx) +{ + EVP_MD_CTX_cleanup(ctx); + free(ctx); +} #endif
static void
commit 500e4176107db9e9797c6decc249d34c9d906abe Author: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Date: Sat May 18 18:41:42 2019 +0300
api: crypto: correct documentation for ODP_AUTH_ALG_SNOW3G_UIA2
Correct it to reference 128-EIA1 instead of 128-EEA1.
Signed-off-by: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Reviewed-by: Petri Savolainen petri.savolainen@nokia.com
diff --git a/include/odp/api/spec/crypto.h b/include/odp/api/spec/crypto.h index 7b782868b..e796ddbfb 100644 --- a/include/odp/api/spec/crypto.h +++ b/include/odp/api/spec/crypto.h @@ -265,7 +265,7 @@ typedef enum { */ ODP_AUTH_ALG_KASUMI_F9,
- /** Integrity UIA2 algorithm (128-EEA1) + /** Integrity UIA2 algorithm (128-EIA1) * * SNOW 3G-based UIA2 algorithm (also known as 128-EIA1). */
commit 619499a4a0bd99989c90260678cc9dbe3948c870 Author: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Date: Sun Apr 21 02:41:49 2019 +0300
linux-gen: crypto: add support for 3GPP AES EEA2/EIA2 algorithms
Add support for AES-CTR variant as 128-EEA2 and AES-CMAC variant as 128-EIA algorithms defined by 3GPP.
Signed-off-by: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Reviewed-by: Petri Savolainen petri.savolainen@nokia.com
diff --git a/platform/linux-generic/odp_crypto_openssl.c b/platform/linux-generic/odp_crypto_openssl.c index 1ff8d03cc..08c8262c8 100644 --- a/platform/linux-generic/odp_crypto_openssl.c +++ b/platform/linux-generic/odp_crypto_openssl.c @@ -48,7 +48,8 @@ * Keep sorted: first by key length, then by IV length */ static const odp_crypto_cipher_capability_t cipher_capa_null[] = { -{.key_len = 0, .iv_len = 0} }; +{.key_len = 0, .iv_len = 0}, +{.key_len = 0, .iv_len = 0, .bit_mode = 1} };
static const odp_crypto_cipher_capability_t cipher_capa_trides_cbc[] = { {.key_len = 24, .iv_len = 8} }; @@ -98,12 +99,17 @@ static const odp_crypto_cipher_capability_t cipher_capa_chacha20_poly1305[] = { {.key_len = 32, .iv_len = 12} }; #endif
+static const odp_crypto_cipher_capability_t cipher_capa_aes_eea2[] = { +{.key_len = 16, .iv_len = 16, .bit_mode = 1} }; + /* * Authentication algorithm capabilities * * Keep sorted: first by digest length, then by key length */ static const odp_crypto_auth_capability_t auth_capa_null[] = { +{.digest_len = 0, .key_len = 0, .aad_len = {.min = 0, .max = 0, .inc = 0}, + .bit_mode = 1}, {.digest_len = 0, .key_len = 0, .aad_len = {.min = 0, .max = 0, .inc = 0} } };
static const odp_crypto_auth_capability_t auth_capa_md5_hmac[] = { @@ -160,6 +166,10 @@ static const odp_crypto_auth_capability_t auth_capa_chacha20_poly1305[] = { {.digest_len = 16, .key_len = 0, .aad_len = {.min = 8, .max = 12, .inc = 4} } }; #endif
+static const odp_crypto_auth_capability_t auth_capa_aes_eia2[] = { +{.digest_len = 4, .key_len = 16, .aad_len = {.min = 0, .max = 0, .inc = 0}, + .iv_len = 8, .bit_mode = 1 } }; + static const odp_crypto_auth_capability_t auth_capa_md5[] = { {.digest_len = 16, .key_len = 0, .aad_len = {.min = 0, .max = 0, .inc = 0} } };
@@ -661,6 +671,102 @@ odp_crypto_alg_err_t auth_cmac_check(odp_packet_t pkt, return ODP_CRYPTO_ALG_ERR_NONE; }
+static +int packet_cmac_eia2(odp_packet_t pkt, + const odp_crypto_packet_op_param_t *param, + odp_crypto_generic_session_t *session, + uint8_t *hash) +{ + CMAC_CTX *ctx = local.cmac_ctx[session->idx]; + void *iv_ptr; + uint32_t offset = param->auth_range.offset; + uint32_t len = (param->auth_range.length + 7) / 8; + size_t outlen; + + if (param->auth_iv_ptr) + iv_ptr = param->auth_iv_ptr; + else if (session->p.auth_iv.data) + iv_ptr = session->auth.iv_data; + else + return ODP_CRYPTO_ALG_ERR_IV_INVALID; + + ODP_ASSERT(offset + len <= odp_packet_len(pkt)); + + /* Reinitialize CMAC calculation without resetting the key */ + CMAC_Init(ctx, NULL, 0, NULL, NULL); + + CMAC_Update(ctx, iv_ptr, session->p.auth_iv.length); + + while (len > 0) { + uint32_t seglen = 0; /* GCC */ + void *mapaddr = odp_packet_offset(pkt, offset, &seglen, NULL); + uint32_t maclen = len > seglen ? seglen : len; + + CMAC_Update(ctx, mapaddr, maclen); + offset += maclen; + len -= maclen; + } + + if (1 != CMAC_Final(ctx, hash, &outlen)) + return ODP_CRYPTO_ALG_ERR_DATA_SIZE; + else + return ODP_CRYPTO_ALG_ERR_NONE; +} + +static +odp_crypto_alg_err_t auth_cmac_eia2_gen(odp_packet_t pkt, + const odp_crypto_packet_op_param_t + *param, + odp_crypto_generic_session_t *session) +{ + uint8_t hash[EVP_MAX_MD_SIZE]; + int ret; + + /* Hash it */ + ret = packet_cmac_eia2(pkt, param, session, hash); + if (ret != ODP_CRYPTO_ALG_ERR_NONE) + return ret; + + /* Copy to the output location */ + odp_packet_copy_from_mem(pkt, + param->hash_result_offset, + session->p.auth_digest_len, + hash); + + return ODP_CRYPTO_ALG_ERR_NONE; +} + +static +odp_crypto_alg_err_t auth_cmac_eia2_check(odp_packet_t pkt, + const odp_crypto_packet_op_param_t + *param, + odp_crypto_generic_session_t *session) +{ + uint32_t bytes = session->p.auth_digest_len; + uint8_t hash_in[EVP_MAX_MD_SIZE]; + uint8_t hash_out[EVP_MAX_MD_SIZE]; + int ret; + + /* Copy current value out and clear it before authentication */ + odp_packet_copy_to_mem(pkt, param->hash_result_offset, + bytes, hash_in); + + _odp_packet_set_data(pkt, param->hash_result_offset, + 0, bytes); + + /* Hash it */ + ret = packet_cmac_eia2(pkt, param, session, hash_out); + if (ret != ODP_CRYPTO_ALG_ERR_NONE) + return ret; + + /* Verify match */ + if (0 != memcmp(hash_in, hash_out, bytes)) + return ODP_CRYPTO_ALG_ERR_ICV_CHECK; + + /* Matched */ + return ODP_CRYPTO_ALG_ERR_NONE; +} + static void packet_digest(odp_packet_t pkt, const odp_crypto_packet_op_param_t *param, @@ -986,6 +1092,112 @@ static int process_cipher_param(odp_crypto_generic_session_t *session, return 0; }
+static +odp_crypto_alg_err_t cipher_encrypt_bits(odp_packet_t pkt, + const odp_crypto_packet_op_param_t + *param, + odp_crypto_generic_session_t *session) +{ + EVP_CIPHER_CTX *ctx = local.cipher_ctx[session->idx]; + void *iv_ptr; + int dummy_len = 0; + int cipher_len; + uint32_t in_len = (param->cipher_range.length + 7) / 8; + uint8_t data[in_len]; + int ret; + + if (param->cipher_iv_ptr) + iv_ptr = param->cipher_iv_ptr; + else if (session->p.cipher_iv.data) + iv_ptr = session->cipher.iv_data; + else + return ODP_CRYPTO_ALG_ERR_IV_INVALID; + + EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, iv_ptr); + + odp_packet_copy_to_mem(pkt, param->cipher_range.offset, in_len, + data); + + EVP_EncryptUpdate(ctx, data, &cipher_len, data, in_len); + + ret = EVP_EncryptFinal_ex(ctx, data + cipher_len, &dummy_len); + cipher_len += dummy_len; + + odp_packet_copy_from_mem(pkt, param->cipher_range.offset, in_len, + data); + + return ret <= 0 ? ODP_CRYPTO_ALG_ERR_DATA_SIZE : + ODP_CRYPTO_ALG_ERR_NONE; +} + +static +odp_crypto_alg_err_t cipher_decrypt_bits(odp_packet_t pkt, + const odp_crypto_packet_op_param_t + *param, + odp_crypto_generic_session_t *session) +{ + EVP_CIPHER_CTX *ctx = local.cipher_ctx[session->idx]; + void *iv_ptr; + int dummy_len = 0; + int cipher_len; + uint32_t in_len = (param->cipher_range.length + 7) / 8; + uint8_t data[in_len]; + int ret; + + if (param->cipher_iv_ptr) + iv_ptr = param->cipher_iv_ptr; + else if (session->p.cipher_iv.data) + iv_ptr = session->cipher.iv_data; + else + return ODP_CRYPTO_ALG_ERR_IV_INVALID; + + EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv_ptr); + + odp_packet_copy_to_mem(pkt, param->cipher_range.offset, in_len, + data); + + EVP_DecryptUpdate(ctx, data, &cipher_len, data, in_len); + + ret = EVP_DecryptFinal_ex(ctx, data + cipher_len, &dummy_len); + cipher_len += dummy_len; + + odp_packet_copy_from_mem(pkt, param->cipher_range.offset, in_len, + data); + + return ret <= 0 ? ODP_CRYPTO_ALG_ERR_DATA_SIZE : + ODP_CRYPTO_ALG_ERR_NONE; +} + +static int process_cipher_param_bits(odp_crypto_generic_session_t *session, + const EVP_CIPHER *cipher) +{ + /* Verify Key len is valid */ + if ((uint32_t)EVP_CIPHER_key_length(cipher) != + session->p.cipher_key.length) + return -1; + + /* Verify IV len is correct */ + if ((uint32_t)EVP_CIPHER_iv_length(cipher) != + session->p.cipher_iv.length) + return -1; + + session->cipher.evp_cipher = cipher; + + memcpy(session->cipher.key_data, session->p.cipher_key.data, + session->p.cipher_key.length); + + /* Set function */ + if (ODP_CRYPTO_OP_ENCODE == session->p.op) { + session->cipher.func = cipher_encrypt_bits; + session->cipher.init = cipher_encrypt_init; + } else { + session->cipher.func = cipher_decrypt_bits; + session->cipher.init = cipher_decrypt_init; + } + + return 0; +} + static void aes_gcm_encrypt_init(odp_crypto_generic_session_t *session) { @@ -1554,6 +1766,38 @@ static int process_auth_cmac_param(odp_crypto_generic_session_t *session, return 0; }
+static int process_auth_cmac_eia2_param(odp_crypto_generic_session_t *session, + const EVP_CIPHER *cipher) +{ + /* Verify Key len is valid */ + if ((uint32_t)EVP_CIPHER_key_length(cipher) != + session->p.auth_key.length) + return -1; + + /* Verify IV len is correct */ + if (8 != session->p.auth_iv.length) + return -1; + + /* Set function */ + if (ODP_CRYPTO_OP_ENCODE == session->p.op) + session->auth.func = auth_cmac_eia2_gen; + else + session->auth.func = auth_cmac_eia2_check; + session->auth.init = auth_cmac_init; + + session->auth.evp_cipher = cipher; + + /* Number of valid bytes */ + if (session->p.auth_digest_len != 4) + return -1; + + /* Convert keys */ + memcpy(session->auth.key, session->p.auth_key.data, + session->p.auth_key.length); + + return 0; +} + static int process_digest_param(odp_crypto_generic_session_t *session, const EVP_MD *md) { @@ -1598,6 +1842,7 @@ int odp_crypto_capability(odp_crypto_capability_t *capa) #if _ODP_HAVE_CHACHA20_POLY1305 capa->ciphers.bit.chacha20_poly1305 = 1; #endif + capa->ciphers.bit.aes_eea2 = 1;
capa->auths.bit.null = 1; capa->auths.bit.md5_hmac = 1; @@ -1614,6 +1859,7 @@ int odp_crypto_capability(odp_crypto_capability_t *capa) #if _ODP_HAVE_CHACHA20_POLY1305 capa->auths.bit.chacha20_poly1305 = 1; #endif + capa->auths.bit.aes_eia2 = 1;
capa->auths.bit.md5 = 1; capa->auths.bit.sha1 = 1; @@ -1690,6 +1936,10 @@ int odp_crypto_cipher_capability(odp_cipher_alg_t cipher, num = sizeof(cipher_capa_chacha20_poly1305) / size; break; #endif + case ODP_CIPHER_ALG_AES_EEA2: + src = cipher_capa_aes_eea2; + num = sizeof(cipher_capa_aes_eea2) / size; + break; default: return -1; } @@ -1764,6 +2014,10 @@ int odp_crypto_auth_capability(odp_auth_alg_t auth, num = sizeof(auth_capa_chacha20_poly1305) / size; break; #endif + case ODP_AUTH_ALG_AES_EIA2: + src = auth_capa_aes_eia2; + num = sizeof(auth_capa_aes_eia2) / size; + break; case ODP_AUTH_ALG_MD5: src = auth_capa_md5; num = sizeof(auth_capa_md5) / size; @@ -1969,6 +2223,13 @@ odp_crypto_session_create(odp_crypto_session_param_t *param, EVP_chacha20_poly1305()); break; #endif + case ODP_CIPHER_ALG_AES_EEA2: + if (param->cipher_key.length == 16) + rc = process_cipher_param_bits(session, + EVP_aes_128_ctr()); + else + rc = -1; + break; default: rc = -1; } @@ -2087,6 +2348,13 @@ odp_crypto_session_create(odp_crypto_session_param_t *param, } break; #endif + case ODP_AUTH_ALG_AES_EIA2: + if (param->auth_key.length == 16) + rc = process_auth_cmac_eia2_param(session, + EVP_aes_128_cbc()); + else + rc = -1; + break; case ODP_AUTH_ALG_MD5: rc = process_digest_param(session, EVP_md5()); break;
commit ff879d5fa8c3ed9ba52cb44d9a4501e66531672d Author: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Date: Sun Apr 21 02:41:49 2019 +0300
validation: crypto: add support for 3GPP AES EEA2/EIA2 algorithms
Add support for AES-CTR variant as 128-EEA2 and AES-CMAC variant as 128-EIA algorithms defined by 3GPP.
Signed-off-by: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Reviewed-by: Petri Savolainen petri.savolainen@nokia.com
diff --git a/test/validation/api/crypto/odp_crypto_test_inp.c b/test/validation/api/crypto/odp_crypto_test_inp.c index 2f5726033..faf4dba83 100644 --- a/test/validation/api/crypto/odp_crypto_test_inp.c +++ b/test/validation/api/crypto/odp_crypto_test_inp.c @@ -68,6 +68,8 @@ static const char *auth_alg_name(odp_auth_alg_t auth) return "ODP_AUTH_ALG_KASUMI_F9"; case ODP_AUTH_ALG_SNOW3G_UIA2: return "ODP_AUTH_ALG_SNOW3G_UIA2"; + case ODP_AUTH_ALG_AES_EIA2: + return "ODP_AUTH_ALG_AES_EIA2"; case ODP_AUTH_ALG_ZUC_EIA3: return "ODP_AUTH_ALG_ZUC_EIA3"; case ODP_AUTH_ALG_MD5: @@ -118,6 +120,8 @@ static const char *cipher_alg_name(odp_cipher_alg_t cipher) return "ODP_CIPHER_ALG_KASUMI_F8"; case ODP_CIPHER_ALG_SNOW3G_UEA2: return "ODP_CIPHER_ALG_SNOW3G_UEA2"; + case ODP_CIPHER_ALG_AES_EEA2: + return "ODP_CIPHER_ALG_AES_EEA2"; case ODP_CIPHER_ALG_ZUC_EEA3: return "ODP_CIPHER_ALG_ZUC_EEA3"; default: @@ -562,6 +566,9 @@ static void check_alg(odp_crypto_op_t op, if (cipher_alg == ODP_CIPHER_ALG_SNOW3G_UEA2 && !(capa.ciphers.bit.snow3g_uea2)) rc = -1; + if (cipher_alg == ODP_CIPHER_ALG_AES_EEA2 && + !(capa.ciphers.bit.aes_eea2)) + rc = -1; if (cipher_alg == ODP_CIPHER_ALG_ZUC_EEA3 && !(capa.ciphers.bit.zuc_eea3)) rc = -1; @@ -596,6 +603,9 @@ static void check_alg(odp_crypto_op_t op, if (auth_alg == ODP_AUTH_ALG_SNOW3G_UIA2 && !(capa.auths.bit.snow3g_uia2)) rc = -1; + if (auth_alg == ODP_AUTH_ALG_AES_EIA2 && + !(capa.auths.bit.aes_eia2)) + rc = -1; if (auth_alg == ODP_AUTH_ALG_ZUC_EIA3 && !(capa.auths.bit.zuc_eia3)) rc = -1; @@ -824,6 +834,10 @@ static int check_alg_support(odp_cipher_alg_t cipher, odp_auth_alg_t auth) if (!capability.ciphers.bit.snow3g_uea2) return ODP_TEST_INACTIVE; break; + case ODP_CIPHER_ALG_AES_EEA2: + if (!capability.ciphers.bit.aes_eea2) + return ODP_TEST_INACTIVE; + break; case ODP_CIPHER_ALG_ZUC_EEA3: if (!capability.ciphers.bit.zuc_eea3) return ODP_TEST_INACTIVE; @@ -895,6 +909,10 @@ static int check_alg_support(odp_cipher_alg_t cipher, odp_auth_alg_t auth) if (!capability.auths.bit.snow3g_uia2) return ODP_TEST_INACTIVE; break; + case ODP_AUTH_ALG_AES_EIA2: + if (!capability.auths.bit.aes_eia2) + return ODP_TEST_INACTIVE; + break; case ODP_AUTH_ALG_ZUC_EIA3: if (!capability.auths.bit.zuc_eia3) return ODP_TEST_INACTIVE; @@ -1622,6 +1640,56 @@ static void crypto_test_dec_alg_snow3g_uea2_ovr_iv(void) true); }
+static int check_alg_aes_eea2(void) +{ + return check_alg_support(ODP_CIPHER_ALG_AES_EEA2, + ODP_AUTH_ALG_NULL); +} + +static void crypto_test_enc_alg_aes_eea2(void) +{ + check_alg(ODP_CRYPTO_OP_ENCODE, + ODP_CIPHER_ALG_AES_EEA2, + ODP_AUTH_ALG_NULL, + aes_eea2_reference, + ARRAY_SIZE(aes_eea2_reference), + false, + true); +} + +static void crypto_test_enc_alg_aes_eea2_ovr_iv(void) +{ + check_alg(ODP_CRYPTO_OP_ENCODE, + ODP_CIPHER_ALG_AES_EEA2, + ODP_AUTH_ALG_NULL, + aes_eea2_reference, + ARRAY_SIZE(aes_eea2_reference), + true, + true); +} + +static void crypto_test_dec_alg_aes_eea2(void) +{ + check_alg(ODP_CRYPTO_OP_DECODE, + ODP_CIPHER_ALG_AES_EEA2, + ODP_AUTH_ALG_NULL, + aes_eea2_reference, + ARRAY_SIZE(aes_eea2_reference), + false, + true); +} + +static void crypto_test_dec_alg_aes_eea2_ovr_iv(void) +{ + check_alg(ODP_CRYPTO_OP_DECODE, + ODP_CIPHER_ALG_AES_EEA2, + ODP_AUTH_ALG_NULL, + aes_eea2_reference, + ARRAY_SIZE(aes_eea2_reference), + true, + true); +} + static int check_alg_zuc_eea3(void) { return check_alg_support(ODP_CIPHER_ALG_ZUC_EEA3, ODP_AUTH_ALG_NULL); @@ -2077,6 +2145,56 @@ static void crypto_test_check_alg_snow3g_uia2_ovr_iv(void) true); }
+static int check_alg_aes_eia2(void) +{ + return check_alg_support(ODP_CIPHER_ALG_NULL, + ODP_AUTH_ALG_AES_EIA2); +} + +static void crypto_test_gen_alg_aes_eia2(void) +{ + check_alg(ODP_CRYPTO_OP_ENCODE, + ODP_CIPHER_ALG_NULL, + ODP_AUTH_ALG_AES_EIA2, + aes_eia2_reference, + ARRAY_SIZE(aes_eia2_reference), + false, + true); +} + +static void crypto_test_gen_alg_aes_eia2_ovr_iv(void) +{ + check_alg(ODP_CRYPTO_OP_ENCODE, + ODP_CIPHER_ALG_NULL, + ODP_AUTH_ALG_AES_EIA2, + aes_eia2_reference, + ARRAY_SIZE(aes_eia2_reference), + true, + true); +} + +static void crypto_test_check_alg_aes_eia2(void) +{ + check_alg(ODP_CRYPTO_OP_DECODE, + ODP_CIPHER_ALG_NULL, + ODP_AUTH_ALG_AES_EIA2, + aes_eia2_reference, + ARRAY_SIZE(aes_eia2_reference), + false, + true); +} + +static void crypto_test_check_alg_aes_eia2_ovr_iv(void) +{ + check_alg(ODP_CRYPTO_OP_DECODE, + ODP_CIPHER_ALG_NULL, + ODP_AUTH_ALG_AES_EIA2, + aes_eia2_reference, + ARRAY_SIZE(aes_eia2_reference), + true, + true); +} + static int check_alg_zuc_eia3(void) { return check_alg_support(ODP_CIPHER_ALG_NULL, ODP_AUTH_ALG_ZUC_EIA3); @@ -2409,6 +2527,14 @@ odp_testinfo_t crypto_suite[] = { check_alg_snow3g_uea2), ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_snow3g_uea2_ovr_iv, check_alg_snow3g_uea2), + ODP_TEST_INFO_CONDITIONAL(crypto_test_enc_alg_aes_eea2, + check_alg_aes_eea2), + ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_aes_eea2, + check_alg_aes_eea2), + ODP_TEST_INFO_CONDITIONAL(crypto_test_enc_alg_aes_eea2_ovr_iv, + check_alg_aes_eea2), + ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_aes_eea2_ovr_iv, + check_alg_aes_eea2), ODP_TEST_INFO_CONDITIONAL(crypto_test_enc_alg_zuc_eea3, check_alg_zuc_eea3), ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_zuc_eea3, @@ -2497,6 +2623,14 @@ odp_testinfo_t crypto_suite[] = { check_alg_snow3g_uia2), ODP_TEST_INFO_CONDITIONAL(crypto_test_check_alg_snow3g_uia2_ovr_iv, check_alg_snow3g_uia2), + ODP_TEST_INFO_CONDITIONAL(crypto_test_gen_alg_aes_eia2, + check_alg_aes_eia2), + ODP_TEST_INFO_CONDITIONAL(crypto_test_check_alg_aes_eia2, + check_alg_aes_eia2), + ODP_TEST_INFO_CONDITIONAL(crypto_test_gen_alg_aes_eia2_ovr_iv, + check_alg_aes_eia2), + ODP_TEST_INFO_CONDITIONAL(crypto_test_check_alg_aes_eia2_ovr_iv, + check_alg_aes_eia2), ODP_TEST_INFO_CONDITIONAL(crypto_test_gen_alg_zuc_eia3, check_alg_zuc_eia3), ODP_TEST_INFO_CONDITIONAL(crypto_test_check_alg_zuc_eia3, diff --git a/test/validation/api/crypto/test_vectors.h b/test/validation/api/crypto/test_vectors.h index e9d702eae..6c4fc5b59 100644 --- a/test/validation/api/crypto/test_vectors.h +++ b/test/validation/api/crypto/test_vectors.h @@ -2536,6 +2536,79 @@ static crypto_test_reference_t snow3g_uia2_reference[] = { } };
+/* + * AES EEA2 and AES EIA2 test vectors from + * Specification of the 3GPP Confidentiality and Integrity + * Algorithms 128-EEA2 & 128-EIA2 + */ +static crypto_test_reference_t aes_eea2_reference[] = { + { + .cipher_key_length = AES_EEA2_KEY_LEN, + .cipher_key = { 0xD3, 0xC5, 0xD5, 0x92, 0x32, 0x7F, 0xB1, 0x1C, + 0x40, 0x35, 0xC6, 0x68, 0x0A, 0xF8, 0xC6, 0xD1}, + .cipher_iv_length = AES_EEA2_IV_LEN, + .cipher_iv = { 0x39, 0x8a, 0x59, 0xb4, 0xac, }, + .length = 248 /* + 5 */, /* 253 bits originally = 31 + 1 bytes*/ + .plaintext = { 0x98, 0x1B, 0xA6, 0x82, 0x4C, 0x1B, 0xFB, 0x1A, + 0xB4, 0x85, 0x47, 0x20, 0x29, 0xB7, 0x1D, 0x80, + 0x8C, 0xE3, 0x3E, 0x2C, 0xC3, 0xC0, 0xB5, 0xFC, + 0x1F, 0x3D, 0xE8, 0xA6, 0xDC, 0x66, 0xB1, 0xF0 }, + .ciphertext = { 0xE9, 0xFE, 0xD8, 0xA6, 0x3D, 0x15, 0x53, 0x04, + 0xD7, 0x1D, 0xF2, 0x0B, 0xF3, 0xE8, 0x22, 0x14, + 0xB2, 0x0E, 0xD7, 0xDA, 0xD2, 0xF2, 0x33, 0xDC, + 0x3C, 0x22, 0xD7, 0xBD, 0xEE, 0xED, 0x8E, 0x78} + }, + { + .cipher_key_length = AES_EEA2_KEY_LEN, + .cipher_key = { 0x2B, 0xD6, 0x45, 0x9F, 0x82, 0xC4, 0x40, 0xE0, + 0x95, 0x2C, 0x49, 0x10, 0x48, 0x05, 0xFF, 0x48}, + .cipher_iv_length = AES_EEA2_IV_LEN, + .cipher_iv = { 0xc6, 0x75, 0xa6, 0x4b, 0x64, }, + .length = 99 /* + 6 */, /* 798 bits originally = 99 + 1 bytes */ + .plaintext = { 0x7E, 0xC6, 0x12, 0x72, 0x74, 0x3B, 0xF1, 0x61, + 0x47, 0x26, 0x44, 0x6A, 0x6C, 0x38, 0xCE, 0xD1, + 0x66, 0xF6, 0xCA, 0x76, 0xEB, 0x54, 0x30, 0x04, + 0x42, 0x86, 0x34, 0x6C, 0xEF, 0x13, 0x0F, 0x92, + 0x92, 0x2B, 0x03, 0x45, 0x0D, 0x3A, 0x99, 0x75, + 0xE5, 0xBD, 0x2E, 0xA0, 0xEB, 0x55, 0xAD, 0x8E, + 0x1B, 0x19, 0x9E, 0x3E, 0xC4, 0x31, 0x60, 0x20, + 0xE9, 0xA1, 0xB2, 0x85, 0xE7, 0x62, 0x79, 0x53, + 0x59, 0xB7, 0xBD, 0xFD, 0x39, 0xBE, 0xF4, 0xB2, + 0x48, 0x45, 0x83, 0xD5, 0xAF, 0xE0, 0x82, 0xAE, + 0xE6, 0x38, 0xBF, 0x5F, 0xD5, 0xA6, 0x06, 0x19, + 0x39, 0x01, 0xA0, 0x8F, 0x4A, 0xB4, 0x1A, 0xAB, + 0x9B, 0x13, 0x48, 0x80 }, + .ciphertext = { 0x59, 0x61, 0x60, 0x53, 0x53, 0xC6, 0x4B, 0xDC, + 0xA1, 0x5B, 0x19, 0x5E, 0x28, 0x85, 0x53, 0xA9, + 0x10, 0x63, 0x25, 0x06, 0xD6, 0x20, 0x0A, 0xA7, + 0x90, 0xC4, 0xC8, 0x06, 0xC9, 0x99, 0x04, 0xCF, + 0x24, 0x45, 0xCC, 0x50, 0xBB, 0x1C, 0xF1, 0x68, + 0xA4, 0x96, 0x73, 0x73, 0x4E, 0x08, 0x1B, 0x57, + 0xE3, 0x24, 0xCE, 0x52, 0x59, 0xC0, 0xE7, 0x8D, + 0x4C, 0xD9, 0x7B, 0x87, 0x09, 0x76, 0x50, 0x3C, + 0x09, 0x43, 0xF2, 0xCB, 0x5A, 0xE8, 0xF0, 0x52, + 0xC7, 0xB7, 0xD3, 0x92, 0x23, 0x95, 0x87, 0xB8, + 0x95, 0x60, 0x86, 0xBC, 0xAB, 0x18, 0x83, 0x60, + 0x42, 0xE2, 0xE6, 0xCE, 0x42, 0x43, 0x2A, 0x17, + 0x10, 0x5C, 0x53, 0xD0 } + }, +}; + +static crypto_test_reference_t aes_eia2_reference[] = { + { + .auth_key_length = AES_EIA2_KEY_LEN, + .auth_key = { 0xD3, 0xC5, 0xD5, 0x92, 0x32, 0x7F, 0xB1, 0x1C, + 0x40, 0x35, 0xC6, 0x68, 0x0A, 0xF8, 0xC6, 0xD1 }, + .auth_iv_length = AES_EIA2_IV_LEN, + .auth_iv = { 0x39, 0x8a, 0x59, 0xb4, 0xd4, }, + .length = 64, /* 8 bytes */ + .plaintext = { 0x48, 0x45, 0x83, 0xd5, 0xaf, 0xe0, 0x82, 0xae }, + .ciphertext = { 0x48, 0x45, 0x83, 0xd5, 0xaf, 0xe0, 0x82, 0xae}, + .digest_length = AES_EIA2_DIGEST_LEN, + .digest = { 0xb9, 0x37, 0x87, 0xe6 } + }, +}; + /* * ZUC EEA3 and EIA3 test vectors from * Specification of the 3GPP Confidentiality and Integrity diff --git a/test/validation/api/crypto/test_vectors_len.h b/test/validation/api/crypto/test_vectors_len.h index fd5bccfc9..17121e12e 100644 --- a/test/validation/api/crypto/test_vectors_len.h +++ b/test/validation/api/crypto/test_vectors_len.h @@ -93,6 +93,10 @@ #define SNOW3G_UEA2_KEY_LEN 16 #define SNOW3G_UEA2_IV_LEN 16
+/* AES_EEA2 */ +#define AES_EEA2_KEY_LEN 16 +#define AES_EEA2_IV_LEN 16 + /* ZUC_EEA3 */ #define ZUC_EEA3_KEY_LEN 16 #define ZUC_EEA3_IV_LEN 16 @@ -107,6 +111,11 @@ #define SNOW3G_UIA2_IV_LEN 16 #define SNOW3G_UIA2_DIGEST_LEN 4
+/* AES_EIA2 */ +#define AES_EIA2_KEY_LEN 16 +#define AES_EIA2_IV_LEN 8 +#define AES_EIA2_DIGEST_LEN 4 + /* ZUC_EIA3 */ #define ZUC_EIA3_KEY_LEN 16 #define ZUC_EIA3_IV_LEN 16
commit 9fc4a95a6c7807a24d1595bd2c8c7884e6ce12a2 Author: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Date: Sun Apr 21 02:41:49 2019 +0300
api: crypto: add support for 3GPP AES EEA2/EIA2 algorithms
Add support for AES-CTR variant as 128-EEA2 and AES-CMAC variant as 128-EIA algorithms defined by 3GPP.
Signed-off-by: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Reviewed-by: Petri Savolainen petri.savolainen@nokia.com
diff --git a/include/odp/api/spec/crypto.h b/include/odp/api/spec/crypto.h index f7a1cae08..7b782868b 100644 --- a/include/odp/api/spec/crypto.h +++ b/include/odp/api/spec/crypto.h @@ -134,6 +134,12 @@ typedef enum { */ ODP_CIPHER_ALG_SNOW3G_UEA2,
+ /** Confidentiality 128-EEA2 algorithm + * + * AES-CTR-based 128-EEA2 algorithm. + */ + ODP_CIPHER_ALG_AES_EEA2, + /** Confidentiality 128-EEA3 algorithm * * ZUC-based 128-EEA3 algorithm. @@ -265,6 +271,12 @@ typedef enum { */ ODP_AUTH_ALG_SNOW3G_UIA2,
+ /** Integrity 128-EIA2 algorithm + * + * AES_CMAC-based 128-EIA2 algorithm. + */ + ODP_AUTH_ALG_AES_EIA2, + /** Integrity 128-EIA3 algorithm * * ZUC-based 128-EIA3 algorithm. @@ -348,6 +360,9 @@ typedef union odp_crypto_cipher_algos_t { /** ODP_CIPHER_ALG_SNOW3G_UEA2 */ uint32_t snow3g_uea2 : 1;
+ /** ODP_CIPHER_ALG_AES_EEA2 */ + uint32_t aes_eea2 : 1; + /** ODP_CIPHER_ALG_ZUC_EEA3 */ uint32_t zuc_eea3 : 1;
@@ -417,6 +432,9 @@ typedef union odp_crypto_auth_algos_t { /** ODP_AUTH_ALG_SNOW3G_UIA2 */ uint32_t snow3g_uia2 : 1;
+ /** ODP_AUTH_ALG_AES_EIA2 */ + uint32_t aes_eia2 : 1; + /** ODP_AUTH_ALG_ZUC_EIA3 */ uint32_t zuc_eia3 : 1;
commit 373baab2f1c03f0ff3c47527c93bed713a0e403c Author: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Date: Tue Apr 16 00:14:18 2019 +0300
linux-gen: crypto: add AES-XTS support
Add support for AES in XEX-based tweaked-codebook mode with ciphertext stealing mode.
Signed-off-by: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Reviewed-by: Petri Savolainen petri.savolainen@nokia.com
diff --git a/platform/linux-generic/odp_crypto_openssl.c b/platform/linux-generic/odp_crypto_openssl.c index ae27a2034..1ff8d03cc 100644 --- a/platform/linux-generic/odp_crypto_openssl.c +++ b/platform/linux-generic/odp_crypto_openssl.c @@ -76,6 +76,10 @@ static const odp_crypto_cipher_capability_t cipher_capa_aes_cfb128[] = { {.key_len = 24, .iv_len = 16}, {.key_len = 32, .iv_len = 16} };
+static const odp_crypto_cipher_capability_t cipher_capa_aes_xts[] = { +{.key_len = 32, .iv_len = 16}, +{.key_len = 64, .iv_len = 16} }; + static const odp_crypto_cipher_capability_t cipher_capa_aes_gcm[] = { {.key_len = 16, .iv_len = 12}, {.key_len = 24, .iv_len = 12}, @@ -1387,6 +1391,110 @@ static int process_aes_ccm_param(odp_crypto_generic_session_t *session, return 0; }
+static +odp_crypto_alg_err_t xts_encrypt(odp_packet_t pkt, + const odp_crypto_packet_op_param_t *param, + odp_crypto_generic_session_t *session) +{ + EVP_CIPHER_CTX *ctx = local.cipher_ctx[session->idx]; + void *iv_ptr; + int dummy_len = 0; + int cipher_len; + uint32_t in_len = param->cipher_range.length; + uint8_t data[in_len]; + int ret; + + if (param->cipher_iv_ptr) + iv_ptr = param->cipher_iv_ptr; + else if (session->p.cipher_iv.data) + iv_ptr = session->cipher.iv_data; + else + return ODP_CRYPTO_ALG_ERR_IV_INVALID; + + EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, iv_ptr); + + odp_packet_copy_to_mem(pkt, param->cipher_range.offset, in_len, + data); + + EVP_EncryptUpdate(ctx, data, &cipher_len, data, in_len); + + ret = EVP_EncryptFinal_ex(ctx, data + cipher_len, &dummy_len); + cipher_len += dummy_len; + + odp_packet_copy_from_mem(pkt, param->cipher_range.offset, in_len, + data); + + return ret <= 0 ? ODP_CRYPTO_ALG_ERR_DATA_SIZE : + ODP_CRYPTO_ALG_ERR_NONE; +} + +static +odp_crypto_alg_err_t xts_decrypt(odp_packet_t pkt, + const odp_crypto_packet_op_param_t *param, + odp_crypto_generic_session_t *session) +{ + EVP_CIPHER_CTX *ctx = local.cipher_ctx[session->idx]; + void *iv_ptr; + int dummy_len = 0; + int cipher_len; + uint32_t in_len = param->cipher_range.length; + uint8_t data[in_len]; + int ret; + + if (param->cipher_iv_ptr) + iv_ptr = param->cipher_iv_ptr; + else if (session->p.cipher_iv.data) + iv_ptr = session->cipher.iv_data; + else + return ODP_CRYPTO_ALG_ERR_IV_INVALID; + + EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv_ptr); + + odp_packet_copy_to_mem(pkt, param->cipher_range.offset, in_len, + data); + + EVP_DecryptUpdate(ctx, data, &cipher_len, data, in_len); + + ret = EVP_DecryptFinal_ex(ctx, data + cipher_len, &dummy_len); + cipher_len += dummy_len; + + odp_packet_copy_from_mem(pkt, param->cipher_range.offset, in_len, + data); + + return ret <= 0 ? ODP_CRYPTO_ALG_ERR_DATA_SIZE : + ODP_CRYPTO_ALG_ERR_NONE; +} + +static int process_xts_param(odp_crypto_generic_session_t *session, + const EVP_CIPHER *cipher) +{ + /* Verify Key len is valid */ + if ((uint32_t)EVP_CIPHER_key_length(cipher) != + session->p.cipher_key.length) + return -1; + + /* Verify IV len is correct */ + if ((uint32_t)EVP_CIPHER_iv_length(cipher) != + session->p.cipher_iv.length) + return -1; + + session->cipher.evp_cipher = cipher; + + memcpy(session->cipher.key_data, session->p.cipher_key.data, + session->p.cipher_key.length); + + /* Set function */ + if (ODP_CRYPTO_OP_ENCODE == session->p.op) { + session->cipher.func = xts_encrypt; + session->cipher.init = cipher_encrypt_init; + } else { + session->cipher.func = xts_decrypt; + session->cipher.init = cipher_decrypt_init; + } + + return 0; +} + static int process_auth_hmac_param(odp_crypto_generic_session_t *session, const EVP_MD *evp_md) { @@ -1484,6 +1592,7 @@ int odp_crypto_capability(odp_crypto_capability_t *capa) capa->ciphers.bit.aes_ctr = 1; capa->ciphers.bit.aes_ecb = 1; capa->ciphers.bit.aes_cfb128 = 1; + capa->ciphers.bit.aes_xts = 1; capa->ciphers.bit.aes_gcm = 1; capa->ciphers.bit.aes_ccm = 1; #if _ODP_HAVE_CHACHA20_POLY1305 @@ -1563,6 +1672,10 @@ int odp_crypto_cipher_capability(odp_cipher_alg_t cipher, src = cipher_capa_aes_cfb128; num = sizeof(cipher_capa_aes_cfb128) / size; break; + case ODP_CIPHER_ALG_AES_XTS: + src = cipher_capa_aes_xts; + num = sizeof(cipher_capa_aes_xts) / size; + break; case ODP_CIPHER_ALG_AES_GCM: src = cipher_capa_aes_gcm; num = sizeof(cipher_capa_aes_gcm) / size; @@ -1797,6 +1910,14 @@ odp_crypto_session_create(odp_crypto_session_param_t *param, else rc = -1; break; + case ODP_CIPHER_ALG_AES_XTS: + if (param->cipher_key.length == 32) + rc = process_xts_param(session, EVP_aes_128_xts()); + else if (param->cipher_key.length == 64) + rc = process_xts_param(session, EVP_aes_256_xts()); + else + rc = -1; + break; #if ODP_DEPRECATED_API case ODP_CIPHER_ALG_AES128_GCM: /* AES-GCM requires to do both auth and
commit 141d0310e97c91be0802670730fd178d0b81152b Author: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Date: Tue Apr 16 00:14:18 2019 +0300
validation: crypto: add AES-XTS support
Add support for AES in XEX-based tweaked-codebook mode with ciphertext stealing mode.
Signed-off-by: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Reviewed-by: Petri Savolainen petri.savolainen@nokia.com
diff --git a/test/validation/api/crypto/odp_crypto_test_inp.c b/test/validation/api/crypto/odp_crypto_test_inp.c index 4f4d8c13f..2f5726033 100644 --- a/test/validation/api/crypto/odp_crypto_test_inp.c +++ b/test/validation/api/crypto/odp_crypto_test_inp.c @@ -106,6 +106,8 @@ static const char *cipher_alg_name(odp_cipher_alg_t cipher) return "ODP_CIPHER_ALG_AES_ECB"; case ODP_CIPHER_ALG_AES_CFB128: return "ODP_CIPHER_ALG_AES_CFB128"; + case ODP_CIPHER_ALG_AES_XTS: + return "ODP_CIPHER_ALG_AES_XTS"; case ODP_CIPHER_ALG_AES_GCM: return "ODP_CIPHER_ALG_AES_GCM"; case ODP_CIPHER_ALG_AES_CCM: @@ -542,6 +544,9 @@ static void check_alg(odp_crypto_op_t op, if (cipher_alg == ODP_CIPHER_ALG_AES_CFB128 && !(capa.ciphers.bit.aes_cfb128)) rc = -1; + if (cipher_alg == ODP_CIPHER_ALG_AES_XTS && + !(capa.ciphers.bit.aes_xts)) + rc = -1; if (cipher_alg == ODP_CIPHER_ALG_AES_GCM && !(capa.ciphers.bit.aes_gcm)) rc = -1; @@ -795,6 +800,10 @@ static int check_alg_support(odp_cipher_alg_t cipher, odp_auth_alg_t auth) if (!capability.ciphers.bit.aes_cfb128) return ODP_TEST_INACTIVE; break; + case ODP_CIPHER_ALG_AES_XTS: + if (!capability.ciphers.bit.aes_xts) + return ODP_TEST_INACTIVE; + break; case ODP_CIPHER_ALG_AES_GCM: if (!capability.ciphers.bit.aes_gcm) return ODP_TEST_INACTIVE; @@ -1449,6 +1458,72 @@ static void crypto_test_dec_alg_aes_cfb128_ovr_iv(void) false); }
+static int check_alg_aes_xts(void) +{ + return check_alg_support(ODP_CIPHER_ALG_AES_XTS, ODP_AUTH_ALG_NULL); +} + +/* This test verifies the correctness of encode (plaintext -> ciphertext) + * operation for AES128_XTS algorithm. IV for the operation is the session IV. + * In addition the test verifies if the implementation can use the + * packet buffer as completion event buffer.*/ +static void crypto_test_enc_alg_aes_xts(void) +{ + check_alg(ODP_CRYPTO_OP_ENCODE, + ODP_CIPHER_ALG_AES_XTS, + ODP_AUTH_ALG_NULL, + aes_xts_reference, + ARRAY_SIZE(aes_xts_reference), + false, + false); +} + +/* This test verifies the correctness of encode (plaintext -> ciphertext) + * operation for AES128_XTS algorithm. IV for the operation is the operation IV. + * */ +static void crypto_test_enc_alg_aes_xts_ovr_iv(void) +{ + check_alg(ODP_CRYPTO_OP_ENCODE, + ODP_CIPHER_ALG_AES_XTS, + ODP_AUTH_ALG_NULL, + aes_xts_reference, + ARRAY_SIZE(aes_xts_reference), + true, + false); +} + +/* This test verifies the correctness of decode (ciphertext -> plaintext) + * operation for AES128_XTS algorithm. IV for the operation is the session IV + * In addition the test verifies if the implementation can use the + * packet buffer as completion event buffer. + * */ +static void crypto_test_dec_alg_aes_xts(void) +{ + check_alg(ODP_CRYPTO_OP_DECODE, + ODP_CIPHER_ALG_AES_XTS, + ODP_AUTH_ALG_NULL, + aes_xts_reference, + ARRAY_SIZE(aes_xts_reference), + false, + false); +} + +/* This test verifies the correctness of decode (ciphertext -> plaintext) + * operation for AES128_XTS algorithm. IV for the operation is the session IV + * In addition the test verifies if the implementation can use the + * packet buffer as completion event buffer. + * */ +static void crypto_test_dec_alg_aes_xts_ovr_iv(void) +{ + check_alg(ODP_CRYPTO_OP_DECODE, + ODP_CIPHER_ALG_AES_XTS, + ODP_AUTH_ALG_NULL, + aes_xts_reference, + ARRAY_SIZE(aes_xts_reference), + true, + false); +} + static int check_alg_kasumi_f8(void) { return check_alg_support(ODP_CIPHER_ALG_KASUMI_F8, ODP_AUTH_ALG_NULL); @@ -2310,6 +2385,14 @@ odp_testinfo_t crypto_suite[] = { check_alg_aes_cfb128), ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_aes_cfb128_ovr_iv, check_alg_aes_cfb128), + ODP_TEST_INFO_CONDITIONAL(crypto_test_enc_alg_aes_xts, + check_alg_aes_xts), + ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_aes_xts, + check_alg_aes_xts), + ODP_TEST_INFO_CONDITIONAL(crypto_test_enc_alg_aes_xts_ovr_iv, + check_alg_aes_xts), + ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_aes_xts_ovr_iv, + check_alg_aes_xts), ODP_TEST_INFO_CONDITIONAL(crypto_test_enc_alg_kasumi_f8, check_alg_kasumi_f8), ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_kasumi_f8, diff --git a/test/validation/api/crypto/test_vectors.h b/test/validation/api/crypto/test_vectors.h index 8d5263098..e9d702eae 100644 --- a/test/validation/api/crypto/test_vectors.h +++ b/test/validation/api/crypto/test_vectors.h @@ -905,6 +905,137 @@ static crypto_test_reference_t aes_cfb128_reference[] = { } };
+static crypto_test_reference_t aes_xts_reference[] = { + /* CAVS 11.0 XTSGen information, #1 */ + { + .cipher_key_length = AES128_XTS_KEY_LEN, + .cipher_key = { 0xa1, 0xb9, 0x0c, 0xba, 0x3f, 0x06, 0xac, 0x35, + 0x3b, 0x2c, 0x34, 0x38, 0x76, 0x08, 0x17, 0x62, + 0x09, 0x09, 0x23, 0x02, 0x6e, 0x91, 0x77, 0x18, + 0x15, 0xf2, 0x9d, 0xab, 0x01, 0x93, 0x2f, 0x2f}, + .cipher_iv_length = AES_XTS_IV_LEN, + .cipher_iv = { 0x4f, 0xae, 0xf7, 0x11, 0x7c, 0xda, 0x59, 0xc6, + 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5}, + .length = 16, + .plaintext = { 0xeb, 0xab, 0xce, 0x95, 0xb1, 0x4d, 0x3c, 0x8d, + 0x6f, 0xb3, 0x50, 0x39, 0x07, 0x90, 0x31, 0x1c}, + .ciphertext = { 0x77, 0x8a, 0xe8, 0xb4, 0x3c, 0xb9, 0x8d, 0x5a, + 0x82, 0x50, 0x81, 0xd5, 0xbe, 0x47, 0x1c, 0x63} + }, + /* CAVS 11.0 XTSGen information, #101 */ + { + .cipher_key_length = AES128_XTS_KEY_LEN, + .cipher_key = { 0xb7, 0xb9, 0x3f, 0x51, 0x6a, 0xef, 0x29, 0x5e, + 0xff, 0x3a, 0x29, 0xd8, 0x37, 0xcf, 0x1f, 0x13, + 0x53, 0x47, 0xe8, 0xa2, 0x1d, 0xae, 0x61, 0x6f, + 0xf5, 0x06, 0x2b, 0x2e, 0x8d, 0x78, 0xce, 0x5e}, + .cipher_iv_length = AES_XTS_IV_LEN, + .cipher_iv = { 0x87, 0x3e, 0xde, 0xa6, 0x53, 0xb6, 0x43, 0xbd, + 0x8b, 0xcf, 0x51, 0x40, 0x31, 0x97, 0xed, 0x14}, + .length = 32, + .plaintext = { 0x23, 0x6f, 0x8a, 0x5b, 0x58, 0xdd, 0x55, 0xf6, + 0x19, 0x4e, 0xd7, 0x0c, 0x4a, 0xc1, 0xa1, 0x7f, + 0x1f, 0xe6, 0x0e, 0xc9, 0xa6, 0xc4, 0x54, 0xd0, + 0x87, 0xcc, 0xb7, 0x7d, 0x6b, 0x63, 0x8c, 0x47}, + .ciphertext = { 0x22, 0xe6, 0xa3, 0xc6, 0x37, 0x9d, 0xcf, 0x75, + 0x99, 0xb0, 0x52, 0xb5, 0xa7, 0x49, 0xc7, 0xf7, + 0x8a, 0xd8, 0xa1, 0x1b, 0x9f, 0x1a, 0xa9, 0x43, + 0x0c, 0xf3, 0xae, 0xf4, 0x45, 0x68, 0x2e, 0x19} + }, + /* CAVS 11.0 XTSGen information, #227 TODO (Length 130 bits)*/ + /* { + .cipher_key_length = AES128_XTS_KEY_LEN, + .cipher_key = { 0xec, 0x14, 0xc0, 0xa3, 0xb7, 0x72, 0x58, 0x5c, + 0x15, 0xd4, 0xeb, 0x94, 0xe6, 0x9e, 0x2c, 0x55, + 0x80, 0xcf, 0x3a, 0x63, 0xc1, 0x7c, 0xe9, 0xda, + 0xd8, 0x2b, 0xb4, 0x54, 0xe3, 0x87, 0x90, 0x45}, + .cipher_iv_length = AES_XTS_IV_LEN, + .cipher_iv = { 0x4a, 0x02, 0x87, 0xc2, 0x6e, 0xd2, 0x41, 0x26, + 0x5b, 0x3a, 0x42, 0xcd, 0xd1, 0x9c, 0xea, 0xe2}, + .length = 17, + .plaintext = { 0x50, 0x82, 0x64, 0x75, 0x82, 0xc6, 0xe5, 0xa7, + 0x88, 0x73, 0x6f, 0xc5, 0x90, 0x5e, 0xa5, 0x65, + 0xc0 }, + .ciphertext = { 0x04, 0x3a, 0xb9, 0xc0, 0x3d, 0x5b, 0x44, 0x13, + 0x1d, 0x3e, 0x6e, 0xb2, 0x57, 0x61, 0x89, 0xde, + 0x80 }, + }, */ + /* CAVS 11.0 XTSGen information, #1 */ + { + .cipher_key_length = AES256_XTS_KEY_LEN, + .cipher_key = { 0x1e, 0xa6, 0x61, 0xc5, 0x8d, 0x94, 0x3a, 0x0e, + 0x48, 0x01, 0xe4, 0x2f, 0x4b, 0x09, 0x47, 0x14, + 0x9e, 0x7f, 0x9f, 0x8e, 0x3e, 0x68, 0xd0, 0xc7, + 0x50, 0x52, 0x10, 0xbd, 0x31, 0x1a, 0x0e, 0x7c, + 0xd6, 0xe1, 0x3f, 0xfd, 0xf2, 0x41, 0x8d, 0x8d, + 0x19, 0x11, 0xc0, 0x04, 0xcd, 0xa5, 0x8d, 0xa3, + 0xd6, 0x19, 0xb7, 0xe2, 0xb9, 0x14, 0x1e, 0x58, + 0x31, 0x8e, 0xea, 0x39, 0x2c, 0xf4, 0x1b, 0x08}, + .cipher_iv_length = AES_XTS_IV_LEN, + .cipher_iv = { 0xad, 0xf8, 0xd9, 0x26, 0x27, 0x46, 0x4a, 0xd2, + 0xf0, 0x42, 0x8e, 0x84, 0xa9, 0xf8, 0x75, 0x64}, + .length = 32, + .plaintext = { 0x2e, 0xed, 0xea, 0x52, 0xcd, 0x82, 0x15, 0xe1, + 0xac, 0xc6, 0x47, 0xe8, 0x10, 0xbb, 0xc3, 0x64, + 0x2e, 0x87, 0x28, 0x7f, 0x8d, 0x2e, 0x57, 0xe3, + 0x6c, 0x0a, 0x24, 0xfb, 0xc1, 0x2a, 0x20, 0x2e}, + .ciphertext = { 0xcb, 0xaa, 0xd0, 0xe2, 0xf6, 0xce, 0xa3, 0xf5, + 0x0b, 0x37, 0xf9, 0x34, 0xd4, 0x6a, 0x9b, 0x13, + 0x0b, 0x9d, 0x54, 0xf0, 0x7e, 0x34, 0xf3, 0x6a, + 0xf7, 0x93, 0xe8, 0x6f, 0x73, 0xc6, 0xd7, 0xdb}, + }, + /* CAVS 11.0 XTSGen information, #110 */ + { + .cipher_key_length = AES256_XTS_KEY_LEN, + .cipher_key = { 0x6b, 0x19, 0x84, 0xc2, 0x4e, 0x7e, 0xb6, 0x62, + 0x8e, 0x3a, 0x11, 0xc9, 0xcc, 0xd2, 0x59, 0x40, + 0x33, 0xa3, 0xa0, 0xd9, 0x01, 0x6e, 0xae, 0x65, + 0xc2, 0xf2, 0x4e, 0x09, 0xb9, 0xa6, 0x6e, 0x9f, + 0xe9, 0xd1, 0x63, 0xa5, 0x06, 0xdf, 0xbc, 0xcf, + 0x2d, 0x93, 0xe8, 0x99, 0x1e, 0x2f, 0xc5, 0x60, + 0xe1, 0x04, 0x35, 0xb8, 0x90, 0xb5, 0x88, 0x9a, + 0x50, 0x03, 0xe4, 0xbf, 0x81, 0x7d, 0xc3, 0xe0}, + .cipher_iv_length = AES_XTS_IV_LEN, + .cipher_iv = { 0x6b, 0xb0, 0xd3, 0xae, 0x4f, 0xa8, 0x6e, 0x43, + 0x16, 0x19, 0xe4, 0x07, 0xd5, 0x9a, 0xd4, 0xf4}, + .length = 48, + .plaintext = { 0x6a, 0x74, 0x1a, 0x94, 0x5b, 0xfb, 0xf0, 0xc6, + 0x7a, 0xfd, 0x43, 0xba, 0x1f, 0x84, 0x18, 0x16, + 0xc0, 0x99, 0x51, 0x58, 0x05, 0xd0, 0xfc, 0x1f, + 0x7d, 0xbf, 0x6d, 0xe9, 0x00, 0xe0, 0xaa, 0x7a, + 0x21, 0x9c, 0x88, 0x56, 0x32, 0x71, 0xb0, 0x09, + 0xd1, 0xac, 0x90, 0xeb, 0x7d, 0xc9, 0x97, 0x35}, + .ciphertext = { 0xe4, 0x7b, 0xce, 0x29, 0x2b, 0xaa, 0x63, 0xbe, + 0xf3, 0x16, 0xf6, 0x80, 0xa5, 0xf4, 0x80, 0xa7, + 0xb8, 0x83, 0xdf, 0xab, 0x6e, 0xd5, 0xa5, 0x7f, + 0x7e, 0x29, 0xec, 0xb8, 0x9e, 0x35, 0x4a, 0x31, + 0xc9, 0xb1, 0x74, 0xc4, 0xab, 0xad, 0x6c, 0xba, + 0xba, 0xba, 0x19, 0x14, 0x0c, 0x46, 0x20, 0xa3}, + }, + /* CAVS 11.0 XTSGen information, #211 TODO: length 140 bits */ + /* { + .cipher_key_length = AES256_XTS_KEY_LEN, + .cipher_key = { 0x62, 0xc2, 0xe4, 0xf8, 0x52, 0xa9, 0x3e, 0xea, + 0x4a, 0x2f, 0x61, 0xe8, 0x67, 0x68, 0x14, 0xf4, + 0xa8, 0x0d, 0xc4, 0x7e, 0xe1, 0x81, 0x32, 0xc8, + 0x38, 0xbf, 0x89, 0xa6, 0x18, 0xfd, 0xb8, 0xe2, + 0x91, 0x3e, 0x2e, 0x5c, 0x32, 0x1b, 0x19, 0xea, + 0x04, 0xbb, 0xa6, 0x34, 0x7d, 0x22, 0x6f, 0x41, + 0xdb, 0xee, 0x88, 0x0d, 0x61, 0x67, 0xb8, 0xe1, + 0xe9, 0x17, 0xfa, 0xf0, 0x46, 0xf0, 0x87, 0x5e}, + .cipher_iv_length = AES_XTS_IV_LEN, + .cipher_iv = { 0x53, 0x7e, 0xe3, 0xdc, 0x13, 0xce, 0x27, 0xa8, + 0xd3, 0x0e, 0x6e, 0x42, 0xb5, 0xb9, 0x96, 0xae}, + .length = 18, + .plaintext = { 0x00, 0xc9, 0xeb, 0x87, 0x78, 0xe0, 0x3d, 0xdd, + 0x5f, 0x3d, 0xe8, 0xc1, 0x8b, 0x34, 0x8f, 0xac, + 0x9c, 0x30}, + .ciphertext = { 0x9d, 0x4a, 0x08, 0xac, 0x0f, 0xb4, 0x4e, 0x90, + 0xd0, 0x5f, 0x62, 0x86, 0x19, 0x3f, 0x3a, 0xab, + 0xc2, 0x90}, + } */ +}; + /* AES-GCM test vectors extracted from * https://tools.ietf.org/html/draft-mcgrew-gcm-test-01#section-2 */ diff --git a/test/validation/api/crypto/test_vectors_len.h b/test/validation/api/crypto/test_vectors_len.h index a9ac6f6fb..fd5bccfc9 100644 --- a/test/validation/api/crypto/test_vectors_len.h +++ b/test/validation/api/crypto/test_vectors_len.h @@ -37,6 +37,11 @@ /* AES-CFB128 */ #define AES_CFB128_IV_LEN 16
+/* AES-XTS */ +#define AES128_XTS_KEY_LEN 32 +#define AES256_XTS_KEY_LEN 64 +#define AES_XTS_IV_LEN 16 + /* AES-GCM */ #define AES_GCM_IV_LEN 12 #define AES_GCM_DIGEST_LEN 16
commit 20944653d0d8640cdc3a7beca6855bc0213b814a Author: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Date: Tue Apr 16 00:13:41 2019 +0300
api: crypto: add AES-XTS support
Add support for AES in XEX-based tweaked-codebook mode with ciphertext stealing mode.
Signed-off-by: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Reviewed-by: Petri Savolainen petri.savolainen@nokia.com
diff --git a/include/odp/api/spec/crypto.h b/include/odp/api/spec/crypto.h index 295ad6bfb..f7a1cae08 100644 --- a/include/odp/api/spec/crypto.h +++ b/include/odp/api/spec/crypto.h @@ -91,6 +91,10 @@ typedef enum { /** AES with 128-bit cipher feedback */ ODP_CIPHER_ALG_AES_CFB128,
+ /** AES with XEX-based tweaked-codebook mode with ciphertext stealing + * (XTS) */ + ODP_CIPHER_ALG_AES_XTS, + /** AES-GCM * * AES in Galois/Counter Mode (GCM) algorithm. GCM provides both @@ -326,6 +330,9 @@ typedef union odp_crypto_cipher_algos_t { /** ODP_CIPHER_ALG_AES_CFB128 */ uint32_t aes_cfb128 : 1;
+ /** ODP_CIPHER_ALG_AES_XTS */ + uint32_t aes_xts : 1; + /** ODP_CIPHER_ALG_AES_GCM */ uint32_t aes_gcm : 1;
commit 8dd36d8d001ae74dd4758b3abe45f49bf752a5f7 Author: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Date: Tue Apr 16 00:11:30 2019 +0300
validation: crypto: add more aes-cbc and aes-ctr test vectors
Signed-off-by: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Reviewed-by: Petri Savolainen petri.savolainen@nokia.com
diff --git a/test/validation/api/crypto/test_vectors.h b/test/validation/api/crypto/test_vectors.h index c469784b4..8d5263098 100644 --- a/test/validation/api/crypto/test_vectors.h +++ b/test/validation/api/crypto/test_vectors.h @@ -192,6 +192,33 @@ static crypto_test_reference_t aes_cbc_reference[] = { 0x8e, 0x0d, 0x7f, 0x02, 0xb6, 0x80, 0x9a, 0x2d, 0x53, 0x1c, 0xc6, 0x98, 0x85, 0xc3, 0x00, 0xe6}, }, + /* NIST Special Publication 800-38A */ + { + .cipher_key_length = AES192_KEY_LEN, + .cipher_key = { 0x8e, 0x73, 0xb0, 0xf7, 0xda, 0x0e, 0x64, 0x52, + 0xc8, 0x10, 0xf3, 0x2b, 0x80, 0x90, 0x79, 0xe5, + 0x62, 0xf8, 0xea, 0xd2, 0x52, 0x2c, 0x6b, 0x7b}, + .cipher_iv_length = AES_CBC_IV_LEN, + .cipher_iv = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, + .length = 64, + .plaintext = { 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, + 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a, + 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c, + 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51, + 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11, + 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef, + 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17, + 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10 }, + .ciphertext = { 0x4f, 0x02, 0x1d, 0xb2, 0x43, 0xbc, 0x63, 0x3d, + 0x71, 0x78, 0x18, 0x3a, 0x9f, 0xa0, 0x71, 0xe8, + 0xb4, 0xd9, 0xad, 0xa9, 0xad, 0x7d, 0xed, 0xf4, + 0xe5, 0xe7, 0x38, 0x76, 0x3f, 0x69, 0x14, 0x5a, + 0x57, 0x1b, 0x24, 0x20, 0x12, 0xfb, 0x7a, 0xe0, + 0x7f, 0xa9, 0xba, 0xac, 0x3d, 0xf1, 0x02, 0xe0, + 0x08, 0xb0, 0xe2, 0x79, 0x88, 0x59, 0x88, 0x81, + 0xd9, 0x20, 0xa9, 0xe6, 0x4f, 0x56, 0x15, 0xcd } + }, { .cipher_key_length = AES256_KEY_LEN, .cipher_key = { 0xab, 0xbc, 0xcd, 0xde, 0xf0, 0x01, 0x12, 0x23, @@ -214,10 +241,57 @@ static crypto_test_reference_t aes_cbc_reference[] = { 0xf1, 0x32, 0xc2, 0xf7, 0x23, 0xb8, 0x83, 0x09, 0xbc, 0x37, 0x1c, 0xeb, 0x95, 0x2c, 0x42, 0x7b, 0x39, 0x10, 0xa8, 0x76, 0xfa, 0xbe, 0x91, 0xe9}, + }, + /* NIST Special Publication 800-38A */ + { + .cipher_key_length = AES256_KEY_LEN, + .cipher_key = { 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe, + 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81, + 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7, + 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4}, + .cipher_iv_length = AES_CBC_IV_LEN, + .cipher_iv = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, + .length = 64, + .plaintext = { 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, + 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a, + 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c, + 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51, + 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11, + 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef, + 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17, + 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10 }, + .ciphertext = { 0xf5, 0x8c, 0x4c, 0x04, 0xd6, 0xe5, 0xf1, 0xba, + 0x77, 0x9e, 0xab, 0xfb, 0x5f, 0x7b, 0xfb, 0xd6, + 0x9c, 0xfc, 0x4e, 0x96, 0x7e, 0xdb, 0x80, 0x8d, + 0x67, 0x9f, 0x77, 0x7b, 0xc6, 0x70, 0x2c, 0x7d, + 0x39, 0xf2, 0x33, 0x69, 0xa9, 0xd9, 0xba, 0xcf, + 0xa5, 0x30, 0xe2, 0x63, 0x04, 0x23, 0x14, 0x61, + 0xb2, 0xeb, 0x05, 0xe2, 0xc3, 0x9b, 0xe9, 0xfc, + 0xda, 0x6c, 0x19, 0x07, 0x8c, 0x6a, 0x9d, 0x1b } } };
static crypto_test_reference_t aes_ctr_reference[] = { + /* RFC3686 https://tools.ietf.org/html/rfc3686 */ + { + .cipher_key_length = AES128_KEY_LEN, + .cipher_key = { 0x7E, 0x24, 0x06, 0x78, 0x17, 0xFA, 0xE0, 0xD7, + 0x43, 0xD6, 0xCE, 0x1F, 0x32, 0x53, 0x91, 0x63}, + .cipher_iv_length = AES_CTR_IV_LEN, + .cipher_iv = { 0x00, 0x6C, 0xB6, 0xDB, 0xC0, 0x54, 0x3B, 0x59, + 0xDA, 0x48, 0xD9, 0x0B, 0x00, 0x00, 0x00, 0x01 }, + .length = 32, + .plaintext = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F }, + .ciphertext = { 0x51, 0x04, 0xA1, 0x06, 0x16, 0x8A, 0x72, 0xD9, + 0x79, 0x0D, 0x41, 0xEE, 0x8E, 0xDA, 0xD3, 0x88, + 0xEB, 0x2E, 0x1E, 0xFC, 0x46, 0xDA, 0x57, 0xC8, + 0xFC, 0xE6, 0x30, 0xDF, 0x91, 0x41, 0xBE, 0x28} + }, + /* NIST Special Publication 800-38A */ { .cipher_key_length = AES128_KEY_LEN, .cipher_key = { 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, @@ -243,6 +317,218 @@ static crypto_test_reference_t aes_ctr_reference[] = { 0x1e, 0x03, 0x1d, 0xda, 0x2f, 0xbe, 0x03, 0xd1, 0x79, 0x21, 0x70, 0xa0, 0xf3, 0x00, 0x9c, 0xee } }, + /* Generated by Crypto++ 5.6.1 (715 bytes data)*/ + { + .cipher_key_length = AES128_KEY_LEN, + .cipher_key = { 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, + 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c}, + .cipher_iv_length = AES_CTR_IV_LEN, + .cipher_iv = { 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, + 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff }, + .length = 715, + .plaintext = { 0x00, 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, + 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, + 0x2a, 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, + 0x9c, 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, + 0x51, 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, + 0x11, 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, + 0xef, 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, + 0x17, 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, + 0x10, 0x00, 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, + 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, + 0x17, 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xF7, 0xC7, 0x18, 0x19, 0xEA, 0x3D, 0xD5, 0xF3, + 0x6C, 0x7B, 0x27, 0xE5, 0x51, 0xFD, 0x23, 0x73, + 0xD0, 0x7F, 0xFD, 0xC7, 0x6A, 0x13, 0xFC, 0x4B, + 0x10, 0xA6, 0xF2, 0x9A, 0x83, 0xD6, 0xF4, 0x65, + 0xAC, 0xB6, 0x96, 0x06, 0x71, 0xEA, 0xCF, 0x21, + 0xA3, 0xE1, 0xCB, 0x44, 0x11, 0xC4, 0xDA, 0xA0, + 0xC2, 0xA8, 0x7D, 0xAE, 0xD2, 0x8A, 0xEE, 0x60, + 0xB7, 0xEC, 0x02, 0x58, 0xA9, 0xAF, 0x12, 0x5F, + 0x2D, 0xDC, 0x80, 0xB9, 0x87, 0x7E, 0xFE, 0x0F, + 0x37, 0x2D, 0x9B, 0x83, 0x2C, 0x78, 0x67, 0x70, + 0xA8, 0x4E, 0xA1, 0xA0, 0x7C, 0xB6, 0xE1, 0xA9, + 0x90, 0x7D, 0x65, 0x1B, 0xBD, 0x0E, 0xFD, 0xEF, + 0x2A, 0xFF, 0xC3 } + }, + /* RFC3686 https://tools.ietf.org/html/rfc3686 */ + { + .cipher_key_length = AES192_KEY_LEN, + .cipher_key = { 0x02, 0xBF, 0x39, 0x1E, 0xE8, 0xEC, 0xB1, 0x59, + 0xB9, 0x59, 0x61, 0x7B, 0x09, 0x65, 0x27, 0x9B, + 0xF5, 0x9B, 0x60, 0xA7, 0x86, 0xD3, 0xE0, 0xFE}, + .cipher_iv_length = AES_CTR_IV_LEN, + .cipher_iv = { 0x00, 0x07, 0xBD, 0xFD, 0x5C, 0xBD, 0x60, 0x27, + 0x8D, 0xCC, 0x09, 0x12, 0x00, 0x00, 0x00, 0x01 }, + .length = 36, + .plaintext = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, + 0x20, 0x21, 0x22, 0x23 }, + .ciphertext = { 0x96, 0x89, 0x3F, 0xC5, 0x5E, 0x5C, 0x72, 0x2F, + 0x54, 0x0B, 0x7D, 0xD1, 0xDD, 0xF7, 0xE7, 0x58, + 0xD2, 0x88, 0xBC, 0x95, 0xC6, 0x91, 0x65, 0x88, + 0x45, 0x36, 0xC8, 0x11, 0x66, 0x2F, 0x21, 0x88, + 0xAB, 0xEE, 0x09, 0x35 } + }, + /* NIST Special Publication 800-38A */ { .cipher_key_length = AES192_KEY_LEN, .cipher_key = { 0x8e, 0x73, 0xb0, 0xf7, 0xda, 0x0e, 0x64, 0x52, @@ -269,6 +555,29 @@ static crypto_test_reference_t aes_ctr_reference[] = { 0x4f, 0x78, 0xa7, 0xf6, 0xd2, 0x98, 0x09, 0x58, 0x5a, 0x97, 0xda, 0xec, 0x58, 0xc6, 0xb0, 0x50 } }, + /* RFC3686 https://tools.ietf.org/html/rfc3686 */ + { + .cipher_key_length = AES256_KEY_LEN, + .cipher_key = { 0xFF, 0x7A, 0x61, 0x7C, 0xE6, 0x91, 0x48, 0xE4, + 0xF1, 0x72, 0x6E, 0x2F, 0x43, 0x58, 0x1D, 0xE2, + 0xAA, 0x62, 0xD9, 0xF8, 0x05, 0x53, 0x2E, 0xDF, + 0xF1, 0xEE, 0xD6, 0x87, 0xFB, 0x54, 0x15, 0x3D}, + .cipher_iv_length = AES_CTR_IV_LEN, + .cipher_iv = { 0x00, 0x1C, 0xC5, 0xB7, 0x51, 0xA5, 0x1D, 0x70, + 0xA1, 0xC1, 0x11, 0x48, 0x00, 0x00, 0x00, 0x01 }, + .length = 36, + .plaintext = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, + 0x20, 0x21, 0x22, 0x23 }, + .ciphertext = { 0xEB, 0x6C, 0x52, 0x82, 0x1D, 0x0B, 0xBB, 0xF7, + 0xCE, 0x75, 0x94, 0x46, 0x2A, 0xCA, 0x4F, 0xAA, + 0xB4, 0x07, 0xDF, 0x86, 0x65, 0x69, 0xFD, 0x07, + 0xF4, 0x8C, 0xC0, 0xB5, 0x83, 0xD6, 0x07, 0x1F, + 0x1E, 0xC0, 0xE6, 0xB8 }, + }, + /* NIST Special Publication 800-38A */ { .cipher_key_length = AES256_KEY_LEN, .cipher_key = { 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe, diff --git a/test/validation/api/crypto/test_vectors_len.h b/test/validation/api/crypto/test_vectors_len.h index 8c9ffeaeb..a9ac6f6fb 100644 --- a/test/validation/api/crypto/test_vectors_len.h +++ b/test/validation/api/crypto/test_vectors_len.h @@ -9,7 +9,7 @@ /* Maximum */ #define MAX_KEY_LEN 64 #define MAX_IV_LEN 16 -#define MAX_DATA_LEN 528 +#define MAX_DATA_LEN 715 #define MAX_AAD_LEN 12 #define MAX_DIGEST_LEN 64
commit fe8b4bcae94c5795885f5ded211d5ebf85abcab5 Author: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Date: Tue Apr 16 00:08:22 2019 +0300
linux-gen: aes-gmac: extend capabilities
Add support for AES-194-GMAC and AES-256-GMAC algorithms.
Signed-off-by: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Reviewed-by: Petri Savolainen petri.savolainen@nokia.com
diff --git a/platform/linux-generic/odp_crypto_openssl.c b/platform/linux-generic/odp_crypto_openssl.c index 239373bbd..ae27a2034 100644 --- a/platform/linux-generic/odp_crypto_openssl.c +++ b/platform/linux-generic/odp_crypto_openssl.c @@ -137,6 +137,10 @@ static const odp_crypto_auth_capability_t auth_capa_aes_ccm[] = {
static const odp_crypto_auth_capability_t auth_capa_aes_gmac[] = { {.digest_len = 16, .key_len = 16, .aad_len = {.min = 0, .max = 0, .inc = 0}, + .iv_len = 12 }, +{.digest_len = 16, .key_len = 24, .aad_len = {.min = 0, .max = 0, .inc = 0}, + .iv_len = 12 }, +{.digest_len = 16, .key_len = 32, .aad_len = {.min = 0, .max = 0, .inc = 0}, .iv_len = 12 } };
static const odp_crypto_auth_capability_t auth_capa_aes_cmac[] = {
commit 60268b670beb5ed89528f498caa932b8eb9d2564 Author: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Date: Tue Apr 16 00:14:49 2019 +0300
validation: aes-gmac: extend capabilities
Add support for AES-194-GMAC and AES-256-GMAC algorithms.
Signed-off-by: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Reviewed-by: Petri Savolainen petri.savolainen@nokia.com
diff --git a/test/validation/api/crypto/test_vectors.h b/test/validation/api/crypto/test_vectors.h index 23e86243c..c469784b4 100644 --- a/test/validation/api/crypto/test_vectors.h +++ b/test/validation/api/crypto/test_vectors.h @@ -932,6 +932,73 @@ static crypto_test_reference_t aes_gmac_reference[] = { .digest = { 0xf2, 0xa9, 0xa8, 0x36, 0xe1, 0x55, 0x10, 0x6a, 0xa8, 0xdc, 0xd6, 0x18, 0xe4, 0x09, 0x9a, 0xaa } }, + /* AES192-GMAC from DPDK 17.02 */ + { + .auth_key_length = AES192_KEY_LEN, + .auth_key = { 0xaa, 0x74, 0x0a, 0xbf, 0xad, 0xcd, 0xa7, 0x79, + 0x22, 0x0d, 0x3b, 0x40, 0x6c, 0x5d, 0x7e, 0xc0, + 0x9a, 0x77, 0xfe, 0x9d, 0x94, 0x10, 0x45, 0x39}, + .auth_iv_length = AES_GCM_IV_LEN, + .auth_iv = { 0xab, 0x22, 0x65, 0xb4, 0xc1, 0x68, 0x95, 0x55, + 0x61, 0xf0, 0x43, 0x15 }, + .length = 80, + .plaintext = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10}, + .ciphertext = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10}, + .digest_length = AES_GCM_DIGEST_LEN, + .digest = { 0xCF, 0x82, 0x80, 0x64, 0x02, 0x46, 0xF4, 0xFB, + 0x33, 0xAE, 0x1D, 0x90, 0xEA, 0x48, 0x83, 0xDB }, + }, + /* AES256-GMAC from DPDK 17.02 */ + { + .auth_key_length = AES256_KEY_LEN, + .auth_key = { 0xb5, 0x48, 0xe4, 0x93, 0x4f, 0x5c, 0x64, 0xd3, + 0xc0, 0xf0, 0xb7, 0x8f, 0x7b, 0x4d, 0x88, 0x24, + 0xaa, 0xc4, 0x6b, 0x3c, 0x8d, 0x2c, 0xc3, 0x5e, + 0xe4, 0xbf, 0xb2, 0x54, 0xe4, 0xfc, 0xba, 0xf7}, + .auth_iv_length = AES_GCM_IV_LEN, + .auth_iv = { 0x2e, 0xed, 0xe1, 0xdc, 0x64, 0x47, 0xc7, 0xaf, + 0xc4, 0x41, 0x53, 0x58 }, + .length = 65, + .plaintext = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, + 0x01, 0x02 }, + .ciphertext = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, + 0x01, 0x02 }, + .digest_length = AES_GCM_DIGEST_LEN, + .digest = { 0x77, 0x46, 0x0D, 0x6F, 0xB1, 0x87, 0xDB, 0xA9, + 0x46, 0xAD, 0xCD, 0xFB, 0xB7, 0xF9, 0x13, 0xA1 }, + } };
/*
commit e7fac06c87efeef4dc9aaef67e20a25e1bc50af2 Author: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Date: Mon Apr 15 21:41:06 2019 +0300
linux-gen: crypto: add AES-CFB128 support
Add support for AES in 128-bit Cipher FeedBack mode.
Signed-off-by: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Reviewed-by: Petri Savolainen petri.savolainen@nokia.com
diff --git a/platform/linux-generic/odp_crypto_openssl.c b/platform/linux-generic/odp_crypto_openssl.c index ac38a7139..239373bbd 100644 --- a/platform/linux-generic/odp_crypto_openssl.c +++ b/platform/linux-generic/odp_crypto_openssl.c @@ -71,6 +71,11 @@ static const odp_crypto_cipher_capability_t cipher_capa_aes_ecb[] = { {.key_len = 24}, {.key_len = 32} };
+static const odp_crypto_cipher_capability_t cipher_capa_aes_cfb128[] = { +{.key_len = 16, .iv_len = 16}, +{.key_len = 24, .iv_len = 16}, +{.key_len = 32, .iv_len = 16} }; + static const odp_crypto_cipher_capability_t cipher_capa_aes_gcm[] = { {.key_len = 16, .iv_len = 12}, {.key_len = 24, .iv_len = 12}, @@ -1474,6 +1479,7 @@ int odp_crypto_capability(odp_crypto_capability_t *capa) capa->ciphers.bit.aes_cbc = 1; capa->ciphers.bit.aes_ctr = 1; capa->ciphers.bit.aes_ecb = 1; + capa->ciphers.bit.aes_cfb128 = 1; capa->ciphers.bit.aes_gcm = 1; capa->ciphers.bit.aes_ccm = 1; #if _ODP_HAVE_CHACHA20_POLY1305 @@ -1549,6 +1555,10 @@ int odp_crypto_cipher_capability(odp_cipher_alg_t cipher, src = cipher_capa_aes_ecb; num = sizeof(cipher_capa_aes_ecb) / size; break; + case ODP_CIPHER_ALG_AES_CFB128: + src = cipher_capa_aes_cfb128; + num = sizeof(cipher_capa_aes_cfb128) / size; + break; case ODP_CIPHER_ALG_AES_GCM: src = cipher_capa_aes_gcm; num = sizeof(cipher_capa_aes_gcm) / size; @@ -1770,6 +1780,19 @@ odp_crypto_session_create(odp_crypto_session_param_t *param, else rc = -1; break; + case ODP_CIPHER_ALG_AES_CFB128: + if (param->cipher_key.length == 16) + rc = process_cipher_param(session, + EVP_aes_128_cfb128()); + else if (param->cipher_key.length == 24) + rc = process_cipher_param(session, + EVP_aes_192_cfb128()); + else if (param->cipher_key.length == 32) + rc = process_cipher_param(session, + EVP_aes_256_cfb128()); + else + rc = -1; + break; #if ODP_DEPRECATED_API case ODP_CIPHER_ALG_AES128_GCM: /* AES-GCM requires to do both auth and
commit f86fa1a7aa137814e023f2fd2783f6abc78e797c Author: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Date: Mon Apr 15 21:40:33 2019 +0300
validation: crypto: add AES-CFB128 support
Add support for AES in 128-bit Cipher FeedBack mode.
Signed-off-by: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Reviewed-by: Petri Savolainen petri.savolainen@nokia.com
diff --git a/test/validation/api/crypto/odp_crypto_test_inp.c b/test/validation/api/crypto/odp_crypto_test_inp.c index caebb4b6e..4f4d8c13f 100644 --- a/test/validation/api/crypto/odp_crypto_test_inp.c +++ b/test/validation/api/crypto/odp_crypto_test_inp.c @@ -104,6 +104,8 @@ static const char *cipher_alg_name(odp_cipher_alg_t cipher) return "ODP_CIPHER_ALG_AES_CTR"; case ODP_CIPHER_ALG_AES_ECB: return "ODP_CIPHER_ALG_AES_ECB"; + case ODP_CIPHER_ALG_AES_CFB128: + return "ODP_CIPHER_ALG_AES_CFB128"; case ODP_CIPHER_ALG_AES_GCM: return "ODP_CIPHER_ALG_AES_GCM"; case ODP_CIPHER_ALG_AES_CCM: @@ -537,6 +539,9 @@ static void check_alg(odp_crypto_op_t op, if (cipher_alg == ODP_CIPHER_ALG_AES_ECB && !(capa.ciphers.bit.aes_ecb)) rc = -1; + if (cipher_alg == ODP_CIPHER_ALG_AES_CFB128 && + !(capa.ciphers.bit.aes_cfb128)) + rc = -1; if (cipher_alg == ODP_CIPHER_ALG_AES_GCM && !(capa.ciphers.bit.aes_gcm)) rc = -1; @@ -786,6 +791,10 @@ static int check_alg_support(odp_cipher_alg_t cipher, odp_auth_alg_t auth) if (!capability.ciphers.bit.aes_ecb) return ODP_TEST_INACTIVE; break; + case ODP_CIPHER_ALG_AES_CFB128: + if (!capability.ciphers.bit.aes_cfb128) + return ODP_TEST_INACTIVE; + break; case ODP_CIPHER_ALG_AES_GCM: if (!capability.ciphers.bit.aes_gcm) return ODP_TEST_INACTIVE; @@ -1372,6 +1381,74 @@ static void crypto_test_dec_alg_aes_ecb(void) false); }
+static int check_alg_aes_cfb128(void) +{ + return check_alg_support(ODP_CIPHER_ALG_AES_CFB128, ODP_AUTH_ALG_NULL); +} + +/* This test verifies the correctness of encode (plaintext -> ciphertext) + * operation for AES128_CFB128 algorithm. IV for the operation is the session + * IV. + * In addition the test verifies if the implementation can use the + * packet buffer as completion event buffer.*/ +static void crypto_test_enc_alg_aes_cfb128(void) +{ + check_alg(ODP_CRYPTO_OP_ENCODE, + ODP_CIPHER_ALG_AES_CFB128, + ODP_AUTH_ALG_NULL, + aes_cfb128_reference, + ARRAY_SIZE(aes_cfb128_reference), + false, + false); +} + +/* This test verifies the correctness of encode (plaintext -> ciphertext) + * operation for AES128_CFB128 algorithm. IV for the operation is the operation + * IV. + * */ +static void crypto_test_enc_alg_aes_cfb128_ovr_iv(void) +{ + check_alg(ODP_CRYPTO_OP_ENCODE, + ODP_CIPHER_ALG_AES_CFB128, + ODP_AUTH_ALG_NULL, + aes_cfb128_reference, + ARRAY_SIZE(aes_cfb128_reference), + true, + false); +} + +/* This test verifies the correctness of decode (ciphertext -> plaintext) + * operation for AES128_CFB128 algorithm. IV for the operation is the session IV + * In addition the test verifies if the implementation can use the + * packet buffer as completion event buffer. + * */ +static void crypto_test_dec_alg_aes_cfb128(void) +{ + check_alg(ODP_CRYPTO_OP_DECODE, + ODP_CIPHER_ALG_AES_CFB128, + ODP_AUTH_ALG_NULL, + aes_cfb128_reference, + ARRAY_SIZE(aes_cfb128_reference), + false, + false); +} + +/* This test verifies the correctness of decode (ciphertext -> plaintext) + * operation for AES128_CFB128 algorithm. IV for the operation is the session IV + * In addition the test verifies if the implementation can use the + * packet buffer as completion event buffer. + * */ +static void crypto_test_dec_alg_aes_cfb128_ovr_iv(void) +{ + check_alg(ODP_CRYPTO_OP_DECODE, + ODP_CIPHER_ALG_AES_CFB128, + ODP_AUTH_ALG_NULL, + aes_cfb128_reference, + ARRAY_SIZE(aes_cfb128_reference), + true, + false); +} + static int check_alg_kasumi_f8(void) { return check_alg_support(ODP_CIPHER_ALG_KASUMI_F8, ODP_AUTH_ALG_NULL); @@ -2225,6 +2302,14 @@ odp_testinfo_t crypto_suite[] = { check_alg_aes_ecb), ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_aes_ecb, check_alg_aes_ecb), + ODP_TEST_INFO_CONDITIONAL(crypto_test_enc_alg_aes_cfb128, + check_alg_aes_cfb128), + ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_aes_cfb128, + check_alg_aes_cfb128), + ODP_TEST_INFO_CONDITIONAL(crypto_test_enc_alg_aes_cfb128_ovr_iv, + check_alg_aes_cfb128), + ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_aes_cfb128_ovr_iv, + check_alg_aes_cfb128), ODP_TEST_INFO_CONDITIONAL(crypto_test_enc_alg_kasumi_f8, check_alg_kasumi_f8), ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_kasumi_f8, diff --git a/test/validation/api/crypto/test_vectors.h b/test/validation/api/crypto/test_vectors.h index c5ca4aebc..23e86243c 100644 --- a/test/validation/api/crypto/test_vectors.h +++ b/test/validation/api/crypto/test_vectors.h @@ -512,6 +512,90 @@ static crypto_test_reference_t aes_ecb_reference[] = { } };
+static crypto_test_reference_t aes_cfb128_reference[] = { + /* NIST Special Publication 800-38A */ + { + .cipher_key_length = AES128_KEY_LEN, + .cipher_key = { 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, + 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c}, + .cipher_iv_length = AES_CFB128_IV_LEN, + .cipher_iv = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, + .length = 64, + .plaintext = { 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, + 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a, + 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c, + 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51, + 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11, + 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef, + 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17, + 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10}, + .ciphertext = { 0x3b, 0x3f, 0xd9, 0x2e, 0xb7, 0x2d, 0xad, 0x20, + 0x33, 0x34, 0x49, 0xf8, 0xe8, 0x3c, 0xfb, 0x4a, + 0xc8, 0xa6, 0x45, 0x37, 0xa0, 0xb3, 0xa9, 0x3f, + 0xcd, 0xe3, 0xcd, 0xad, 0x9f, 0x1c, 0xe5, 0x8b, + 0x26, 0x75, 0x1f, 0x67, 0xa3, 0xcb, 0xb1, 0x40, + 0xb1, 0x80, 0x8c, 0xf1, 0x87, 0xa4, 0xf4, 0xdf, + 0xc0, 0x4b, 0x05, 0x35, 0x7c, 0x5d, 0x1c, 0x0e, + 0xea, 0xc4, 0xc6, 0x6f, 0x9f, 0xf7, 0xf2, 0xe6 } + }, + /* NIST Special Publication 800-38A */ + { + .cipher_key_length = AES192_KEY_LEN, + .cipher_key = { 0x8e, 0x73, 0xb0, 0xf7, 0xda, 0x0e, 0x64, 0x52, + 0xc8, 0x10, 0xf3, 0x2b, 0x80, 0x90, 0x79, 0xe5, + 0x62, 0xf8, 0xea, 0xd2, 0x52, 0x2c, 0x6b, 0x7b}, + .cipher_iv_length = AES_CFB128_IV_LEN, + .cipher_iv = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, + .length = 64, + .plaintext = { 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, + 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a, + 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c, + 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51, + 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11, + 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef, + 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17, + 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10 }, + .ciphertext = { 0xcd, 0xc8, 0x0d, 0x6f, 0xdd, 0xf1, 0x8c, 0xab, + 0x34, 0xc2, 0x59, 0x09, 0xc9, 0x9a, 0x41, 0x74, + 0x67, 0xce, 0x7f, 0x7f, 0x81, 0x17, 0x36, 0x21, + 0x96, 0x1a, 0x2b, 0x70, 0x17, 0x1d, 0x3d, 0x7a, + 0x2e, 0x1e, 0x8a, 0x1d, 0xd5, 0x9b, 0x88, 0xb1, + 0xc8, 0xe6, 0x0f, 0xed, 0x1e, 0xfa, 0xc4, 0xc9, + 0xc0, 0x5f, 0x9f, 0x9c, 0xa9, 0x83, 0x4f, 0xa0, + 0x42, 0xae, 0x8f, 0xba, 0x58, 0x4b, 0x09, 0xff } + }, + /* NIST Special Publication 800-38A */ + { + .cipher_key_length = AES256_KEY_LEN, + .cipher_key = { 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe, + 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81, + 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7, + 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4}, + .cipher_iv_length = AES_CFB128_IV_LEN, + .cipher_iv = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, + .length = 64, + .plaintext = { 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, + 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a, + 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c, + 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51, + 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11, + 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef, + 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17, + 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10 }, + .ciphertext = { 0xdc, 0x7e, 0x84, 0xbf, 0xda, 0x79, 0x16, 0x4b, + 0x7e, 0xcd, 0x84, 0x86, 0x98, 0x5d, 0x38, 0x60, + 0x39, 0xff, 0xed, 0x14, 0x3b, 0x28, 0xb1, 0xc8, + 0x32, 0x11, 0x3c, 0x63, 0x31, 0xe5, 0x40, 0x7b, + 0xdf, 0x10, 0x13, 0x24, 0x15, 0xe5, 0x4b, 0x92, + 0xa1, 0x3e, 0xd0, 0xa8, 0x26, 0x7a, 0xe2, 0xf9, + 0x75, 0xa3, 0x85, 0x74, 0x1a, 0xb9, 0xce, 0xf8, + 0x20, 0x31, 0x62, 0x3d, 0x55, 0xb1, 0xe4, 0x71 } + } +}; + /* AES-GCM test vectors extracted from * https://tools.ietf.org/html/draft-mcgrew-gcm-test-01#section-2 */ diff --git a/test/validation/api/crypto/test_vectors_len.h b/test/validation/api/crypto/test_vectors_len.h index 0b8ed9b64..8c9ffeaeb 100644 --- a/test/validation/api/crypto/test_vectors_len.h +++ b/test/validation/api/crypto/test_vectors_len.h @@ -34,6 +34,9 @@ /* AES-CTR */ #define AES_CTR_IV_LEN 16
+/* AES-CFB128 */ +#define AES_CFB128_IV_LEN 16 + /* AES-GCM */ #define AES_GCM_IV_LEN 12 #define AES_GCM_DIGEST_LEN 16
commit a7492121cbf3a30cf5219744dc5774177f3d9496 Author: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Date: Mon Apr 15 21:38:55 2019 +0300
api: crypto: add AES-CFB128 support
Add support for AES in 128-bit Cipher FeedBack mode.
Signed-off-by: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Reviewed-by: Petri Savolainen petri.savolainen@nokia.com
diff --git a/include/odp/api/spec/crypto.h b/include/odp/api/spec/crypto.h index a77295c6e..295ad6bfb 100644 --- a/include/odp/api/spec/crypto.h +++ b/include/odp/api/spec/crypto.h @@ -88,6 +88,9 @@ typedef enum { /** AES with electronic codebook */ ODP_CIPHER_ALG_AES_ECB,
+ /** AES with 128-bit cipher feedback */ + ODP_CIPHER_ALG_AES_CFB128, + /** AES-GCM * * AES in Galois/Counter Mode (GCM) algorithm. GCM provides both @@ -320,6 +323,9 @@ typedef union odp_crypto_cipher_algos_t { /** ODP_CIPHER_ALG_AES_ECB */ uint32_t aes_ecb : 1;
+ /** ODP_CIPHER_ALG_AES_CFB128 */ + uint32_t aes_cfb128 : 1; + /** ODP_CIPHER_ALG_AES_GCM */ uint32_t aes_gcm : 1;
commit 72c3f81f56169ac6f1bd7d7f1c1f0b18ab2e1fdb Author: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Date: Mon Apr 15 21:35:11 2019 +0300
linux-gen: crypto: add AES-ECB support
Add support for AES in Electronic CodeBook mode.
Signed-off-by: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Reviewed-by: Petri Savolainen petri.savolainen@nokia.com
diff --git a/platform/linux-generic/odp_crypto_openssl.c b/platform/linux-generic/odp_crypto_openssl.c index b2543aa9e..ac38a7139 100644 --- a/platform/linux-generic/odp_crypto_openssl.c +++ b/platform/linux-generic/odp_crypto_openssl.c @@ -66,6 +66,11 @@ static const odp_crypto_cipher_capability_t cipher_capa_aes_ctr[] = { {.key_len = 24, .iv_len = 16}, {.key_len = 32, .iv_len = 16} };
+static const odp_crypto_cipher_capability_t cipher_capa_aes_ecb[] = { +{.key_len = 16}, +{.key_len = 24}, +{.key_len = 32} }; + static const odp_crypto_cipher_capability_t cipher_capa_aes_gcm[] = { {.key_len = 16, .iv_len = 12}, {.key_len = 24, .iv_len = 12}, @@ -1468,6 +1473,7 @@ int odp_crypto_capability(odp_crypto_capability_t *capa) capa->ciphers.bit.trides_ecb = 1; capa->ciphers.bit.aes_cbc = 1; capa->ciphers.bit.aes_ctr = 1; + capa->ciphers.bit.aes_ecb = 1; capa->ciphers.bit.aes_gcm = 1; capa->ciphers.bit.aes_ccm = 1; #if _ODP_HAVE_CHACHA20_POLY1305 @@ -1539,6 +1545,10 @@ int odp_crypto_cipher_capability(odp_cipher_alg_t cipher, src = cipher_capa_aes_ctr; num = sizeof(cipher_capa_aes_ctr) / size; break; + case ODP_CIPHER_ALG_AES_ECB: + src = cipher_capa_aes_ecb; + num = sizeof(cipher_capa_aes_ecb) / size; + break; case ODP_CIPHER_ALG_AES_GCM: src = cipher_capa_aes_gcm; num = sizeof(cipher_capa_aes_gcm) / size; @@ -1750,6 +1760,16 @@ odp_crypto_session_create(odp_crypto_session_param_t *param, else rc = -1; break; + case ODP_CIPHER_ALG_AES_ECB: + if (param->cipher_key.length == 16) + rc = process_cipher_param(session, EVP_aes_128_ecb()); + else if (param->cipher_key.length == 24) + rc = process_cipher_param(session, EVP_aes_192_ecb()); + else if (param->cipher_key.length == 32) + rc = process_cipher_param(session, EVP_aes_256_ecb()); + else + rc = -1; + break; #if ODP_DEPRECATED_API case ODP_CIPHER_ALG_AES128_GCM: /* AES-GCM requires to do both auth and
commit 8a662a3e7566994bac18113c2d4ea5ed3047bc62 Author: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Date: Mon Apr 15 21:22:51 2019 +0300
validation: crypto: add AES-ECB support
Add support for AES in Electronic CodeBook mode.
Signed-off-by: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Reviewed-by: Petri Savolainen petri.savolainen@nokia.com
diff --git a/test/validation/api/crypto/odp_crypto_test_inp.c b/test/validation/api/crypto/odp_crypto_test_inp.c index 5ad66b55f..caebb4b6e 100644 --- a/test/validation/api/crypto/odp_crypto_test_inp.c +++ b/test/validation/api/crypto/odp_crypto_test_inp.c @@ -102,6 +102,8 @@ static const char *cipher_alg_name(odp_cipher_alg_t cipher) return "ODP_CIPHER_ALG_AES_CBC"; case ODP_CIPHER_ALG_AES_CTR: return "ODP_CIPHER_ALG_AES_CTR"; + case ODP_CIPHER_ALG_AES_ECB: + return "ODP_CIPHER_ALG_AES_ECB"; case ODP_CIPHER_ALG_AES_GCM: return "ODP_CIPHER_ALG_AES_GCM"; case ODP_CIPHER_ALG_AES_CCM: @@ -532,6 +534,9 @@ static void check_alg(odp_crypto_op_t op, if (cipher_alg == ODP_CIPHER_ALG_AES_CTR && !(capa.ciphers.bit.aes_ctr)) rc = -1; + if (cipher_alg == ODP_CIPHER_ALG_AES_ECB && + !(capa.ciphers.bit.aes_ecb)) + rc = -1; if (cipher_alg == ODP_CIPHER_ALG_AES_GCM && !(capa.ciphers.bit.aes_gcm)) rc = -1; @@ -777,6 +782,10 @@ static int check_alg_support(odp_cipher_alg_t cipher, odp_auth_alg_t auth) if (!capability.ciphers.bit.aes_ctr) return ODP_TEST_INACTIVE; break; + case ODP_CIPHER_ALG_AES_ECB: + if (!capability.ciphers.bit.aes_ecb) + return ODP_TEST_INACTIVE; + break; case ODP_CIPHER_ALG_AES_GCM: if (!capability.ciphers.bit.aes_gcm) return ODP_TEST_INACTIVE; @@ -1330,6 +1339,39 @@ static void crypto_test_dec_alg_aes_ctr_ovr_iv(void) false); }
+static int check_alg_aes_ecb(void) +{ + return check_alg_support(ODP_CIPHER_ALG_AES_ECB, ODP_AUTH_ALG_NULL); +} + +/* This test verifies the correctness of encode (plaintext -> ciphertext) + * operation for AES128_ECB algorithm. + */ +static void crypto_test_enc_alg_aes_ecb(void) +{ + check_alg(ODP_CRYPTO_OP_ENCODE, + ODP_CIPHER_ALG_AES_ECB, + ODP_AUTH_ALG_NULL, + aes_ecb_reference, + ARRAY_SIZE(aes_ecb_reference), + false, + false); +} + +/* This test verifies the correctness of decode (ciphertext -> plaintext) + * operation for AES128_ECB algorithm. + * */ +static void crypto_test_dec_alg_aes_ecb(void) +{ + check_alg(ODP_CRYPTO_OP_DECODE, + ODP_CIPHER_ALG_AES_ECB, + ODP_AUTH_ALG_NULL, + aes_ecb_reference, + ARRAY_SIZE(aes_ecb_reference), + false, + false); +} + static int check_alg_kasumi_f8(void) { return check_alg_support(ODP_CIPHER_ALG_KASUMI_F8, ODP_AUTH_ALG_NULL); @@ -2179,6 +2221,10 @@ odp_testinfo_t crypto_suite[] = { check_alg_aes_ctr), ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_aes_ctr_ovr_iv, check_alg_aes_ctr), + ODP_TEST_INFO_CONDITIONAL(crypto_test_enc_alg_aes_ecb, + check_alg_aes_ecb), + ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_aes_ecb, + check_alg_aes_ecb), ODP_TEST_INFO_CONDITIONAL(crypto_test_enc_alg_kasumi_f8, check_alg_kasumi_f8), ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_kasumi_f8, diff --git a/test/validation/api/crypto/test_vectors.h b/test/validation/api/crypto/test_vectors.h index 03a2ac895..c5ca4aebc 100644 --- a/test/validation/api/crypto/test_vectors.h +++ b/test/validation/api/crypto/test_vectors.h @@ -298,6 +298,220 @@ static crypto_test_reference_t aes_ctr_reference[] = { }, };
+static crypto_test_reference_t aes_ecb_reference[] = { + /* NIST Special Publication 800-38A */ + { + .cipher_key_length = AES128_KEY_LEN, + .cipher_key = { 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, + 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c}, + .length = 64, + .plaintext = { 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, + 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a, + 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c, + 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51, + 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11, + 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef, + 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17, + 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10}, + .ciphertext = { 0x3a, 0xd7, 0x7b, 0xb4, 0x0d, 0x7a, 0x36, 0x60, + 0xa8, 0x9e, 0xca, 0xf3, 0x24, 0x66, 0xef, 0x97, + 0xf5, 0xd3, 0xd5, 0x85, 0x03, 0xb9, 0x69, 0x9d, + 0xe7, 0x85, 0x89, 0x5a, 0x96, 0xfd, 0xba, 0xaf, + 0x43, 0xb1, 0xcd, 0x7f, 0x59, 0x8e, 0xce, 0x23, + 0x88, 0x1b, 0x00, 0xe3, 0xed, 0x03, 0x06, 0x88, + 0x7b, 0x0c, 0x78, 0x5e, 0x27, 0xe8, 0xad, 0x3f, + 0x82, 0x23, 0x20, 0x71, 0x04, 0x72, 0x5d, 0xd4 } + }, + /* Generated by Crypto++ 5.6.1 (528 bytes) */ + { + .cipher_key_length = AES128_KEY_LEN, + .cipher_key = { 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, + 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c}, + .length = 528, + .plaintext = { 0x00, 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, + 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, + 0x2a, 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, + 0x9c, 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, + 0x51, 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, + 0x11, 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, + 0xef, 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, + 0x17, 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, + 0x10, 0x00, 0x00, 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, + 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, + 0x93, 0x17, 0x2a, 0xae, 0x2d, 0x8a, 0x57, 0x1e, + 0x03, 0xac, 0x9c, 0x9e, 0xb7, 0x6f, 0xac, 0x45, + 0xaf, 0x8e, 0x51, 0x30, 0xc8, 0x1c, 0x46, 0xa3, + 0x5c, 0xe4, 0x11, 0xe5, 0xfb, 0xc1, 0x19, 0x1a, + 0x0a, 0x52, 0xef, 0xf6, 0x9f, 0x24, 0x45, 0xdf, + 0x4f, 0x9b, 0x17, 0xad, 0x2b, 0x41, 0x7b, 0xe6, + 0x6c, 0x37, 0x10, 0x00, 0x00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0xFD, 0xF6, 0x28, 0x5B, 0x0A, 0x77, 0xBA, + 0xE0, 0x7D, 0x98, 0x7F, 0x9C, 0xE1, 0x72, 0xA5, + 0x48, 0xE6, 0xBF, 0x0A, 0x30, 0xCF, 0x09, 0x9A, + 0xA8, 0x2B, 0xE0, 0xA2, 0x5E, 0x0E, 0x89, 0x19 } + }, + /* NIST Special Publication 800-38A */ + { + .cipher_key_length = AES192_KEY_LEN, + .cipher_key = { 0x8e, 0x73, 0xb0, 0xf7, 0xda, 0x0e, 0x64, 0x52, + 0xc8, 0x10, 0xf3, 0x2b, 0x80, 0x90, 0x79, 0xe5, + 0x62, 0xf8, 0xea, 0xd2, 0x52, 0x2c, 0x6b, 0x7b}, + .length = 64, + .plaintext = { 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, + 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a, + 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c, + 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51, + 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11, + 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef, + 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17, + 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10 }, + .ciphertext = { 0xbd, 0x33, 0x4f, 0x1d, 0x6e, 0x45, 0xf2, 0x5f, + 0xf7, 0x12, 0xa2, 0x14, 0x57, 0x1f, 0xa5, 0xcc, + 0x97, 0x41, 0x04, 0x84, 0x6d, 0x0a, 0xd3, 0xad, + 0x77, 0x34, 0xec, 0xb3, 0xec, 0xee, 0x4e, 0xef, + 0xef, 0x7a, 0xfd, 0x22, 0x70, 0xe2, 0xe6, 0x0a, + 0xdc, 0xe0, 0xba, 0x2f, 0xac, 0xe6, 0x44, 0x4e, + 0x9a, 0x4b, 0x41, 0xba, 0x73, 0x8d, 0x6c, 0x72, + 0xfb, 0x16, 0x69, 0x16, 0x03, 0xc1, 0x8e, 0x0e } + }, + /* NIST Special Publication 800-38A */ + { + .cipher_key_length = AES256_KEY_LEN, + .cipher_key = { 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe, + 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81, + 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7, + 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4}, + .length = 64, + .plaintext = { 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, + 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a, + 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c, + 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51, + 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11, + 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef, + 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17, + 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10 }, + .ciphertext = { 0xf3, 0xee, 0xd1, 0xbd, 0xb5, 0xd2, 0xa0, 0x3c, + 0x06, 0x4b, 0x5a, 0x7e, 0x3d, 0xb1, 0x81, 0xf8, + 0x59, 0x1c, 0xcb, 0x10, 0xd4, 0x10, 0xed, 0x26, + 0xdc, 0x5b, 0xa7, 0x4a, 0x31, 0x36, 0x28, 0x70, + 0xb6, 0xed, 0x21, 0xb9, 0x9c, 0xa6, 0xf4, 0xf9, + 0xf1, 0x53, 0xe7, 0xb1, 0xbe, 0xaf, 0xed, 0x1d, + 0x23, 0x30, 0x4b, 0x7a, 0x39, 0xf9, 0xf3, 0xff, + 0x06, 0x7d, 0x8d, 0x8f, 0x9e, 0x24, 0xec, 0xc7} + } +}; + /* AES-GCM test vectors extracted from * https://tools.ietf.org/html/draft-mcgrew-gcm-test-01#section-2 */ diff --git a/test/validation/api/crypto/test_vectors_len.h b/test/validation/api/crypto/test_vectors_len.h index 6263b8ec4..0b8ed9b64 100644 --- a/test/validation/api/crypto/test_vectors_len.h +++ b/test/validation/api/crypto/test_vectors_len.h @@ -9,7 +9,7 @@ /* Maximum */ #define MAX_KEY_LEN 64 #define MAX_IV_LEN 16 -#define MAX_DATA_LEN 270 +#define MAX_DATA_LEN 528 #define MAX_AAD_LEN 12 #define MAX_DIGEST_LEN 64
commit 27e79f97b32df3426f7bc13fd0b1b3bff2cbf835 Author: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Date: Mon Apr 15 21:22:01 2019 +0300
api: crypto: add AES-ECB support
Add support for AES in Electronic CodeBook mode.
Signed-off-by: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Reviewed-by: Petri Savolainen petri.savolainen@nokia.com
diff --git a/include/odp/api/spec/crypto.h b/include/odp/api/spec/crypto.h index efcc9c454..a77295c6e 100644 --- a/include/odp/api/spec/crypto.h +++ b/include/odp/api/spec/crypto.h @@ -85,6 +85,9 @@ typedef enum { /** AES with counter mode */ ODP_CIPHER_ALG_AES_CTR,
+ /** AES with electronic codebook */ + ODP_CIPHER_ALG_AES_ECB, + /** AES-GCM * * AES in Galois/Counter Mode (GCM) algorithm. GCM provides both @@ -314,6 +317,9 @@ typedef union odp_crypto_cipher_algos_t { /** ODP_CIPHER_ALG_AES_CTR */ uint32_t aes_ctr : 1;
+ /** ODP_CIPHER_ALG_AES_ECB */ + uint32_t aes_ecb : 1; + /** ODP_CIPHER_ALG_AES_GCM */ uint32_t aes_gcm : 1;
commit be29376373fe098955f4bb1d24f76157dae82065 Author: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Date: Mon Apr 15 19:59:54 2019 +0300
linux-gen: crypto: add digest algorithms support
Add support for md5/sha1/sha* algorithms implemented as auth alg with zero key.
Signed-off-by: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Reviewed-by: Petri Savolainen petri.savolainen@nokia.com
diff --git a/platform/linux-generic/odp_crypto_openssl.c b/platform/linux-generic/odp_crypto_openssl.c index 766a0d0ee..b2543aa9e 100644 --- a/platform/linux-generic/odp_crypto_openssl.c +++ b/platform/linux-generic/odp_crypto_openssl.c @@ -142,6 +142,24 @@ static const odp_crypto_auth_capability_t auth_capa_chacha20_poly1305[] = { {.digest_len = 16, .key_len = 0, .aad_len = {.min = 8, .max = 12, .inc = 4} } }; #endif
+static const odp_crypto_auth_capability_t auth_capa_md5[] = { +{.digest_len = 16, .key_len = 0, .aad_len = {.min = 0, .max = 0, .inc = 0} } }; + +static const odp_crypto_auth_capability_t auth_capa_sha1[] = { +{.digest_len = 20, .key_len = 0, .aad_len = {.min = 0, .max = 0, .inc = 0} } }; + +static const odp_crypto_auth_capability_t auth_capa_sha224[] = { +{.digest_len = 28, .key_len = 0, .aad_len = {.min = 0, .max = 0, .inc = 0} } }; + +static const odp_crypto_auth_capability_t auth_capa_sha256[] = { +{.digest_len = 32, .key_len = 0, .aad_len = {.min = 0, .max = 0, .inc = 0} } }; + +static const odp_crypto_auth_capability_t auth_capa_sha384[] = { +{.digest_len = 48, .key_len = 0, .aad_len = {.min = 0, .max = 0, .inc = 0} } }; + +static const odp_crypto_auth_capability_t auth_capa_sha512[] = { +{.digest_len = 64, .key_len = 0, .aad_len = {.min = 0, .max = 0, .inc = 0} } }; + /** Forward declaration of session structure */ typedef struct odp_crypto_generic_session_t odp_crypto_generic_session_t;
@@ -205,6 +223,7 @@ struct odp_crypto_global_s { static odp_crypto_global_t *global;
typedef struct crypto_local_t { + EVP_MD_CTX *md_ctx[MAX_SESSIONS]; HMAC_CTX *hmac_ctx[MAX_SESSIONS]; CMAC_CTX *cmac_ctx[MAX_SESSIONS]; EVP_CIPHER_CTX *cipher_ctx[MAX_SESSIONS]; @@ -624,6 +643,83 @@ odp_crypto_alg_err_t auth_cmac_check(odp_packet_t pkt, return ODP_CRYPTO_ALG_ERR_NONE; }
+static +void packet_digest(odp_packet_t pkt, + const odp_crypto_packet_op_param_t *param, + odp_crypto_generic_session_t *session, + uint8_t *hash) +{ + EVP_MD_CTX *ctx = local.md_ctx[session->idx]; + uint32_t offset = param->auth_range.offset; + uint32_t len = param->auth_range.length; + + ODP_ASSERT(offset + len <= odp_packet_len(pkt)); + + EVP_DigestInit_ex(ctx, + session->auth.evp_md, + NULL); + + /* Hash it */ + while (len > 0) { + uint32_t seglen = 0; /* GCC */ + void *mapaddr = odp_packet_offset(pkt, offset, &seglen, NULL); + uint32_t maclen = len > seglen ? seglen : len; + + EVP_DigestUpdate(ctx, mapaddr, maclen); + offset += maclen; + len -= maclen; + } + + EVP_DigestFinal_ex(ctx, hash, NULL); +} + +static +odp_crypto_alg_err_t auth_digest_gen(odp_packet_t pkt, + const odp_crypto_packet_op_param_t *param, + odp_crypto_generic_session_t *session) +{ + uint8_t hash[EVP_MAX_MD_SIZE]; + + /* Hash it */ + packet_digest(pkt, param, session, hash); + + /* Copy to the output location */ + odp_packet_copy_from_mem(pkt, + param->hash_result_offset, + session->p.auth_digest_len, + hash); + + return ODP_CRYPTO_ALG_ERR_NONE; +} + +static +odp_crypto_alg_err_t auth_digest_check(odp_packet_t pkt, + const odp_crypto_packet_op_param_t + *param, + odp_crypto_generic_session_t *session) +{ + uint32_t bytes = session->p.auth_digest_len; + uint8_t hash_in[EVP_MAX_MD_SIZE]; + uint8_t hash_out[EVP_MAX_MD_SIZE]; + + /* Copy current value out and clear it before authentication */ + odp_packet_copy_to_mem(pkt, param->hash_result_offset, + bytes, hash_in); + + _odp_packet_set_data(pkt, param->hash_result_offset, + 0, bytes); + + /* Hash it */ + packet_digest(pkt, param, session, hash_out); + + /* Verify match */ + if (0 != memcmp(hash_in, hash_out, bytes)) + return ODP_CRYPTO_ALG_ERR_ICV_CHECK; + + /* Matched */ + return ODP_CRYPTO_ALG_ERR_NONE; +} + static int internal_aad(EVP_CIPHER_CTX *ctx, odp_packet_t pkt, @@ -1336,6 +1432,26 @@ static int process_auth_cmac_param(odp_crypto_generic_session_t *session, return 0; }
+static int process_digest_param(odp_crypto_generic_session_t *session, + const EVP_MD *md) +{ + /* Verify Key len is valid */ + if ((uint32_t)EVP_MD_size(md) != + session->p.auth_digest_len) + return -1; + + /* Set function */ + if (ODP_CRYPTO_OP_ENCODE == session->p.op) + session->auth.func = auth_digest_gen; + else + session->auth.func = auth_digest_check; + session->auth.init = null_crypto_init_routine; + + session->auth.evp_md = md; + + return 0; +} + int odp_crypto_capability(odp_crypto_capability_t *capa) { if (NULL == capa) @@ -1374,6 +1490,13 @@ int odp_crypto_capability(odp_crypto_capability_t *capa) capa->auths.bit.chacha20_poly1305 = 1; #endif
+ capa->auths.bit.md5 = 1; + capa->auths.bit.sha1 = 1; + capa->auths.bit.sha224 = 1; + capa->auths.bit.sha256 = 1; + capa->auths.bit.sha384 = 1; + capa->auths.bit.sha512 = 1; + #if ODP_DEPRECATED_API capa->ciphers.bit.aes128_cbc = 1; capa->ciphers.bit.aes128_gcm = 1; @@ -1504,6 +1627,30 @@ int odp_crypto_auth_capability(odp_auth_alg_t auth, num = sizeof(auth_capa_chacha20_poly1305) / size; break; #endif + case ODP_AUTH_ALG_MD5: + src = auth_capa_md5; + num = sizeof(auth_capa_md5) / size; + break; + case ODP_AUTH_ALG_SHA1: + src = auth_capa_sha1; + num = sizeof(auth_capa_sha1) / size; + break; + case ODP_AUTH_ALG_SHA224: + src = auth_capa_sha224; + num = sizeof(auth_capa_sha224) / size; + break; + case ODP_AUTH_ALG_SHA256: + src = auth_capa_sha256; + num = sizeof(auth_capa_sha256) / size; + break; + case ODP_AUTH_ALG_SHA384: + src = auth_capa_sha384; + num = sizeof(auth_capa_sha384) / size; + break; + case ODP_AUTH_ALG_SHA512: + src = auth_capa_sha512; + num = sizeof(auth_capa_sha512) / size; + break; default: return -1; } @@ -1772,6 +1919,24 @@ odp_crypto_session_create(odp_crypto_session_param_t *param, } break; #endif + case ODP_AUTH_ALG_MD5: + rc = process_digest_param(session, EVP_md5()); + break; + case ODP_AUTH_ALG_SHA1: + rc = process_digest_param(session, EVP_sha1()); + break; + case ODP_AUTH_ALG_SHA224: + rc = process_digest_param(session, EVP_sha224()); + break; + case ODP_AUTH_ALG_SHA256: + rc = process_digest_param(session, EVP_sha256()); + break; + case ODP_AUTH_ALG_SHA384: + rc = process_digest_param(session, EVP_sha384()); + break; + case ODP_AUTH_ALG_SHA512: + rc = process_digest_param(session, EVP_sha512()); + break; default: rc = -1; } @@ -1960,8 +2125,11 @@ int _odp_crypto_init_local(void) local.cmac_ctx[i] = CMAC_CTX_new(); local.cipher_ctx[i] = EVP_CIPHER_CTX_new(); local.mac_cipher_ctx[i] = EVP_CIPHER_CTX_new(); + local.md_ctx[i] = EVP_MD_CTX_new();
if (local.hmac_ctx[i] == NULL || + local.cmac_ctx[i] == NULL || + local.md_ctx[i] == NULL || local.cipher_ctx[i] == NULL || local.mac_cipher_ctx[i] == NULL) { _odp_crypto_term_local(); @@ -1989,6 +2157,8 @@ int _odp_crypto_term_local(void) EVP_CIPHER_CTX_free(local.cipher_ctx[i]); if (local.mac_cipher_ctx[i] != NULL) EVP_CIPHER_CTX_free(local.mac_cipher_ctx[i]); + if (local.md_ctx[i] != NULL) + EVP_MD_CTX_free(local.md_ctx[i]); }
return 0;
commit 7f6413db99c5e7172ae255116bdbdfd53c2171b7 Author: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Date: Mon Apr 15 19:59:54 2019 +0300
validation: crypto: add digest tests
Add tests for digest algorithms.
Signed-off-by: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Reviewed-by: Petri Savolainen petri.savolainen@nokia.com
diff --git a/test/validation/api/crypto/odp_crypto_test_inp.c b/test/validation/api/crypto/odp_crypto_test_inp.c index 6ed4df257..5ad66b55f 100644 --- a/test/validation/api/crypto/odp_crypto_test_inp.c +++ b/test/validation/api/crypto/odp_crypto_test_inp.c @@ -70,6 +70,18 @@ static const char *auth_alg_name(odp_auth_alg_t auth) return "ODP_AUTH_ALG_SNOW3G_UIA2"; case ODP_AUTH_ALG_ZUC_EIA3: return "ODP_AUTH_ALG_ZUC_EIA3"; + case ODP_AUTH_ALG_MD5: + return "ODP_AUTH_ALG_MD5"; + case ODP_AUTH_ALG_SHA1: + return "ODP_AUTH_ALG_SHA1"; + case ODP_AUTH_ALG_SHA224: + return "ODP_AUTH_ALG_SHA224"; + case ODP_AUTH_ALG_SHA256: + return "ODP_AUTH_ALG_SHA256"; + case ODP_AUTH_ALG_SHA384: + return "ODP_AUTH_ALG_SHA384"; + case ODP_AUTH_ALG_SHA512: + return "ODP_AUTH_ALG_SHA512"; default: return "Unknown"; } @@ -596,6 +608,24 @@ static void check_alg(odp_crypto_op_t op, if (auth_alg == ODP_AUTH_ALG_AES_XCBC_MAC && !(capa.auths.bit.aes_xcbc_mac)) rc = -1; + if (auth_alg == ODP_AUTH_ALG_MD5 && + !(capa.auths.bit.md5)) + rc = -1; + if (auth_alg == ODP_AUTH_ALG_SHA1 && + !(capa.auths.bit.sha1)) + rc = -1; + if (auth_alg == ODP_AUTH_ALG_SHA224 && + !(capa.auths.bit.sha224)) + rc = -1; + if (auth_alg == ODP_AUTH_ALG_SHA256 && + !(capa.auths.bit.sha256)) + rc = -1; + if (auth_alg == ODP_AUTH_ALG_SHA384 && + !(capa.auths.bit.sha384)) + rc = -1; + if (auth_alg == ODP_AUTH_ALG_SHA512 && + !(capa.auths.bit.sha512)) + rc = -1;
CU_ASSERT(!rc); CU_ASSERT((~capa.auths.all_bits & capa.hw_auths.all_bits) == 0); @@ -842,6 +872,30 @@ static int check_alg_support(odp_cipher_alg_t cipher, odp_auth_alg_t auth) if (!capability.auths.bit.zuc_eia3) return ODP_TEST_INACTIVE; break; + case ODP_AUTH_ALG_MD5: + if (!capability.auths.bit.md5) + return ODP_TEST_INACTIVE; + break; + case ODP_AUTH_ALG_SHA1: + if (!capability.auths.bit.sha1) + return ODP_TEST_INACTIVE; + break; + case ODP_AUTH_ALG_SHA224: + if (!capability.auths.bit.sha224) + return ODP_TEST_INACTIVE; + break; + case ODP_AUTH_ALG_SHA256: + if (!capability.auths.bit.sha256) + return ODP_TEST_INACTIVE; + break; + case ODP_AUTH_ALG_SHA384: + if (!capability.auths.bit.sha384) + return ODP_TEST_INACTIVE; + break; + case ODP_AUTH_ALG_SHA512: + if (!capability.auths.bit.sha512) + return ODP_TEST_INACTIVE; + break; default: fprintf(stderr, "Unsupported authentication algorithm\n"); return ODP_TEST_INACTIVE; @@ -1878,6 +1932,168 @@ static void crypto_test_check_alg_zuc_eia3_ovr_iv(void) true); }
+static int check_alg_md5(void) +{ + return check_alg_support(ODP_CIPHER_ALG_NULL, ODP_AUTH_ALG_MD5); +} + +static void crypto_test_gen_alg_md5(void) +{ + check_alg(ODP_CRYPTO_OP_ENCODE, + ODP_CIPHER_ALG_NULL, + ODP_AUTH_ALG_MD5, + md5_reference, + ARRAY_SIZE(md5_reference), + false, + false); +} + +static void crypto_test_check_alg_md5(void) +{ + check_alg(ODP_CRYPTO_OP_DECODE, + ODP_CIPHER_ALG_NULL, + ODP_AUTH_ALG_MD5, + md5_reference, + ARRAY_SIZE(md5_reference), + false, + false); +} + +static int check_alg_sha1(void) +{ + return check_alg_support(ODP_CIPHER_ALG_NULL, ODP_AUTH_ALG_SHA1); +} + +static void crypto_test_gen_alg_sha1(void) +{ + check_alg(ODP_CRYPTO_OP_ENCODE, + ODP_CIPHER_ALG_NULL, + ODP_AUTH_ALG_SHA1, + sha1_reference, + ARRAY_SIZE(sha1_reference), + false, + false); +} + +static void crypto_test_check_alg_sha1(void) +{ + check_alg(ODP_CRYPTO_OP_DECODE, + ODP_CIPHER_ALG_NULL, + ODP_AUTH_ALG_SHA1, + sha1_reference, + ARRAY_SIZE(sha1_reference), + false, + false); +} + +static int check_alg_sha224(void) +{ + return check_alg_support(ODP_CIPHER_ALG_NULL, ODP_AUTH_ALG_SHA224); +} + +static void crypto_test_gen_alg_sha224(void) +{ + check_alg(ODP_CRYPTO_OP_ENCODE, + ODP_CIPHER_ALG_NULL, + ODP_AUTH_ALG_SHA224, + sha224_reference, + ARRAY_SIZE(sha224_reference), + false, + false); +} + +static void crypto_test_check_alg_sha224(void) +{ + check_alg(ODP_CRYPTO_OP_DECODE, + ODP_CIPHER_ALG_NULL, + ODP_AUTH_ALG_SHA224, + sha224_reference, + ARRAY_SIZE(sha224_reference), + false, + false); +} + +static int check_alg_sha256(void) +{ + return check_alg_support(ODP_CIPHER_ALG_NULL, ODP_AUTH_ALG_SHA256); +} + +static void crypto_test_gen_alg_sha256(void) +{ + check_alg(ODP_CRYPTO_OP_ENCODE, + ODP_CIPHER_ALG_NULL, + ODP_AUTH_ALG_SHA256, + sha256_reference, + ARRAY_SIZE(sha256_reference), + false, + false); +} + +static void crypto_test_check_alg_sha256(void) +{ + check_alg(ODP_CRYPTO_OP_DECODE, + ODP_CIPHER_ALG_NULL, + ODP_AUTH_ALG_SHA256, + sha256_reference, + ARRAY_SIZE(sha256_reference), + false, + false); +} + +static int check_alg_sha384(void) +{ + return check_alg_support(ODP_CIPHER_ALG_NULL, ODP_AUTH_ALG_SHA384); +} + +static void crypto_test_gen_alg_sha384(void) +{ + check_alg(ODP_CRYPTO_OP_ENCODE, + ODP_CIPHER_ALG_NULL, + ODP_AUTH_ALG_SHA384, + sha384_reference, + ARRAY_SIZE(sha384_reference), + false, + false); +} + +static void crypto_test_check_alg_sha384(void) +{ + check_alg(ODP_CRYPTO_OP_DECODE, + ODP_CIPHER_ALG_NULL, + ODP_AUTH_ALG_SHA384, + sha384_reference, + ARRAY_SIZE(sha384_reference), + false, + false); +} + +static int check_alg_sha512(void) +{ + return check_alg_support(ODP_CIPHER_ALG_NULL, ODP_AUTH_ALG_SHA512); +} + +static void crypto_test_gen_alg_sha512(void) +{ + check_alg(ODP_CRYPTO_OP_ENCODE, + ODP_CIPHER_ALG_NULL, + ODP_AUTH_ALG_SHA512, + sha512_reference, + ARRAY_SIZE(sha512_reference), + false, + false); +} + +static void crypto_test_check_alg_sha512(void) +{ + check_alg(ODP_CRYPTO_OP_DECODE, + ODP_CIPHER_ALG_NULL, + ODP_AUTH_ALG_SHA512, + sha512_reference, + ARRAY_SIZE(sha512_reference), + false, + false); +} + static int crypto_suite_sync_init(void) { suite_context.pool = odp_pool_lookup("packet_pool"); @@ -2075,6 +2291,30 @@ odp_testinfo_t crypto_suite[] = { check_alg_zuc_eia3), ODP_TEST_INFO_CONDITIONAL(crypto_test_check_alg_zuc_eia3_ovr_iv, check_alg_zuc_eia3), + ODP_TEST_INFO_CONDITIONAL(crypto_test_gen_alg_md5, + check_alg_md5), + ODP_TEST_INFO_CONDITIONAL(crypto_test_check_alg_md5, + check_alg_md5), + ODP_TEST_INFO_CONDITIONAL(crypto_test_gen_alg_sha1, + check_alg_sha1), + ODP_TEST_INFO_CONDITIONAL(crypto_test_check_alg_sha1, + check_alg_sha1), + ODP_TEST_INFO_CONDITIONAL(crypto_test_gen_alg_sha224, + check_alg_sha224), + ODP_TEST_INFO_CONDITIONAL(crypto_test_check_alg_sha224, + check_alg_sha224), + ODP_TEST_INFO_CONDITIONAL(crypto_test_gen_alg_sha256, + check_alg_sha256), + ODP_TEST_INFO_CONDITIONAL(crypto_test_check_alg_sha256, + check_alg_sha256), + ODP_TEST_INFO_CONDITIONAL(crypto_test_gen_alg_sha384, + check_alg_sha384), + ODP_TEST_INFO_CONDITIONAL(crypto_test_check_alg_sha384, + check_alg_sha384), + ODP_TEST_INFO_CONDITIONAL(crypto_test_gen_alg_sha512, + check_alg_sha512), + ODP_TEST_INFO_CONDITIONAL(crypto_test_check_alg_sha512, + check_alg_sha512), ODP_TEST_INFO_NULL, };
diff --git a/test/validation/api/crypto/test_vectors.h b/test/validation/api/crypto/test_vectors.h index ff6ee8cc2..03a2ac895 100644 --- a/test/validation/api/crypto/test_vectors.h +++ b/test/validation/api/crypto/test_vectors.h @@ -1811,4 +1811,256 @@ static crypto_test_reference_t zuc_eia3_reference[] = { } };
+/* + * MD5 test vectors from RFC 1321 + */ +static crypto_test_reference_t md5_reference[] = { + { + .length = 3, + .plaintext = { 0x61, 0x62, 0x63 }, + .ciphertext = { 0x61, 0x62, 0x63 }, + .digest_length = MD5_DIGEST_LEN, + .digest = { 0x90, 0x01, 0x50, 0x98, 0x3c, 0xd2, 0x4f, 0xb0, + 0xd6, 0x96, 0x3f, 0x7d, 0x28, 0xe1, 0x7f, 0x72} + }, + { + .length = 62, + .plaintext = { 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, + 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, + 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, + 0x59, 0x5a, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, + 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, + 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, + 0x77, 0x78, 0x79, 0x7a, 0x30, 0x31, 0x32, 0x33, + 0x34, 0x35, 0x36, 0x37, 0x38, 0x39 }, + .ciphertext = { 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, + 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, + 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, + 0x59, 0x5a, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, + 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, + 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, + 0x77, 0x78, 0x79, 0x7a, 0x30, 0x31, 0x32, 0x33, + 0x34, 0x35, 0x36, 0x37, 0x38, 0x39 }, + .digest_length = MD5_DIGEST_LEN, + .digest = { 0xd1, 0x74, 0xab, 0x98, 0xd2, 0x77, 0xd9, 0xf5, + 0xa5, 0x61, 0x1c, 0x2c, 0x9f, 0x41, 0x9d, 0x9f}, + } +}; + +/* + * SHA test vectors from Crypto++ + */ +static crypto_test_reference_t sha1_reference[] = { + { + .length = 3, + .plaintext = { 0x61, 0x62, 0x63 }, + .ciphertext = { 0x61, 0x62, 0x63 }, + .digest_length = SHA1_DIGEST_LEN, + .digest = { 0xA9, 0x99, 0x3E, 0x36, 0x47, 0x06, 0x81, 0x6A, + 0xBA, 0x3E, 0x25, 0x71, 0x78, 0x50, 0xC2, 0x6C, + 0x9C, 0xD0, 0xD8, 0x9D}, + }, + { + .length = 56, + .plaintext = { 0x61, 0x62, 0x63, 0x64, 0x62, 0x63, 0x64, 0x65, + 0x63, 0x64, 0x65, 0x66, 0x64, 0x65, 0x66, 0x67, + 0x65, 0x66, 0x67, 0x68, 0x66, 0x67, 0x68, 0x69, + 0x67, 0x68, 0x69, 0x6a, 0x68, 0x69, 0x6a, 0x6b, + 0x69, 0x6a, 0x6b, 0x6c, 0x6a, 0x6b, 0x6c, 0x6d, + 0x6b, 0x6c, 0x6d, 0x6e, 0x6c, 0x6d, 0x6e, 0x6f, + 0x6d, 0x6e, 0x6f, 0x70, 0x6e, 0x6f, 0x70, 0x71}, + .ciphertext = { 0x61, 0x62, 0x63, 0x64, 0x62, 0x63, 0x64, 0x65, + 0x63, 0x64, 0x65, 0x66, 0x64, 0x65, 0x66, 0x67, + 0x65, 0x66, 0x67, 0x68, 0x66, 0x67, 0x68, 0x69, + 0x67, 0x68, 0x69, 0x6a, 0x68, 0x69, 0x6a, 0x6b, + 0x69, 0x6a, 0x6b, 0x6c, 0x6a, 0x6b, 0x6c, 0x6d, + 0x6b, 0x6c, 0x6d, 0x6e, 0x6c, 0x6d, 0x6e, 0x6f, + 0x6d, 0x6e, 0x6f, 0x70, 0x6e, 0x6f, 0x70, 0x71}, + .digest_length = SHA1_DIGEST_LEN, + .digest = { 0x84, 0x98, 0x3E, 0x44, 0x1C, 0x3B, 0xD2, 0x6E, + 0xBA, 0xAE, 0x4A, 0xA1, 0xF9, 0x51, 0x29, 0xE5, + 0xE5, 0x46, 0x70, 0xF1}, + } +}; + +static crypto_test_reference_t sha224_reference[] = { + { + .length = 3, + .plaintext = { 0x61, 0x62, 0x63 }, + .ciphertext = { 0x61, 0x62, 0x63 }, + .digest_length = SHA224_DIGEST_LEN, + .digest = { 0x23, 0x09, 0x7d, 0x22, 0x34, 0x05, 0xd8, 0x22, + 0x86, 0x42, 0xa4, 0x77, 0xbd, 0xa2, 0x55, 0xb3, + 0x2a, 0xad, 0xbc, 0xe4, 0xbd, 0xa0, 0xb3, 0xf7, + 0xe3, 0x6c, 0x9d, 0xa7 }, + }, + { + .length = 56, + .plaintext = { 0x61, 0x62, 0x63, 0x64, 0x62, 0x63, 0x64, 0x65, + 0x63, 0x64, 0x65, 0x66, 0x64, 0x65, 0x66, 0x67, + 0x65, 0x66, 0x67, 0x68, 0x66, 0x67, 0x68, 0x69, + 0x67, 0x68, 0x69, 0x6a, 0x68, 0x69, 0x6a, 0x6b, + 0x69, 0x6a, 0x6b, 0x6c, 0x6a, 0x6b, 0x6c, 0x6d, + 0x6b, 0x6c, 0x6d, 0x6e, 0x6c, 0x6d, 0x6e, 0x6f, + 0x6d, 0x6e, 0x6f, 0x70, 0x6e, 0x6f, 0x70, 0x71}, + .ciphertext = { 0x61, 0x62, 0x63, 0x64, 0x62, 0x63, 0x64, 0x65, + 0x63, 0x64, 0x65, 0x66, 0x64, 0x65, 0x66, 0x67, + 0x65, 0x66, 0x67, 0x68, 0x66, 0x67, 0x68, 0x69, + 0x67, 0x68, 0x69, 0x6a, 0x68, 0x69, 0x6a, 0x6b, + 0x69, 0x6a, 0x6b, 0x6c, 0x6a, 0x6b, 0x6c, 0x6d, + 0x6b, 0x6c, 0x6d, 0x6e, 0x6c, 0x6d, 0x6e, 0x6f, + 0x6d, 0x6e, 0x6f, 0x70, 0x6e, 0x6f, 0x70, 0x71}, + .digest_length = SHA224_DIGEST_LEN, + .digest = { 0x75, 0x38, 0x8b, 0x16, 0x51, 0x27, 0x76, 0xcc, + 0x5d, 0xba, 0x5d, 0xa1, 0xfd, 0x89, 0x01, 0x50, + 0xb0, 0xc6, 0x45, 0x5c, 0xb4, 0xf5, 0x8b, 0x19, + 0x52, 0x52, 0x25, 0x25}, + } +}; + +static crypto_test_reference_t sha256_reference[] = { + { + .length = 3, + .plaintext = { 0x61, 0x62, 0x63 }, + .ciphertext = { 0x61, 0x62, 0x63 }, + .digest_length = SHA256_DIGEST_LEN, + .digest = { 0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, + 0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23, + 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, + 0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad}, + }, + { + .length = 56, + .plaintext = { 0x61, 0x62, 0x63, 0x64, 0x62, 0x63, 0x64, 0x65, + 0x63, 0x64, 0x65, 0x66, 0x64, 0x65, 0x66, 0x67, + 0x65, 0x66, 0x67, 0x68, 0x66, 0x67, 0x68, 0x69, + 0x67, 0x68, 0x69, 0x6a, 0x68, 0x69, 0x6a, 0x6b, + 0x69, 0x6a, 0x6b, 0x6c, 0x6a, 0x6b, 0x6c, 0x6d, + 0x6b, 0x6c, 0x6d, 0x6e, 0x6c, 0x6d, 0x6e, 0x6f, + 0x6d, 0x6e, 0x6f, 0x70, 0x6e, 0x6f, 0x70, 0x71}, + .ciphertext = { 0x61, 0x62, 0x63, 0x64, 0x62, 0x63, 0x64, 0x65, + 0x63, 0x64, 0x65, 0x66, 0x64, 0x65, 0x66, 0x67, + 0x65, 0x66, 0x67, 0x68, 0x66, 0x67, 0x68, 0x69, + 0x67, 0x68, 0x69, 0x6a, 0x68, 0x69, 0x6a, 0x6b, + 0x69, 0x6a, 0x6b, 0x6c, 0x6a, 0x6b, 0x6c, 0x6d, + 0x6b, 0x6c, 0x6d, 0x6e, 0x6c, 0x6d, 0x6e, 0x6f, + 0x6d, 0x6e, 0x6f, 0x70, 0x6e, 0x6f, 0x70, 0x71}, + .digest_length = SHA256_DIGEST_LEN, + .digest = { 0x24, 0x8d, 0x6a, 0x61, 0xd2, 0x06, 0x38, 0xb8, + 0xe5, 0xc0, 0x26, 0x93, 0x0c, 0x3e, 0x60, 0x39, + 0xa3, 0x3c, 0xe4, 0x59, 0x64, 0xff, 0x21, 0x67, + 0xf6, 0xec, 0xed, 0xd4, 0x19, 0xdb, 0x06, 0xc1}, + } +}; + +static crypto_test_reference_t sha384_reference[] = { + { + .length = 3, + .plaintext = { 0x61, 0x62, 0x63 }, + .ciphertext = { 0x61, 0x62, 0x63 }, + .digest_length = SHA384_DIGEST_LEN, + .digest = { 0xcb, 0x00, 0x75, 0x3f, 0x45, 0xa3, 0x5e, 0x8b, + 0xb5, 0xa0, 0x3d, 0x69, 0x9a, 0xc6, 0x50, 0x07, + 0x27, 0x2c, 0x32, 0xab, 0x0e, 0xde, 0xd1, 0x63, + 0x1a, 0x8b, 0x60, 0x5a, 0x43, 0xff, 0x5b, 0xed, + 0x80, 0x86, 0x07, 0x2b, 0xa1, 0xe7, 0xcc, 0x23, + 0x58, 0xba, 0xec, 0xa1, 0x34, 0xc8, 0x25, 0xa7}, + }, + { + .length = 112, + .plaintext = { 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, + 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, + 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, + 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, + 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, + 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, + 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, + 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, + 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, + 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, + 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, + 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, + 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, + 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75}, + .ciphertext = { 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, + 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, + 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, + 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, + 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, + 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, + 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, + 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, + 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, + 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, + 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, + 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, + 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, + 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75}, + .digest_length = SHA384_DIGEST_LEN, + .digest = { 0x09, 0x33, 0x0c, 0x33, 0xf7, 0x11, 0x47, 0xe8, + 0x3d, 0x19, 0x2f, 0xc7, 0x82, 0xcd, 0x1b, 0x47, + 0x53, 0x11, 0x1b, 0x17, 0x3b, 0x3b, 0x05, 0xd2, + 0x2f, 0xa0, 0x80, 0x86, 0xe3, 0xb0, 0xf7, 0x12, + 0xfc, 0xc7, 0xc7, 0x1a, 0x55, 0x7e, 0x2d, 0xb9, + 0x66, 0xc3, 0xe9, 0xfa, 0x91, 0x74, 0x60, 0x39}, + } +}; + +static crypto_test_reference_t sha512_reference[] = { + { + .length = 3, + .plaintext = { 0x61, 0x62, 0x63 }, + .ciphertext = { 0x61, 0x62, 0x63 }, + .digest_length = SHA512_DIGEST_LEN, + .digest = { 0xdd, 0xaf, 0x35, 0xa1, 0x93, 0x61, 0x7a, 0xba, + 0xcc, 0x41, 0x73, 0x49, 0xae, 0x20, 0x41, 0x31, + 0x12, 0xe6, 0xfa, 0x4e, 0x89, 0xa9, 0x7e, 0xa2, + 0x0a, 0x9e, 0xee, 0xe6, 0x4b, 0x55, 0xd3, 0x9a, + 0x21, 0x92, 0x99, 0x2a, 0x27, 0x4f, 0xc1, 0xa8, + 0x36, 0xba, 0x3c, 0x23, 0xa3, 0xfe, 0xeb, 0xbd, + 0x45, 0x4d, 0x44, 0x23, 0x64, 0x3c, 0xe8, 0x0e, + 0x2a, 0x9a, 0xc9, 0x4f, 0xa5, 0x4c, 0xa4, 0x9f}, + }, + { + .length = 112, + .plaintext = { 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, + 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, + 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, + 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, + 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, + 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, + 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, + 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, + 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, + 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, + 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, + 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, + 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, + 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75}, + .ciphertext = { 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, + 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, + 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, + 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, + 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, + 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, + 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, + 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, + 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, + 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, + 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, + 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, + 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, + 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75}, + .digest_length = SHA512_DIGEST_LEN, + .digest = { 0x8e, 0x95, 0x9b, 0x75, 0xda, 0xe3, 0x13, 0xda, + 0x8c, 0xf4, 0xf7, 0x28, 0x14, 0xfc, 0x14, 0x3f, + 0x8f, 0x77, 0x79, 0xc6, 0xeb, 0x9f, 0x7f, 0xa1, + 0x72, 0x99, 0xae, 0xad, 0xb6, 0x88, 0x90, 0x18, + 0x50, 0x1d, 0x28, 0x9e, 0x49, 0x00, 0xf7, 0xe4, + 0x33, 0x1b, 0x99, 0xde, 0xc4, 0xb5, 0x43, 0x3a, + 0xc7, 0xd3, 0x29, 0xee, 0xb6, 0xdd, 0x26, 0x54, + 0x5e, 0x96, 0xe5, 0x5b, 0x87, 0x4b, 0xe9, 0x09}, + } +}; + #endif diff --git a/test/validation/api/crypto/test_vectors_len.h b/test/validation/api/crypto/test_vectors_len.h index db6e5bc9f..6263b8ec4 100644 --- a/test/validation/api/crypto/test_vectors_len.h +++ b/test/validation/api/crypto/test_vectors_len.h @@ -104,4 +104,22 @@ #define ZUC_EIA3_IV_LEN 16 #define ZUC_EIA3_DIGEST_LEN 4
+/* MD5 */ +#define MD5_DIGEST_LEN 16 + +/* SHA1 */ +#define SHA1_DIGEST_LEN 20 + +/* SHA224 */ +#define SHA224_DIGEST_LEN 28 + +/* SHA256 */ +#define SHA256_DIGEST_LEN 32 + +/* SHA384 */ +#define SHA384_DIGEST_LEN 48 + +/* SHA512 */ +#define SHA512_DIGEST_LEN 64 + #endif
commit 181118b438f3abb6bc0b4f6df6b4656215e12158 Author: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Date: Mon Apr 15 19:57:44 2019 +0300
api: crypto: add digests enumeration
Add enumeration for digest (unkeyed) algorithms. They are added as auth algorithms with empty key required.
Signed-off-by: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Reviewed-by: Petri Savolainen petri.savolainen@nokia.com
diff --git a/include/odp/api/spec/crypto.h b/include/odp/api/spec/crypto.h index ec4711c01..efcc9c454 100644 --- a/include/odp/api/spec/crypto.h +++ b/include/odp/api/spec/crypto.h @@ -261,6 +261,24 @@ typedef enum { */ ODP_AUTH_ALG_ZUC_EIA3,
+ /** MD5 algorithm */ + ODP_AUTH_ALG_MD5, + + /** SHA1 algorithm */ + ODP_AUTH_ALG_SHA1, + + /** 224 bit SHA2 algorithm */ + ODP_AUTH_ALG_SHA224, + + /** 256 bit SHA2 algorithm */ + ODP_AUTH_ALG_SHA256, + + /** 384 bit SHA2 algorithm */ + ODP_AUTH_ALG_SHA384, + + /** 512 bit SHA2 algorithm */ + ODP_AUTH_ALG_SHA512, + /** @deprecated Use ODP_AUTH_ALG_MD5_HMAC instead */ ODP_DEPRECATE(ODP_AUTH_ALG_MD5_96),
@@ -383,6 +401,24 @@ typedef union odp_crypto_auth_algos_t { /** ODP_AUTH_ALG_ZUC_EIA3 */ uint32_t zuc_eia3 : 1;
+ /** ODP_AUTH_ALG_MD5 */ + uint32_t md5 : 1; + + /** ODP_AUTH_ALG_SHA1 */ + uint32_t sha1 : 1; + + /** ODP_AUTH_ALG_SHA224 */ + uint32_t sha224 : 1; + + /** ODP_AUTH_ALG_SHA256 */ + uint32_t sha256 : 1; + + /** ODP_AUTH_ALG_SHA384 */ + uint32_t sha384 : 1; + + /** ODP_AUTH_ALG_SHA512 */ + uint32_t sha512 : 1; + /** @deprecated Use md5_hmac instead */ uint32_t ODP_DEPRECATE(md5_96) : 1;
commit 44cde88d44b123d5726351599e8a043c38920762 Author: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Date: Sat Apr 6 14:55:04 2019 +0300
linux-gen: crypto: add HMAC-SHA224 algorithm support
Signed-off-by: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Reviewed-by: Petri Savolainen petri.savolainen@nokia.com
diff --git a/platform/linux-generic/odp_crypto_openssl.c b/platform/linux-generic/odp_crypto_openssl.c index 25fa11a78..766a0d0ee 100644 --- a/platform/linux-generic/odp_crypto_openssl.c +++ b/platform/linux-generic/odp_crypto_openssl.c @@ -100,6 +100,9 @@ static const odp_crypto_auth_capability_t auth_capa_sha1_hmac[] = { {.digest_len = 12, .key_len = 20, .aad_len = {.min = 0, .max = 0, .inc = 0} }, {.digest_len = 20, .key_len = 20, .aad_len = {.min = 0, .max = 0, .inc = 0} } };
+static const odp_crypto_auth_capability_t auth_capa_sha224_hmac[] = { +{.digest_len = 28, .key_len = 28, .aad_len = {.min = 0, .max = 0, .inc = 0} } }; + static const odp_crypto_auth_capability_t auth_capa_sha256_hmac[] = { {.digest_len = 16, .key_len = 32, .aad_len = {.min = 0, .max = 0, .inc = 0} }, {.digest_len = 32, .key_len = 32, .aad_len = {.min = 0, .max = 0, .inc = 0} } }; @@ -1358,6 +1361,7 @@ int odp_crypto_capability(odp_crypto_capability_t *capa) capa->auths.bit.null = 1; capa->auths.bit.md5_hmac = 1; capa->auths.bit.sha1_hmac = 1; + capa->auths.bit.sha224_hmac = 1; capa->auths.bit.sha256_hmac = 1; capa->auths.bit.sha384_hmac = 1; capa->auths.bit.sha512_hmac = 1; @@ -1458,6 +1462,10 @@ int odp_crypto_auth_capability(odp_auth_alg_t auth, src = auth_capa_sha1_hmac; num = sizeof(auth_capa_sha1_hmac) / size; break; + case ODP_AUTH_ALG_SHA224_HMAC: + src = auth_capa_sha224_hmac; + num = sizeof(auth_capa_sha224_hmac) / size; + break; case ODP_AUTH_ALG_SHA256_HMAC: src = auth_capa_sha256_hmac; num = sizeof(auth_capa_sha256_hmac) / size; @@ -1677,6 +1685,9 @@ odp_crypto_session_create(odp_crypto_session_param_t *param, case ODP_AUTH_ALG_SHA1_HMAC: rc = process_auth_hmac_param(session, EVP_sha1()); break; + case ODP_AUTH_ALG_SHA224_HMAC: + rc = process_auth_hmac_param(session, EVP_sha224()); + break; #if ODP_DEPRECATED_API case ODP_AUTH_ALG_SHA256_128: /* Fixed digest tag length with deprecated algo */
commit c0e82fab2c677480bf4774eb4c854e0ed31d893c Author: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Date: Mon Apr 15 21:16:03 2019 +0300
validation: crypto: add HMAC-SHA224 test vectors
Add test vectors for HMAC-SHA224 algorithm.
Signed-off-by: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Reviewed-by: Petri Savolainen petri.savolainen@nokia.com
diff --git a/test/validation/api/crypto/odp_crypto_test_inp.c b/test/validation/api/crypto/odp_crypto_test_inp.c index 12dcd4518..6ed4df257 100644 --- a/test/validation/api/crypto/odp_crypto_test_inp.c +++ b/test/validation/api/crypto/odp_crypto_test_inp.c @@ -44,6 +44,8 @@ static const char *auth_alg_name(odp_auth_alg_t auth) return "ODP_AUTH_ALG_MD5_HMAC"; case ODP_AUTH_ALG_SHA1_HMAC: return "ODP_AUTH_ALG_SHA1_HMAC"; + case ODP_AUTH_ALG_SHA224_HMAC: + return "ODP_AUTH_ALG_SHA224_HMAC"; case ODP_AUTH_ALG_SHA256_HMAC: return "ODP_AUTH_ALG_SHA256_HMAC"; case ODP_AUTH_ALG_SHA384_HMAC: @@ -579,6 +581,9 @@ static void check_alg(odp_crypto_op_t op, if (auth_alg == ODP_AUTH_ALG_SHA1_HMAC && !(capa.auths.bit.sha1_hmac)) rc = -1; + if (auth_alg == ODP_AUTH_ALG_SHA224_HMAC && + !(capa.auths.bit.sha224_hmac)) + rc = -1; if (auth_alg == ODP_AUTH_ALG_SHA256_HMAC && !(capa.auths.bit.sha256_hmac)) rc = -1; @@ -785,6 +790,10 @@ static int check_alg_support(odp_cipher_alg_t cipher, odp_auth_alg_t auth) if (!capability.auths.bit.sha1_hmac) return ODP_TEST_INACTIVE; break; + case ODP_AUTH_ALG_SHA224_HMAC: + if (!capability.auths.bit.sha224_hmac) + return ODP_TEST_INACTIVE; + break; case ODP_AUTH_ALG_SHA256_HMAC: if (!capability.auths.bit.sha256_hmac) return ODP_TEST_INACTIVE; @@ -1482,6 +1491,33 @@ static void crypto_test_check_alg_hmac_sha1(void) false); }
+static int check_alg_hmac_sha224(void) +{ + return check_alg_support(ODP_CIPHER_ALG_NULL, ODP_AUTH_ALG_SHA224_HMAC); +} + +static void crypto_test_gen_alg_hmac_sha224(void) +{ + check_alg(ODP_CRYPTO_OP_ENCODE, + ODP_CIPHER_ALG_NULL, + ODP_AUTH_ALG_SHA224_HMAC, + hmac_sha224_reference, + ARRAY_SIZE(hmac_sha224_reference), + false, + false); +} + +static void crypto_test_check_alg_hmac_sha224(void) +{ + check_alg(ODP_CRYPTO_OP_DECODE, + ODP_CIPHER_ALG_NULL, + ODP_AUTH_ALG_SHA224_HMAC, + hmac_sha224_reference, + ARRAY_SIZE(hmac_sha224_reference), + false, + false); +} + static int check_alg_hmac_sha256(void) { return check_alg_support(ODP_CIPHER_ALG_NULL, ODP_AUTH_ALG_SHA256_HMAC); @@ -1983,6 +2019,10 @@ odp_testinfo_t crypto_suite[] = { check_alg_hmac_sha1), ODP_TEST_INFO_CONDITIONAL(crypto_test_check_alg_hmac_sha1, check_alg_hmac_sha1), + ODP_TEST_INFO_CONDITIONAL(crypto_test_gen_alg_hmac_sha224, + check_alg_hmac_sha224), + ODP_TEST_INFO_CONDITIONAL(crypto_test_check_alg_hmac_sha224, + check_alg_hmac_sha224), ODP_TEST_INFO_CONDITIONAL(crypto_test_gen_alg_hmac_sha256, check_alg_hmac_sha256), ODP_TEST_INFO_CONDITIONAL(crypto_test_check_alg_hmac_sha256, diff --git a/test/validation/api/crypto/test_vectors.h b/test/validation/api/crypto/test_vectors.h index ed0036ca1..ff6ee8cc2 100644 --- a/test/validation/api/crypto/test_vectors.h +++ b/test/validation/api/crypto/test_vectors.h @@ -1100,6 +1100,70 @@ static crypto_test_reference_t hmac_sha1_reference[] = { } };
+static crypto_test_reference_t hmac_sha224_reference[] = { + { + .auth_key_length = HMAC_SHA224_KEY_LEN, + .auth_key = { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, + 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, + 0x0b, 0x0b, 0x0b, 0x0b }, + .length = 8, + /* "Hi There" */ + .plaintext = { 0x48, 0x69, 0x20, 0x54, 0x68, 0x65, 0x72, 0x65}, + .ciphertext = { 0x48, 0x69, 0x20, 0x54, 0x68, 0x65, 0x72, 0x65}, + .digest_length = HMAC_SHA224_CHECK_LEN, + .digest = { 0x89, 0x6f, 0xb1, 0x12, 0x8a, 0xbb, 0xdf, 0x19, + 0x68, 0x32, 0x10, 0x7c, 0xd4, 0x9d, 0xf3, 0x3f, + 0x47, 0xb4, 0xb1, 0x16, 0x99, 0x12, 0xba, 0x4f, + 0x53, 0x68, 0x4b, 0x22 } + }, + { + .auth_key_length = HMAC_SHA224_KEY_LEN, + /* "Jefe" */ + .auth_key = { 0x4a, 0x65, 0x66, 0x65 }, + .length = 28, + /* what do ya want for nothing?*/ + .plaintext = { 0x77, 0x68, 0x61, 0x74, 0x20, 0x64, 0x6f, 0x20, + 0x79, 0x61, 0x20, 0x77, 0x61, 0x6e, 0x74, 0x20, + 0x66, 0x6f, 0x72, 0x20, 0x6e, 0x6f, 0x74, 0x68, + 0x69, 0x6e, 0x67, 0x3f }, + .ciphertext = { 0x77, 0x68, 0x61, 0x74, 0x20, 0x64, 0x6f, 0x20, + 0x79, 0x61, 0x20, 0x77, 0x61, 0x6e, 0x74, 0x20, + 0x66, 0x6f, 0x72, 0x20, 0x6e, 0x6f, 0x74, 0x68, + 0x69, 0x6e, 0x67, 0x3f }, + .digest_length = HMAC_SHA224_CHECK_LEN, + .digest = { 0xa3, 0x0e, 0x01, 0x09, 0x8b, 0xc6, 0xdb, 0xbf, + 0x45, 0x69, 0x0f, 0x3a, 0x7e, 0x9e, 0x6d, 0x0f, + 0x8b, 0xbe, 0xa2, 0xa3, 0x9e, 0x61, 0x48, 0x00, + 0x8f, 0xd0, 0x5e, 0x44 } + }, + { + .auth_key_length = HMAC_SHA224_KEY_LEN, + .auth_key = { 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa }, + .length = 50, + .plaintext = { 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd }, + .ciphertext = { 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd }, + .digest_length = HMAC_SHA224_CHECK_LEN, + .digest = { 0x7f, 0xb3, 0xcb, 0x35, 0x88, 0xc6, 0xc1, 0xf6, + 0xff, 0xa9, 0x69, 0x4d, 0x7d, 0x6a, 0xd2, 0x64, + 0x93, 0x65, 0xb0, 0xc1, 0xf6, 0x5d, 0x69, 0xd1, + 0xec, 0x83, 0x33, 0xea } + } +}; + static crypto_test_reference_t hmac_sha256_reference[] = { { .auth_key_length = HMAC_SHA256_KEY_LEN, diff --git a/test/validation/api/crypto/test_vectors_len.h b/test/validation/api/crypto/test_vectors_len.h index d2e35b4d3..db6e5bc9f 100644 --- a/test/validation/api/crypto/test_vectors_len.h +++ b/test/validation/api/crypto/test_vectors_len.h @@ -43,16 +43,20 @@ #define HMAC_MD5_96_CHECK_LEN 12 #define HMAC_MD5_CHECK_LEN 16
-/* HMAC-SHA256 */ -#define HMAC_SHA256_KEY_LEN 32 -#define HMAC_SHA256_128_CHECK_LEN 16 -#define HMAC_SHA256_CHECK_LEN 32 - /* HMAC-SHA1 */ #define HMAC_SHA1_KEY_LEN 20 #define HMAC_SHA1_96_CHECK_LEN 12 #define HMAC_SHA1_CHECK_LEN 20
+/* HMAC-SHA224 */ +#define HMAC_SHA224_KEY_LEN 28 +#define HMAC_SHA224_CHECK_LEN 28 + +/* HMAC-SHA256 */ +#define HMAC_SHA256_KEY_LEN 32 +#define HMAC_SHA256_128_CHECK_LEN 16 +#define HMAC_SHA256_CHECK_LEN 32 + /* HMAC-SHA384 */ #define HMAC_SHA384_KEY_LEN 48 #define HMAC_SHA384_192_CHECK_LEN 24
commit 21bf585ca33eea0073c41f4d5115dcc8765bd122 Author: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Date: Sat Apr 6 14:52:54 2019 +0300
api: crypto: add HMAC-SHA224 algorithm support
Signed-off-by: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Reviewed-by: Petri Savolainen petri.savolainen@nokia.com
diff --git a/include/odp/api/spec/crypto.h b/include/odp/api/spec/crypto.h index 9e1191088..ec4711c01 100644 --- a/include/odp/api/spec/crypto.h +++ b/include/odp/api/spec/crypto.h @@ -157,6 +157,12 @@ typedef enum { */ ODP_AUTH_ALG_SHA1_HMAC,
+ /** HMAC-SHA-224 + * + * SHA-224 algorithm in HMAC mode + */ + ODP_AUTH_ALG_SHA224_HMAC, + /** HMAC-SHA-256 * * SHA-256 algorithm in HMAC mode @@ -338,6 +344,9 @@ typedef union odp_crypto_auth_algos_t { /** ODP_AUTH_ALG_SHA1_HMAC */ uint32_t sha1_hmac : 1;
+ /** ODP_AUTH_ALG_SHA224_HMAC */ + uint32_t sha224_hmac : 1; + /** ODP_AUTH_ALG_SHA256_HMAC */ uint32_t sha256_hmac : 1;
commit 2cb1bd572c9cc17f39742a46884a147ebf6f2302 Author: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Date: Sat Apr 6 14:50:57 2019 +0300
linux-gen: add 3DES-ECB algorithm support
Signed-off-by: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Reviewed-by: Petri Savolainen petri.savolainen@nokia.com
diff --git a/platform/linux-generic/odp_crypto_openssl.c b/platform/linux-generic/odp_crypto_openssl.c index b7cce4a39..25fa11a78 100644 --- a/platform/linux-generic/odp_crypto_openssl.c +++ b/platform/linux-generic/odp_crypto_openssl.c @@ -53,6 +53,9 @@ static const odp_crypto_cipher_capability_t cipher_capa_null[] = { static const odp_crypto_cipher_capability_t cipher_capa_trides_cbc[] = { {.key_len = 24, .iv_len = 8} };
+static const odp_crypto_cipher_capability_t cipher_capa_trides_ecb[] = { +{.key_len = 24} }; + static const odp_crypto_cipher_capability_t cipher_capa_aes_cbc[] = { {.key_len = 16, .iv_len = 16}, {.key_len = 24, .iv_len = 16}, @@ -1343,6 +1346,7 @@ int odp_crypto_capability(odp_crypto_capability_t *capa)
capa->ciphers.bit.null = 1; capa->ciphers.bit.trides_cbc = 1; + capa->ciphers.bit.trides_ecb = 1; capa->ciphers.bit.aes_cbc = 1; capa->ciphers.bit.aes_ctr = 1; capa->ciphers.bit.aes_gcm = 1; @@ -1396,6 +1400,10 @@ int odp_crypto_cipher_capability(odp_cipher_alg_t cipher, src = cipher_capa_trides_cbc; num = sizeof(cipher_capa_trides_cbc) / size; break; + case ODP_CIPHER_ALG_3DES_ECB: + src = cipher_capa_trides_ecb; + num = sizeof(cipher_capa_trides_ecb) / size; + break; case ODP_CIPHER_ALG_AES_CBC: src = cipher_capa_aes_cbc; num = sizeof(cipher_capa_aes_cbc) / size; @@ -1556,6 +1564,9 @@ odp_crypto_session_create(odp_crypto_session_param_t *param, case ODP_CIPHER_ALG_3DES_CBC: rc = process_cipher_param(session, EVP_des_ede3_cbc()); break; + case ODP_CIPHER_ALG_3DES_ECB: + rc = process_cipher_param(session, EVP_des_ede3_ecb()); + break; #if ODP_DEPRECATED_API case ODP_CIPHER_ALG_AES128_CBC: if (param->cipher_key.length == 16)
commit 067f57be454ce360fedb7501c51e5f1ef2824b7e Author: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Date: Sat Apr 6 14:52:19 2019 +0300
validation: crypto: add 3DES-ECB algorithm support
Signed-off-by: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Reviewed-by: Petri Savolainen petri.savolainen@nokia.com
diff --git a/test/validation/api/crypto/odp_crypto_test_inp.c b/test/validation/api/crypto/odp_crypto_test_inp.c index b2f599ec2..12dcd4518 100644 --- a/test/validation/api/crypto/odp_crypto_test_inp.c +++ b/test/validation/api/crypto/odp_crypto_test_inp.c @@ -82,6 +82,8 @@ static const char *cipher_alg_name(odp_cipher_alg_t cipher) return "ODP_CIPHER_ALG_DES"; case ODP_CIPHER_ALG_3DES_CBC: return "ODP_CIPHER_ALG_3DES_CBC"; + case ODP_CIPHER_ALG_3DES_ECB: + return "ODP_CIPHER_ALG_3DES_ECB"; case ODP_CIPHER_ALG_AES_CBC: return "ODP_CIPHER_ALG_AES_CBC"; case ODP_CIPHER_ALG_AES_CTR: @@ -507,6 +509,9 @@ static void check_alg(odp_crypto_op_t op, if (cipher_alg == ODP_CIPHER_ALG_3DES_CBC && !(capa.ciphers.bit.trides_cbc)) rc = -1; + if (cipher_alg == ODP_CIPHER_ALG_3DES_ECB && + !(capa.ciphers.bit.trides_ecb)) + rc = -1; if (cipher_alg == ODP_CIPHER_ALG_AES_CBC && !(capa.ciphers.bit.aes_cbc)) rc = -1; @@ -725,6 +730,10 @@ static int check_alg_support(odp_cipher_alg_t cipher, odp_auth_alg_t auth) if (!capability.ciphers.bit.trides_cbc) return ODP_TEST_INACTIVE; break; + case ODP_CIPHER_ALG_3DES_ECB: + if (!capability.ciphers.bit.trides_ecb) + return ODP_TEST_INACTIVE; + break; case ODP_CIPHER_ALG_AES_CBC: if (!capability.ciphers.bit.aes_cbc) return ODP_TEST_INACTIVE; @@ -926,6 +935,40 @@ static void crypto_test_dec_alg_3des_cbc_ovr_iv(void) false); }
+static int check_alg_3des_ecb(void) +{ + return check_alg_support(ODP_CIPHER_ALG_3DES_ECB, ODP_AUTH_ALG_NULL); +} + +/* This test verifies the correctness of encode (plaintext -> ciphertext) + * operation for 3DES_ECB algorithm. */ +static void crypto_test_enc_alg_3des_ecb(void) +{ + check_alg(ODP_CRYPTO_OP_ENCODE, + ODP_CIPHER_ALG_3DES_ECB, + ODP_AUTH_ALG_NULL, + tdes_ecb_reference, + ARRAY_SIZE(tdes_ecb_reference), + false, + false); +} + +/* This test verifies the correctness of decode (ciphertext -> plaintext) + * operation for 3DES_ECB algorithm. IV for the operation is the session IV + * In addition the test verifies if the implementation can use the + * packet buffer as completion event buffer. + * */ +static void crypto_test_dec_alg_3des_ecb(void) +{ + check_alg(ODP_CRYPTO_OP_DECODE, + ODP_CIPHER_ALG_3DES_ECB, + ODP_AUTH_ALG_NULL, + tdes_ecb_reference, + ARRAY_SIZE(tdes_ecb_reference), + false, + false); +} + static int check_alg_chacha20_poly1305(void) { return check_alg_support(ODP_CIPHER_ALG_CHACHA20_POLY1305, @@ -1864,6 +1907,10 @@ odp_testinfo_t crypto_suite[] = { check_alg_3des_cbc), ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_3des_cbc_ovr_iv, check_alg_3des_cbc), + ODP_TEST_INFO_CONDITIONAL(crypto_test_enc_alg_3des_ecb, + check_alg_3des_ecb), + ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_3des_ecb, + check_alg_3des_ecb), ODP_TEST_INFO_CONDITIONAL(crypto_test_enc_alg_aes_cbc, check_alg_aes_cbc), ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_aes_cbc, diff --git a/test/validation/api/crypto/test_vectors.h b/test/validation/api/crypto/test_vectors.h index 3e40d708f..ed0036ca1 100644 --- a/test/validation/api/crypto/test_vectors.h +++ b/test/validation/api/crypto/test_vectors.h @@ -72,6 +72,37 @@ static crypto_test_reference_t tdes_cbc_reference[] = { } };
+/* + * TDES-ECB reference vectors, according to + * CAVS 18.0 TECBMMT + */ +static crypto_test_reference_t tdes_ecb_reference[] = { + /* CAVS 18.0 TECBMMT2.rsp #0 */ + { + .cipher_key_length = TDES_ECB_KEY_LEN, + .cipher_key = { 0x15, 0x1f, 0x10, 0x38, 0x3d, 0x6d, 0x19, 0x9b, + 0x4a, 0x76, 0x3b, 0xd5, 0x4a, 0x46, 0xa4, 0x45, + 0x15, 0x1f, 0x10, 0x38, 0x3d, 0x6d, 0x19, 0x9b}, + .length = 8, + .plaintext = { 0xd8, 0xda, 0x89, 0x29, 0x88, 0x78, 0xed, 0x7d }, + .ciphertext = { 0x89, 0x32, 0x1b, 0xa7, 0x5b, 0xa5, 0x45, 0xdb } + }, + /* CAVS 18.0 TECBMMT2.rsp #2 */ + { + .cipher_key_length = TDES_ECB_KEY_LEN, + .cipher_key = { 0xcd, 0x3d, 0x9b, 0xf7, 0x2f, 0x8c, 0x8a, 0xb5, + 0xfe, 0xe6, 0x73, 0x34, 0x31, 0x1c, 0xa4, 0x62, + 0xcd, 0x3d, 0x9b, 0xf7, 0x2f, 0x8c, 0x8a, 0xb5}, + .length = 24, + .plaintext = { 0x2f, 0x2a, 0x36, 0x1c, 0x8e, 0x14, 0x5d, 0xc0, + 0xa7, 0x4a, 0x1b, 0xdb, 0x7c, 0xa9, 0x29, 0xc3, + 0x38, 0x14, 0x4d, 0x89, 0x13, 0x5b, 0x50, 0xa7 }, + .ciphertext = { 0x7f, 0x1f, 0xd3, 0x2b, 0x36, 0x90, 0x05, 0x4b, + 0xfa, 0x1b, 0x17, 0x35, 0x15, 0x79, 0x33, 0x80, + 0x99, 0xff, 0xa8, 0x4f, 0xea, 0x16, 0x8c, 0x6b } + } +}; + static crypto_test_reference_t aes_cbc_reference[] = { { .cipher_key_length = AES128_KEY_LEN, diff --git a/test/validation/api/crypto/test_vectors_len.h b/test/validation/api/crypto/test_vectors_len.h index 3418ef279..d2e35b4d3 100644 --- a/test/validation/api/crypto/test_vectors_len.h +++ b/test/validation/api/crypto/test_vectors_len.h @@ -17,6 +17,9 @@ #define TDES_CBC_KEY_LEN 24 #define TDES_CBC_IV_LEN 8
+/* TDES-ECB */ +#define TDES_ECB_KEY_LEN 24 + /* AES common */
#define AES128_KEY_LEN 16
commit 379bbf144141d41ee31df11d8a8d3a0758c1db06 Author: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Date: Sat Apr 6 14:50:15 2019 +0300
api: add 3DES-ECB algorithm support
Signed-off-by: Dmitry Eremin-Solenikov deremin-solenikov@cavium.com Reviewed-by: Petri Savolainen petri.savolainen@nokia.com
diff --git a/include/odp/api/spec/crypto.h b/include/odp/api/spec/crypto.h index c57873abe..9e1191088 100644 --- a/include/odp/api/spec/crypto.h +++ b/include/odp/api/spec/crypto.h @@ -76,6 +76,9 @@ typedef enum { /** Triple DES with cipher block chaining */ ODP_CIPHER_ALG_3DES_CBC,
+ /** Triple DES with Electronic Codebook */ + ODP_CIPHER_ALG_3DES_ECB, + /** AES with cipher block chaining */ ODP_CIPHER_ALG_AES_CBC,
@@ -278,6 +281,9 @@ typedef union odp_crypto_cipher_algos_t { /** ODP_CIPHER_ALG_3DES_CBC */ uint32_t trides_cbc : 1;
+ /** ODP_CIPHER_ALG_3DES_ECB */ + uint32_t trides_ecb : 1; + /** ODP_CIPHER_ALG_AES_CBC */ uint32_t aes_cbc : 1;
-----------------------------------------------------------------------
Summary of changes: configure.ac | 2 +- include/odp/api/spec/crypto.h | 126 ++- platform/linux-generic/odp_crypto_openssl.c | 644 +++++++++++- test/validation/api/crypto/odp_crypto_test_inp.c | 675 ++++++++++++ test/validation/api/crypto/test_vectors.h | 1225 ++++++++++++++++++++++ test/validation/api/crypto/test_vectors_len.h | 54 +- 6 files changed, 2717 insertions(+), 9 deletions(-)
hooks/post-receive