All of lore.kernel.org
 help / color / mirror / Atom feed
From: Heinrich Schuchardt <xypron.glpk@gmx.de>
To: u-boot@lists.denx.de
Subject: [PATCH] Add optional salt to AUTOBOOT_STOP_STR_SHA256
Date: Fri, 20 Nov 2020 17:56:04 +0100	[thread overview]
Message-ID: <0704a7b8-b3ca-76e6-ec31-489b874af8d6@gmx.de> (raw)
In-Reply-To: <20201120014114.48895-1-jp933255@xl-irv-13.lvn.broadcom.net>

On 11/20/20 2:41 AM, Joel Peshkin wrote:
> From: Joel Peshkin <joel.peshkin@broadcom.com>
>
> Adds an optional SALT value to AUTOBOOT_STOP_STR_SHA256.   If a string
> followed by a ":" is prepended to the sha256, the portion to the left
> of the colon will be used as a salt and the password will be appended
> to the salt before the sha256 is computed and compared.
>
> Signed-off-by: Joel Peshkin <joel.peshkin@broadcom.com>
> ---
>   common/Kconfig.boot |  5 ++++-
>   common/autoboot.c   | 10 +++++++++-
>   2 files changed, 13 insertions(+), 2 deletions(-)
>
> diff --git a/common/Kconfig.boot b/common/Kconfig.boot
> index 3f6d9c1..8a98672 100644
> --- a/common/Kconfig.boot
> +++ b/common/Kconfig.boot
> @@ -819,7 +819,10 @@ config AUTOBOOT_STOP_STR_SHA256
>   	  This option adds the feature to only stop the autobooting,
>   	  and therefore boot into the U-Boot prompt, when the input
>   	  string / password matches a values that is encypted via
> -	  a SHA256 hash and saved in the environment.
> +	  a SHA256 hash and saved in the environment variable
> +	  "bootstopkeysha256". If the value in that variable
> +	  includes a ":", the portion prior to the ":" will be treated
> +	  as a salt value.
>
>   config AUTOBOOT_USE_MENUKEY
>   	bool "Allow a specify key to run a menu from the environment"
> diff --git a/common/autoboot.c b/common/autoboot.c
> index e628baf..0c4e6ff 100644
> --- a/common/autoboot.c
> +++ b/common/autoboot.c
> @@ -80,6 +80,7 @@ static int passwd_abort_sha256(uint64_t etime)
>   	u8 sha_env[SHA256_SUM_LEN];
>   	u8 *sha;
>   	char *presskey;
> +	char *c;
>   	const char *algo_name = "sha256";
>   	u_int presskey_len = 0;
>   	int abort = 0;
> @@ -89,6 +90,14 @@ static int passwd_abort_sha256(uint64_t etime)
>   	if (sha_env_str == NULL)
>   		sha_env_str = AUTOBOOT_STOP_STR_SHA256;
>
> +	presskey = malloc_cache_aligned(MAX_DELAY_STOP_STR);
> +	c = strstr(sha_env_str, ":");
> +	if (c) {
> +		/* preload presskey with salt */
> +		memcpy(presskey, sha_env_str, c - sha_env_str);

Dear Joel,

thank you for your contribution helping to fend of password attacks
using lookup-tables for hashes.

Please, safeguard against

     c - sha_env_str > MAX_DELAY_STOP_STR

to avoid a possible buffer overflow.

We have

     #define MAX_DELAY_STOP_STR 32

Shouldn't this value be enlarged to encompass a salt with 256 bits of
randomness (matching the SHA256 algorithm)? If you encode 6 bits of
entropy in each character, you need 43 characters for the salt and 43
characters for the password.

> +		presskey_len += c - sha_env_str;

This would be more readable:

     presskey_len = c - sha_env_str;

Best regards

Heinrich

> +		sha_env_str = c + 1;
> +	}
>   	/*
>   	 * Generate the binary value from the environment hash value
>   	 * so that we can compare this value with the computed hash
> @@ -100,7 +109,6 @@ static int passwd_abort_sha256(uint64_t etime)
>   		return 0;
>   	}
>
> -	presskey = malloc_cache_aligned(MAX_DELAY_STOP_STR);
>   	sha = malloc_cache_aligned(SHA256_SUM_LEN);
>   	size = SHA256_SUM_LEN;
>   	/*
>

  reply	other threads:[~2020-11-20 16:56 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-20  1:41 [PATCH] Add optional salt to AUTOBOOT_STOP_STR_SHA256 Joel Peshkin
2020-11-20 16:56 ` Heinrich Schuchardt [this message]
2020-11-20 18:05 ` [PATCH v2] " Joel Peshkin
2020-11-20 21:06   ` Joel Peshkin
2020-11-21 23:07   ` Simon Glass
2020-11-22  1:18   ` [PATCH v3] " Joel Peshkin
2020-11-23  1:28     ` Simon Glass
2020-11-23  4:47     ` Heiko Schocher
2021-01-18 13:00     ` Tom Rini

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=0704a7b8-b3ca-76e6-ec31-489b874af8d6@gmx.de \
    --to=xypron.glpk@gmx.de \
    --cc=u-boot@lists.denx.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.