Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp4850914ybf; Wed, 4 Mar 2020 11:59:17 -0800 (PST) X-Google-Smtp-Source: ADFU+vv4ufFRaJRXNTQjT24nzlyBAvxUTSC2neSc1BvaSjkPKkw+zmoFNZ5ag/OdwfwMvoMUfgvD X-Received: by 2002:aca:815:: with SMTP id 21mr3066255oii.52.1583351957632; Wed, 04 Mar 2020 11:59:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583351957; cv=none; d=google.com; s=arc-20160816; b=nwx+BysJ+zEIzTdWwhFpFjD/QE6I9GIwJzc7BxKocxMJzzUzFx0Kkq9XXzYtUTioq5 uvo5QJNyxJVZObsfjRn8sYkETu+DlrKJ5O5iqhT+nROWvPplhbIJNBApsYHFL/X0nSsh eX4cb6IiFFn+ctkemWGjITWXOcp3BfmcUbGOt4GKgd+P94BhMUhdatppta0okk5KeX5z GgULbjQ+yqV4gp32o4pWm9Bv/7L+4pu5wMdIPeT97G/QgffaTIenFESwi11Ab74F6f7E nCKDWnY44HpUem7OGsGlZZZfQsO9n60dvdsZjiykVkjH1FqeZOxMADcvZ3J+a+Nh4Ds/ bfeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=lw4eS86LmfOZO/R52hG7X3juT92bAm/j/Ya5Ty/Q65s=; b=bA9uYS2YJ+sZ1DFSYKXo62gwXaH8KcZHt4lN6hy4mcDfXahtCGBVmSlbfXypjsh1m3 G/tmuwaxtga1wCy8Ngwu71LLNIac5j1nN8eRGZN0NXHH+LCboLnbPyE9Zo/uuVmFWG5+ xjdPmLeZzFEVqUxZhVuyVJmXxTZaOVVQ1GuvlSyd9gOyhAivBQvUtpdPMU+bFFhu6rXP rv80tRXbJmTUEjDMEnGkylflPfvdwNZtDVsaw8ajn8E4blupYQvXNOKixzeiicFhdqcn +KYHNKB1INnthd3ixSm9iTJSK9SieYXGzeeYJrIw16E1INd0S9042TnXCdx1gj4WoIEX qQpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="b/hUefZv"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d15si1856440oib.196.2020.03.04.11.58.58; Wed, 04 Mar 2020 11:59:17 -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=@kernel.org header.s=default header.b="b/hUefZv"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729008AbgCDT64 (ORCPT + 99 others); Wed, 4 Mar 2020 14:58:56 -0500 Received: from mail.kernel.org ([198.145.29.99]:54610 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728665AbgCDT64 (ORCPT ); Wed, 4 Mar 2020 14:58:56 -0500 Received: from sol.localdomain (c-107-3-166-239.hsd1.ca.comcast.net [107.3.166.239]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8DB7B21556; Wed, 4 Mar 2020 19:58:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583351935; bh=KpWyyTa4QUWn4Sv9w00wWJszehOXETZlcXXiDJFXdEw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=b/hUefZv6HPded/GJr4NJQF470NkRyMxIfwu9wKwQRVkgb/kNj67tMlpBpQVJ4EM7 tjwbUSJkJWIMRMxtXFoJlSDMqlWMb6MKb35+V9UwrKBSFiOf0empjE9I9xQGEmFCjQ Lrfak6gCVQ1v3s9p+Rzrxk8nyx/036tPVhnqaK68= Date: Wed, 4 Mar 2020 11:58:53 -0800 From: Eric Biggers To: Gilad Ben-Yossef Cc: Herbert Xu , "David S. Miller" , Ofir Drang , Geert Uytterhoeven , Linux Crypto Mailing List , Linux kernel mailing list Subject: Re: [PATCH v2] crypto: testmgr - sync both RFC4106 IV copies Message-ID: <20200304195853.GA1005@sol.localdomain> References: <20200303120925.12067-1-gilad@benyossef.com> <20200304000606.GB89804@sol.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Wed, Mar 04, 2020 at 03:48:47PM +0200, Gilad Ben-Yossef wrote: > > > > > > + const unsigned int aad_tail_size = suite->skip_aad_iv ? aad_ivsize : 0; > > > const unsigned int authsize = vec->clen - vec->plen; > > > > > > if (prandom_u32() % 2 == 0 && vec->alen > aad_tail_size) { > > > /* Mutate the AAD */ > > > flip_random_bit((u8 *)vec->assoc, vec->alen - aad_tail_size); > > > + if (suite->auth_aad_iv) > > > + memcpy((u8 *)vec->iv, > > > + (vec->assoc + vec->alen - aad_ivsize), > > > + aad_ivsize); > > > > Why sync the IV copies here? When 'auth_aad_iv', we assume the copy of the IV > > in the AAD (which was just corrupted) is authenticated. So we already know that > > decryption should fail, regardless of the other IV copy. > > Nope. We know there needs to be a copy of the IV in the AAD and we know the IV > should be included in calculating in the authentication tag. We don't know which > copy of the IV will be used by the implementation. > > Case in point - the ccree driver actually currently uses the copy of > the IV passed via > req->iv for calculating the IV contribution to the authentication tag, > not the one in the AAD. > > And what happens then if you don't do this copy than is that you get > an unexpected > decryption success where the test expects failure, because the driver > fed the HW the > none mutated copy of the IV from req->iv and not the mutated copy > found in the AAD. Okay, well in that case I don't see any difference between the two flags. This is because changing the IV *must* affect the authentication tag for *any* AEAD algorithm, otherwise it's not actually authenticated encryption. So why don't we just use a single flag 'aad_iv' that's set on rfc4106, rfc4309, rfc4543, and rfc7539esp? This flag would mean that the last bytes of the AAD buffer must contain another copy of the IV for the behavior to be well-defined. > > > @@ -2208,6 +2220,10 @@ static void generate_aead_message(struct aead_request *req, > > > /* Generate the AAD. */ > > > generate_random_bytes((u8 *)vec->assoc, vec->alen); > > > > > > + if (suite->auth_aad_iv && (vec->alen > ivsize)) > > > + memcpy(((u8 *)vec->assoc + vec->alen - ivsize), vec->iv, > > > + ivsize); > > > > Shouldn't this be >= ivsize, not > ivsize? > Indeed. > > > And doesn't the IV need to be synced > > in both the skip_aad_iv and auth_aad_iv cases? > > Nope, because in the skip_aad_iv case we never mutate the IV, so no > point in copying. But even if the IV isn't mutated, both copies still need to be the same, right? We seem to have concluded that the behavior should be implementation-defined when they're different, so that's the logical consequence... - Eric