From patchwork Sat Jul 1 09:00:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 106799 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp3284259qge; Sat, 1 Jul 2017 02:11:09 -0700 (PDT) X-Received: by 10.237.45.3 with SMTP id h3mr30127682qtd.110.1498900269755; Sat, 01 Jul 2017 02:11:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1498900269; cv=none; d=google.com; s=arc-20160816; b=E9RB7NIz0mh6UJi2nCxkAcbMJbCXqJJHtT3VR1+plLuRJetUTq/ro7eCBAl9uiuLSC ZGq651N8kJIKf3cv1Rg+cmM1PN0/XJ9zxGiDJkdHy3Wtc4M80J5YpWf/DjioeqUq4v1B 63rAt9Qmdo3LZ0zCU09ci+zySN1XisirpKa2YF3CB8H8e8CPv4k+O3TXXL7KGeJy4BLK 6CHQG7P+meXI159cl4vijCdHJDwpyf4ULmknjs4tarXTpgB5qNKK7/VIuJVIqxskMZi0 a19mRaffoFpgghvLevxhTqdXsZHPlXxQPJKQxUawsZ1ziYyNYA4TRzmnPVgKX/Uy9w2Q lFqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=Stf1ReX6SDdtH0wwIvqKmmAFfNWMIny8UTAcE52uwZk=; b=gKS8vTe3Ysb55zxxTPfPl96PA6ifnTmMp4MF0T+fVOmZTniyTZzYc74DyLQznhGj8a 2HRcgNmXhJTdc4bSLVQGXXyj1DQ20TBQ+ak0SYpB87HXv5v84nn5fbgn7exn2gw5gW06 JEbSII9z+4DAj9r3//sjZu22tHKNY05uKqpw9hptaD+aBzkgpKLB2OjF5HRDQW/s2Bd5 f/tNqZTU2QyvmfLfmZv7Uu5v9YLWI1lP7qZnUJ0Ny2SnrBcBj/TVT+0fxajEqUweAQjH 1EdktWQWLsTKWGLXlYiYbEKCvN1n1D9zH2OcMvh8fEBBm0InsT3iE6ku2rpxtvZoaWBQ V4aA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id i57si9817286qta.55.2017.07.01.02.11.09; Sat, 01 Jul 2017 02:11:09 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id 72DE162B5D; Sat, 1 Jul 2017 09:11:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 3068262DA3; Sat, 1 Jul 2017 09:02:14 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id F2F2E62D29; Sat, 1 Jul 2017 09:02:04 +0000 (UTC) Received: from forward3p.cmail.yandex.net (forward3p.cmail.yandex.net [77.88.31.18]) by lists.linaro.org (Postfix) with ESMTPS id BE47A6067F for ; Sat, 1 Jul 2017 09:00:41 +0000 (UTC) Received: from smtp4o.mail.yandex.net (smtp4o.mail.yandex.net [37.140.190.29]) by forward3p.cmail.yandex.net (Yandex) with ESMTP id B8BC820733 for ; Sat, 1 Jul 2017 12:00:40 +0300 (MSK) Received: from smtp4o.mail.yandex.net (localhost.localdomain [127.0.0.1]) by smtp4o.mail.yandex.net (Yandex) with ESMTP id 6F3936C01096 for ; Sat, 1 Jul 2017 12:00:39 +0300 (MSK) Received: by smtp4o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id XD0Z6RfmK2-0c0G1001; Sat, 01 Jul 2017 12:00:38 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) X-Yandex-Suid-Status: 1 0 From: Github ODP bot To: lng-odp@lists.linaro.org Date: Sat, 1 Jul 2017 12:00:19 +0300 Message-Id: <1498899622-7167-8-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1498899622-7167-1-git-send-email-odpbot@yandex.ru> References: <1498899622-7167-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 64 Subject: [lng-odp] [PATCH API-NEXT v4 7/10] validation: crypto: tests for Crypto packet API X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Dmitry Eremin-Solenikov Signed-off-by: Dmitry Eremin-Solenikov --- /** Email created from pull request 64 (lumag:crypto-packet) ** https://github.com/Linaro/odp/pull/64 ** Patch: https://github.com/Linaro/odp/pull/64.patch ** Base sha: 7a5813042d58598e1c66243d8cfed548302edfc4 ** Merge commit sha: 146b16d49677b9566cc5728feee6ff96f0cefd37 **/ test/common_plat/validation/api/crypto/crypto.c | 8 +- .../validation/api/crypto/odp_crypto_test_inp.c | 309 +++++++++++++++++---- .../validation/api/crypto/odp_crypto_test_inp.h | 6 +- 3 files changed, 271 insertions(+), 52 deletions(-) diff --git a/test/common_plat/validation/api/crypto/crypto.c b/test/common_plat/validation/api/crypto/crypto.c index fde95ab7..8a6c20ec 100644 --- a/test/common_plat/validation/api/crypto/crypto.c +++ b/test/common_plat/validation/api/crypto/crypto.c @@ -13,8 +13,12 @@ #define PKT_POOL_LEN (1 * 1024) odp_suiteinfo_t crypto_suites[] = { - {ODP_CRYPTO_SYNC_INP, crypto_suite_sync_init, crypto_suite_term, - crypto_suite}, + {ODP_CRYPTO_SYNC_INP, crypto_suite_sync_init, + crypto_suite_term, crypto_suite}, + {ODP_CRYPTO_PACKET_SYNC_INP, crypto_suite_packet_sync_init, + crypto_suite_term, crypto_suite}, + {ODP_CRYPTO_PACKET_ASYNC_INP, crypto_suite_packet_async_init, + crypto_suite_term, crypto_suite}, ODP_SUITE_INFO_NULL, }; diff --git a/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c b/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c index d42ecb68..60c2b690 100644 --- a/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c +++ b/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c @@ -14,6 +14,8 @@ #define MAX_ALG_CAPA 32 struct suite_context_s { + odp_bool_t packet; + odp_crypto_op_mode_t packet_op_mode; odp_pool_t pool; odp_queue_t queue; }; @@ -58,6 +60,217 @@ static const char *cipher_alg_name(odp_cipher_alg_t cipher) } } +static int alg_op(odp_packet_t pkt, + odp_bool_t *ok, + odp_crypto_session_t session, + uint8_t *op_iv_ptr, + odp_packet_data_range_t *cipher_range, + odp_packet_data_range_t *auth_range, + uint8_t *aad, + uint32_t aad_len, + unsigned int plaintext_len) +{ + int data_off = 0, rc; + odp_crypto_op_result_t result; + odp_crypto_op_param_t op_params; + odp_bool_t posted; + odp_event_subtype_t subtype; + + /* Prepare input/output params */ + memset(&op_params, 0, sizeof(op_params)); + op_params.session = session; + op_params.pkt = pkt; + op_params.out_pkt = pkt; + + if (cipher_range) { + op_params.cipher_range = *cipher_range; + data_off = cipher_range->offset; + } else { + op_params.cipher_range.offset = data_off; + op_params.cipher_range.length = plaintext_len; + } + if (auth_range) { + op_params.auth_range = *auth_range; + } else { + op_params.auth_range.offset = data_off; + op_params.auth_range.length = plaintext_len; + } + if (op_iv_ptr) + op_params.override_iv_ptr = op_iv_ptr; + + op_params.aad.ptr = aad; + op_params.aad.length = aad_len; + + op_params.hash_result_offset = plaintext_len; + + rc = odp_crypto_operation(&op_params, &posted, &result); + if (rc < 0) { + CU_FAIL("Failed odp_crypto_operation()"); + return rc; + } + + CU_ASSERT(posted == 0); + CU_ASSERT(result.pkt == pkt); + CU_ASSERT(ODP_EVENT_PACKET == + odp_event_type(odp_packet_to_event(result.pkt))); + CU_ASSERT(ODP_EVENT_PACKET_BASIC == + odp_event_subtype(odp_packet_to_event(result.pkt))); + CU_ASSERT(ODP_EVENT_PACKET == + odp_event_types(odp_packet_to_event(result.pkt), &subtype)); + CU_ASSERT(ODP_EVENT_PACKET_BASIC == subtype); + + *ok = result.ok; + + return 0; +} + +static int alg_packet_op(odp_packet_t pkt, + odp_bool_t *ok, + odp_crypto_session_t session, + uint8_t *op_iv_ptr, + odp_packet_data_range_t *cipher_range, + odp_packet_data_range_t *auth_range, + uint8_t *aad, + uint32_t aad_len, + unsigned int plaintext_len) +{ + int data_off = 0, rc; + odp_crypto_packet_op_result_t result; + odp_crypto_packet_op_param_t op_params; + odp_event_subtype_t subtype; + odp_packet_t out_pkt = pkt; + + /* Prepare input/output params */ + memset(&op_params, 0, sizeof(op_params)); + op_params.session = session; + + if (cipher_range) { + op_params.cipher_range = *cipher_range; + data_off = cipher_range->offset; + } else { + op_params.cipher_range.offset = data_off; + op_params.cipher_range.length = plaintext_len; + } + if (auth_range) { + op_params.auth_range = *auth_range; + } else { + op_params.auth_range.offset = data_off; + op_params.auth_range.length = plaintext_len; + } + if (op_iv_ptr) + op_params.override_iv_ptr = op_iv_ptr; + + op_params.aad.ptr = aad; + op_params.aad.length = aad_len; + + op_params.hash_result_offset = plaintext_len; + + rc = odp_crypto_packet_op(&pkt, &out_pkt, &op_params, 1); + if (rc < 0) { + CU_FAIL("Failed odp_crypto_packet_op()"); + return rc; + } + + CU_ASSERT(out_pkt == pkt); + CU_ASSERT(ODP_EVENT_PACKET == + odp_event_type(odp_packet_to_event(pkt))); + CU_ASSERT(ODP_EVENT_PACKET_CRYPTO == + odp_event_subtype(odp_packet_to_event(pkt))); + CU_ASSERT(ODP_EVENT_PACKET == + odp_event_types(odp_packet_to_event(pkt), &subtype)); + CU_ASSERT(ODP_EVENT_PACKET_CRYPTO == subtype); + + rc = odp_crypto_packet_result(&result, pkt); + if (rc < 0) { + CU_FAIL("Failed odp_crypto_packet_result()"); + return rc; + } + + *ok = result.ok; + + return 0; +} + +static int alg_packet_op_enq(odp_packet_t pkt, + odp_bool_t *ok, + odp_crypto_session_t session, + uint8_t *op_iv_ptr, + odp_packet_data_range_t *cipher_range, + odp_packet_data_range_t *auth_range, + uint8_t *aad, + uint32_t aad_len, + unsigned int plaintext_len) +{ + int data_off = 0, rc; + odp_event_t event; + odp_crypto_packet_op_result_t result; + odp_crypto_packet_op_param_t op_params; + odp_event_subtype_t subtype; + odp_packet_t out_pkt = pkt; + + /* Prepare input/output params */ + memset(&op_params, 0, sizeof(op_params)); + op_params.session = session; + + if (cipher_range) { + op_params.cipher_range = *cipher_range; + data_off = cipher_range->offset; + } else { + op_params.cipher_range.offset = data_off; + op_params.cipher_range.length = plaintext_len; + } + if (auth_range) { + op_params.auth_range = *auth_range; + } else { + op_params.auth_range.offset = data_off; + op_params.auth_range.length = plaintext_len; + } + if (op_iv_ptr) + op_params.override_iv_ptr = op_iv_ptr; + + op_params.aad.ptr = aad; + op_params.aad.length = aad_len; + + op_params.hash_result_offset = plaintext_len; + + rc = odp_crypto_packet_op_enq(&pkt, &pkt, &op_params, 1); + if (rc < 0) { + CU_FAIL("Failed odp_crypto_op_enq()"); + return rc; + } + + /* Poll completion queue for results */ + do { + event = odp_queue_deq(suite_context.queue); + } while (event == ODP_EVENT_INVALID); + + CU_ASSERT(ODP_EVENT_PACKET == odp_event_type(event)); + CU_ASSERT(ODP_EVENT_PACKET_CRYPTO == odp_event_subtype(event)); + CU_ASSERT(ODP_EVENT_PACKET == odp_event_types(event, &subtype)); + CU_ASSERT(ODP_EVENT_PACKET_CRYPTO == subtype); + + pkt = odp_crypto_packet_from_event(event); + + CU_ASSERT(out_pkt == pkt); + CU_ASSERT(ODP_EVENT_PACKET == + odp_event_type(odp_packet_to_event(pkt))); + CU_ASSERT(ODP_EVENT_PACKET_CRYPTO == + odp_event_subtype(odp_packet_to_event(pkt))); + CU_ASSERT(ODP_EVENT_PACKET == + odp_event_types(odp_packet_to_event(pkt), &subtype)); + CU_ASSERT(ODP_EVENT_PACKET_CRYPTO == subtype); + + rc = odp_crypto_packet_result(&result, pkt); + if (rc < 0) { + CU_FAIL("Failed odp_crypto_packet_result()"); + return rc; + } + + *ok = result.ok; + + return 0; +} + /* Basic algorithm run function for async inplace mode. * Creates a session from input parameters and runs one operation * on input_vec. Checks the output of the crypto operation against @@ -90,17 +303,13 @@ static void alg_test(odp_crypto_op_t op, odp_crypto_capability_t capa; int rc; odp_crypto_ses_create_err_t status; - odp_bool_t posted; - odp_crypto_op_result_t result; + odp_bool_t ok; odp_crypto_session_param_t ses_params; - odp_crypto_op_param_t op_params; uint8_t *data_addr; - int data_off; odp_crypto_cipher_capability_t cipher_capa[MAX_ALG_CAPA]; odp_crypto_auth_capability_t auth_capa[MAX_ALG_CAPA]; int num, i; int found; - odp_event_subtype_t subtype; rc = odp_crypto_capability(&capa); CU_ASSERT(!rc); @@ -193,6 +402,7 @@ static void alg_test(odp_crypto_op_t op, odp_crypto_session_param_init(&ses_params); ses_params.op = op; ses_params.auth_cipher_text = false; + ses_params.packet_op_mode = suite_context.packet_op_mode; ses_params.cipher_alg = cipher_alg; ses_params.auth_alg = auth_alg; ses_params.compl_queue = suite_context.queue; @@ -214,67 +424,40 @@ static void alg_test(odp_crypto_op_t op, CU_ASSERT(pkt != ODP_PACKET_INVALID); data_addr = odp_packet_data(pkt); memcpy(data_addr, plaintext, plaintext_len); - data_off = 0; - - /* Prepare input/output params */ - memset(&op_params, 0, sizeof(op_params)); - op_params.session = session; - op_params.pkt = pkt; - op_params.out_pkt = pkt; - - if (cipher_range) { - op_params.cipher_range = *cipher_range; - data_off = cipher_range->offset; - } else { - op_params.cipher_range.offset = data_off; - op_params.cipher_range.length = plaintext_len; - } - if (auth_range) { - op_params.auth_range = *auth_range; - } else { - op_params.auth_range.offset = data_off; - op_params.auth_range.length = plaintext_len; - } - if (op_iv_ptr) - op_params.override_iv_ptr = op_iv_ptr; - - op_params.aad.ptr = aad; - op_params.aad.length = aad_len; - - op_params.hash_result_offset = plaintext_len; if (0 != digest_len) { - memcpy(data_addr + op_params.hash_result_offset, + memcpy(data_addr + plaintext_len, digest, digest_len); } - rc = odp_crypto_operation(&op_params, &posted, &result); + if (!suite_context.packet) + rc = alg_op(pkt, &ok, session, op_iv_ptr, + cipher_range, auth_range, aad, aad_len, + plaintext_len); + else if (ODP_CRYPTO_ASYNC == suite_context.packet_op_mode) + rc = alg_packet_op_enq(pkt, &ok, session, op_iv_ptr, + cipher_range, auth_range, aad, aad_len, + plaintext_len); + else + rc = alg_packet_op(pkt, &ok, session, op_iv_ptr, + cipher_range, auth_range, aad, aad_len, + plaintext_len); if (rc < 0) { - CU_FAIL("Failed odp_crypto_operation()"); goto cleanup; } - CU_ASSERT(posted == 0); - CU_ASSERT(result.pkt == pkt); - CU_ASSERT(ODP_EVENT_PACKET == - odp_event_type(odp_packet_to_event(result.pkt))); - CU_ASSERT(ODP_EVENT_PACKET_BASIC == - odp_event_subtype(odp_packet_to_event(result.pkt))); - CU_ASSERT(ODP_EVENT_PACKET == - odp_event_types(odp_packet_to_event(result.pkt), &subtype)); - CU_ASSERT(ODP_EVENT_PACKET_BASIC == subtype); - if (should_fail) { - CU_ASSERT(!result.ok); + CU_ASSERT(!ok); goto cleanup; } - CU_ASSERT(result.ok); + CU_ASSERT(ok); + data_addr = odp_packet_data(pkt); if (cipher_alg != ODP_CIPHER_ALG_NULL) CU_ASSERT(!memcmp(data_addr, ciphertext, ciphertext_len)); if (op == ODP_CRYPTO_OP_ENCODE && auth_alg != ODP_AUTH_ALG_NULL) - CU_ASSERT(!memcmp(data_addr + op_params.hash_result_offset, + CU_ASSERT(!memcmp(data_addr + plaintext_len, digest, digest_len)); cleanup: rc = odp_crypto_session_destroy(session); @@ -1498,6 +1681,34 @@ int crypto_suite_sync_init(void) return 0; } +int crypto_suite_packet_sync_init(void) +{ + suite_context.packet = true; + suite_context.packet_op_mode = ODP_CRYPTO_SYNC; + + suite_context.pool = odp_pool_lookup("packet_pool"); + if (suite_context.pool == ODP_POOL_INVALID) + return -1; + + suite_context.queue = ODP_QUEUE_INVALID; + return 0; +} + +int crypto_suite_packet_async_init(void) +{ + suite_context.packet = true; + suite_context.packet_op_mode = ODP_CRYPTO_ASYNC; + + suite_context.pool = odp_pool_lookup("packet_pool"); + if (suite_context.pool == ODP_POOL_INVALID) + return -1; + + suite_context.queue = odp_queue_lookup("crypto-out"); + if (suite_context.queue == ODP_QUEUE_INVALID) + return -1; + return 0; +} + odp_testinfo_t crypto_suite[] = { ODP_TEST_INFO_CONDITIONAL(crypto_test_enc_alg_null, check_alg_null), diff --git a/test/common_plat/validation/api/crypto/odp_crypto_test_inp.h b/test/common_plat/validation/api/crypto/odp_crypto_test_inp.h index 86ecce8e..2bc77a94 100644 --- a/test/common_plat/validation/api/crypto/odp_crypto_test_inp.h +++ b/test/common_plat/validation/api/crypto/odp_crypto_test_inp.h @@ -9,12 +9,16 @@ #include /* Suite names */ -#define ODP_CRYPTO_SYNC_INP "odp_crypto_sync_inp" +#define ODP_CRYPTO_SYNC_INP "odp_crypto_sync_inp" +#define ODP_CRYPTO_PACKET_SYNC_INP "odp_crypto_packet_sync_inp" +#define ODP_CRYPTO_PACKET_ASYNC_INP "odp_crypto_packet_async_inp" /* Suite test array */ extern odp_testinfo_t crypto_suite[]; int crypto_suite_sync_init(void); +int crypto_suite_packet_sync_init(void); +int crypto_suite_packet_async_init(void); int crypto_suite_term(void); #endif