Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp476632pxu; Fri, 4 Dec 2020 07:49:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJwCnjwZrJZVj01yUOP6LZfc0qihmgfR8wCuVEua0xMCoujO0f1rYgpPklZAPKVoDIJhI7Qj X-Received: by 2002:a17:906:13c5:: with SMTP id g5mr7601579ejc.125.1607096980669; Fri, 04 Dec 2020 07:49:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607096980; cv=none; d=google.com; s=arc-20160816; b=aUKKLDDkzJX3qQMYgv+EHyJ+OMz0y6abR3TDM2ogR+KQiQqvoXP8FRopkM7mXSPpIx KfImm6eYPfddgYmJlWRP7uDrEvd+ymoHO/p3ucctNkD1gVbSZlhiXj7aW12P4AlYjTf2 K4iW1xNvL++LnedBonFE48Oc6nUPu8gUBP3md9k2CC1863rf82zKIDzly9vC0hHq6eqN eMLBMIf0N4Jw9DKBc1hMPw+Pq1KZL3sHaN+qLtIN9f0lelc0PoF6wH8iu3ixSQFcXNMV zL31l3lzP6njFT4IqhcKSM4ogLf1VZtXsv5hjkYZK3O58hrQBU7YJItqqlOjq8f4e1Wz PVJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature:dkim-filter; bh=wHiljjMIkY8nl/ZnPYa+9FcyCXYDIXfFUmp0/iytMrM=; b=n0Ap0BPdQTUAVc+I+SX+hMAlvACuI2orYMl07YYUtzQQ61WfctC7kFiUUzRMW4gnOO TT7n3BMNvxcnNOjhufsUsdbhdGb3dZ0BYwi3kt4wAQrNrhsFWT+sO58hrklqYwkQcTVX 8gazlcv6UVX2wc5ys1ZAruHz2aFxipuKMj+B0rodscG/oH/4T51DuxoHsvomTBHTCkMi Sbv63DDxsNgAf2FpS3mHRQuGQQnWNP1QOoG42YY6+Ty7lKkup2+C8oR5W8IJNE7aUone vIs9gaipLUZCWbUWHM3hWxT/RvJqDb1zleeCk4mMQzvm/vrwizLN/e2PGibspXdIKNQq fIhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fieldses.org header.s=default header.b="jTPxHvE/"; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e9si1571608ejk.493.2020.12.04.07.49.06; Fri, 04 Dec 2020 07:49:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@fieldses.org header.s=default header.b="jTPxHvE/"; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730596AbgLDPrH (ORCPT + 99 others); Fri, 4 Dec 2020 10:47:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726427AbgLDPrH (ORCPT ); Fri, 4 Dec 2020 10:47:07 -0500 Received: from fieldses.org (fieldses.org [IPv6:2600:3c00:e000:2f7::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C104C061A52; Fri, 4 Dec 2020 07:46:27 -0800 (PST) Received: by fieldses.org (Postfix, from userid 2815) id 084D96F73; Fri, 4 Dec 2020 10:46:26 -0500 (EST) DKIM-Filter: OpenDKIM Filter v2.11.0 fieldses.org 084D96F73 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fieldses.org; s=default; t=1607096786; bh=wHiljjMIkY8nl/ZnPYa+9FcyCXYDIXfFUmp0/iytMrM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=jTPxHvE/rGumvGlYaM+xc80ODgvFi/CXOAPyE56Pd0+nQhVPHOXFK7EhdOBinOa3w LrUc+fa/1stZlpjT2QV+/OO2Ze/68TbyZoZBkhon+I4vAfX+PbuUS0sWT9pcimjm9x 9vqFoS4izZ03kMWkuY7cWfCH4jd08F1FWv66Hfr4= Date: Fri, 4 Dec 2020 10:46:26 -0500 From: Bruce Fields To: David Howells Cc: Chuck Lever , CIFS , Linux NFS Mailing List , Herbert Xu , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Trond Myklebust , linux-crypto@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-afs@lists.infradead.org Subject: Re: Why the auxiliary cipher in gss_krb5_crypto.c? Message-ID: <20201204154626.GA26255@fieldses.org> References: <2F96670A-58DC-43A6-A20E-696803F0BFBA@oracle.com> <160518586534.2277919.14475638653680231924.stgit@warthog.procyon.org.uk> <118876.1607093975@warthog.procyon.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <118876.1607093975@warthog.procyon.org.uk> User-Agent: Mutt/1.5.21 (2010-09-15) Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org On Fri, Dec 04, 2020 at 02:59:35PM +0000, David Howells wrote: > Hi Chuck, Bruce, > > Why is gss_krb5_crypto.c using an auxiliary cipher? For reference, the > gss_krb5_aes_encrypt() code looks like the attached. > > >From what I can tell, in AES mode, the difference between the main cipher and > the auxiliary cipher is that the latter is "cbc(aes)" whereas the former is > "cts(cbc(aes))" - but they have the same key. > > Reading up on CTS, I'm guessing the reason it's like this is that CTS is the > same as the non-CTS, except for the last two blocks, but the non-CTS one is > more efficient. CTS is cipher-text stealing, isn't it? I think it was Kevin Coffman that did that, and I don't remember the history. I thought it was required by some spec or peer implementation (maybe Windows?) but I really don't remember. It may predate git. I'll dig around and see what I can find. --b. > > David > --- > nbytes = buf->len - offset - GSS_KRB5_TOK_HDR_LEN; > nblocks = (nbytes + blocksize - 1) / blocksize; > cbcbytes = 0; > if (nblocks > 2) > cbcbytes = (nblocks - 2) * blocksize; > > memset(desc.iv, 0, sizeof(desc.iv)); > > if (cbcbytes) { > SYNC_SKCIPHER_REQUEST_ON_STACK(req, aux_cipher); > > desc.pos = offset + GSS_KRB5_TOK_HDR_LEN; > desc.fragno = 0; > desc.fraglen = 0; > desc.pages = pages; > desc.outbuf = buf; > desc.req = req; > > skcipher_request_set_sync_tfm(req, aux_cipher); > skcipher_request_set_callback(req, 0, NULL, NULL); > > sg_init_table(desc.infrags, 4); > sg_init_table(desc.outfrags, 4); > > err = xdr_process_buf(buf, offset + GSS_KRB5_TOK_HDR_LEN, > cbcbytes, encryptor, &desc); > skcipher_request_zero(req); > if (err) > goto out_err; > } > > /* Make sure IV carries forward from any CBC results. */ > err = gss_krb5_cts_crypt(cipher, buf, > offset + GSS_KRB5_TOK_HDR_LEN + cbcbytes, > desc.iv, pages, 1); > if (err) { > err = GSS_S_FAILURE; > goto out_err; > }