From patchwork Thu Nov 9 14:00:00 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: 118446 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp6627045qgn; Thu, 9 Nov 2017 06:00:27 -0800 (PST) X-Google-Smtp-Source: AGs4zMZviiXM06cxHXNV3goi/m9o1ru985N++xrHgB/Tij5DLAHT9ixVEzxPzpQOutxIKDmY4Mw8 X-Received: by 10.200.36.68 with SMTP id d4mr926366qtd.180.1510236027156; Thu, 09 Nov 2017 06:00:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510236027; cv=none; d=google.com; s=arc-20160816; b=brEF6ufm16t4XV45Xk097G2sdnxKt/p1VtIel1HTT+YkCbqJbVzTIeeMANX+5foL5r 2/qwZTQPD79myi0WNdMcUayyGIB3wibyXa+qFC5brO5V0dZyk8XM2zRO5KHxxJp6zSld BW/TQ5aRK4SmnQ1RpT+of/cQW7xlVIL8SUykIiXvwHCKrrNu6La3QSH/1CY4/9C5usX6 MPZpkhyztt7EgXKZuUiI+KYWfdA4g3bN0qN3Sev9uhgQFw1fBvGzSCT8Az/ajBP80hsg QIEIKP4lh2xOOBcK3H2zGBeZVlpy/RC0UvZlyha01D9PyK9aGZqCIikGyen4VOec8PdC G85g== 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=Y1fMK/oMb/n92PMJ/xmcFmQ3eGVd/t8j3YZr/LrYN4o=; b=PQaEfTkiettTFSqSgTlAVajqjG+G7a2F3XxKsjj5xq2dsehJrwJRDbhCZ/d7R2Ls7E mvl6MrOUbrslWsMfyz1vpPDxF2dSpFWwYYgnujlWNmCcuF/8mf0uqYNosbS6xEJFIpT9 cJ8Ox2ANDz2IBd9x+GgGiW+9SOs4VlGwsHXV/WCYc9fcydfb2xCiURBWUXH25/8EMcgJ T9MQymV22Mp9ZMFeqJ3C89BBF5nAs0CuXjdLcwlk3Tiww/pHbnqStw8t/Ny57ubLAEDr hpjX6p0d4elo0tQutZnDBdAQPMqiEEO1yCIANzHE2EW80noe82Qn2PMWNdUzCeq838SD sOjQ== 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 i48si3803758qta.66.2017.11.09.06.00.26; Thu, 09 Nov 2017 06:00:26 -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 4ED49607FE; Thu, 9 Nov 2017 14:00:26 +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 2301360762; Thu, 9 Nov 2017 14:00:23 +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 F287860C0F; Thu, 9 Nov 2017 14:00:13 +0000 (UTC) Received: from forward100o.mail.yandex.net (forward100o.mail.yandex.net [37.140.190.180]) by lists.linaro.org (Postfix) with ESMTPS id 658CB607FE for ; Thu, 9 Nov 2017 14:00:11 +0000 (UTC) Received: from mxback1j.mail.yandex.net (mxback1j.mail.yandex.net [IPv6:2a02:6b8:0:1619::10a]) by forward100o.mail.yandex.net (Yandex) with ESMTP id C83A62A2372B for ; Thu, 9 Nov 2017 17:00:09 +0300 (MSK) Received: from smtp2p.mail.yandex.net (smtp2p.mail.yandex.net [2a02:6b8:0:1472:2741:0:8b6:7]) by mxback1j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id 8Uvl8FKaBn-099q46mg; Thu, 09 Nov 2017 17:00:09 +0300 Received: by smtp2p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id 9u564oQ33p-09nKFpQ1; Thu, 09 Nov 2017 17:00:09 +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: Thu, 9 Nov 2017 17:00:00 +0300 Message-Id: <1510236007-28235-2-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1510236007-28235-1-git-send-email-odpbot@yandex.ru> References: <1510236007-28235-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 288 Subject: [lng-odp] [PATCH API-NEXT v3 1/8] linux-gen: ipsec: use counter instead of random IV for GCM 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 Reusing IV block with GCM results in disastrous consequences. Use counter instead of random-generated IV to remove possibility for IV reuse. 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: d22c949cc466bf28de559855a1cb525740578137 ** Merge commit sha: ba7b9d98bb5dfe0cf7d7d28767c7a9c02d421d2d **/ platform/linux-generic/include/odp_ipsec_internal.h | 16 +++++++++++++--- platform/linux-generic/odp_ipsec.c | 19 ++++++++++++++++++- platform/linux-generic/odp_ipsec_sad.c | 6 ++++++ 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/platform/linux-generic/include/odp_ipsec_internal.h b/platform/linux-generic/include/odp_ipsec_internal.h index 1340ca7bd..afc2f686e 100644 --- a/platform/linux-generic/include/odp_ipsec_internal.h +++ b/platform/linux-generic/include/odp_ipsec_internal.h @@ -118,9 +118,17 @@ struct ipsec_sa_s { uint8_t salt[IPSEC_MAX_SALT_LEN]; uint32_t salt_length; - unsigned dec_ttl : 1; - unsigned copy_dscp : 1; - unsigned copy_df : 1; + union { + unsigned flags; + struct { + unsigned dec_ttl : 1; + unsigned copy_dscp : 1; + unsigned copy_df : 1; + + /* Only for outbound */ + unsigned use_counter_iv : 1; + }; + }; union { struct { @@ -136,6 +144,8 @@ struct ipsec_sa_s { odp_atomic_u32_t tun_hdr_id; odp_atomic_u32_t seq; + odp_atomic_u64_t counter; /* for CTR/GCM */ + uint8_t tun_ttl; uint8_t tun_dscp; uint8_t tun_df; diff --git a/platform/linux-generic/odp_ipsec.c b/platform/linux-generic/odp_ipsec.c index e57736c2a..1aa437b8e 100644 --- a/platform/linux-generic/odp_ipsec.c +++ b/platform/linux-generic/odp_ipsec.c @@ -676,7 +676,24 @@ static ipsec_sa_t *ipsec_out_single(odp_packet_t pkt, ip_data_len + ipsec_sa->icv_len; - if (ipsec_sa->esp_iv_len) { + if (ipsec_sa->use_counter_iv) { + uint64_t ctr; + + /* Both GCM and CTR use 8-bit counters */ + 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; + } else if (ipsec_sa->esp_iv_len) { uint32_t len; len = odp_random_data(iv + ipsec_sa->salt_length, diff --git a/platform/linux-generic/odp_ipsec_sad.c b/platform/linux-generic/odp_ipsec_sad.c index f0b5b9e4a..5d20bb66c 100644 --- a/platform/linux-generic/odp_ipsec_sad.c +++ b/platform/linux-generic/odp_ipsec_sad.c @@ -207,6 +207,7 @@ odp_ipsec_sa_t odp_ipsec_sa_create(const odp_ipsec_sa_param_t *param) ipsec_sa->context = param->context; ipsec_sa->queue = param->dest_queue; ipsec_sa->mode = param->mode; + ipsec_sa->flags = 0; if (ODP_IPSEC_DIR_INBOUND == param->dir) { ipsec_sa->in.lookup_mode = param->inbound.lookup_mode; if (ODP_IPSEC_LOOKUP_DSTADDR_SPI == ipsec_sa->in.lookup_mode) @@ -315,6 +316,7 @@ odp_ipsec_sa_t odp_ipsec_sa_create(const odp_ipsec_sa_param_t *param) case ODP_CIPHER_ALG_AES128_GCM: #endif case ODP_CIPHER_ALG_AES_GCM: + ipsec_sa->use_counter_iv = 1; ipsec_sa->esp_iv_len = 8; ipsec_sa->esp_block_len = 16; crypto_param.iv.length = 12; @@ -323,6 +325,10 @@ odp_ipsec_sa_t odp_ipsec_sa_create(const odp_ipsec_sa_param_t *param) return ODP_IPSEC_SA_INVALID; } + if (1 == ipsec_sa->use_counter_iv && + ODP_IPSEC_DIR_OUTBOUND == param->dir) + odp_atomic_init_u64(&ipsec_sa->out.counter, 1); + crypto_param.auth_digest_len = ipsec_sa->icv_len; if (param->crypto.cipher_key_extra.length) { From patchwork Thu Nov 9 14:00:01 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: 118448 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp6631339qgn; Thu, 9 Nov 2017 06:03:20 -0800 (PST) X-Google-Smtp-Source: AGs4zMYvhriN1E477lb3e49qzNnknVhiKkddXfQT2JNbUKdTdLtHf3v1IJKlJyWb0TZ00Y5vyMHW X-Received: by 10.200.9.91 with SMTP id z27mr894153qth.207.1510236200226; Thu, 09 Nov 2017 06:03:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510236200; cv=none; d=google.com; s=arc-20160816; b=NdN8/r0yCQe8ae13B6H3RqPS/LcciuxqTEfZBv1XTu4yy06k2wxhd5xXvfVZw2NQCh wY4s0oZsupEME7kLz3Ba3OPoNIcc8C4C0NLeVBvVDaxCIcXoA6yIR+Gg1UhoKSHDMICY BpYGetdp7puBp4sdAG6Ngmyc8/3IMiFeths6DEcy0kl/aPutRVPCRZIEHcA5kdn4oR+b 6OV/PNTzADN62FMjqJQp+3tP5F5VUnhTNz/+65KoIRARirvnbs7w45EU9bwI9836QFH8 NILrg+74jWJyDJIzVOt96xfewEgb6i7cUB6gEZNHVANjDC8D/oglmU+3xFRzJtYyjHjz EQEw== 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=gZWlBVIxSXqXSU5MfrkIuQJo9OmUobHW+CCdj5KsImo=; b=ZiJifi7C5/s676p/43k5Ri6op5xHWwtHrba1is4jQjB2eYtfmZKIoA5n/wbwjl+JuG Oq+h2AHEhfL3vpfVNSdLiElbRAL6GgbeTuBOp20F9ZdPxLZJarytZe7oH4pZ2i/1krza JU7tKLbbKVAO63ThPgr99HyUYPijgoBqaFja+HBIAOB1h1172qKmRRMvs37ovOop7nbu pS667xFJZTy0Tz+EXD84kdN0ySQKbT/4OYKBgU3+VtdztLU9gS7Ll53ARoJ3gHqEoPCC XK3dxwcauMfShookCvd0DKYkNZ7X86+b77PDNHSG+LzxGMKHqGS6eu/8C028PSEMbqGT Yz9A== 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 u127si6279116qkf.280.2017.11.09.06.03.19; Thu, 09 Nov 2017 06:03:20 -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 BB61760C26; Thu, 9 Nov 2017 14:03:19 +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 221EC60CCE; Thu, 9 Nov 2017 14:00:33 +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 1B04B60C15; Thu, 9 Nov 2017 14:00:18 +0000 (UTC) Received: from forward102j.mail.yandex.net (forward102j.mail.yandex.net [5.45.198.243]) by lists.linaro.org (Postfix) with ESMTPS id 3614E609FD for ; Thu, 9 Nov 2017 14:00:12 +0000 (UTC) Received: from mxback1o.mail.yandex.net (mxback1o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::1b]) by forward102j.mail.yandex.net (Yandex) with ESMTP id C698356035D3 for ; Thu, 9 Nov 2017 17:00:10 +0300 (MSK) Received: from smtp2p.mail.yandex.net (smtp2p.mail.yandex.net [2a02:6b8:0:1472:2741:0:8b6:7]) by mxback1o.mail.yandex.net (nwsmtp/Yandex) with ESMTP id jTld8KMMHt-0A9SEtrA; Thu, 09 Nov 2017 17:00:10 +0300 Received: by smtp2p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id 9u564oQ33p-09newLAT; Thu, 09 Nov 2017 17:00:09 +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: Thu, 9 Nov 2017 17:00:01 +0300 Message-Id: <1510236007-28235-3-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1510236007-28235-1-git-send-email-odpbot@yandex.ru> References: <1510236007-28235-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 288 Subject: [lng-odp] [PATCH API-NEXT v3 2/8] linux-gen: ipsec: don't leak SA on creation error 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 Some paths during odp_ipsec_sa_create() can lead to SA leakage. Fix them by always releasing SA in error case. 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: d22c949cc466bf28de559855a1cb525740578137 ** Merge commit sha: ba7b9d98bb5dfe0cf7d7d28767c7a9c02d421d2d **/ platform/linux-generic/odp_ipsec_sad.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/linux-generic/odp_ipsec_sad.c b/platform/linux-generic/odp_ipsec_sad.c index 5d20bb66c..457b81d04 100644 --- a/platform/linux-generic/odp_ipsec_sad.c +++ b/platform/linux-generic/odp_ipsec_sad.c @@ -292,7 +292,7 @@ odp_ipsec_sa_t odp_ipsec_sa_create(const odp_ipsec_sa_param_t *param) ipsec_sa->icv_len = 16; break; default: - return ODP_IPSEC_SA_INVALID; + goto error; } switch (crypto_param.cipher_alg) { @@ -322,7 +322,7 @@ odp_ipsec_sa_t odp_ipsec_sa_create(const odp_ipsec_sa_param_t *param) crypto_param.iv.length = 12; break; default: - return ODP_IPSEC_SA_INVALID; + goto error; } if (1 == ipsec_sa->use_counter_iv && From patchwork Thu Nov 9 14:00:02 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: 118449 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp6632693qgn; Thu, 9 Nov 2017 06:04:14 -0800 (PST) X-Google-Smtp-Source: AGs4zMbMrWfBtaUmhEvKAppGupETWHkxXF4FQwcFzoICRJBKOSxXSr/x2g8X/2/F0i7AK9sY45Jc X-Received: by 10.237.61.118 with SMTP id h51mr897466qtf.36.1510236254784; Thu, 09 Nov 2017 06:04:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510236254; cv=none; d=google.com; s=arc-20160816; b=smDkr2m8AjXyDHhGgZK16e3/wMHjPPGkVOn73hnTCi/HLQWcIC+IGAiN9QMzUx7Wad eelnyUafOXvtKpQdaaKiz+BSeKfN+kC6MD8lI93se0PSI0YKf/0+XWMQF/ysRsfBLh1U o2GgDw6p8ZImC1xX+zO5mEWoVYg8T0Qh2lPGHRU7gF5Rf2VC9YzCKOlig+t6dVIAuyJW fNY9VTgh+pB7qu6XFwXg4j2yPkocL43KcNBBWxK3opXcWO5paqmaYECJXQ/vGLrmR4Gm GM75BXOix6GhrE67ADFLmdQJGpfnnUfpTDOeHvHf38s+T+41SuyPZxcKSRf+khIK6eYc 2eUw== 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=tNGEWNJUirgAhhq4s0TxjUcOyA6nr/Df9BATZop3CSY=; b=Keoq4/27g2okfnFOFfVjMiCXFJGjwuiCpZ/yTOKkPR3cUCmo7PBIf5s7wjP4KPHF1U CsOVJqTEs8RFvh9zL/BisKdYjouL0Ib9wW+WCQIyvpgZLAoo+2rG2UzM8kGwS6fr+FEP OobYfwzK/Q2T5OpmBvNGtk7BJLnJmlHDNE1s3ebPlwdeyp6D4pKkC5ClqZ7xxAW9P8og X000dnAddaMv1eOLzFzrzzbj71beJsJb4YuVtCv2ApXhDo24GGXS8kyjsL5/CGNzEEba QNnvP3WmiIU8doBr82HoYCL57vrLTE3U8N++RxLwS2ztmoOnc1tjtAMZ1D7icXVkF5oT /hQw== 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 p128si2389386qka.361.2017.11.09.06.04.14; Thu, 09 Nov 2017 06:04:14 -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 5B53961010; Thu, 9 Nov 2017 14:04:14 +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 729C160D3C; Thu, 9 Nov 2017 14:00: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 B63B56023D; Thu, 9 Nov 2017 14:00:20 +0000 (UTC) Received: from forward104p.mail.yandex.net (forward104p.mail.yandex.net [77.88.28.107]) by lists.linaro.org (Postfix) with ESMTPS id 61E646023D for ; Thu, 9 Nov 2017 14:00:13 +0000 (UTC) Received: from mxback3o.mail.yandex.net (mxback3o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::1d]) by forward104p.mail.yandex.net (Yandex) with ESMTP id C7DD5182D59 for ; Thu, 9 Nov 2017 17:00:11 +0300 (MSK) Received: from smtp2p.mail.yandex.net (smtp2p.mail.yandex.net [2a02:6b8:0:1472:2741:0:8b6:7]) by mxback3o.mail.yandex.net (nwsmtp/Yandex) with ESMTP id Z059gm0njq-0Bb4sCYQ; Thu, 09 Nov 2017 17:00:11 +0300 Received: by smtp2p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id 9u564oQ33p-0AnSpt2w; Thu, 09 Nov 2017 17:00:10 +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: Thu, 9 Nov 2017 17:00:02 +0300 Message-Id: <1510236007-28235-4-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1510236007-28235-1-git-send-email-odpbot@yandex.ru> References: <1510236007-28235-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 288 Subject: [lng-odp] [PATCH API-NEXT v3 3/8] api: crypto: add AES-GMAC declarations 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 Add AES-GMAC declarations to support RFC4543. 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: d22c949cc466bf28de559855a1cb525740578137 ** Merge commit sha: ba7b9d98bb5dfe0cf7d7d28767c7a9c02d421d2d **/ include/odp/api/spec/crypto.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/odp/api/spec/crypto.h b/include/odp/api/spec/crypto.h index 7dcb71264..34530c7f6 100644 --- a/include/odp/api/spec/crypto.h +++ b/include/odp/api/spec/crypto.h @@ -131,6 +131,16 @@ typedef enum { */ ODP_AUTH_ALG_AES_GCM, + /** AES in Galois/Counter MAC Mode + * + * @note Specification uses term AAD with GMAC. ODP uses packet + * payload for GMAC authentication, like the rest of MAC algorithms. + * Pass GMAC IV via session IV or per-packet IV override. + * + * @note Must be paired with cipher ODP_CIPHER_ALG_NULL + */ + ODP_AUTH_ALG_AES_GMAC, + /** @deprecated Use ODP_AUTH_ALG_MD5_HMAC instead */ ODP_DEPRECATE(ODP_AUTH_ALG_MD5_96), @@ -202,6 +212,9 @@ typedef union odp_crypto_auth_algos_t { /** ODP_AUTH_ALG_AES_GCM */ uint32_t aes_gcm : 1; + /** ODP_AUTH_ALG_AES_GMAC*/ + uint32_t aes_gmac : 1; + /** @deprecated Use md5_hmac instead */ uint32_t ODP_DEPRECATE(md5_96) : 1; From patchwork Thu Nov 9 14:00:03 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: 118447 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp6629598qgn; Thu, 9 Nov 2017 06:02:10 -0800 (PST) X-Google-Smtp-Source: ABhQp+S5w2Q1xLy54TuZ79I16+U2CmBmi3ISeG7StQYFB1tALJJegkz3/fS6zMnZe23aVFp3WsjV X-Received: by 10.129.87.215 with SMTP id l206mr380098ywb.190.1510236129917; Thu, 09 Nov 2017 06:02:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510236129; cv=none; d=google.com; s=arc-20160816; b=LAN5EO2Hshtxfeg2Tpg9liiQaRM/m+/I2GtMpX06Tj3qmsFJqrvHwKWkrV70pWRFr9 yZGjlPzU/EV/nkmdETPvMCucMAWpu7q/siNUAOJmRPBLUl2CTZtXhgQ66L07jABz3WpL xlIBAvvDjeyTe9xDM1bm0ocacgoDsyaad/ovmZkBtKUNrTn4ZoZRGxTKLcwkyL7J/VUh 9TSCo6JQH7vlb8FrFAzyOPFklrDvswIbO8vS5nDgP6eXuquZTZSX5IIuj0HojNWp6cLg yO48ajCQD/VVuKmMrznl5OTNq0Wuhxv6nRJRI6JafblhVjhnE1YcGREWyNFNUNmDeiDg 0+2w== 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=lX9AxZaryDfF5BAiUShCOPd3xIXruYa7thQzgXjppLU=; b=0qJ9JJywj7Uv1X7yEGSPCaNxQuuw/+3tqYfQzqk1Yq3nYjDxmHtE10WXGVMg/4r5g5 iwAI00muv13DQ+QZWsrbZgppRTpTHDDrM1uXVAPBi1lVWLajwds9caJ7a5HhmwNlkZVd yRSlJ80IvD1AcHQNaPXSa06ib1bR77LtwMvdjXEZY2zH528AQqWBGKqfi1DuiahVUEcS A2FUPc+tp3tEW3cUzL/aPrfzVil5q5xGPsbGUMv/URIgo03xm739tgq61poMg2BjKLRk eVSYxs40DLgfsaa1cc9nvLj/vMx0JbpZ2VkjxWaMv1bt+sAoAxRDVBdvkDpvJA5ssrQx OPog== 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 t126si1146288qkc.467.2017.11.09.06.02.09; Thu, 09 Nov 2017 06:02:09 -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 72DC761015; Thu, 9 Nov 2017 14:02:09 +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.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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 C6BD560C1C; Thu, 9 Nov 2017 14:00:30 +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 882A060C15; Thu, 9 Nov 2017 14:00:17 +0000 (UTC) Received: from forward104j.mail.yandex.net (forward104j.mail.yandex.net [5.45.198.247]) by lists.linaro.org (Postfix) with ESMTPS id E2BD4607F6 for ; Thu, 9 Nov 2017 14:00:14 +0000 (UTC) Received: from mxback5o.mail.yandex.net (mxback5o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::1f]) by forward104j.mail.yandex.net (Yandex) with ESMTP id 65D3640E3C for ; Thu, 9 Nov 2017 17:00:12 +0300 (MSK) Received: from smtp2p.mail.yandex.net (smtp2p.mail.yandex.net [2a02:6b8:0:1472:2741:0:8b6:7]) by mxback5o.mail.yandex.net (nwsmtp/Yandex) with ESMTP id lanubBJwFl-0CROH1Op; Thu, 09 Nov 2017 17:00:12 +0300 Received: by smtp2p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id 9u564oQ33p-0BnKR0tl; Thu, 09 Nov 2017 17:00:11 +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: Thu, 9 Nov 2017 17:00:03 +0300 Message-Id: <1510236007-28235-5-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1510236007-28235-1-git-send-email-odpbot@yandex.ru> References: <1510236007-28235-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 288 Subject: [lng-odp] [PATCH API-NEXT v3 4/8] validation: crypto: add AES-GMAC testcase 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 Add AES-GMAC test vector based on draft-mcgrew-gcm-test-01. 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: d22c949cc466bf28de559855a1cb525740578137 ** Merge commit sha: ba7b9d98bb5dfe0cf7d7d28767c7a9c02d421d2d **/ test/validation/api/crypto/crypto.h | 2 ++ test/validation/api/crypto/odp_crypto_test_inp.c | 46 ++++++++++++++++++++++++ test/validation/api/crypto/test_vectors.h | 33 +++++++++++++++++ 3 files changed, 81 insertions(+) diff --git a/test/validation/api/crypto/crypto.h b/test/validation/api/crypto/crypto.h index 71f862ec3..550d2bbff 100644 --- a/test/validation/api/crypto/crypto.h +++ b/test/validation/api/crypto/crypto.h @@ -32,6 +32,8 @@ void crypto_test_gen_alg_hmac_sha256(void); void crypto_test_check_alg_hmac_sha256(void); void crypto_test_gen_alg_hmac_sha512(void); void crypto_test_check_alg_hmac_sha512(void); +void crypto_test_gen_alg_aes_gmac(void); +void crypto_test_check_alg_aes_gmac(void); /* test arrays: */ extern odp_testinfo_t crypto_suite[]; diff --git a/test/validation/api/crypto/odp_crypto_test_inp.c b/test/validation/api/crypto/odp_crypto_test_inp.c index f05780377..596c8370b 100644 --- a/test/validation/api/crypto/odp_crypto_test_inp.c +++ b/test/validation/api/crypto/odp_crypto_test_inp.c @@ -50,6 +50,8 @@ static const char *auth_alg_name(odp_auth_alg_t auth) return "ODP_AUTH_ALG_SHA512_HMAC"; case ODP_AUTH_ALG_AES_GCM: return "ODP_AUTH_ALG_AES_GCM"; + case ODP_AUTH_ALG_AES_GMAC: + return "ODP_AUTH_ALG_AES_GMAC"; default: return "Unknown"; } @@ -341,6 +343,9 @@ static void alg_test(odp_crypto_op_t op, if (auth_alg == ODP_AUTH_ALG_AES_GCM && !(capa.auths.bit.aes_gcm)) rc = -1; + if (auth_alg == ODP_AUTH_ALG_AES_GMAC && + !(capa.auths.bit.aes_gmac)) + rc = -1; if (auth_alg == ODP_AUTH_ALG_MD5_HMAC && !(capa.auths.bit.md5_hmac)) rc = -1; @@ -581,6 +586,10 @@ static int check_alg_support(odp_cipher_alg_t cipher, odp_auth_alg_t auth) if (!capability.auths.bit.aes_gcm) return ODP_TEST_INACTIVE; break; + case ODP_AUTH_ALG_AES_GMAC: + if (!capability.auths.bit.aes_gmac) + return ODP_TEST_INACTIVE; + break; default: fprintf(stderr, "Unsupported authentication algorithm\n"); return ODP_TEST_INACTIVE; @@ -1025,6 +1034,39 @@ void crypto_test_check_alg_hmac_sha512(void) false); } +static int check_alg_aes_gmac(void) +{ + return check_alg_support(ODP_CIPHER_ALG_NULL, ODP_AUTH_ALG_AES_GMAC); +} + +void crypto_test_gen_alg_aes_gmac(void) +{ + unsigned int test_vec_num = (sizeof(aes_gmac_reference) / + sizeof(aes_gmac_reference[0])); + unsigned int i; + + for (i = 0; i < test_vec_num; i++) + alg_test(ODP_CRYPTO_OP_ENCODE, + ODP_CIPHER_ALG_NULL, + ODP_AUTH_ALG_AES_GMAC, + &aes_gmac_reference[i], + false); +} + +void crypto_test_check_alg_aes_gmac(void) +{ + unsigned int test_vec_num = (sizeof(aes_gmac_reference) / + sizeof(aes_gmac_reference[0])); + unsigned int i; + + for (i = 0; i < test_vec_num; i++) + alg_test(ODP_CRYPTO_OP_DECODE, + ODP_CIPHER_ALG_NULL, + ODP_AUTH_ALG_AES_GMAC, + &aes_gmac_reference[i], + false); +} + int crypto_suite_sync_init(void) { suite_context.pool = odp_pool_lookup("packet_pool"); @@ -1122,6 +1164,10 @@ odp_testinfo_t crypto_suite[] = { check_alg_hmac_sha512), ODP_TEST_INFO_CONDITIONAL(crypto_test_check_alg_hmac_sha512, check_alg_hmac_sha512), + ODP_TEST_INFO_CONDITIONAL(crypto_test_gen_alg_aes_gmac, + check_alg_aes_gmac), + ODP_TEST_INFO_CONDITIONAL(crypto_test_check_alg_aes_gmac, + check_alg_aes_gmac), ODP_TEST_INFO_NULL, }; diff --git a/test/validation/api/crypto/test_vectors.h b/test/validation/api/crypto/test_vectors.h index 652968be7..5cc143660 100644 --- a/test/validation/api/crypto/test_vectors.h +++ b/test/validation/api/crypto/test_vectors.h @@ -361,6 +361,39 @@ static crypto_test_reference_t aes_gcm_reference[] = { } }; +static crypto_test_reference_t aes_gmac_reference[] = { + { + .auth_key_length = AES128_GCM_KEY_LEN, + .auth_key = { 0x4c, 0x80, 0xcd, 0xef, 0xbb, 0x5d, 0x10, 0xda, + 0x90, 0x6a, 0xc7, 0x3c, 0x36, 0x13, 0xa6, 0x34}, + .iv_length = AES_GCM_IV_LEN, + .iv = { 0x22, 0x43, 0x3c, 0x64, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00 }, + .length = 68, + .plaintext = { 0x00, 0x00, 0x43, 0x21, 0x00, 0x00, 0x00, 0x07, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x45, 0x00, 0x00, 0x30, 0xda, 0x3a, 0x00, 0x00, + 0x80, 0x01, 0xdf, 0x3b, 0xc0, 0xa8, 0x00, 0x05, + 0xc0, 0xa8, 0x00, 0x01, 0x08, 0x00, 0xc6, 0xcd, + 0x02, 0x00, 0x07, 0x00, 0x61, 0x62, 0x63, 0x64, + 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, + 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, + 0x01, 0x02, 0x02, 0x01 }, + .ciphertext = { 0x00, 0x00, 0x43, 0x21, 0x00, 0x00, 0x00, 0x07, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x45, 0x00, 0x00, 0x30, 0xda, 0x3a, 0x00, 0x00, + 0x80, 0x01, 0xdf, 0x3b, 0xc0, 0xa8, 0x00, 0x05, + 0xc0, 0xa8, 0x00, 0x01, 0x08, 0x00, 0xc6, 0xcd, + 0x02, 0x00, 0x07, 0x00, 0x61, 0x62, 0x63, 0x64, + 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, + 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, + 0x01, 0x02, 0x02, 0x01 }, + .digest_length = AES_GCM_DIGEST_LEN, + .digest = { 0xf2, 0xa9, 0xa8, 0x36, 0xe1, 0x55, 0x10, 0x6a, + 0xa8, 0xdc, 0xd6, 0x18, 0xe4, 0x09, 0x9a, 0xaa } + }, +}; + static crypto_test_reference_t hmac_md5_reference[] = { { .auth_key_length = HMAC_MD5_KEY_LEN, From patchwork Thu Nov 9 14:00:04 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: 118452 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp6635376qgn; Thu, 9 Nov 2017 06:06:06 -0800 (PST) X-Google-Smtp-Source: AGs4zMbxlvSiXm8rnOrsEce6Bt16sfe3xQknEHtXO4jfwGKZUyBE48MA121wkHU6HhvQDc53oAht X-Received: by 10.107.31.143 with SMTP id f137mr716857iof.86.1510236365869; Thu, 09 Nov 2017 06:06:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510236365; cv=none; d=google.com; s=arc-20160816; b=y8V8oVi2XwYtB2vDHSu2XI3tuh9X3rTAjEfyV0wd06UeFaHRM6Pw0KO5ZzqZVNs/kF Xok8XvFx9A51uvLURfhqAud4OWCAIltWSSxIQH5B1tLV2WrLdxHW9716ncfU8STdVZFX zzPROBf0sGogq2zD1Y9+Ek/TpZ2h6WCahrigX/2kagjAa3p4KZUIrUU1AQeejkxfdTI5 qmUs97VIP0FbELLXmzvPe9BzmdVXmOQIhRO+8542Zdjbha+pgJT/cOWane7HH26KWotg Jq+M+gHrbWhoGa1P4PAUm7xGxjPknNBpPIyegCNe8RUN7OQxpHbB8Oo++mJWwpbDHLVk GWfQ== 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=7e468IB5xAHHv6jLsuWCN+o8WTqY0IVSsolKck3tikM=; b=ygv9NBfPhhOQJqmmi6k+PPmf0v9ReIyAaDX3Nh2HToDYzVBDwYdk4BLrvIeRHgQI9l hdMiTZMswqeygCxFgD+XdSVszQyqnPfcVEXD2smAPPAdPPl9rY+oB4y5kAbBvFjOWw/N uuuB8iUatqF8NYffjYfYN5zBpu5WdTJt/tqGRTYQAFPckBx89Z1K7wCwUATDQ5tmFt1N dS0UfMBOnLJkSnFKFBB9zVlfZmGx/avKhDMcWwxP7tyutFXvGRGUal8kifeVNW8soQLu 7YWlsmyXu5fkCYmup8Hw9et4hrp7NBgi/GFoiCz0TAnF2jfRnFWzinp7oEVP+iIsl2aH eh0w== 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 z1si6636593itd.6.2017.11.09.06.06.05; Thu, 09 Nov 2017 06:06:05 -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 5E66360D35; Thu, 9 Nov 2017 14:06:05 +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 4338761011; Thu, 9 Nov 2017 14:00:59 +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 E87D3609FF; Thu, 9 Nov 2017 14:00:23 +0000 (UTC) Received: from forward105o.mail.yandex.net (forward105o.mail.yandex.net [37.140.190.183]) by lists.linaro.org (Postfix) with ESMTPS id 9C4AC607FE for ; Thu, 9 Nov 2017 14:00:15 +0000 (UTC) Received: from mxback11j.mail.yandex.net (mxback11j.mail.yandex.net [IPv6:2a02:6b8:0:1619::84]) by forward105o.mail.yandex.net (Yandex) with ESMTP id AFE8B4442BB5 for ; Thu, 9 Nov 2017 17:00:13 +0300 (MSK) Received: from smtp2p.mail.yandex.net (smtp2p.mail.yandex.net [2a02:6b8:0:1472:2741:0:8b6:7]) by mxback11j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id trOeHbQRT9-0DYmLei9; Thu, 09 Nov 2017 17:00:13 +0300 Received: by smtp2p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id 9u564oQ33p-0CnGBrdc; Thu, 09 Nov 2017 17:00:12 +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: Thu, 9 Nov 2017 17:00:04 +0300 Message-Id: <1510236007-28235-6-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1510236007-28235-1-git-send-email-odpbot@yandex.ru> References: <1510236007-28235-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 288 Subject: [lng-odp] [PATCH API-NEXT v3 5/8] linux-gen: crypto: add AES-GMAC implementation 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 on top of OpenSSL AES-GCM with all text going into AAD part. 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: d22c949cc466bf28de559855a1cb525740578137 ** Merge commit sha: ba7b9d98bb5dfe0cf7d7d28767c7a9c02d421d2d **/ .../linux-generic/include/odp_crypto_internal.h | 5 +- platform/linux-generic/odp_crypto.c | 149 ++++++++++++++++++++- 2 files changed, 152 insertions(+), 2 deletions(-) diff --git a/platform/linux-generic/include/odp_crypto_internal.h b/platform/linux-generic/include/odp_crypto_internal.h index 12d1720b7..21174daa4 100644 --- a/platform/linux-generic/include/odp_crypto_internal.h +++ b/platform/linux-generic/include/odp_crypto_internal.h @@ -51,7 +51,10 @@ struct odp_crypto_generic_session { uint8_t key[EVP_MAX_KEY_LENGTH]; uint32_t key_length; uint32_t bytes; - const EVP_MD *evp_md; + union { + const EVP_MD *evp_md; + const EVP_CIPHER *evp_cipher; + }; crypto_func_t func; } auth; }; diff --git a/platform/linux-generic/odp_crypto.c b/platform/linux-generic/odp_crypto.c index 3174feee0..ac0fa337b 100644 --- a/platform/linux-generic/odp_crypto.c +++ b/platform/linux-generic/odp_crypto.c @@ -38,7 +38,9 @@ * Keep sorted: first by key length, then by IV length */ static const odp_crypto_cipher_capability_t cipher_capa_null[] = { -{.key_len = 0, .iv_len = 0} }; +{.key_len = 0, .iv_len = 0}, +/* Special case for GMAC */ +{.key_len = 0, .iv_len = 12} }; static const odp_crypto_cipher_capability_t cipher_capa_des[] = { {.key_len = 24, .iv_len = 8} }; @@ -83,6 +85,9 @@ static const odp_crypto_auth_capability_t auth_capa_sha512_hmac[] = { static const odp_crypto_auth_capability_t auth_capa_aes_gcm[] = { {.digest_len = 16, .key_len = 0, .aad_len = {.min = 8, .max = 12, .inc = 4} } }; +static const odp_crypto_auth_capability_t auth_capa_aes_gmac[] = { +{.digest_len = 16, .key_len = 16, .aad_len = {.min = 0, .max = 0, .inc = 0} } }; + typedef struct odp_crypto_global_s odp_crypto_global_t; struct odp_crypto_global_s { @@ -235,6 +240,33 @@ odp_crypto_alg_err_t auth_check(odp_packet_t pkt, } static +int internal_aad(EVP_CIPHER_CTX *ctx, + odp_packet_t pkt, + const odp_crypto_packet_op_param_t *param) +{ + uint32_t offset = param->auth_range.offset; + uint32_t len = param->auth_range.length; + int dummy_len; + int ret; + + ODP_ASSERT(offset + len <= odp_packet_len(pkt)); + + while (len > 0) { + uint32_t seglen = 0; /* GCC */ + void *mapaddr = odp_packet_offset(pkt, offset, &seglen, NULL); + uint32_t maclen = len > seglen ? seglen : len; + + EVP_EncryptUpdate(ctx, NULL, &dummy_len, mapaddr, maclen); + offset += maclen; + len -= maclen; + } + + ret = EVP_EncryptFinal_ex(ctx, NULL, &dummy_len); + + return ret; +} + +static int internal_encrypt(EVP_CIPHER_CTX *ctx, odp_packet_t pkt, const odp_crypto_packet_op_param_t *param) @@ -555,6 +587,106 @@ static int process_aes_gcm_param(odp_crypto_generic_session_t *session, return 0; } +static +odp_crypto_alg_err_t aes_gmac_gen(odp_packet_t pkt, + const odp_crypto_packet_op_param_t *param, + odp_crypto_generic_session_t *session) +{ + EVP_CIPHER_CTX *ctx; + void *iv_ptr; + uint8_t block[EVP_MAX_MD_SIZE]; + int ret; + + if (param->override_iv_ptr) + iv_ptr = param->override_iv_ptr; + else if (session->p.iv.data) + iv_ptr = session->cipher.iv_data; + else + return ODP_CRYPTO_ALG_ERR_IV_INVALID; + + /* Encrypt it */ + ctx = EVP_CIPHER_CTX_new(); + EVP_EncryptInit_ex(ctx, session->auth.evp_cipher, NULL, + session->auth.key, NULL); + EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_IVLEN, + session->p.iv.length, NULL); + EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, iv_ptr); + EVP_CIPHER_CTX_set_padding(ctx, 0); + + ret = internal_aad(ctx, pkt, param); + + EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_GET_TAG, + session->p.auth_digest_len, block); + odp_packet_copy_from_mem(pkt, param->hash_result_offset, + session->p.auth_digest_len, block); + + EVP_CIPHER_CTX_free(ctx); + + return ret <= 0 ? ODP_CRYPTO_ALG_ERR_DATA_SIZE : + ODP_CRYPTO_ALG_ERR_NONE; +} + +static +odp_crypto_alg_err_t aes_gmac_check(odp_packet_t pkt, + const odp_crypto_packet_op_param_t *param, + odp_crypto_generic_session_t *session) +{ + EVP_CIPHER_CTX *ctx; + void *iv_ptr; + uint8_t block[EVP_MAX_MD_SIZE]; + int ret; + + if (param->override_iv_ptr) + iv_ptr = param->override_iv_ptr; + else if (session->p.iv.data) + iv_ptr = session->cipher.iv_data; + else + return ODP_CRYPTO_ALG_ERR_IV_INVALID; + + /* Decrypt it */ + ctx = EVP_CIPHER_CTX_new(); + EVP_DecryptInit_ex(ctx, session->auth.evp_cipher, NULL, + session->auth.key, NULL); + EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_IVLEN, + session->p.iv.length, NULL); + EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv_ptr); + EVP_CIPHER_CTX_set_padding(ctx, 0); + + odp_packet_copy_to_mem(pkt, param->hash_result_offset, + session->p.auth_digest_len, block); + EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_TAG, + session->p.auth_digest_len, block); + + ret = internal_aad(ctx, pkt, param); + + EVP_CIPHER_CTX_free(ctx); + + return ret <= 0 ? ODP_CRYPTO_ALG_ERR_ICV_CHECK : + ODP_CRYPTO_ALG_ERR_NONE; +} + +static int process_aes_gmac_param(odp_crypto_generic_session_t *session, + const EVP_CIPHER *cipher) +{ + /* Verify Key len is valid */ + if ((uint32_t)EVP_CIPHER_key_length(cipher) != + session->p.auth_key.length) + return -1; + + memcpy(session->auth.key, session->p.auth_key.data, + session->p.auth_key.length); + + session->auth.evp_cipher = cipher; + + /* Set function */ + if (ODP_CRYPTO_OP_ENCODE == session->p.op) + session->auth.func = aes_gmac_gen; + else + session->auth.func = aes_gmac_check; + + return 0; +} + static int process_auth_param(odp_crypto_generic_session_t *session, uint32_t key_length, const EVP_MD *evp_md) @@ -600,6 +732,7 @@ int odp_crypto_capability(odp_crypto_capability_t *capa) capa->auths.bit.sha256_hmac = 1; capa->auths.bit.sha512_hmac = 1; capa->auths.bit.aes_gcm = 1; + capa->auths.bit.aes_gmac = 1; #if ODP_DEPRECATED_API capa->ciphers.bit.aes128_cbc = 1; @@ -687,6 +820,10 @@ int odp_crypto_auth_capability(odp_auth_alg_t auth, src = auth_capa_aes_gcm; num = sizeof(auth_capa_aes_gcm) / size; break; + case ODP_AUTH_ALG_AES_GMAC: + src = auth_capa_aes_gmac; + num = sizeof(auth_capa_aes_gmac) / size; + break; default: return -1; } @@ -849,6 +986,16 @@ odp_crypto_session_create(odp_crypto_session_param_t *param, rc = -1; } break; + case ODP_AUTH_ALG_AES_GMAC: + if (param->auth_key.length == 16) + rc = process_aes_gmac_param(session, EVP_aes_128_gcm()); + else if (param->auth_key.length == 24) + rc = process_aes_gmac_param(session, EVP_aes_192_gcm()); + else if (param->auth_key.length == 32) + rc = process_aes_gmac_param(session, EVP_aes_256_gcm()); + else + rc = -1; + break; default: rc = -1; } From patchwork Thu Nov 9 14: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: 118451 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp6633918qgn; Thu, 9 Nov 2017 06:05:02 -0800 (PST) X-Google-Smtp-Source: AGs4zMbPuZ8kmSFQD6qjds+3tWQw5u4c4jec8I/A7jw3DrsaFs8R4rIgH+2raMs9YxMYGdqMU4CM X-Received: by 10.55.20.153 with SMTP id 25mr881769qku.315.1510236302571; Thu, 09 Nov 2017 06:05:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510236302; cv=none; d=google.com; s=arc-20160816; b=NVgXjYj0HOvNMdfMn+UbIpvbIvMR9LasF5BICThr1/CGWNKiyy7SFebnfsk1o6itD9 qT0Qv5RjoVME/G1CdRM48OIVn4apUxDhs32YkFdSGsas/crt+p0Na6egNGfABduH/mC7 rLWeW8fSXCFSaK/8DzHJYO4P3F6zJsoHk8oZCaz7Ji0WqHDBkNG0LyMIexbrlh6T+ggE F5GO6Bic0q6PUsdPegZl+V7lRl1OeL3wEDuV+V23ith6YnEEUnCEX/uhgJ9ChnkcuxN9 0qC5rZjqBx+heFmYVf9jHC8Xp1+t0xK2nRr1ovZ2OXgz6/IpfN8atrS53+H5AUEFHwAT ngFw== 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=e6tRcwcm3FJNgQavy6lRoBe4N8Uh2MATTjg8eDbXjGc=; b=A65FbNQb/g8ox3Q823G+F3wNs+oI60P1Yl35/k7QMeHjxbgU6DnUYXDAbaKBqGe28L QfrvXDHsNyRobYAGzoLJRPwUMbF9uofjb2DYJ18ek43m5rIJne/UlwgUu4azXSNFYdF9 wxrXzo6cPjy48HFPn6T7K4XXdsYom9D7xCmHRMOeHSKaq+qcb8eptS0RwzxNZ2ENkUMW faMJW2Szb3PdS8UEjL2nfVH/+61j02YDyv2bfq+6k10zTOVah7lBXCGrjfxCaOP6B8Wv 0LpGrEPEXlDOqAiBwckyvvp7PEiKBjj1CJu0ebDFnd0oHy+YUwZsV556+sUGHgD59/o0 CZLw== 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 l15si6548559qtc.440.2017.11.09.06.05.02; Thu, 09 Nov 2017 06:05: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 408DF60CCE; Thu, 9 Nov 2017 14:05: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,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 0803561004; Thu, 9 Nov 2017 14:00:55 +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 4AB96607F1; Thu, 9 Nov 2017 14:00:21 +0000 (UTC) Received: from forward106j.mail.yandex.net (forward106j.mail.yandex.net [5.45.198.249]) by lists.linaro.org (Postfix) with ESMTPS id 6632D609FF for ; Thu, 9 Nov 2017 14:00:16 +0000 (UTC) Received: from mxback3j.mail.yandex.net (mxback3j.mail.yandex.net [IPv6:2a02:6b8:0:1619::10c]) by forward106j.mail.yandex.net (Yandex) with ESMTP id AC0D11802D6C for ; Thu, 9 Nov 2017 17:00:14 +0300 (MSK) Received: from smtp2p.mail.yandex.net (smtp2p.mail.yandex.net [2a02:6b8:0:1472:2741:0:8b6:7]) by mxback3j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id tmULjHmSho-0ExmugXW; Thu, 09 Nov 2017 17:00:14 +0300 Received: by smtp2p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id 9u564oQ33p-0DnWToOG; Thu, 09 Nov 2017 17:00:14 +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: Thu, 9 Nov 2017 17:00:05 +0300 Message-Id: <1510236007-28235-7-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1510236007-28235-1-git-send-email-odpbot@yandex.ru> References: <1510236007-28235-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 288 Subject: [lng-odp] [PATCH API-NEXT v3 6/8] linux-gen: ipsec: add support for AES-GMAC-ESP 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-ESP support. 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: d22c949cc466bf28de559855a1cb525740578137 ** Merge commit sha: ba7b9d98bb5dfe0cf7d7d28767c7a9c02d421d2d **/ platform/linux-generic/odp_ipsec_sad.c | 60 +++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/platform/linux-generic/odp_ipsec_sad.c b/platform/linux-generic/odp_ipsec_sad.c index 457b81d04..369d927ee 100644 --- a/platform/linux-generic/odp_ipsec_sad.c +++ b/platform/linux-generic/odp_ipsec_sad.c @@ -263,6 +263,36 @@ odp_ipsec_sa_t odp_ipsec_sa_create(const odp_ipsec_sa_param_t *param) crypto_param.auth_alg = param->crypto.auth_alg; crypto_param.auth_key = param->crypto.auth_key; + switch (crypto_param.cipher_alg) { + case ODP_CIPHER_ALG_NULL: + ipsec_sa->esp_iv_len = 0; + ipsec_sa->esp_block_len = 1; + break; + case ODP_CIPHER_ALG_DES: + case ODP_CIPHER_ALG_3DES_CBC: + ipsec_sa->esp_iv_len = 8; + ipsec_sa->esp_block_len = 8; + break; +#if ODP_DEPRECATED_API + case ODP_CIPHER_ALG_AES128_CBC: +#endif + case ODP_CIPHER_ALG_AES_CBC: + ipsec_sa->esp_iv_len = 16; + ipsec_sa->esp_block_len = 16; + break; +#if ODP_DEPRECATED_API + case ODP_CIPHER_ALG_AES128_GCM: +#endif + case ODP_CIPHER_ALG_AES_GCM: + ipsec_sa->use_counter_iv = 1; + ipsec_sa->esp_iv_len = 8; + ipsec_sa->esp_block_len = 16; + ipsec_sa->icv_len = 16; + break; + default: + goto error; + } + switch (crypto_param.auth_alg) { case ODP_AUTH_ALG_NULL: ipsec_sa->icv_len = 0; @@ -291,35 +321,13 @@ odp_ipsec_sa_t odp_ipsec_sa_create(const odp_ipsec_sa_param_t *param) case ODP_AUTH_ALG_AES_GCM: ipsec_sa->icv_len = 16; break; - default: - goto error; - } - - switch (crypto_param.cipher_alg) { - case ODP_CIPHER_ALG_NULL: - ipsec_sa->esp_iv_len = 0; - ipsec_sa->esp_block_len = 1; - break; - case ODP_CIPHER_ALG_DES: - case ODP_CIPHER_ALG_3DES_CBC: - ipsec_sa->esp_iv_len = 8; - ipsec_sa->esp_block_len = 8; - break; -#if ODP_DEPRECATED_API - case ODP_CIPHER_ALG_AES128_CBC: -#endif - case ODP_CIPHER_ALG_AES_CBC: - ipsec_sa->esp_iv_len = 16; - ipsec_sa->esp_block_len = 16; - break; -#if ODP_DEPRECATED_API - case ODP_CIPHER_ALG_AES128_GCM: -#endif - case ODP_CIPHER_ALG_AES_GCM: + case ODP_AUTH_ALG_AES_GMAC: + if (ODP_CIPHER_ALG_NULL != crypto_param.cipher_alg) + return ODP_IPSEC_SA_INVALID; ipsec_sa->use_counter_iv = 1; ipsec_sa->esp_iv_len = 8; ipsec_sa->esp_block_len = 16; - crypto_param.iv.length = 12; + ipsec_sa->icv_len = 16; break; default: goto error; From patchwork Thu Nov 9 14:00:07 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: 118450 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp6632777qgn; Thu, 9 Nov 2017 06:04:17 -0800 (PST) X-Google-Smtp-Source: AGs4zMYx8HILoIPoZWIMzb1eiiUjFZjeSMFH1o1QRVMYbJ3Ld6KeKA0Iyp2Jdd2WaLKgnSVc9may X-Received: by 10.200.63.79 with SMTP id w15mr871728qtk.224.1510236257842; Thu, 09 Nov 2017 06:04:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510236257; cv=none; d=google.com; s=arc-20160816; b=oRwHHGqJYCQR+rSxNhaa2FP3tM3ogdcbZLWFBySnml+epbkEDMy+2RtakDS+NAqNHH 8cG4Sgh/8dFUN22TsBksdtbTVJblMDiKYZGn9Eq2xNfqaC20kXqA9M3CYZo0vtMQF3Yw q38JkM4fpEwDYB/zMnhhtS1rDqYgDX+eHLeeqq12hOUzTat1x2fzcqzYXsXz9Mo5nAEr Q/i8tpVsNKYw7LuHtjPhNjs/isFbpftZM8+UFl1gGbmyG7uSCdsjpGB+h+VgNbI7GO56 6Bszk7EPGb9DCpmCw9jAic1L2tJte8IMR5WHpusQc8vX8Y8FYX5sgaldAqC9QeAQoB/C NcEw== 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=Nk+ad48OJ5pu0rjN1d1tShfhy/8JnnOI4STaVFWD9ME=; b=Vp8sMCMHQ4bxhonJLowEp2/4vt5IEbM/08xbqod5dOk+l6j9cCJwOmgftK9kVQOSrT 91tERzKzpkb6WIXUNRU7t5LORynBr+ndvEkINvFU5birqoLSs9NczrQ0DfbXuiqBIyea UPWcaAoptNqGjd/Yk4uNW0oLJ65vChE2+O4f3w5f7+DGZXYxNu+U0y+tLZ4sjcvrW91i ltYozfKCxlpoEvIUgYOIy2J11yJzw1HVrc3cXFddYQe+ky/RNcAmWuo+njYqHgCLP6Qs ZSrIQ2PIB+Rl51EH1E6qSe/LYwtE4c8HooRF+9/llrHTz2KODi9jE26VPoheTu+fu2OF kxJg== 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 x42si1045114qtb.7.2017.11.09.06.04.17; Thu, 09 Nov 2017 06:04:17 -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 6080F60CDF; Thu, 9 Nov 2017 14:04:17 +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 BFA4061001; Thu, 9 Nov 2017 14:00:48 +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 3381E60762; Thu, 9 Nov 2017 14:00:21 +0000 (UTC) Received: from forward102j.mail.yandex.net (forward102j.mail.yandex.net [5.45.198.243]) by lists.linaro.org (Postfix) with ESMTPS id 1E179607F1 for ; Thu, 9 Nov 2017 14:00:17 +0000 (UTC) Received: from mxback12g.mail.yandex.net (mxback12g.mail.yandex.net [IPv6:2a02:6b8:0:1472:2741:0:8b7:91]) by forward102j.mail.yandex.net (Yandex) with ESMTP id CACFB56035CD for ; Thu, 9 Nov 2017 17:00:15 +0300 (MSK) Received: from smtp2p.mail.yandex.net (smtp2p.mail.yandex.net [2a02:6b8:0:1472:2741:0:8b6:7]) by mxback12g.mail.yandex.net (nwsmtp/Yandex) with ESMTP id AofTedtdnQ-0Fm8oIhb; Thu, 09 Nov 2017 17:00:15 +0300 Received: by smtp2p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id 9u564oQ33p-0FnC4jQG; Thu, 09 Nov 2017 17: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: Thu, 9 Nov 2017 17:00:07 +0300 Message-Id: <1510236007-28235-9-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1510236007-28235-1-git-send-email-odpbot@yandex.ru> References: <1510236007-28235-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 288 Subject: [lng-odp] [PATCH API-NEXT v3 8/8] validation: ipsec: support AES-GMAC-ESP validation 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 Add AES-GMAC-ESP testcase based on draft-mcgrew-gcm-test-01. 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: d22c949cc466bf28de559855a1cb525740578137 ** Merge commit sha: ba7b9d98bb5dfe0cf7d7d28767c7a9c02d421d2d **/ test/validation/api/ipsec/ipsec.c | 10 +++++ test/validation/api/ipsec/ipsec.h | 1 + test/validation/api/ipsec/ipsec_test_in.c | 33 ++++++++++++++++ test/validation/api/ipsec/ipsec_test_out.c | 44 ++++++++++++++++++++++ test/validation/api/ipsec/test_vectors.h | 60 ++++++++++++++++++++++++++++++ 5 files changed, 148 insertions(+) diff --git a/test/validation/api/ipsec/ipsec.c b/test/validation/api/ipsec/ipsec.c index fb5f7863e..8d63c36a1 100644 --- a/test/validation/api/ipsec/ipsec.c +++ b/test/validation/api/ipsec/ipsec.c @@ -201,6 +201,10 @@ int ipsec_check(odp_bool_t ah, if (!capa.auths.bit.aes_gcm) return ODP_TEST_INACTIVE; break; + case ODP_AUTH_ALG_AES_GMAC: + if (!capa.auths.bit.aes_gmac) + return ODP_TEST_INACTIVE; + break; default: fprintf(stderr, "Unsupported authentication algorithm\n"); return ODP_TEST_INACTIVE; @@ -284,6 +288,12 @@ int ipsec_check_esp_aes_gcm_256(void) ODP_AUTH_ALG_AES_GCM, 0); } +int ipsec_check_esp_null_aes_gmac_128(void) +{ + return ipsec_check_esp(ODP_CIPHER_ALG_NULL, 0, + ODP_AUTH_ALG_AES_GMAC, 128); +} + void ipsec_sa_param_fill(odp_ipsec_sa_param_t *param, odp_bool_t in, odp_bool_t ah, diff --git a/test/validation/api/ipsec/ipsec.h b/test/validation/api/ipsec/ipsec.h index 9dd0feabf..4532fe7ce 100644 --- a/test/validation/api/ipsec/ipsec.h +++ b/test/validation/api/ipsec/ipsec.h @@ -86,5 +86,6 @@ int ipsec_check_esp_aes_cbc_128_null(void); int ipsec_check_esp_aes_cbc_128_sha256(void); int ipsec_check_esp_aes_gcm_128(void); int ipsec_check_esp_aes_gcm_256(void); +int ipsec_check_esp_null_aes_gmac_128(void); #endif diff --git a/test/validation/api/ipsec/ipsec_test_in.c b/test/validation/api/ipsec/ipsec_test_in.c index 25fc00e11..8e692f678 100644 --- a/test/validation/api/ipsec/ipsec_test_in.c +++ b/test/validation/api/ipsec/ipsec_test_in.c @@ -752,6 +752,37 @@ static void test_in_mcgrew_gcm_12_esp(void) ipsec_sa_destroy(sa); } +static void test_in_mcgrew_gcm_15_esp(void) +{ + odp_ipsec_tunnel_param_t tunnel = {}; + odp_ipsec_sa_param_t param; + odp_ipsec_sa_t sa; + + ipsec_sa_param_fill(¶m, + true, false, 0x00004321, &tunnel, + ODP_CIPHER_ALG_NULL, NULL, + ODP_AUTH_ALG_AES_GMAC, &key_mcgrew_gcm_15, + &key_mcgrew_gcm_salt_15); + + sa = odp_ipsec_sa_create(¶m); + + CU_ASSERT_NOT_EQUAL_FATAL(ODP_IPSEC_SA_INVALID, sa); + + ipsec_test_part test = { + .pkt_in = &pkt_mcgrew_gcm_test_15_esp, + .out_pkt = 1, + .out = { + { .status.warn.all = 0, + .status.error.all = 0, + .pkt_out = &pkt_mcgrew_gcm_test_15}, + }, + }; + + ipsec_check_in_one(&test, sa); + + ipsec_sa_destroy(sa); +} + static void ipsec_test_capability(void) { odp_ipsec_capability_t capa; @@ -779,6 +810,8 @@ odp_testinfo_t ipsec_in_suite[] = { ipsec_check_esp_aes_gcm_128), ODP_TEST_INFO_CONDITIONAL(test_in_mcgrew_gcm_12_esp, ipsec_check_esp_aes_gcm_128), + ODP_TEST_INFO_CONDITIONAL(test_in_mcgrew_gcm_15_esp, + ipsec_check_esp_null_aes_gmac_128), ODP_TEST_INFO_CONDITIONAL(test_in_ah_sha256, ipsec_check_ah_sha256), ODP_TEST_INFO_CONDITIONAL(test_in_ah_sha256_tun, diff --git a/test/validation/api/ipsec/ipsec_test_out.c b/test/validation/api/ipsec/ipsec_test_out.c index 39a3c30ff..7be07d095 100644 --- a/test/validation/api/ipsec/ipsec_test_out.c +++ b/test/validation/api/ipsec/ipsec_test_out.c @@ -319,6 +319,48 @@ static void test_out_esp_aes_gcm128(void) ipsec_sa_destroy(sa); } +static void test_out_esp_aes_null_gmac128(void) +{ + odp_ipsec_sa_param_t param; + odp_ipsec_sa_t sa; + odp_ipsec_sa_t sa2; + + ipsec_sa_param_fill(¶m, + false, false, 123, NULL, + ODP_CIPHER_ALG_NULL, NULL, + ODP_AUTH_ALG_AES_GMAC, &key_a5_128, + &key_mcgrew_gcm_salt_2); + + sa = odp_ipsec_sa_create(¶m); + + CU_ASSERT_NOT_EQUAL_FATAL(ODP_IPSEC_SA_INVALID, sa); + + ipsec_sa_param_fill(¶m, + true, false, 123, NULL, + ODP_CIPHER_ALG_NULL, NULL, + ODP_AUTH_ALG_AES_GMAC, &key_a5_128, + &key_mcgrew_gcm_salt_2); + + sa2 = odp_ipsec_sa_create(¶m); + + CU_ASSERT_NOT_EQUAL_FATAL(ODP_IPSEC_SA_INVALID, sa2); + + ipsec_test_part test = { + .pkt_in = &pkt_icmp_0, + .out_pkt = 1, + .out = { + { .status.warn.all = 0, + .status.error.all = 0, + .pkt_out = &pkt_icmp_0 }, + }, + }; + + ipsec_check_out_in_one(&test, sa, sa2); + + ipsec_sa_destroy(sa2); + ipsec_sa_destroy(sa); +} + static void ipsec_test_capability(void) { odp_ipsec_capability_t capa; @@ -344,5 +386,7 @@ odp_testinfo_t ipsec_out_suite[] = { ipsec_check_esp_aes_cbc_128_sha256), ODP_TEST_INFO_CONDITIONAL(test_out_esp_aes_gcm128, ipsec_check_esp_aes_gcm_128), + ODP_TEST_INFO_CONDITIONAL(test_out_esp_aes_null_gmac128, + ipsec_check_esp_null_aes_gmac_128), ODP_TEST_INFO_NULL, }; diff --git a/test/validation/api/ipsec/test_vectors.h b/test/validation/api/ipsec/test_vectors.h index 2fb06b2b7..20e737c99 100644 --- a/test/validation/api/ipsec/test_vectors.h +++ b/test/validation/api/ipsec/test_vectors.h @@ -45,6 +45,9 @@ KEY(key_mcgrew_gcm_salt_4, 0x00, 0x00, 0x00, 0x00); KEY(key_mcgrew_gcm_12, 0x7d, 0x77, 0x3d, 0x00, 0xc1, 0x44, 0xc5, 0x25, 0xac, 0x61, 0x9d, 0x18, 0xc8, 0x4a, 0x3f, 0x47); KEY(key_mcgrew_gcm_salt_12, 0xd9, 0x66, 0x42, 0x67); +KEY(key_mcgrew_gcm_15, 0x4c, 0x80, 0xcd, 0xef, 0xbb, 0x5d, 0x10, 0xda, + 0x90, 0x6a, 0xc7, 0x3c, 0x36, 0x13, 0xa6, 0x34); +KEY(key_mcgrew_gcm_salt_15, 0x22, 0x43, 0x3c, 0x64); static const ODP_UNUSED ipsec_test_packet pkt_icmp_0 = { .len = 142, @@ -962,4 +965,61 @@ static const ipsec_test_packet pkt_mcgrew_gcm_test_12_esp = { }, }; +static const ipsec_test_packet pkt_mcgrew_gcm_test_15 = { + .len = 62, + .l2_offset = 0, + .l3_offset = 14, + .l4_offset = 34, + .data = { + /* ETH - not a part of RFC, added for simplicity */ + 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, + 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0x08, 0x00, + + /* IP */ + 0x45, 0x00, 0x00, 0x30, 0xda, 0x3a, 0x00, 0x00, + 0x80, 0x01, 0xdf, 0x3b, 0xc0, 0xa8, 0x00, 0x05, + 0xc0, 0xa8, 0x00, 0x01, + + /* ICMP */ + 0x08, 0x00, 0xc6, 0xcd, 0x02, 0x00, 0x07, 0x00, + 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, + 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, + 0x71, 0x72, 0x73, 0x74, + }, +}; + +static const ipsec_test_packet pkt_mcgrew_gcm_test_15_esp = { + .len = 118, + .l2_offset = 0, + .l3_offset = 14, + .l4_offset = 34, + .data = { + /* ETH - not a part of RFC, added for simplicity */ + 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, + 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0x08, 0x00, + + /* IP - not a part of RFC, added for simplicity */ + 0x45, 0x00, 0x00, 0x68, 0x69, 0x8f, 0x00, 0x00, + 0x80, 0x32, 0x4d, 0xb2, 0xc0, 0xa8, 0x01, 0x02, + 0xc0, 0xa8, 0x01, 0x01, + + /* ESP */ + 0x00, 0x00, 0x43, 0x21, 0x00, 0x00, 0x00, 0x07, + + /* IV */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + + /* IP */ + 0x45, 0x00, 0x00, 0x30, 0xda, 0x3a, 0x00, 0x00, + 0x80, 0x01, 0xdf, 0x3b, 0xc0, 0xa8, 0x00, 0x05, + 0xc0, 0xa8, 0x00, 0x01, 0x08, 0x00, 0xc6, 0xcd, + 0x02, 0x00, 0x07, 0x00, 0x61, 0x62, 0x63, 0x64, + 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, + 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, + 0x01, 0x02, 0x02, 0x01, 0xf2, 0xa9, 0xa8, 0x36, + 0xe1, 0x55, 0x10, 0x6a, 0xa8, 0xdc, 0xd6, 0x18, + 0xe4, 0x09, 0x9a, 0xaa, + }, +}; + #endif