From patchwork Tue Nov 14 20:00:08 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: 118887 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp3464949qgn; Tue, 14 Nov 2017 12:05:08 -0800 (PST) X-Google-Smtp-Source: AGs4zMaYh8cGXti0rCx2N+UPIqxxjvHJ6q76Ow3mk3ajmO3SXfunNQyQ+eB0XsRIdh4v7hVTUuBg X-Received: by 10.237.34.45 with SMTP id n42mr22288003qtc.80.1510689908599; Tue, 14 Nov 2017 12:05:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510689908; cv=none; d=google.com; s=arc-20160816; b=XnEPL4EiDivsT9VflEmUcVIlevOo/SkHVhVbIBioQOULFCmmd2dDyCoWgsSmaXWN06 ifgo1HYKZi+YC8RzL/QUHuz+LLQ8APUaaFg7G0cRmhycywMUfX23yqKQ/0wQoQY1gStw s1iylVkgPTIU7l+v2LTiHbxQ6Lt95zj7OAYlloYpAT3Q4VSGYdnBaYhk7qsc00oiOK7i 3GIBAbQSHUQ8faNREXN2kIfuoU3/FU8hruVmtwbaBdyKjHMAW8p8aVHk7cY84hpWgFb+ mdHqGTbVgTBn9SNH0Fc6w7OoimSIisjQsRk/RrJ0X7kcEnZW11WUQ10o2B9I43/mOTzr clew== 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=xZVd0VpAdCKlrXlynCKRXFyEvAcAaMpjjxon7JSHkvc=; b=Hp0/nQQuVeOKvnfypBv0TqG30jQqMT/vMH6rUrfuT+UeeI28AO0DSW84plGNc8ziL7 RCwuUsuKgwA8e7pl+fJSaics81aXLcWa8GlH/tUWC6XofVKwDDKQnKM5JhGAdAPwbOdg XvV7twqLeUx+rAFIC2B/IJphbKmnaIEL4YeA5TtSQr1cMN1NeRRxUrsGIYShYwcvsdU/ AqeEo/45vueQv678uXMiMBFArS3jt4H30CtQlhKvhJFYsgYrJushTGFFxY7Y93VXmMmV 7V6vdk+CrJwNgukoJuEJ6nwT1XPmXryYSx08O9hlpN4wyaTkxgqBteDhzYy6EhWPZoaF BTGA== 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 o123si892452qkc.114.2017.11.14.12.05.08; Tue, 14 Nov 2017 12:05:08 -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 4A2A060676; Tue, 14 Nov 2017 20:05:08 +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=-5.4 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, 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 A26A66074C; Tue, 14 Nov 2017 20:01:03 +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 DC8B760690; Tue, 14 Nov 2017 20:00:27 +0000 (UTC) Received: from forward106p.mail.yandex.net (forward106p.mail.yandex.net [77.88.28.109]) by lists.linaro.org (Postfix) with ESMTPS id 41DE260646 for ; Tue, 14 Nov 2017 20:00:17 +0000 (UTC) Received: from mxback14j.mail.yandex.net (mxback14j.mail.yandex.net [IPv6:2a02:6b8:0:1619::90]) by forward106p.mail.yandex.net (Yandex) with ESMTP id 8AE252D82EEF for ; Tue, 14 Nov 2017 23:00:15 +0300 (MSK) Received: from smtp3p.mail.yandex.net (smtp3p.mail.yandex.net [2a02:6b8:0:1472:2741:0:8b6:8]) by mxback14j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id c8ROSWedwo-0FKWjmlq; Tue, 14 Nov 2017 23:00:15 +0300 Received: by smtp3p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id ZsDLds7hfB-0Fp4fHXC; Tue, 14 Nov 2017 23:00:15 +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: Tue, 14 Nov 2017 23:00:08 +0300 Message-Id: <1510689611-17861-8-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1510689611-17861-1-git-send-email-odpbot@yandex.ru> References: <1510689611-17861-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 288 Subject: [lng-odp] [PATCH API-NEXT v8 7/10] linux-gen: ipsec: implement AES-GMAC-AH 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 Implement AES-GMAC authentication support for AH. Signed-off-by: Dmitry Eremin-Solenikov --- /** Email created from pull request 288 (lumag:gmac) ** https://github.com/Linaro/odp/pull/288 ** Patch: https://github.com/Linaro/odp/pull/288.patch ** Base sha: ba93e355ddf151215aa18b59cbfca08fe175fe65 ** Merge commit sha: 8363c3a4073075d0f3dd68864b9a33819005aab4 **/ platform/linux-generic/odp_ipsec.c | 46 +++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/platform/linux-generic/odp_ipsec.c b/platform/linux-generic/odp_ipsec.c index 9533ca422..d54ec3286 100644 --- a/platform/linux-generic/odp_ipsec.c +++ b/platform/linux-generic/odp_ipsec.c @@ -400,6 +400,16 @@ static ipsec_sa_t *ipsec_in_single(odp_packet_t pkt, } } + memcpy(iv, ipsec_sa->salt, ipsec_sa->salt_length); + if (odp_packet_copy_to_mem(pkt, + ipsec_offset + _ODP_AHHDR_LEN, + ipsec_sa->esp_iv_len, + iv + ipsec_sa->salt_length) < 0) { + status->error.alg = 1; + goto err; + } + param.override_iv_ptr = iv; + hdr_len = (ah.ah_len + 2) * 4; trl_len = 0; @@ -425,7 +435,8 @@ static ipsec_sa_t *ipsec_in_single(odp_packet_t pkt, param.auth_range.offset = ip_offset; param.auth_range.length = odp_be_to_cpu_16(ip->tot_len); - param.hash_result_offset = ipsec_offset + _ODP_AHHDR_LEN; + param.hash_result_offset = ipsec_offset + _ODP_AHHDR_LEN + + ipsec_sa->esp_iv_len; stats_length = param.auth_range.length; } else { @@ -826,7 +837,8 @@ static ipsec_sa_t *ipsec_out_single(odp_packet_t pkt, } else if (ipsec_sa->proto == ODP_IPSEC_AH) { _odp_ahhdr_t ah; - hdr_len = _ODP_AHHDR_LEN + ipsec_sa->icv_len; + hdr_len = _ODP_AHHDR_LEN + ipsec_sa->esp_iv_len + + ipsec_sa->icv_len; trl_len = 0; /* Save IPv4 stuff */ @@ -853,7 +865,7 @@ static ipsec_sa_t *ipsec_out_single(odp_packet_t pkt, memset(&ah, 0, sizeof(ah)); ah.spi = odp_cpu_to_be_32(ipsec_sa->spi); - ah.ah_len = 1 + (ipsec_sa->icv_len / 4); + ah.ah_len = 1 + (ipsec_sa->esp_iv_len + ipsec_sa->icv_len) / 4; ah.seq_no = odp_cpu_to_be_32(ipsec_seq_no(ipsec_sa)); ah.next_header = ip->proto; ip->proto = _ODP_IPPROTO_AH; @@ -864,11 +876,34 @@ static ipsec_sa_t *ipsec_out_single(odp_packet_t pkt, param.aad.ptr = (uint8_t *)&aad; param.aad.length = sizeof(aad); + /* For GMAC */ + if (ipsec_sa->use_counter_iv) { + uint64_t ctr; + + ODP_ASSERT(sizeof(ctr) == ipsec_sa->esp_iv_len); + + ctr = odp_atomic_fetch_add_u64(&ipsec_sa->out.counter, + 1); + /* Check for overrun */ + if (ctr == 0) + goto err; + + memcpy(iv, ipsec_sa->salt, ipsec_sa->salt_length); + memcpy(iv + ipsec_sa->salt_length, &ctr, + ipsec_sa->esp_iv_len); + param.override_iv_ptr = iv; + } + odp_packet_copy_from_mem(pkt, ipsec_offset, _ODP_AHHDR_LEN, &ah); + odp_packet_copy_from_mem(pkt, + ipsec_offset + _ODP_AHHDR_LEN, + ipsec_sa->esp_iv_len, + iv + ipsec_sa->salt_length); _odp_packet_set_data(pkt, - ipsec_offset + _ODP_AHHDR_LEN, + ipsec_offset + _ODP_AHHDR_LEN + + ipsec_sa->esp_iv_len, 0, ipsec_sa->icv_len); ip->chksum = 0; @@ -878,7 +913,8 @@ static ipsec_sa_t *ipsec_out_single(odp_packet_t pkt, param.auth_range.offset = ip_offset; param.auth_range.length = odp_be_to_cpu_16(ip->tot_len); - param.hash_result_offset = ipsec_offset + _ODP_AHHDR_LEN; + param.hash_result_offset = ipsec_offset + _ODP_AHHDR_LEN + + ipsec_sa->esp_iv_len; stats_length = param.auth_range.length; } else {