From patchwork Sun Jan 28 09:00:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 126071 Delivered-To: patch@linaro.org Received: by 10.46.84.92 with SMTP id y28csp1562582ljd; Sun, 28 Jan 2018 01:12:02 -0800 (PST) X-Google-Smtp-Source: AH8x227P5ZZJARbqBe8Y8XyzdNCt5O8qJjVLC4WhgNJzVkjHIaxsOOVvM8Hh0o9lMreUBENBummv X-Received: by 10.55.112.132 with SMTP id l126mr29108974qkc.296.1517130722564; Sun, 28 Jan 2018 01:12:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517130722; cv=none; d=google.com; s=arc-20160816; b=yvUb+S98egl8G7OZblwfjRKfEBkMhThoag9ylzRNPx8dGgkeeMu/pubny3OAL/4W9y u1gp1WrOLN59hABN+VJhlp34beRu1ndpFhjw6GPyzZ0zpnO7xKthowg0GJfXHWkt3ota HngHomUnd3IY32Q4lgnmVOMPV0A9f6XB4fA37bhxMqdk6xWi2E55TodHMmlCz98YFjej m8ojG9ZrEBveuvORrCMvDJptHC+IQmbfTn0tp18mNdkTpj1rZI4enzCy09G9Sh62EcQ6 8vbotDi4b+9DdxmNOx4Sx0W1+lWye/ol4kpclA44ZPvVDsyBUnjtOp+6XYZrB35LsnOW Wotg== 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=QuUP4V6s7MtFe8r7fykkhuzyoOGG/fypytnuukXYEug=; b=MOHq7x90FD+4EaKJ+xPsq5u7rJHUQwjJygz47Fificul96rw989jR40hmJiEFNk23y s9KN2Ty8+5lPVWjeXcKK6BWe++1z0h3w4oDG1QE9dVAOx7PfilZEe+BJYAfJEWL9El9Y XpaPia2Wx7K/wJd7ejlTZdluED+DfNIp6TwwJ5dlmp5L9ht2sVPXHLG4eDf2OkO55G4q ylG/XRw1KBZQ5eU5abxcDuEkpqKu0AxwyYq9UyBBvwOzMRnGwA+/dfTeHG7ZYePfAkEb rES/KnHG9N3/U8mj3RWNLH2fdjCrHLQIOLkerifJOteCx5/6WRzDjPTKLphu4dCElR7o Iuxw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 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 (ec2-54-197-127-237.compute-1.amazonaws.com. [54.197.127.237]) by mx.google.com with ESMTP id o42si9111174qtf.258.2018.01.28.01.12.02; Sun, 28 Jan 2018 01:12:02 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) client-ip=54.197.127.237; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 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 398826176A; Sun, 28 Jan 2018 09:12:02 +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 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 72BA162784; Sun, 28 Jan 2018 09:01:26 +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 3A769617E5; Sun, 28 Jan 2018 09:00:34 +0000 (UTC) Received: from forward103j.mail.yandex.net (forward103j.mail.yandex.net [5.45.198.246]) by lists.linaro.org (Postfix) with ESMTPS id C212E6173A for ; Sun, 28 Jan 2018 09:00:21 +0000 (UTC) Received: from mxback4o.mail.yandex.net (mxback4o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::1e]) by forward103j.mail.yandex.net (Yandex) with ESMTP id 0628934C1C7F for ; Sun, 28 Jan 2018 12:00:19 +0300 (MSK) Received: from smtp3p.mail.yandex.net (smtp3p.mail.yandex.net [2a02:6b8:0:1472:2741:0:8b6:8]) by mxback4o.mail.yandex.net (nwsmtp/Yandex) with ESMTP id fhDLpdH8nE-0IUiXKY2; Sun, 28 Jan 2018 12:00:18 +0300 Received: by smtp3p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id kBi2pciDaV-0IXSi7BF; Sun, 28 Jan 2018 12:00:18 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Github ODP bot To: lng-odp@lists.linaro.org Date: Sun, 28 Jan 2018 12:00:06 +0300 Message-Id: <1517130009-11837-14-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1517130009-11837-1-git-send-email-odpbot@yandex.ru> References: <1517130009-11837-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 434 Subject: [lng-odp] [PATCH API-NEXT v2 13/16] linux-gen: crypto: rename auth functions 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 Point that current authentication functions use HMAC by including hmac in their names. Signed-off-by: Dmitry Eremin-Solenikov --- /** Email created from pull request 434 (lumag:crypto-upd) ** https://github.com/Linaro/odp/pull/434 ** Patch: https://github.com/Linaro/odp/pull/434.patch ** Base sha: 0bdad6d2562166eec4abeb957b6bb5067de9fe94 ** Merge commit sha: 8947b874421e06f87f32ec66357967a71e46e986 **/ platform/linux-generic/odp_crypto.c | 92 +++++++++++++++---------------------- 1 file changed, 38 insertions(+), 54 deletions(-) diff --git a/platform/linux-generic/odp_crypto.c b/platform/linux-generic/odp_crypto.c index 7423864ff..1e2356373 100644 --- a/platform/linux-generic/odp_crypto.c +++ b/platform/linux-generic/odp_crypto.c @@ -148,8 +148,6 @@ struct odp_crypto_generic_session_t { struct { uint8_t key[EVP_MAX_KEY_LENGTH]; uint8_t iv_data[EVP_MAX_IV_LENGTH]; - uint32_t key_length; - uint32_t bytes; union { const EVP_MD *evp_md; const EVP_CIPHER *evp_cipher; @@ -202,13 +200,30 @@ null_crypto_routine(odp_packet_t pkt ODP_UNUSED, return ODP_CRYPTO_ALG_ERR_NONE; } +/* Mimic new OpenSSL 1.1.y API */ +#if OPENSSL_VERSION_NUMBER < 0x10100000L +static HMAC_CTX *HMAC_CTX_new(void) +{ + HMAC_CTX *ctx = malloc(sizeof(*ctx)); + + HMAC_CTX_init(ctx); + return ctx; +} + +static void HMAC_CTX_free(HMAC_CTX *ctx) +{ + HMAC_CTX_cleanup(ctx); + free(ctx); +} +#endif + static -void packet_hmac_calculate(HMAC_CTX *ctx, - odp_packet_t pkt, - const odp_crypto_packet_op_param_t *param, - odp_crypto_generic_session_t *session, - uint8_t *hash) +void packet_hmac(odp_packet_t pkt, + const odp_crypto_packet_op_param_t *param, + odp_crypto_generic_session_t *session, + uint8_t *hash) { + HMAC_CTX *ctx = HMAC_CTX_new(); uint32_t offset = param->auth_range.offset; uint32_t len = param->auth_range.length; @@ -216,7 +231,7 @@ void packet_hmac_calculate(HMAC_CTX *ctx, HMAC_Init_ex(ctx, session->auth.key, - session->auth.key_length, + session->p.auth_key.length, session->auth.evp_md, NULL); @@ -231,42 +246,13 @@ void packet_hmac_calculate(HMAC_CTX *ctx, } HMAC_Final(ctx, hash, NULL); -} - -#if OPENSSL_VERSION_NUMBER < 0x10100000L -static -void packet_hmac(odp_packet_t pkt, - const odp_crypto_packet_op_param_t *param, - odp_crypto_generic_session_t *session, - uint8_t *hash) -{ - HMAC_CTX ctx; - - /* Hash it */ - HMAC_CTX_init(&ctx); - packet_hmac_calculate(&ctx, pkt, param, session, hash); - HMAC_CTX_cleanup(&ctx); -} -#else -static -void packet_hmac(odp_packet_t pkt, - const odp_crypto_packet_op_param_t *param, - odp_crypto_generic_session_t *session, - uint8_t *hash) -{ - HMAC_CTX *ctx; - - /* Hash it */ - ctx = HMAC_CTX_new(); - packet_hmac_calculate(ctx, pkt, param, session, hash); HMAC_CTX_free(ctx); } -#endif static -odp_crypto_alg_err_t auth_gen(odp_packet_t pkt, - const odp_crypto_packet_op_param_t *param, - odp_crypto_generic_session_t *session) +odp_crypto_alg_err_t auth_hmac_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]; @@ -283,9 +269,9 @@ odp_crypto_alg_err_t auth_gen(odp_packet_t pkt, } static -odp_crypto_alg_err_t auth_check(odp_packet_t pkt, - const odp_crypto_packet_op_param_t *param, - odp_crypto_generic_session_t *session) +odp_crypto_alg_err_t auth_hmac_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]; @@ -907,15 +893,14 @@ static int process_aes_ccm_param(odp_crypto_generic_session_t *session, return 0; } -static int process_auth_param(odp_crypto_generic_session_t *session, - uint32_t key_length, - const EVP_MD *evp_md) +static int process_auth_hmac_param(odp_crypto_generic_session_t *session, + const EVP_MD *evp_md) { /* Set function */ if (ODP_CRYPTO_OP_ENCODE == session->p.op) - session->auth.func = auth_gen; + session->auth.func = auth_hmac_gen; else - session->auth.func = auth_check; + session->auth.func = auth_hmac_check; session->auth.evp_md = evp_md; @@ -924,9 +909,8 @@ static int process_auth_param(odp_crypto_generic_session_t *session, return -1; /* Convert keys */ - session->auth.key_length = key_length; memcpy(session->auth.key, session->p.auth_key.data, - session->auth.key_length); + session->p.auth_key.length); return 0; } @@ -1245,10 +1229,10 @@ odp_crypto_session_create(odp_crypto_session_param_t *param, #endif /* Fallthrough */ case ODP_AUTH_ALG_MD5_HMAC: - rc = process_auth_param(session, 16, EVP_md5()); + rc = process_auth_hmac_param(session, EVP_md5()); break; case ODP_AUTH_ALG_SHA1_HMAC: - rc = process_auth_param(session, 20, EVP_sha1()); + rc = process_auth_hmac_param(session, EVP_sha1()); break; #if ODP_DEPRECATED_API case ODP_AUTH_ALG_SHA256_128: @@ -1257,10 +1241,10 @@ odp_crypto_session_create(odp_crypto_session_param_t *param, #endif /* Fallthrough */ case ODP_AUTH_ALG_SHA256_HMAC: - rc = process_auth_param(session, 32, EVP_sha256()); + rc = process_auth_hmac_param(session, EVP_sha256()); break; case ODP_AUTH_ALG_SHA512_HMAC: - rc = process_auth_param(session, 64, EVP_sha512()); + rc = process_auth_hmac_param(session, EVP_sha512()); break; #if ODP_DEPRECATED_API case ODP_AUTH_ALG_AES128_GCM: