From patchwork Thu Jun 1 09:03:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Eremin-Solenikov X-Patchwork-Id: 100851 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp709489qge; Thu, 1 Jun 2017 02:14:57 -0700 (PDT) X-Received: by 10.200.49.194 with SMTP id i2mr439986qte.156.1496308497195; Thu, 01 Jun 2017 02:14:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496308497; cv=none; d=google.com; s=arc-20160816; b=jyumzUlcg1srgxczLE5ph2Xw9jEFLC+wRZiL8qf17aCCLfV+3vneOTJUdlUi9s42oi zbVXvc0spiht0o1s0d+lKi4gNUExn8bsWRK9QDBzH5C7cxprnpMm9dOQnbQr9/6CUDuQ FiW4Bsa/FckkK9eXppCSG+ug3eu1Sj5Ay72WLywcIDt7l7upzwDXZKzFeSN8X8RHKBV+ ZT++LilJwoxGIdYSzD9QyvO1qlblEvuwPCNp29Qpoq+835zjpDFLJy1aKjg0YNzwP1BM piZ+FSbF+6OmLzmrJiyg1M6JCWnxpsIq4L+Zf3/cYxm8go3L4HCpGhHXuR2ULYqZgnYh 1Hig== 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:references:in-reply-to :message-id:date:to:from:delivered-to:arc-authentication-results; bh=fLzjIFcldBOpgQdK19AdmEyX6AyyyYPFVrc/c50YTaM=; b=YSMJQNPwGNn0wYmzX8IZaov9vYTCMNHxvBQvLIoksRst3p+hC5UvKTfWZFfdc68cXJ gn6So37hZ2OXsWRzy9RKrj1uMJSsG70eZc0v0XrJ8CKl7F+U/YU/G/2+9or09t9LcQLB slgrJi9JTT/qKEQRkTL0B98QVyUCVwFMsP3TpNvkPNzgnhOFT6TR7bI8LAg92m/NhGt6 4uZjhm6h9a2XEdZ5wzHj62GOIVpYam7tsUPa+dF0kN1J2fxb3gxtxFCTQm171JIXM1a6 fo405HDW9GLbOAMcNWHR7NVJ6rCe/f3RgWm1E15yxnu7l7RpH6MkXcxfqyIm/J4aoUG7 MIuA== 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id m40si19093268qtb.229.2017.06.01.02.14.56; Thu, 01 Jun 2017 02:14:57 -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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id CF5A060846; Thu, 1 Jun 2017 09:14:56 +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=-1.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_SPAM, 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 EA4D760BF5; Thu, 1 Jun 2017 09:06:02 +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 D266260D7C; Thu, 1 Jun 2017 09:05:52 +0000 (UTC) Received: from mail-lf0-f44.google.com (mail-lf0-f44.google.com [209.85.215.44]) by lists.linaro.org (Postfix) with ESMTPS id 4695860A3D for ; Thu, 1 Jun 2017 09:03:59 +0000 (UTC) Received: by mail-lf0-f44.google.com with SMTP id a136so8035524lfa.0 for ; Thu, 01 Jun 2017 02:03:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=fLzjIFcldBOpgQdK19AdmEyX6AyyyYPFVrc/c50YTaM=; b=XBaxWLpFZxKYHspvKvjO5ALolGKjav6h76B/EIQKnqQlfMDQtQrHKVdnRirMRWt4nf c5VXF/+qkmMUKQ+lxeNGuJnj352nKt/KEaooOUsIixowytWY0Li2B/qCcxcpEAIQGwgo mFBTlCTW1mZMaUsdrA0aga5obpbdFoXf9psyk9T+Gqr9uoemJa2PXejnqyMcqNKrxtGk S7UoCD0IDa4UluPV8+i3eS+tdgMe1703BjeIUj1mTxDtkqIAnNPiYRq6DSc90eVnETdC m/3nZeveJKwtBgx9rMv8nKGGiLhTZMNqDuh8lWAT5j3xIjwq4UlYQQ9d4hy89aA+dhq7 PC3A== X-Gm-Message-State: AODbwcA9mx61pt/fRK950Aqmw2DEjRHovXpIYF5gj1FN0xM2NEmf5uZ+ Zfk5gwgKVMU13VBx4bHTPT9r X-Received: by 10.46.72.9 with SMTP id v9mr175017lja.21.1496307837932; Thu, 01 Jun 2017 02:03:57 -0700 (PDT) Received: from forlindon.lumag.auriga.ru ([188.162.64.12]) by smtp.gmail.com with ESMTPSA id 129sm4232819ljf.36.2017.06.01.02.03.57 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Jun 2017 02:03:57 -0700 (PDT) From: Dmitry Eremin-Solenikov To: lng-odp@lists.linaro.org Date: Thu, 1 Jun 2017 12:03:30 +0300 Message-Id: <20170601090339.9313-15-dmitry.ereminsolenikov@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170601090339.9313-1-dmitry.ereminsolenikov@linaro.org> References: <20170601090339.9313-1-dmitry.ereminsolenikov@linaro.org> Subject: [lng-odp] [PATCH API-NEXT v5 14/23] linux-generic: crypto: make HMAC work across segmented packets 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" Signed-off-by: Dmitry Eremin-Solenikov --- platform/linux-generic/odp_crypto.c | 78 +++++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 33 deletions(-) -- 2.11.0 diff --git a/platform/linux-generic/odp_crypto.c b/platform/linux-generic/odp_crypto.c index 2ba077f9dcd9..7ea90fb92b48 100644 --- a/platform/linux-generic/odp_crypto.c +++ b/platform/linux-generic/odp_crypto.c @@ -112,29 +112,53 @@ null_crypto_routine(odp_crypto_op_param_t *param ODP_UNUSED, } static +void packet_hmac(odp_crypto_op_param_t *param, + odp_crypto_generic_session_t *session, + uint8_t *hash) +{ + odp_packet_t pkt = param->out_pkt; + uint32_t offset = param->auth_range.offset; + uint32_t len = param->auth_range.length; + HMAC_CTX ctx; + + ODP_ASSERT(offset + len <= odp_packet_len(pkt)); + + /* Hash it */ + HMAC_CTX_init(&ctx); + HMAC_Init_ex(&ctx, + session->auth.key, + session->auth.key_length, + session->auth.evp_md, + NULL); + + while (len > 0) { + uint32_t seglen = 0; /* GCC */ + void *mapaddr = odp_packet_offset(pkt, offset, &seglen, NULL); + uint32_t maclen = len > seglen ? seglen : len; + + HMAC_Update(&ctx, mapaddr, maclen); + offset += maclen; + len -= maclen; + } + + HMAC_Final(&ctx, hash, NULL); + HMAC_CTX_cleanup(&ctx); +} + +static odp_crypto_alg_err_t auth_gen(odp_crypto_op_param_t *param, odp_crypto_generic_session_t *session) { - uint8_t *data = odp_packet_data(param->out_pkt); - uint8_t *icv = data; - uint32_t len = param->auth_range.length; uint8_t hash[EVP_MAX_MD_SIZE]; - /* Adjust pointer for beginning of area to auth */ - data += param->auth_range.offset; - icv += param->hash_result_offset; - /* Hash it */ - HMAC(session->auth.evp_md, - session->auth.key, - session->auth.key_length, - data, - len, - hash, - NULL); + packet_hmac(param, session, hash); /* Copy to the output location */ - memcpy(icv, hash, session->auth.bytes); + odp_packet_copy_from_mem(param->out_pkt, + param->hash_result_offset, + session->auth.bytes, + hash); return ODP_CRYPTO_ALG_ERR_NONE; } @@ -143,31 +167,19 @@ static odp_crypto_alg_err_t auth_check(odp_crypto_op_param_t *param, odp_crypto_generic_session_t *session) { - uint8_t *data = odp_packet_data(param->out_pkt); - uint8_t *icv = data; - uint32_t len = param->auth_range.length; uint32_t bytes = session->auth.bytes; uint8_t hash_in[EVP_MAX_MD_SIZE]; uint8_t hash_out[EVP_MAX_MD_SIZE]; - /* Adjust pointer for beginning of area to auth */ - data += param->auth_range.offset; - icv += param->hash_result_offset; - /* Copy current value out and clear it before authentication */ - memset(hash_in, 0, sizeof(hash_in)); - memcpy(hash_in, icv, bytes); - memset(icv, 0, bytes); - memset(hash_out, 0, sizeof(hash_out)); + odp_packet_copy_to_mem(param->out_pkt, param->hash_result_offset, + bytes, hash_in); + + _odp_packet_set_data(param->out_pkt, param->hash_result_offset, + 0, bytes); /* Hash it */ - HMAC(session->auth.evp_md, - session->auth.key, - session->auth.key_length, - data, - len, - hash_out, - NULL); + packet_hmac(param, session, hash_out); /* Verify match */ if (0 != memcmp(hash_in, hash_out, bytes))