Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp2355227rwr; Fri, 28 Apr 2023 09:14:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5Vg92yyPu8sR0CdNJsX274XaiY72xKj6oMzkEEJXX+JWPwOJDke4l+hxFjolGDrd4DysG0 X-Received: by 2002:a05:6a20:429e:b0:f5:b4a5:73b4 with SMTP id o30-20020a056a20429e00b000f5b4a573b4mr7396789pzj.27.1682698465076; Fri, 28 Apr 2023 09:14:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682698465; cv=none; d=google.com; s=arc-20160816; b=gM/y9LVs/rik/4fT4l21rD+CjICX43GQaQPu7OGm1pGSzemrElHjKIN/ItF4aL09d5 lxeiTv4r4z17aBsDAEoJPfymyMjrrrMsVLO4Cyb3vPl8j6HQHOrNU4ZxWHpg0E9de/Hj C8qoCKU2HHE9vA2cgXoUpmlBI/ByXd1uvNb5x7Zw3v1owXqtW0mY9GPVrpxxo3wu0bdB l+r1tRe9SA1l/4NjtWjasyL8La3SWadoT5x0o3kOEQJ89iK6RJShY4Nrn/ArbGqcJ46I 8h6K7NbmoUKnSmeUAiPozmnL8kLXOYBOVWkVcGPYvFn/hwCUndxbVqJ0Ozico+MyhO2u 8A7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=QJqbTbx18cm8BtkJ9IkaHo2jQOCPTFMtrpFdjMEeGbY=; b=pndhbg6xkFFItzUpBZaO48cGj/yjH/kpBKHv6hdmhkrVacytq+QgNPOxZgXE+l8C7B TKSJR/l5VXY6iXH5Ql9IyVBbP8EoWRp12rkWgimlWWYlbg/9w9+saz2V3tU5qsS/Po/k gpsB11Zw4BWJTt3T7z5b74r+enlK/nO2oVux19ZONDw3NxwhflaXh6b2QgALWMU8gXIh z1reEqRu2bjVuxID9Tx26653/QOYrhWeesEV7C0QStcRK7RUnQvFqhlTuCBL/iTHUNQd qfIhNoBYguVshfkG7t21LFrXMY0F417zhBxfNwG6pkJpq5A8scTXbO9dqX8fQ9Psw+ql BLgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=V51PKVs4; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v16-20020a63d550000000b00524da606618si18670496pgi.227.2023.04.28.09.14.09; Fri, 28 Apr 2023 09:14:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=V51PKVs4; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S1346202AbjD1QKH (ORCPT + 99 others); Fri, 28 Apr 2023 12:10:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345696AbjD1QKD (ORCPT ); Fri, 28 Apr 2023 12:10:03 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A58972122; Fri, 28 Apr 2023 09:10:01 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2F0A764452; Fri, 28 Apr 2023 16:10:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 94A4BC4339E; Fri, 28 Apr 2023 16:10:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1682698200; bh=007b4S/NC/47+Xn6WdUbKm6mcGQCZUOKnNFXK/7j2dA=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=V51PKVs499KBlRCIQGP0Zp14i4tJ7b6hbjDUklGdc7INC3Dr49F6zuCOe1NaqRFEv BVdoHyqh7lIcHKhH0u0pgvuuGlymVA8n13S+4g1MD3u4U0re1pMFqJyCiXPIyxhPrw SZhT9SgQh162rOUdFTJ7SYT8UneRph8jLi44cCkizFvJbMhRK8nckpqiqFBZeAm1kC AFKVWkHfMXSvgKc4qCx+B5OMSHL6N/itzgoo/2U0BDj9mEtxA0g4e0uiS8MuGgZBTs 9MCruYNm70RsqmsQRK2PO4JIRFJkpa0dA/fBjBxgxr8qJv/9+8y/gYIetV7N8v5M84 MhHvQjABfxmdw== Received: by mail-lf1-f50.google.com with SMTP id 2adb3069b0e04-4efd6e26585so72618e87.1; Fri, 28 Apr 2023 09:10:00 -0700 (PDT) X-Gm-Message-State: AC+VfDz9mm62zifXknrN/tU0vITExhVuWZoOf0PzFHmZXsD/On8HJUna 3lEPK+yvLR2BAUMvMPpAX7+HZEoMJ5rQfk/4UbY= X-Received: by 2002:ac2:5284:0:b0:4ed:b842:3a99 with SMTP id q4-20020ac25284000000b004edb8423a99mr2075509lfm.59.1682698198447; Fri, 28 Apr 2023 09:09:58 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Ard Biesheuvel Date: Fri, 28 Apr 2023 17:09:47 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: RPCSEC GSS krb5 KUnit test fails on arm64 with h/w accelerated ciphers enabled To: Chuck Lever III Cc: Herbert Xu , Scott Mayhew , "linux-crypto@vger.kernel.org" , Linux NFS Mailing List Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Fri, 28 Apr 2023 at 13:59, Chuck Lever III wrote: > > > > > On Apr 28, 2023, at 5:57 AM, Ard Biesheuvel wrote: > > > > On Fri, 28 Apr 2023 at 10:44, Herbert Xu wrote: > >> > >> Scott Mayhew wrote: > >>> > >>> diff --git a/arch/arm64/crypto/aes-modes.S b/arch/arm64/crypto/aes-modes.S > >>> index 0e834a2c062c..477605fad76b 100644 > >>> --- a/arch/arm64/crypto/aes-modes.S > >>> +++ b/arch/arm64/crypto/aes-modes.S > >>> @@ -268,6 +268,7 @@ AES_FUNC_START(aes_cbc_cts_encrypt) > >>> add x4, x0, x4 > >>> st1 {v0.16b}, [x4] /* overlapping stores */ > >>> st1 {v1.16b}, [x0] > >>> + st1 {v1.16b}, [x5] > >>> ret > >>> AES_FUNC_END(aes_cbc_cts_encrypt) > >>> > >>> But I don't know if that change is at all correct! (I've never even > >>> looked at arm64 asm before). If someone who's knowledgeable about this > >>> code could chime in, I'd appreciate it. > >> > >> Ard, could you please take a look at this? > >> > > > > The issue seems to be that the caller expects iv_out to have been > > populated even when doing ciphertext stealing. > > > > This is meaningless, because the output IV can only be used to chain > > additional encrypted data if the split is at a block boundary. The > > ciphertext stealing fundamentally terminates the encryption, and > > produces a block of ciphertext that is shorter than the block size, so > > what the output IV should be is actually unspecified. > > > > IOW, test cases having plain/ciphertext vectors whose size is not a > > multiple of the cipher block size should not specify an expected value > > for the output IV. > > The test cases are extracted from RFC 3962 Appendix B. The > standard clearly expects there to be a non-zero next IV for > plaintext sizes that are not block-aligned. > OK, so this is the Kerberos V specific spec on how to use AES in CBC mode, which appears to describe how to chain multiple CBC encryptions together. CBC-CTS itself does not define this: the IV is an input only, and the reason we happen to return the IV is because a single CBC operation may be broken up into several ones, which can only be done on block boundaries. This is why CBC-CTS itself passes all its tests: a single CBC-CTS encryption only performs ciphertext stealing at the very end, and the next IV is never used in that case. (This is why the CTS mode tests in crypto/testmgr.h don't have iv_out vectors) Note that RFC3962 defines that the penultimate block of CBC-CTS ciphertext is used as the next IV. CBC returns the last ciphertext block as the output IV. It is a happy coincidence that the generic CTS template encapsulates CBC in a way where its output IV ends up in the right place. > Also, these test cases pass on other hardware platforms. > Fair enough. I am not opposed to fixing this, but given that it is the RFC3962 spec that defines that the next IV is the penultimate full block of the previous CBC-CTS ciphertext, we might consider doing the memcpy() in the Kerberos code not in the CBC-CTS implementations. (The 32-bit ARM code will be broken in the same way, and potentially other implementations as well)