From patchwork Mon Nov 13 14: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: 118756 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp1841320qgn; Mon, 13 Nov 2017 06:11:42 -0800 (PST) X-Google-Smtp-Source: AGs4zMbn6R3n3Fp+A7jK3jryw5sxFlZOsPLga4lpFrDslQNysjuITEQkCL0scN5kuhG0lBjbfCTM X-Received: by 10.200.55.37 with SMTP id o34mr1828646qtb.79.1510582302787; Mon, 13 Nov 2017 06:11:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510582302; cv=none; d=google.com; s=arc-20160816; b=ouMWx/N6Nn9V1Ezv4qtCo8oJkYVfnn54Y6BuXO8aDAWDAgvoYDpztArPiEjvjjyRRP DiRsr0NdfSjS0zl+88gVu6DxEBV8jauRUI5pAoZ3n29itc2vtr+XnJkMCvAzOi9WLiEY TXxneEZcSetVzsr48GxGJfCQ1/K586pBPJaJ8d1Q3bqI67sFiMIiHoyAOaeqXyLYizWK +kLw0vLhuOlGu7VSvQRBU1JJOKxBVM9P9ah5JygOEungRF89ldlQlTW80JAuhMzqrdJK HIm3avY3QYWQFL7ihmoZ6OUnDcRueORQ2+fmqvbxptaREOp8twTYeex659x9AbXsUlH+ fiyA== 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=eQJ2c3pNKwWLC3MGuvyh6U/N/4T3HbGtTgTSytmWOwc=; b=NmMWyedsd6IHeQYvQuBS0yf83CStnxJYWMyQ0Ayexk0SPeecZb/719Q27GvlFvcwhh Y9MaHCVMI2+03r4IZg6nqaqHt87LowPoFVEZUOcJTRgvDnKn9fAtXIAV7Di9aOuruCNN rdnzbWH3aS8cGdHi7lfly2kper9wiwqE2UYHrnQahiFfhvgUA/Ji2RZggLlQxmAYnFrZ Nne1XiGsSy+g+vbYs08ekmnbIM6Zsdnsjnsza55f1dD326LEgM02UEMIEEAt2QEF20lD zbxgjNJXEPAO6Z9YbW1mDGo25aipNuDTotP5g1474k9fwN2zaPDrTfVlsb5F4kETTRaR SCVQ== 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 n66si2070502qkh.382.2017.11.13.06.11.42; Mon, 13 Nov 2017 06:11:42 -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 487AB60BDF; Mon, 13 Nov 2017 14:11:42 +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 C2AEA60B47; Mon, 13 Nov 2017 14:01: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 B344A60B47; Mon, 13 Nov 2017 14:00:33 +0000 (UTC) Received: from forward106o.mail.yandex.net (forward106o.mail.yandex.net [37.140.190.187]) by lists.linaro.org (Postfix) with ESMTPS id 5551E60BDF for ; Mon, 13 Nov 2017 14:00:20 +0000 (UTC) Received: from mxback20j.mail.yandex.net (mxback20j.mail.yandex.net [IPv6:2a02:6b8:0:1619::114]) by forward106o.mail.yandex.net (Yandex) with ESMTP id 83373782AAD for ; Mon, 13 Nov 2017 17:00:18 +0300 (MSK) Received: from smtp4o.mail.yandex.net (smtp4o.mail.yandex.net [2a02:6b8:0:1a2d::28]) by mxback20j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id MtmInaJ4Ap-0IBK2RTb; Mon, 13 Nov 2017 17:00:18 +0300 Received: by smtp4o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id eBFPNklri7-0H8aCNkg; Mon, 13 Nov 2017 17:00:17 +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: Mon, 13 Nov 2017 17:00:08 +0300 Message-Id: <1510581611-13870-10-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1510581611-13870-1-git-send-email-odpbot@yandex.ru> References: <1510581611-13870-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 288 Subject: [lng-odp] [PATCH API-NEXT v6 9/12] 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: a908a4dead95321e84d6a8a23de060051dcd8969 ** Merge commit sha: 60f2c36c67f6b216666f85876af63f7091b1bff0 **/ 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 6a731e999..9ca215c23 100644 --- a/platform/linux-generic/odp_ipsec.c +++ b/platform/linux-generic/odp_ipsec.c @@ -385,6 +385,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 out; + } + param.override_iv_ptr = iv; + hdr_len = (ah.ah_len + 2) * 4; trl_len = 0; @@ -404,7 +414,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 { @@ -776,7 +787,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 */ @@ -803,16 +815,39 @@ 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; + /* 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 out; + + 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; @@ -822,7 +857,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 {