public inbox for linux-nvme@lists.infradead.org
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: Hannes Reinecke <hare@suse.de>
Cc: Christoph Hellwig <hch@lst.de>, Sagi Grimberg <sagi@grimberg.me>,
	Keith Busch <keith.busch@wdc.com>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	"David S . Miller" <davem@davemloft.net>,
	linux-nvme@lists.infradead.org, linux-crypto@vger.kernel.org
Subject: Re: [PATCH 04/13] lib/base64: RFC4648-compliant base64 encoding
Date: Tue, 10 Aug 2021 12:13:40 -0700	[thread overview]
Message-ID: <YRLP5JuQrF/SJPBt@gmail.com> (raw)
In-Reply-To: <20210810124230.12161-5-hare@suse.de>

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 <hare@suse.de>
> ---
>  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

_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

  reply	other threads:[~2021-08-10 19:14 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-10 12:42 [PATCHv2 00/13] nvme: In-band authentication support Hannes Reinecke
2021-08-10 12:42 ` [PATCH 01/13] crypto: add crypto_has_shash() Hannes Reinecke
2021-08-10 12:42 ` [PATCH 02/13] crypto: add crypto_has_kpp() Hannes Reinecke
2021-08-10 12:42 ` [PATCH 03/13] crypto/ffdhe: Finite Field DH Ephemeral Parameters Hannes Reinecke
2021-08-10 12:42 ` [PATCH 04/13] lib/base64: RFC4648-compliant base64 encoding Hannes Reinecke
2021-08-10 19:13   ` Eric Biggers [this message]
2021-08-11  5:57     ` Hannes Reinecke
2021-08-10 12:42 ` [PATCH 05/13] nvme: add definitions for NVMe In-Band authentication Hannes Reinecke
2021-08-10 12:42 ` [PATCH 06/13] nvme-fabrics: decode 'authentication required' connect error Hannes Reinecke
2021-08-10 12:42 ` [PATCH 07/13] nvme: Implement In-Band authentication Hannes Reinecke
2021-08-10 12:42 ` [PATCH 08/13] nvme-auth: Diffie-Hellman key exchange support Hannes Reinecke
2021-08-10 12:42 ` [PATCH 09/13] nvmet: Parse fabrics commands on all queues Hannes Reinecke
2021-08-10 12:42 ` [PATCH 10/13] nvmet: Implement basic In-Band Authentication Hannes Reinecke
2021-08-10 12:42 ` [PATCH 11/13] nvmet-auth: Diffie-Hellman key exchange support Hannes Reinecke
2021-08-10 12:42 ` [PATCH 12/13] nvmet-auth: expire authentication sessions Hannes Reinecke
2021-08-10 12:42 ` [PATCH 13/13] nvme: add non-standard ECDH and curve25517 algorithms Hannes Reinecke
2021-08-12 12:25   ` Christoph Hellwig
2021-08-12 12:51     ` Hannes Reinecke
2021-08-17 21:21 ` [PATCHv2 00/13] nvme: In-band authentication support Sagi Grimberg
2021-08-18  5:44   ` Hannes Reinecke

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YRLP5JuQrF/SJPBt@gmail.com \
    --to=ebiggers@kernel.org \
    --cc=davem@davemloft.net \
    --cc=hare@suse.de \
    --cc=hch@lst.de \
    --cc=herbert@gondor.apana.org.au \
    --cc=keith.busch@wdc.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=sagi@grimberg.me \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox