Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1932612lqe; Tue, 9 Apr 2024 05:11:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWDc+lZADtKLarz0ECmYu12lXnEIMlggf95SDozQA6CesT3skZdWdSJ3qnt8syDpSwfbJXcv2p7Fq9b5ZjI1nOB5kv9F8tObBNsl6wtdQ== X-Google-Smtp-Source: AGHT+IHi6cktMKQU2Vddo082GXbyZPa0/8YYEpYfVHfgemxEz31QFBnoZY2Zl/58EDCnj89hR0Qs X-Received: by 2002:a17:906:68c5:b0:a4e:7cd6:cbd with SMTP id y5-20020a17090668c500b00a4e7cd60cbdmr7334719ejr.68.1712664710554; Tue, 09 Apr 2024 05:11:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712664710; cv=pass; d=google.com; s=arc-20160816; b=FovHQH8guGWr8Jg3uWp4715hbQzAPxr0NCi8N5jQ5/xhdyYZcxFxz04SyjAGwBACxf L6bQ6C2ka01/xZH4Bh42jploG9c3yjC47qB5GQ+iW655Dc9KEmJ219CX+oneOKOhicgc 5KrEuvW8XWBDVPDA9B18j9xasaAYEUSpUbffSV4Z5tHOYFKhOH1hXeIt2UBMrSBwjw9+ 9ArJ2muOEWob4K3vUIHlF9LiEIgpuU2rXwAxtCGx6HTC1PzUHR9uLO8J1ySVpPxvhvCJ ak7c4Ja7a7Eysikx3AIW5GQDdKaEKU3i8qAzzDAOauUj1RoWw5duR5t1t9zzqs2l7LXa yD6g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=RR0aubFewYT+FdbhLY8ez66l5IfwBqUdo1iwtl0eS8w=; fh=uVa8sN+Byf1EgMOsQgorEGsBUyEsDfvjSkwFpaXB26k=; b=0j1IRekvMTiz6ee1+vwK956wdZUSBf393MJZxOXVeVjVBO/eMj6asj7He6J0By4d4E 9y4GMkyR4/dCMIMrwJkcvaTDJxnIYs1Hv1szTSqJXEIlgFf3Txpp4Vtnod6GhiK37NuL Aj04z98QXXY78L3NeagJHzKKoGVYUVXycFUujxo16KzzC9ON0ZkQXcSyZImlBNKRt242 Z9CMuHUKm5ObYXkeTP2op06ZHc6KtgqhofIzjDMaGRs1efRYhQDtWsJO5k7qnki29Jxj XtHazDZDHzGtUdvxDKb1DtlhGGF9I7WymoDypaklEfqewICjHTtJL5oBBoSipTwKSbY0 6PFg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lKb8gmM1; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-3421-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-crypto+bounces-3421-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id la17-20020a170906ad9100b00a51f0fc6539si768282ejb.385.2024.04.09.05.11.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 05:11:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto+bounces-3421-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lKb8gmM1; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-3421-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-crypto+bounces-3421-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 4A6831F21F16 for ; Tue, 9 Apr 2024 12:11:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 108BE12AAC8; Tue, 9 Apr 2024 12:11:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lKb8gmM1" X-Original-To: linux-crypto@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C261B80043; Tue, 9 Apr 2024 12:11:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712664704; cv=none; b=OUGrZxN9mPOWZuKPkAgD5KHmWZslHJl2op+EDJNJQlI13YJkwPid6tPnAd7WRAR4DSGLqtMZwoTOYeGanrudvB8TfI64Y7nCSHeTVs2vEuBCULLoBWEEbyBRDHyUdqOtALQ6lkDz56KdBiE4UEYz2ypv/Sc58ou7S0zC4zqlOMY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712664704; c=relaxed/simple; bh=BVOgIna6UH5Fe8n7tYM9YU/VXuuxjddECrXcSWyZ7o8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=oJc4jtjX2nh4bDY+5UilMcVkRBgD+aqmLgXPpP2Zh9BbWzjUXlN0XdZXtW23HWbYQ8mXEAm1XCn1kErcQO4wxKhza4YOXM/hl5izjxRwx6l5sv8csj457FXqlVCqbNa5RygWFGUzvQyaRSZHXe5jVIbjp2s/TnHVPcwP9G8xvME= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lKb8gmM1; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id E98ECC433C7; Tue, 9 Apr 2024 12:11:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712664704; bh=BVOgIna6UH5Fe8n7tYM9YU/VXuuxjddECrXcSWyZ7o8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=lKb8gmM1SkcPviIvDzzDRveN1RMXmKptiNLqx9jwXfonJ3yB6Ka1G6UANgBrEWbXO 1UdU7vx3HTF5/t3c1vEsJMKeGLGTWRpY8PFtBjDBZ5AhVjoyW82ta8HkFay3RrTOKV VQ2e1SUdWIiJFDYOH61EEpXcZGhb3mjo5zxucB33i2JkBvCqllTCs9yP8Lc8hhwapC Yg2OYl+NL4eI9QY2XE9aGgO/BGQupNpJqgM/t5wjnCNXo7CRDfV5yvNEiM5meRh8iD DW+71Fuy2cgloaC/YgW7j99vfMMQaY7qLx2zUhwSDmzEZgfTEEHhzRokvlWOV2azNT Fdn9WMTLyH8rQ== Date: Tue, 9 Apr 2024 08:11:41 -0400 From: Eric Biggers To: Ard Biesheuvel Cc: linux-crypto@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, "Chang S . Bae" , Stefan Kanthak Subject: Re: [PATCH] crypto: x86/aes-xts - access round keys using single-byte offsets Message-ID: <20240409121141.GA717@quark.localdomain> References: <20240409000154.29799-1-ebiggers@kernel.org> Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Tue, Apr 09, 2024 at 11:12:11AM +0200, Ard Biesheuvel wrote: > On Tue, 9 Apr 2024 at 02:02, Eric Biggers wrote: > > > > From: Eric Biggers > > > > Access the AES round keys using offsets -7*16 through 7*16, instead of > > 0*16 through 14*16. This allows VEX-encoded instructions to address all > > round keys using 1-byte offsets, whereas before some needed 4-byte > > offsets. This decreases the code size of aes-xts-avx-x86_64.o by 4.2%. > > > > Signed-off-by: Eric Biggers > > Nice optimization! > > Do you think we might be able to macrofy this a bit so we can use zero > based indexing for the round keys, and hide the arithmetic? > > There are two alternatives I considered: defining variables KEYOFF0 through KEYOFF14 and writing the offsets as KEYOFF\i(KEY), or defining one variable KEYOFF and writing the offsets as \i*16-KEYOFF(KEY). I think I slightly prefer the current patch where it's less abstracted out, though. It makes it clear the offsets really are single-byte, and also index 7 is the exact mid-point so going from -7 to 7 still feels fairly natural. If we wanted to do something more complex like use different offsets for AVX vs. AVX512, then we'd need the abstraction to handle that, but it doesn't seem useful to do that. - Eric