Add optional salt to AUTOBOOT_STOP_STR_SHA256
PATCH 1/1 Add optional salt to AUTOBOOT_STOP_STR_SHA256
From: Joel Peshkin <[email protected]>
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.
--- common/Kconfig.boot | 5 ++++- common/autoboot.c | 10 +++++++++- 2 files changed, 13 insertions(+), 2 deletions(-)
common/Kconfig.boot +4 -1
@@ -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"
common/autoboot.c +9 -1
@@ -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); + presskey_len += c - sha_env_str; + 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 ;/*
Signature · 9 lines
1.8.3.1 -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 4166 bytes Desc: S/MIME Cryptographic Signature URL: <https://lists.denx.de/pipermail/u-boot/attachments/20201119/d0d56012/attachment.bin>
PATCH 1/1 Add optional salt to AUTOBOOT_STOP_STR_SHA256
Quoted 42 lines · Joel Peshkin
From: Joel Peshkin <[email protected]>
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 <[email protected]>--- common/Kconfig.boot | 5 ++++- common/autoboot.c | 10 +++++++++- 2 files changed, 13 insertions(+), 2 deletions(-)common/Kconfig.boot +4
-1@@ -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"common/autoboot.c +1
-0@@ -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 ;
common/autoboot.c static int passwd_abort_sha256(uint64_t etime) · line 97
Quoted 8 lines
common/autoboot.c +5
-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.
common/autoboot.c static int passwd_abort_sha256(uint64_t etime) · line 98
Quoted 1 line
common/autoboot.c +1
-0+ presskey_len += c - sha_env_str;
This would be more readable:
presskey_len = c - sha_env_str;
Best regards
Heinrich
Quoted 14 lines
common/autoboot.c +2
-1+ 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 ;/*
PATCH v2 1/1 Add optional salt to AUTOBOOT_STOP_STR_SHA256
In reply to Joel PeshkinFrom: Joel Peshkin <[email protected]>
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.
To: u-boot at lists.denx.de
---
Changes for v2:
- Increase MAX_DELAY_STOP_STR
- Check salt size against MAX_DELAY_STOP_STR before copying
- Minor cleanup
--- common/Kconfig.boot | 5 ++++- common/autoboot.c | 12 ++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-)
common/Kconfig.boot +4 -1
@@ -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"
common/autoboot.c +10 -2
@@ -25,7 +25,7 @@DECLARE_GLOBAL_DATA_PTR ; -#define MAX_DELAY_STOP_STR 32 +#define MAX_DELAY_STOP_STR 64#ifndef DEBUG_BOOTKEYS #define DEBUG_BOOTKEYS 0
@@ -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) && (c - sha_env_str <MAX_DELAY_STOP_STR )) { +/* preload presskey with salt */ +memcpy (presskey, sha_env_str, c - sha_env_str); + presskey_len = c - sha_env_str; + 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 ;/*
Signature · 9 lines
1.8.3.1 -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 4166 bytes Desc: S/MIME Cryptographic Signature URL: <https://lists.denx.de/pipermail/u-boot/attachments/20201120/87158666/attachment.bin>
PATCH v2 1/1 Add optional salt to AUTOBOOT_STOP_STR_SHA256
Hi Heinrich,
Thank you for the review. I increased the max size to 64 characters.
The size, in the end, is the size of the salt plus the size of the
password the human user would type. In most places I have seen salt used,
it is only a few characters (modern Linux password databases use 8) and the actual password (as opposed to its sha256) is unlikely to be more than 15 characters.
Regards,
Joel
Quoted 88 lines · Joel Peshkin
From: Joel Peshkin <[email protected]>
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 <[email protected]>Cc Simon Glass <[email protected]>Cc Bin Meng <[email protected]>Cc Patrick Delaunay <[email protected]>Cc Heiko Schocher <[email protected]>Cc trini at konsulko.comCc Heinrich Schuchardt <[email protected]>Cc Joel Peshkin <[email protected]>To: u-boot at lists.denx.de
---
Changes for v2:
- IncreaseMAX_DELAY_STOP_STR
- Check salt size againstMAX_DELAY_STOP_STRbefore copying
- Minor cleanup--- common/Kconfig.boot | 5 ++++- common/autoboot.c | 12 ++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-)common/Kconfig.boot +4
-1@@ -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"common/autoboot.c +10
-3@@ -25,7 +25,7 @@DECLARE_GLOBAL_DATA_PTR ; -#define MAX_DELAY_STOP_STR 32 +#define MAX_DELAY_STOP_STR 64#ifndef DEBUG_BOOTKEYS #define DEBUG_BOOTKEYS 0@@ -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) && (c - sha_env_str <MAX_DELAY_STOP_STR )) { +/* preload presskey with salt */ +memcpy (presskey, sha_env_str, c - sha_env_str); + presskey_len = c - sha_env_str; + 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 ;/* --
Quoted 3 lines
1.8.3.1
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4166 bytes
Desc: S/MIME Cryptographic Signature
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20201120/e137d676/attachment.bin>
PATCH v2 1/1 Add optional salt to AUTOBOOT_STOP_STR_SHA256
In reply to Joel PeshkinQuoted 23 lines · Joel Peshkin
From: Joel Peshkin <[email protected]>
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 <[email protected]>Cc Simon Glass <[email protected]>Cc Bin Meng <[email protected]>Cc Patrick Delaunay <[email protected]>Cc Heiko Schocher <[email protected]>Cc trini at konsulko.comCc Heinrich Schuchardt <[email protected]>Cc Joel Peshkin <[email protected]>To: u-boot at lists.denx.de
---
Changes for v2:
- IncreaseMAX_DELAY_STOP_STR
- Check salt size againstMAX_DELAY_STOP_STRbefore copying
- Minor cleanup
Quoted 4 lines
--- common/Kconfig.boot | 5 ++++- common/autoboot.c | 12 ++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-)
Please see below
Quoted 39 lines
common/Kconfig.boot +4
-1@@ -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"common/autoboot.c +2
-1@@ -25,7 +25,7 @@DECLARE_GLOBAL_DATA_PTR ; -#define MAX_DELAY_STOP_STR 32 +#define MAX_DELAY_STOP_STR 64#ifndef DEBUG_BOOTKEYS #define DEBUG_BOOTKEYS 0@@ -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 ;
common/autoboot.c static int passwd_abort_sha256(uint64_t etime) · line 95
Quoted 6 lines
common/autoboot.c +3
-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) && (c - sha_env_str <MAX_DELAY_STOP_STR )) {
Use c instead of (c)
Quoted 19 lines
common/autoboot.c +5
-2+/* preload presskey with salt */ +memcpy (presskey, sha_env_str, c - sha_env_str); + presskey_len = c - sha_env_str; + 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 ;/* -- 1.8.3.1
PATCH v3 1/1 Add optional salt to AUTOBOOT_STOP_STR_SHA256
In reply to Joel PeshkinAdds 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.
To: u-boot at lists.denx.de
---
Changes for v2:
- Increase MAX_DELAY_STOP_STR
- Check salt size against MAX_DELAY_STOP_STR before copying
- Minor cleanup
Changes for v3:
- Cleanup changing (c) to c after review feedback
--- common/Kconfig.boot | 5 ++++- common/autoboot.c | 12 ++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-)
common/Kconfig.boot +4 -1
@@ -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"
common/autoboot.c +10 -2
@@ -25,7 +25,7 @@DECLARE_GLOBAL_DATA_PTR ; -#define MAX_DELAY_STOP_STR 32 +#define MAX_DELAY_STOP_STR 64#ifndef DEBUG_BOOTKEYS #define DEBUG_BOOTKEYS 0
@@ -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 && (c - sha_env_str <MAX_DELAY_STOP_STR )) { +/* preload presskey with salt */ +memcpy (presskey, sha_env_str, c - sha_env_str); + presskey_len = c - sha_env_str; + 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 ;/*
Signature · 9 lines
1.8.3.1 -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 4166 bytes Desc: S/MIME Cryptographic Signature URL: <https://lists.denx.de/pipermail/u-boot/attachments/20201121/bedb38a1/attachment.bin>
PATCH v3 1/1 Add optional salt to AUTOBOOT_STOP_STR_SHA256
Quoted 22 lines · Joel Peshkin
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 <[email protected]>Cc Simon Glass <[email protected]>Cc Bin Meng <[email protected]>Cc Patrick Delaunay <[email protected]>Cc Heiko Schocher <[email protected]>Cc Heinrich Schuchardt <[email protected]>Cc Joel Peshkin <[email protected]>To: u-boot at lists.denx.de
---
Changes for v2:
- IncreaseMAX_DELAY_STOP_STR
- Check salt size againstMAX_DELAY_STOP_STRbefore copying
- Minor cleanup
Changes for v3:
- Cleanup changing (c) to c after review feedback
Quoted 5 lines
--- common/Kconfig.boot | 5 ++++- common/autoboot.c | 12 ++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-)
(as I don't see it in v2)
PATCH v3 1/1 Add optional salt to AUTOBOOT_STOP_STR_SHA256
In reply to Joel PeshkinHello Joel,
Am 22.11.20 um 02:18 schrieb Joel Peshkin:
Quoted 21 lines
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 <[email protected]>Cc Simon Glass <[email protected]>Cc Bin Meng <[email protected]>Cc Patrick Delaunay <[email protected]>Cc Heiko Schocher <[email protected]>Cc Heinrich Schuchardt <[email protected]>Cc Joel Peshkin <[email protected]>To: u-boot at lists.denx.de
---
Changes for v2:
- IncreaseMAX_DELAY_STOP_STR
- Check salt size againstMAX_DELAY_STOP_STRbefore copying
- Minor cleanup
Changes for v3:
- Cleanup changing (c) to c after review feedback
Quoted 4 lines
--- common/Kconfig.boot | 5 ++++- common/autoboot.c | 12 ++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-)
bye,
Heiko
Signature · 3 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: +49-8142-66989-52 Fax: +49-8142-66989-80 Email: hs at denx.de
PATCH v3 1/1 Add optional salt to AUTOBOOT_STOP_STR_SHA256
In reply to Joel PeshkinQuoted 12 lines · Joel Peshkin
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 <[email protected]>Cc Simon Glass <[email protected]>Cc Bin Meng <[email protected]>Cc Patrick Delaunay <[email protected]>Cc Heiko Schocher <[email protected]>Cc Heinrich Schuchardt <[email protected]>Cc Joel Peshkin <[email protected]>
Quoted 3 lines
To: u-boot at lists.denx.de
Reviewed-by Simon Glass <[email protected]>Reviewed-by Heiko Schocher <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210118/479f0e72/attachment.sig>