From patchwork Tue May 30 15:00:14 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: 100715 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp256827qge; Tue, 30 May 2017 08:01:13 -0700 (PDT) X-Received: by 10.36.111.139 with SMTP id x133mr2448417itb.25.1496156473477; Tue, 30 May 2017 08:01:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496156473; cv=none; d=google.com; s=arc-20160816; b=vrFEIWl8KYuYLqNijtaBCwcN60pIoDkuZi4rIk74W5r7au/bHU4a60YiMz4NcF9Wk5 BN16thOe7dhcgT8XCgSB6HOOPS1/CfHnhrVjJ/n4ZghNbcEJLxQqju9Bl+imRVSDCESU xol6E43dE3HPcUeuIeyoENbiXr15FShzys57XE9CCVvzsY41wMfHx8rdzmRLiWJVrNf/ ZkVXzJcuc6bl1Bvd0U9lWFMmduBQH1Al9ZLFsnzUXcICzr4R5tPMIVOLhkIOGeaFf71G /Jm4Npa3+7x2wtj6eMzADpbHkP3WOmwSFZ2CWwZc7MUYA3AdP3VgO1RD1DgrAeNiy9qf 8Izw== 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=TWIUIUJVbOZXkoDnTi4drQ/ld6I7/IRE1vzqZrySR8I=; b=xaN3lTBzuqIvMezGGIOU2xtx1CZFZZOLRQaTc7TLYwoif51xXdYibCOAvDCzSG02TG j+fmdPmPN5W7eDrcTX6kX0htf578X6Q+H8aVceHkG7AmQ4RU2KLt3IqJl6G091kWdneo pKWlsSJxnaExDUMdMMoqufu4LfPth+rGl3Uvdsu38Tyz3TbdReV+OLjtm7dwj+9tND4F VWLCFVyKV3NmCRrMkoSLGfv03RgNCPOr78REaiyslUFUAvgKnx1nMDV5XHKasuCfER3S nZs3YYHFvcLRObiD5QlYXm5C84YHXjiSk5z8BBJhOU9iwfW7L6wrpGmNiSlKJsW7Bw3n FcEg== 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 i199si12160896ioi.249.2017.05.30.08.01.13; Tue, 30 May 2017 08:01:13 -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 E980F60641; Tue, 30 May 2017 15:01:12 +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 86D2160B51; Tue, 30 May 2017 15:00:41 +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 23FD760B54; Tue, 30 May 2017 15:00:37 +0000 (UTC) Received: from forward4o.cmail.yandex.net (forward4o.cmail.yandex.net [37.9.109.248]) by lists.linaro.org (Postfix) with ESMTPS id 283CB607CD for ; Tue, 30 May 2017 15:00:34 +0000 (UTC) Received: from smtp1h.mail.yandex.net (smtp1h.mail.yandex.net [IPv6:2a02:6b8:0:f05::115]) by forward4o.cmail.yandex.net (Yandex) with ESMTP id 5B6442112A for ; Tue, 30 May 2017 18:00:32 +0300 (MSK) Received: from smtp1h.mail.yandex.net (localhost.localdomain [127.0.0.1]) by smtp1h.mail.yandex.net (Yandex) with ESMTP id 6745E8C0F8C for ; Tue, 30 May 2017 18:00:24 +0300 (MSK) Received: by smtp1h.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id ZQjkrMiaVl-0NBmn6Lx; Tue, 30 May 2017 18:00:23 +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: Tue, 30 May 2017 18:00:14 +0300 Message-Id: <1496156414-29557-2-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1496156414-29557-1-git-send-email-odpbot@yandex.ru> References: <1496156414-29557-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 37 Subject: [lng-odp] [PATCH API-NEXT v5 1/1] api: crypto: add odp_crypto_session_create2 returning odp_crypto_session_t 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 Currently odp_crypto_session_create() (unlike other creation functions) returns int result with session being returned through pointer argument. Replace it with odp_crypto_session_create2 directly returning a session (or ODP_CRYPTO_SESSION_INVALID in case of an error). Signed-off-by: Dmitry Eremin-Solenikov --- /** Email created from pull request 37 (lumag:crypto-create-ret) ** https://github.com/Linaro/odp/pull/37 ** Patch: https://github.com/Linaro/odp/pull/37.patch ** Base sha: 552817483e9d4b6a84d49960920f1de50029f111 ** Merge commit sha: 6f929f89f7e0ffd3726e5f2f799496b8112fa574 **/ example/ipsec/odp_ipsec_cache.c | 4 +- include/odp/api/spec/crypto.h | 27 +++++++-- platform/linux-generic/odp_crypto.c | 18 +++--- test/common_plat/performance/odp_crypto.c | 68 +++++++++++----------- .../validation/api/crypto/odp_crypto_test_inp.c | 6 +- 5 files changed, 69 insertions(+), 54 deletions(-) diff --git a/example/ipsec/odp_ipsec_cache.c b/example/ipsec/odp_ipsec_cache.c index b2a91c24..8bb36076 100644 --- a/example/ipsec/odp_ipsec_cache.c +++ b/example/ipsec/odp_ipsec_cache.c @@ -114,8 +114,8 @@ int create_ipsec_cache_entry(sa_db_entry_t *cipher_sa, return -1; } - /* Synchronous session create for now */ - if (odp_crypto_session_create(¶ms, &session, &ses_create_rc)) + session = odp_crypto_session_create2(¶ms, &ses_create_rc); + if (ODP_CRYPTO_SESSION_INVALID == session) return -1; if (ODP_CRYPTO_SES_CREATE_ERR_NONE != ses_create_rc) return -1; diff --git a/include/odp/api/spec/crypto.h b/include/odp/api/spec/crypto.h index c47d3149..d4ea17ff 100644 --- a/include/odp/api/spec/crypto.h +++ b/include/odp/api/spec/crypto.h @@ -585,15 +585,34 @@ int odp_crypto_auth_capability(odp_auth_alg_t auth, * default values. * * @param param Session parameters - * @param session Created session else ODP_CRYPTO_SESSION_INVALID * @param status Failure code if unsuccessful * - * @retval 0 on success - * @retval <0 on failure + * @retval created session on success + * @retval ODP_CRYPTO_SESSION_INVALID on failure */ +odp_crypto_session_t odp_crypto_session_create2(odp_crypto_session_param_t + *param, + odp_crypto_ses_create_err_t + *status); + +#if ODP_DEPRECATED_API +static inline int odp_crypto_session_create(odp_crypto_session_param_t *param, odp_crypto_session_t *session, - odp_crypto_ses_create_err_t *status); + odp_crypto_ses_create_err_t *status) +{ + odp_crypto_session_t sess; + + sess = odp_crypto_session_create2(param, status); + + if (ODP_CRYPTO_SESSION_INVALID == sess) + return -1; + + *session = sess; + + return 0; +} +#endif /** * Crypto session destroy diff --git a/platform/linux-generic/odp_crypto.c b/platform/linux-generic/odp_crypto.c index a993542f..b5f75000 100644 --- a/platform/linux-generic/odp_crypto.c +++ b/platform/linux-generic/odp_crypto.c @@ -656,10 +656,9 @@ int odp_crypto_auth_capability(odp_auth_alg_t auth, return num; } -int -odp_crypto_session_create(odp_crypto_session_param_t *param, - odp_crypto_session_t *session_out, - odp_crypto_ses_create_err_t *status) +odp_crypto_session_t +odp_crypto_session_create2(odp_crypto_session_param_t *param, + odp_crypto_ses_create_err_t *status) { int rc; odp_crypto_generic_session_t *session; @@ -672,7 +671,7 @@ odp_crypto_session_create(odp_crypto_session_param_t *param, session = alloc_session(); if (NULL == session) { *status = ODP_CRYPTO_SES_CREATE_ERR_ENOMEM; - return -1; + return ODP_CRYPTO_SESSION_INVALID; } /* Copy parameters */ @@ -683,7 +682,7 @@ odp_crypto_session_create(odp_crypto_session_param_t *param, if (session->p.iv.length > MAX_IV_LEN) { ODP_DBG("Maximum IV length exceeded\n"); free_session(session); - return -1; + return ODP_CRYPTO_SESSION_INVALID; } memcpy(session->cipher.iv_data, session->p.iv.data, @@ -734,7 +733,7 @@ odp_crypto_session_create(odp_crypto_session_param_t *param, if (rc) { *status = ODP_CRYPTO_SES_CREATE_ERR_INV_CIPHER; free_session(session); - return -1; + return ODP_CRYPTO_SESSION_INVALID; } aes_gcm = 0; @@ -781,12 +780,11 @@ odp_crypto_session_create(odp_crypto_session_param_t *param, if (rc) { *status = ODP_CRYPTO_SES_CREATE_ERR_INV_AUTH; free_session(session); - return -1; + return ODP_CRYPTO_SESSION_INVALID; } /* We're happy */ - *session_out = (intptr_t)session; - return 0; + return (odp_crypto_session_t)(intptr_t)session; } int odp_crypto_session_destroy(odp_crypto_session_t session) diff --git a/test/common_plat/performance/odp_crypto.c b/test/common_plat/performance/odp_crypto.c index b3857973..f976523c 100644 --- a/test/common_plat/performance/odp_crypto.c +++ b/test/common_plat/performance/odp_crypto.c @@ -415,13 +415,13 @@ print_mem(const char *msg, /** * Create ODP crypto session for given config. */ -static int -create_session_from_config(odp_crypto_session_t *session, - crypto_alg_config_t *config, +static odp_crypto_session_t +create_session_from_config(crypto_alg_config_t *config, crypto_args_t *cargs) { odp_crypto_session_param_t params; odp_crypto_ses_create_err_t ses_create_rc; + odp_crypto_session_t session; odp_pool_t pkt_pool; odp_queue_t out_queue; @@ -434,7 +434,7 @@ create_session_from_config(odp_crypto_session_t *session, pkt_pool = odp_pool_lookup("packet_pool"); if (pkt_pool == ODP_POOL_INVALID) { app_err("packet_pool pool not found\n"); - return -1; + return ODP_CRYPTO_SESSION_INVALID; } params.output_pool = pkt_pool; @@ -442,20 +442,21 @@ create_session_from_config(odp_crypto_session_t *session, out_queue = odp_queue_lookup("crypto-out"); if (out_queue == ODP_QUEUE_INVALID) { app_err("crypto-out queue not found\n"); - return -1; + return ODP_CRYPTO_SESSION_INVALID; } params.compl_queue = out_queue; } else { params.compl_queue = ODP_QUEUE_INVALID; } - if (odp_crypto_session_create(¶ms, session, - &ses_create_rc)) { + + session = odp_crypto_session_create2(¶ms, + &ses_create_rc); + + if (session == ODP_CRYPTO_SESSION_INVALID) app_err("crypto session create failed.\n"); - return -1; - } - return 0; + return session; } /** @@ -664,35 +665,34 @@ run_measure_one_config(crypto_args_t *cargs, odp_crypto_session_t session; int rc = 0; - if (create_session_from_config(&session, config, cargs)) - rc = -1; - - if (!rc) { - if (cargs->payload_length) { - rc = run_measure_one(cargs, config, &session, - cargs->payload_length, &result); - if (!rc) { - print_result_header(); - print_result(cargs, cargs->payload_length, - config, &result); - } - } else { - unsigned i; + session = create_session_from_config(config, cargs); + if (session == ODP_CRYPTO_SESSION_INVALID) + return -1; + if (cargs->payload_length) { + rc = run_measure_one(cargs, config, &session, + cargs->payload_length, &result); + if (!rc) { print_result_header(); - for (i = 0; i < num_payloads; i++) { - rc = run_measure_one(cargs, config, &session, - payloads[i], &result); - if (rc) - break; - print_result(cargs, payloads[i], - config, &result); - } + print_result(cargs, cargs->payload_length, + config, &result); + } + } else { + unsigned i; + + print_result_header(); + for (i = 0; i < num_payloads; i++) { + rc = run_measure_one(cargs, config, &session, + payloads[i], &result); + if (rc) + break; + print_result(cargs, payloads[i], + config, &result); } } - if (session != ODP_CRYPTO_SESSION_INVALID) - odp_crypto_session_destroy(session); + odp_crypto_session_destroy(session); + return rc; } 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 bfc9da3c..be819a5b 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 @@ -202,11 +202,9 @@ static void alg_test(odp_crypto_op_t op, ses_params.iv = ses_iv; ses_params.auth_key = auth_key; - rc = odp_crypto_session_create(&ses_params, &session, &status); - CU_ASSERT_FATAL(!rc); + session = odp_crypto_session_create2(&ses_params, &status); + CU_ASSERT_FATAL(session != ODP_CRYPTO_SESSION_INVALID); CU_ASSERT(status == ODP_CRYPTO_SES_CREATE_ERR_NONE); - CU_ASSERT(odp_crypto_session_to_u64(session) != - odp_crypto_session_to_u64(ODP_CRYPTO_SESSION_INVALID)); /* Prepare input data */ odp_packet_t pkt = odp_packet_alloc(suite_context.pool,