Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp3827381pxt; Tue, 10 Aug 2021 12:14:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJynw83SV5CXnTphBYw/+7dxq2Yifrbym0TCsczc0xCjKiocmwmYSxHyQi1t+6zyjnOqn9Uf X-Received: by 2002:a05:6402:26d1:: with SMTP id x17mr6959043edd.126.1628622858192; Tue, 10 Aug 2021 12:14:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628622858; cv=none; d=google.com; s=arc-20160816; b=VOgJer6t26VSAyF2F8Tf7vHYkKCyDj/+IPyxBkwQe0yS8hn8nG0TzLtb6nQXE4Strf UcKS5qzZBWin2BbpdjpBGRLD3sPMCMD7Ur7kTwjcskSRiMWhFu29Qh+kshZwQ4Mj62tF bBISf7Iq0JcJbtQIw/j++N6YubyXL3xANZYPVkOVdt5InlDwhtI6Vc2RA4DedbJ2CP26 udvoS4sa91TAmNKIvXw0YbuILZxZEee+YBKeSTMsd4Asakx/9cZbqXdXvfXkgmstJF++ wfzZ92BB1GFMwi6zRasgrF15Eccjc3WVj2t7yfEmoOOVxknXMOgTsxMw8aKk9rGdlWph iafw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=C1dJ0e7GXvrg+r9pMpSCYNajmI3u0jKfBV+eOLxXNZc=; b=KFTUQsU/NvMKohMh+4YAbFypo5IsuOmyadubLWxeNqmNr3pAe0u1br58kvxoI99yZn E0Hj0XYSnw1btwraKVm5nwvEP+aWCRcA1OON3Z+ECI6ICsyTNyjsQavjCvYpdtpFAJZU u6wjZS6dn4GLK5ddOqMR8qmN93oryfXjzD5n1WkoS63hdMovHXRix+zhj0tGkLjXFwG6 c1KerTq+MGHf6se/qDSxv+zM36q9yZE9wF8j+JkqPssNcCQ5MpAECRRflJpQStbA50ij AhzdXwb6I5qeH6DbnRGGBuNJu80MpmkpEqWCgVxE1XtgTfkHggst+6vxoCHi5p3IYZo6 1TtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZQC0NEk0; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id y3si1807878eds.548.2021.08.10.12.13.44; Tue, 10 Aug 2021 12:14:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-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=@kernel.org header.s=k20201202 header.b=ZQC0NEk0; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 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 S231324AbhHJTOE (ORCPT + 99 others); Tue, 10 Aug 2021 15:14:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:38850 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230295AbhHJTOE (ORCPT ); Tue, 10 Aug 2021 15:14:04 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id BE7F261019; Tue, 10 Aug 2021 19:13:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1628622822; bh=3rE5qc+iJNNSvC4ekgPf62m2QsbfzCpL6SJxL+syab8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ZQC0NEk0Him79x8hhE3+Sr+z7EPYmUxL8PTeYH/CjZGvf4FrabhG8oPj/dhV15wp9 bM0E6Zb3ZtrKA/55nDzFReeOSLZs2MDcZ5Jx6FlungZ+C+lrN9hH7gY9VyNACyRvS+ jU/O6+Wzzt8CtrpVTelrqQvpOLxSLPaKxbPMGZp3q0xK72zRV+qU8YkdRUpkWHoF+G uHv8MCo6c3pHEq90IVKsjmQcSvf4Ctu3fECrFTuNySU3qLZSvlgGv3Lx2tqqUtYtH/ gyHADC9n6cHisQamSGltETg5lyyE9Ap1yi8YmBiGU5swo57pTX4Cc8RJn0N0JNCqPO 0TB1Iqe4arR8A== Date: Tue, 10 Aug 2021 12:13:40 -0700 From: Eric Biggers To: Hannes Reinecke Cc: Christoph Hellwig , Sagi Grimberg , Keith Busch , Herbert Xu , "David S . Miller" , linux-nvme@lists.infradead.org, linux-crypto@vger.kernel.org Subject: Re: [PATCH 04/13] lib/base64: RFC4648-compliant base64 encoding Message-ID: References: <20210810124230.12161-1-hare@suse.de> <20210810124230.12161-5-hare@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210810124230.12161-5-hare@suse.de> Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Tue, Aug 10, 2021 at 02:42:21PM +0200, Hannes Reinecke wrote: > Add RFC4648-compliant base64 encoding and decoding routines. > > Signed-off-by: Hannes Reinecke > --- > include/linux/base64.h | 16 ++++++ > lib/Makefile | 2 +- > lib/base64.c | 115 +++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 132 insertions(+), 1 deletion(-) > create mode 100644 include/linux/base64.h > create mode 100644 lib/base64.c > > diff --git a/include/linux/base64.h b/include/linux/base64.h > new file mode 100644 > index 000000000000..660d4cb1ef31 > --- /dev/null > +++ b/include/linux/base64.h > @@ -0,0 +1,16 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * base64 encoding, lifted from fs/crypto/fname.c. > + */ As I mentioned previously, please make it very clear which variant of Base64 it is (including whether padding is included and required or not), and update all the comments accordingly. I've done so in fs/crypto/fname.c with https://lkml.kernel.org/r/20210718000125.59701-1-ebiggers@kernel.org. It would probably be best to start over with a copy of that and modify it accordingly to implement the desired variant of Base64. > +/** > + * base64_decode() - base64-decode some bytes > + * @src: the base64-encoded string to decode > + * @len: number of bytes to decode > + * @dst: (output) the decoded bytes. "@len: number of bytes to decode" is ambiguous as it could refer to either @src or @dst. I've fixed this in the fs/crypto/fname.c version. > + * > + * Decodes the base64-encoded bytes @src according to RFC 4648. > + * > + * Return: number of decoded bytes > + */ Shouldn't this return an error if the string is invalid? Again, see the latest fs/crypto/fname.c version. > +int base64_decode(const char *src, int len, u8 *dst) > +{ > + int i, bits = 0, pad = 0; > + u32 ac = 0; > + size_t dst_len = 0; > + > + for (i = 0; i < len; i++) { > + int c, p = -1; > + > + if (src[i] == '=') { > + pad++; > + if (i + 1 < len && src[i + 1] == '=') > + pad++; > + break; > + } > + for (c = 0; c < strlen(lookup_table); c++) { strlen() shouldn't be used in a loop condition like this. - Eric