From patchwork Fri Jun 30 16:00:05 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: 106744 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp2519989qge; Fri, 30 Jun 2017 09:07:17 -0700 (PDT) X-Received: by 10.237.62.58 with SMTP id l55mr26549872qtf.20.1498838837441; Fri, 30 Jun 2017 09:07:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1498838837; cv=none; d=google.com; s=arc-20160816; b=KVQ3LUL53VL0CA7xsyRojKv6R3PgCDu4zEN6CDQwa/fxIw91kDI6UmiwJ21HGShSE9 F7rd0G5tkh0BsTXa7gxxu7GvkCEsAAeta45b2uOCCNQ1fu0h3bDMAscajvzRnL1QOtn/ mKjl8eIbWPSqE/yYYr33ROu8sXu4l8EF3cn4fwHU+RN3q987rCgeoM2HIjSkATSvfoU7 K6R/h3xrfSgeX8bZJa96y4Cep0QjaC5/D6XncDa/QBzSBAzTTdej1zwXoZMX8L6LZ7M2 8pdjwm8FE0JIp7N1ywI9cehuV6IliHJEUNbfW9tE7aNYb5PhaO7qiINGn4Sbqa7kChy2 wILg== 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=3O3rCbwY2nFqKjen2SkRiDCWhgljLffBhUhX1Vj5lc0=; b=ieuWBziWNrDzja3SNJ4BO02rw99Axbn/NaySA1t9oeDNY9V0yuB0pXFZ+w+TidQsBj sIDPB/KYw5VWs5svSYGyEan3c2cGVLMmZmTQmsGSEstoBD7D5tp6ioaxcyHhdYSeq2g9 QXPck4i6zaV7Kn45WdvoybnvyfpLsnOZ5SMDW00mxFL/h0BqOB4e41CrxgWMZMNwaJkb KHgE5APoSxQ1Kg01iQAbLZ2Kjrjg1UIctpyp0k4Wsb4sCilWEbuKLbSE8qgjNAIxKMEL rgt60EYrua/RzD+PfT1ApSGN6erU5U7gfP5ON5arpxOt+QBxUqWUhBZJCgvv86U1/6E9 Sruw== 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 w24si8015248qta.233.2017.06.30.09.07.16; Fri, 30 Jun 2017 09:07:17 -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 BF7F260CB2; Fri, 30 Jun 2017 16:07:16 +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,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 A027860A58; Fri, 30 Jun 2017 16:05:11 +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 059BA60CA9; Fri, 30 Jun 2017 16:05:00 +0000 (UTC) Received: from forward4h.cmail.yandex.net (forward4h.cmail.yandex.net [87.250.230.101]) by lists.linaro.org (Postfix) with ESMTPS id BB6786156A for ; Fri, 30 Jun 2017 16:03:20 +0000 (UTC) Received: from smtp2m.mail.yandex.net (smtp2m.mail.yandex.net [IPv6:2a02:6b8:0:2519::122]) by forward4h.cmail.yandex.net (Yandex) with ESMTP id 138F220EA5 for ; Fri, 30 Jun 2017 19:03:19 +0300 (MSK) Received: from smtp2m.mail.yandex.net (localhost.localdomain [127.0.0.1]) by smtp2m.mail.yandex.net (Yandex) with ESMTP id E8FAD2301696 for ; Fri, 30 Jun 2017 19:00:22 +0300 (MSK) Received: by smtp2m.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id 3uDDcvG1pt-0KZSl3d1; Fri, 30 Jun 2017 19:00:21 +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: Fri, 30 Jun 2017 19:00:05 +0300 Message-Id: <1498838409-4597-6-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1498838409-4597-1-git-send-email-odpbot@yandex.ru> References: <1498838409-4597-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 64 Subject: [lng-odp] [PATCH API-NEXT v1 5/9] api: crypto: add crypto packet operation interface 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 Input and output of crypto operations are packets. API is more flexible for application and API pipelining when output is packet with additional metadata. Application or API pipeline stages which do not care about crypto results may work on basic packet metadata. Crypto result event type changes from ODP_EVENT_CRYPTO_COMPL to ODP_EVENT_PACKET. Event subtype (ODP_EVENT_PACKET_CRYPTO) can be used to identify packets with crypto metadata. 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: 25273ed7dee29d26a2ef7357e84a36aa4443f63e **/ include/odp/api/spec/crypto.h | 175 +++++++++++++++++++++++++++++-- include/odp/arch/default/api/abi/event.h | 3 +- 2 files changed, 167 insertions(+), 11 deletions(-) diff --git a/include/odp/api/spec/crypto.h b/include/odp/api/spec/crypto.h index d987de54..2dfd6161 100644 --- a/include/odp/api/spec/crypto.h +++ b/include/odp/api/spec/crypto.h @@ -16,6 +16,7 @@ #include #include +#include #ifdef __cplusplus extern "C" { @@ -276,6 +277,9 @@ typedef struct odp_crypto_session_param_t { * data in non-posted mode */ odp_crypto_op_mode_t ODP_DEPRECATE(pref_mode); + /** Operation mode when using packet interface: sync or async */ + odp_crypto_op_mode_t packet_op_mode; + /** Cipher algorithm * * Use odp_crypto_capability() for supported algorithms. @@ -311,16 +315,15 @@ typedef struct odp_crypto_session_param_t { /** Async mode completion event queue * - * When odp_crypto_operation() is asynchronous, the completion queue is - * used to return the completion status of the operation to the - * application. + * The completion queue is used to return odp_crypto_packet_op_enq() + * results to the application. */ odp_queue_t compl_queue; /** Output pool * * When the output packet is not specified during the call to - * odp_crypto_operation(), the output packet will be allocated + * crypto operation, the output packet will be allocated * from this pool. */ odp_pool_t output_pool; @@ -400,6 +403,44 @@ typedef struct odp_crypto_op_param_t { typedef odp_crypto_op_param_t ODP_DEPRECATE(odp_crypto_op_params_t); /** + * Crypto packet API per packet operation parameters + */ +typedef struct odp_crypto_packet_op_param_t { + /** Session handle from creation */ + odp_crypto_session_t session; + + /** Override session IV pointer */ + uint8_t *override_iv_ptr; + + /** Offset from start of packet for hash result + * + * Specifies the offset where the hash result is to be stored. In case + * of decode sessions, input hash values will be read from this offset, + * and overwritten with hash results. If this offset lies within + * specified 'auth_range', implementation will mute this field before + * calculating the hash result. + */ + uint32_t hash_result_offset; + + /** Additional Authenticated Data (AAD) */ + struct { + /** Pointer to ADD */ + uint8_t *ptr; + + /** AAD length in bytes. Use odp_crypto_auth_capability() for + * supported AAD lengths. */ + uint32_t length; + } aad; + + /** Data range to apply cipher */ + odp_packet_data_range_t cipher_range; + + /** Data range to authenticate */ + odp_packet_data_range_t auth_range; + +} odp_crypto_packet_op_param_t; + +/** * Crypto API session creation return code */ typedef enum { @@ -444,14 +485,17 @@ typedef enum { /** * Cryto API per packet operation completion status */ -typedef struct odp_crypto_compl_status { +typedef struct odp_crypto_op_status { /** Algorithm specific return code */ odp_crypto_alg_err_t alg_err; /** Hardware specific return code */ odp_crypto_hw_err_t hw_err; -} odp_crypto_compl_status_t; +} odp_crypto_op_status_t; + +/** @deprecated Use ODP_DEPRECATE(odp_crypto_op_status_t) instead */ +typedef odp_crypto_op_status_t ODP_DEPRECATE(odp_crypto_compl_status_t); /** * Crypto API operation result @@ -460,27 +504,51 @@ typedef struct odp_crypto_op_result { /** Request completed successfully */ odp_bool_t ok; - /** User context from request */ - void *ctx; + /** User context from request + * + * @deprecated No need to pass context around sync calls + * */ + void *ODP_DEPRECATE(ctx); /** Output packet */ odp_packet_t pkt; /** Cipher status */ - odp_crypto_compl_status_t cipher_status; + odp_crypto_op_status_t cipher_status; /** Authentication status */ - odp_crypto_compl_status_t auth_status; + odp_crypto_op_status_t auth_status; } odp_crypto_op_result_t; /** + * Crypto packet API operation result + */ +typedef struct odp_crypto_packet_op_result_t { + /** Request completed successfully */ + odp_bool_t ok; + + /** Cipher status */ + odp_crypto_op_status_t cipher_status; + + /** Authentication status */ + odp_crypto_op_status_t auth_status; + +} odp_crypto_packet_op_result_t; + +/** * Crypto capabilities */ typedef struct odp_crypto_capability_t { /** Maximum number of crypto sessions */ uint32_t max_sessions; + /** Supported packet operation in SYNC mode */ + odp_support_t packet_sync_mode; + + /** Supported packet operation in ASYNC mode */ + odp_support_t packet_async_mode; + /** Supported cipher algorithms */ odp_crypto_cipher_algos_t ciphers; @@ -706,6 +774,93 @@ uint64_t ODP_DEPRECATE(odp_crypto_compl_to_u64)(ODP_DEPRECATE(odp_crypto_compl_t void odp_crypto_session_param_init(odp_crypto_session_param_t *param); /** + * Return crypto processed packet that is associated with event + * + * Get packet handle to an crypto processed packet event. Event subtype must be + * ODP_EVENT_PACKET_CRYPTO. Crypto operation results can be examined with + * odp_crypto_packet_result(). + * + * Note: any invalid parameters will cause undefined behavior and may cause + * the application to abort or crash. + * + * @param ev Event handle + * + * @return Packet handle + */ +odp_packet_t odp_crypto_packet_from_event(odp_event_t ev); + +/** + * Convert crypto packet handle to event + * + * The packet handle must be an output of an crypto operation. + * + * @param pkt Packet handle from crypto operation + * + * @return Event handle + */ +odp_event_t odp_crypto_packet_to_event(odp_packet_t pkt); + +/** + * Get crypto operation results from an crypto processed packet + * + * Successful crypto operations of all types (SYNC and ASYNC) produce packets + * which contain crypto result metadata. This function copies the operation + * results from an crypto processed packet. Event subtype of this kind of + * packet is ODP_EVENT_PACKET_crypto. Results are undefined if a non-crypto + * processed packet is passed as input. + * + * @param packet An crypto processed packet (ODP_EVENT_PACKET_CRYPTO) + * @param[out] result Pointer to operation result for output + * + * @retval 0 On success + * @retval <0 On failure + */ +int odp_crypto_packet_result(odp_crypto_packet_op_result_t *result, + odp_packet_t packet); + +/** + * Crypto packet operation + * + * Performs the ASYNC cryptographic operations specified during session creation + * on the packets. Caller should initialize pkt_out either with desired output + * packet handles or with ODP_PACKET_INVALID to make ODP allocate new packets + * from provided pool. + * + * @param pkt_in Packets to be processed + * @param num_in Number of packets to be processed + * @param[in,out] pkt_out Packet handle array specifyint resulting packets + * @param param Operation parameters array + * + * @return Number of input packets consumed (0 ... num_in) + * @retval <0 on failure + */ +int odp_crypto_packet_op(const odp_packet_t pkt_in[], + odp_packet_t pkt_out[], + int num_in, + const odp_crypto_packet_op_param_t param[]); + +/** + * Crypto packet operation + * + * Performs the ASYNC cryptographic operations specified during session creation + * on the packets. Caller should initialize pkt_out either with desired output + * packet handles or with ODP_PACKET_INVALID to make ODP allocate new packets + * from provided pool. Resulting packets are returned through events + * + * @param pkt_in Packets to be processed + * @param num_in Number of packets to be processed + * @param pkt_out Packet handle array specifying resulting packets + * @param param Operation parameters array + * + * @return Number of input packets consumed (0 ... num_in) + * @retval <0 on failure + */ +int odp_crypto_packet_op_enq(const odp_packet_t pkt_in[], + const odp_packet_t pkt_out[], + int num_in, + const odp_crypto_packet_op_param_t param[]); + +/** * @} */ diff --git a/include/odp/arch/default/api/abi/event.h b/include/odp/arch/default/api/abi/event.h index 23b16efd..871d2cf9 100644 --- a/include/odp/arch/default/api/abi/event.h +++ b/include/odp/arch/default/api/abi/event.h @@ -37,7 +37,8 @@ typedef enum odp_event_type_t { typedef enum odp_event_subtype_t { ODP_EVENT_NO_SUBTYPE = 0, ODP_EVENT_PACKET_BASIC = 1, - ODP_EVENT_PACKET_IPSEC = 2 + ODP_EVENT_PACKET_CRYPTO = 2, + ODP_EVENT_PACKET_IPSEC = 3 } odp_event_subtype_t; /**