Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp5024921ybv; Wed, 26 Feb 2020 07:10:39 -0800 (PST) X-Google-Smtp-Source: APXvYqxxv3h21pDE1vWbolD+25aZQU+mibQNshJRFRx2qlP7R4x2nWjatXF4ZKBe2eLwjhwZPhiq X-Received: by 2002:a05:6830:1d4:: with SMTP id r20mr3294430ota.107.1582729839254; Wed, 26 Feb 2020 07:10:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582729839; cv=none; d=google.com; s=arc-20160816; b=ycQ5wV5CWwndNcJ/Z8otMrwPygbjWthDeY0KiNd/l2Htr/6upPMJ4tNsXNstqx16aR 6439Ve+uPdOLJDV5c7HmeThI2WX2PR9EQ695CmhRktmhMegqJuAOZPzPPVoTuZ/9VUFA hYFEe5lX+zMyOs47jdD5KVX4MMpj9OJYpMnALWItcvr6ihalJtheiR0QOMsOUlQwXX2F 5+YcUcQexxzH3DWRKi0yR5Pt/gqo1b+XVu1dUXrZqIetRXPCymOz766CxUvYSj1XmXKC pbl90w6FdN5gLBuo7ae60qK12NBLt2UOzoJ5/drfzn9+KU00mWc17jvSB8Aw9Wt8sNaE lxqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=YwH333YB+c5WkNcA+ALefDNi+G9uKbYvmmOr7YCboTE=; b=yrxYu150rJzV2XvGvv2vw+sTEQ/5HiP88/NKZqEtdbHjvmVzIalx+MnEcWtsVvCCtq 2qH4yHiLufEFpLbzbGN96XqnhGxBaGc1h8ZO9zqHSGveDyGt3e9zI3uNCOOastJ6y1Ty LhlVP1NaKCRiwVPdC8C3uLy7Oik+7KP8N1/XA6+B+UoCV2s7EyIl1y9GmGEh1oNRUwnI GF9EjO2RgpPNL5wgUWZ6ZRnim1/farnE6rSr88L88uxpMQtLxqGZHMK//fCUk/pStxsq BYAU/WE0xtoU+kYo1kDQCR66B3ZKD4JYExexZGE90fkdUSC/Vml8O0Znntdqp3PitYL5 KiZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@benyossef-com.20150623.gappssmtp.com header.s=20150623 header.b=UVJiUfAM; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r10si1305955otk.83.2020.02.26.07.10.16; Wed, 26 Feb 2020 07:10:39 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@benyossef-com.20150623.gappssmtp.com header.s=20150623 header.b=UVJiUfAM; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727066AbgBZPKK (ORCPT + 99 others); Wed, 26 Feb 2020 10:10:10 -0500 Received: from mail-vs1-f65.google.com ([209.85.217.65]:34567 "EHLO mail-vs1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726990AbgBZPKK (ORCPT ); Wed, 26 Feb 2020 10:10:10 -0500 Received: by mail-vs1-f65.google.com with SMTP id g15so2012715vsf.1 for ; Wed, 26 Feb 2020 07:10:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=benyossef-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=YwH333YB+c5WkNcA+ALefDNi+G9uKbYvmmOr7YCboTE=; b=UVJiUfAM4+zL4FNaj6BWYdjJGVhdYrZfxgPsMy4YFA55x/zCRNyODDutNTxqY0nTIg 9nolSHFWRVM7Xz0TSM5heUPkXwtIU1E+AP8FJpKxBYfkPHs41xNr5dn1R+q3q7SIqTNZ l+dV/+msKw16rgXj4sEXcry9wQHS2ghleCeww1vAE+i3Y39i1nZ4sdf+2f9o7bkPD6sz 2r5o3NvdSJRw9Dnd/YoopW/vlFsbXcVY64fkCd5eyffDT4+Y8G2ziT7TO04UC4It3Wql ByluCAQ7A++4rKUYkyhEeTBwre6uDoIbUDShNNwgXpKnMe/tOUdzEFHuZRy7as4Bg06v p4kA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=YwH333YB+c5WkNcA+ALefDNi+G9uKbYvmmOr7YCboTE=; b=gSYMqSXw1Xyb/PBwBpaE6+shtM3E7qHCivSdxbBedKCiwxNQV/gr4zwuOKcWFuTWv7 lGrYZ5OYGalGPdFsNgsSoJ84Ra6eGuzf9Obpy5kF0sf2zC5pYJ8Chcj/8e7SILccLUV5 3FhoMoU7VkyxlQpQ6vuXLeKVYQQBsFM9efCzbyA6UD5+ZCdvcjHgrSIWtMmyaZPXAYac TvnzU6M/ZMtQJtC3fl2Xfo74u74Zv/99YbaL1oDopSI3obwKMX2Y2LZJBlUVWdiojr96 PyB9h9ERKEshc6EyDR82Sl7Qm4k8AfrffQi0kZdR/XAt0j5Ry3xlmOESvTT6Z++QfMyC pMHA== X-Gm-Message-State: APjAAAVS4fn4W2DDYgEIJ3DBdaLBYTL94pQYxRM0y8cqYXX/M47eAirZ vd1L8t+z7IhLzaCB91Qm1iHeFth4NS4feY1/UWN8dQ== X-Received: by 2002:a67:6746:: with SMTP id b67mr4354659vsc.193.1582729808210; Wed, 26 Feb 2020 07:10:08 -0800 (PST) MIME-Version: 1.0 References: <20200225154834.25108-1-gilad@benyossef.com> <20200225154834.25108-3-gilad@benyossef.com> <20200225200244.GB114977@gmail.com> In-Reply-To: <20200225200244.GB114977@gmail.com> From: Gilad Ben-Yossef Date: Wed, 26 Feb 2020 17:09:57 +0200 Message-ID: Subject: Re: [PATCH 2/2] crypto: testmgr - sync both RFC4106 IV copies To: Eric Biggers Cc: Herbert Xu , "David S. Miller" , Ofir Drang , Geert Uytterhoeven , Linux Crypto Mailing List , Linux kernel mailing list Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Tue, Feb 25, 2020 at 10:02 PM Eric Biggers wrote: > > On Tue, Feb 25, 2020 at 05:48:34PM +0200, Gilad Ben-Yossef wrote: > > RFC4106 AEAD ciphers the AAD is the concatenation of associated > > authentication data || IV || plaintext or ciphertext but the > > random AEAD message generation in testmgr extended tests did > > not obey this requirements producing messages with undefined > > behaviours. Fix it by syncing the copies if needed. > > > > Since this only relevant for developer only extended tests any > > additional cycles/run time costs are negligible. > > > > This fixes extended AEAD test failures with the ccree driver > > caused by illegal input. > > > > Signed-off-by: Gilad Ben-Yossef > > Reported-by: Geert Uytterhoeven > > Cc: Eric Biggers > > --- > > crypto/testmgr.c | 20 ++++++++++++++++++++ > > 1 file changed, 20 insertions(+) > > > > diff --git a/crypto/testmgr.c b/crypto/testmgr.c > > index cf565b063cdf..288f349a0cae 100644 > > --- a/crypto/testmgr.c > > +++ b/crypto/testmgr.c > > @@ -95,6 +95,11 @@ struct aead_test_suite { > > /* > > * Set if the algorithm intentionally ignores the last 8 bytes of= the > > * AAD buffer during decryption. > > */ > > unsigned int esp_aad : 1; > > + > > + /* > > + * Set if the algorithm requires the IV to trail the AAD buffer. > > + */ > > + unsigned int iv_aad : 1; > > }; > > What's the difference between esp_aad and iv_aad? Are you sure we need a= nother > flag and not just use the existing flag? Yes, because we have 3 distinct states - 1. No IV in the AAD buffer - "normal" AEAD. 2. There is a copy of the IV in the AAD buffer and it is NOT used for ICV computation purposes - RFC4106 and RFC 4309. 3, There is a copy of the IV in the AAD buffer and it is used for ICV computation purposes - RFC 4543. 3 states needs at least 2 bits. > If they're both needed, please document them properly. You're currently = setting I will add a remark explaining this. I chose to keep the "esp_aad" name, since it was there before, but possibly this is not a good choice in light of your comments so will change that too. > them both on some algorithms, which based on the current comments is a lo= gical > contradiction because esp_aad is documented to mean that the last 8 bytes= are > ignored while iv_aad is documented to mean that these bytes must be the I= V. I believe it isn't a contradiction after all. Consider - RFC 4106 needs to have a copy of the IV in the AAD buffer which is identical to the one being passed via the normal mechanism in the API. If they are not identical, we have no way to know which copy of the IV is being used by an implementation as part of the AES-GCM nonce and so the generated message may be different from the one being used by the generic implementation. which results in encryption test failing when compared to the generic implementation results, even though there is nothing wrong with the tested implementation and indeed the previous compassion against the precomputed test vectors passes. This is what happened with the ccree driver. Note that this has nothing to do with mutating the message - this is an encryption test failing. This is the iv_aad flag, which will need to be true in this case. On the other hand when testing decryption and mutating the AEAD message, we need to know not to mutate the IV copy in the AAD buffer, since it is ignored. This is the esp_aad flag, which will also needs to be true in this case. Last but not least, RFC 4543 need a copy of the IV in the AAD buffer However, this copy DOES get hashed as part of the ICV computation, so - We need iv_aad flag to be true to let us know we need to copy the IV. However, we need esp_aad to be false since it's fine and even desirable to mutate the IV copy in the AAD buffer. You are correct though that I can make the 2nd copy of the IV post mutation dependant on esp_aad not being set, though... I hope this explains this mess better. It certainly took me a while to figure out what is going on... > > > > > struct cipher_test_suite { > > @@ -2207,6 +2212,10 @@ static void generate_aead_message(struct aead_re= quest *req, > > > > /* Generate the AAD. */ > > generate_random_bytes((u8 *)vec->assoc, vec->alen); > > + /* For RFC4106 algs, a copy of the IV is part of the AAD */ > > + if (suite->iv_aad) > > + memcpy(((u8 *)vec->assoc + vec->alen - ivsize), vec->iv, > > + ivsize); > > What guarantees that vec->alen >=3D ivsize? You are right, I need to check for that. However, if it isn't this can't be a legal RFC4106 message and we will fail encryption . Thanks! Gilad --=20 Gilad Ben-Yossef Chief Coffee Drinker values of =CE=B2 will give rise to dom!