Skip to contentSkip to conversation

prepare for rsa support

PATCH Superseded Jean-Christophe PLAGNIOL-VILLARD 2 participants 23 messages Mar 16, 2015 Crypto API

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover prepare for rsa support

Hi,

The following patch series prepare for the adding of the rsa digest support

This will allow to verify a rsa signature of a file

Introduction of a new command digest to handle the digest and check

The next patch series will add RSA and keystore support

v2:

- rebase on next
- add pbkdf2 to password/login framework
- command allow to have runtime output
used it in the new digest to print the supported algo

v3:
add more fix to ensure all the digest_xx call return are checked

The following changes since commit bbba2d05585637d04657dce293c0cb0611dbfeea:

Merge branch 'for-next/state' into next (2015-03-13 08:32:38 +0100)

are available in the git repository at:

git://git.jcrosoft.org/barebox.git delivery/digest

for you to fetch changes up to e4ec247ea29b5b48386f6a959f96f78d9cef729b:

digest: digest_file_window: check every digest_xxx return (2015-03-14 11:08:05 +0800)

----------------------------------------------------------------
Jean-Christophe PLAGNIOL-VILLARD (10):
digest: add verify callback
command: rename digest.c to hashsum.c
command: allow runtime usage
command: add generic digest command
digest: add digest callback
crypto: add pbkdf2 hmac key generator
password: add pbkdf2 support
digest: allow algo to specify their length at runtime
crypto: hmac: use digest_digest and check the return of every digest_xxx
digest: digest_file_window: check every digest_xxx return

 commands/Kconfig        |  26 +++++++++++++------
 commands/Makefile       |   3 ++-
 commands/digest.c       | 268 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------------------------------------------------------------------------------------------
 commands/hashsum.c      | 187 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 commands/internal.h     |   3 +++
 common/Kconfig          |   4 +++
 common/command.c        |   2 ++
 common/password.c       |  79 ++++++++++++++++++++++++++++++++++++--------------------
 crypto/Kconfig          |   5 ++++
 crypto/Makefile         |   2 ++
 crypto/digest.c         |  75 +++++++++++++++++++++++++++++++++++++++++++++++------
 crypto/hmac.c           |  51 +++++++++++++++++++++++-------------
 crypto/internal.h       |   4 +++
 crypto/md5.c            |   2 ++
 crypto/pbkdf2.c         |  94 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 crypto/sha1.c           |   2 ++
 crypto/sha2.c           |   3 +++
 crypto/sha4.c           |   3 +++
 include/command.h       |   3 +++
 include/crypto/pbkdf2.h |  23 +++++++++++++++++
 include/digest.h        |  25 +++++++++++++++---
 21 files changed, 647 insertions(+), 217 deletions(-)
 create mode 100644 commands/hashsum.c
 create mode 100644 commands/internal.h
 create mode 100644 crypto/pbkdf2.c
 create mode 100644 include/crypto/pbkdf2.h

Best Regards,
J.

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#22 lore raw

PATCH v3 10/10 digest: digest_file_window: check every digest_xxx return

In reply to Jean-Christophe PLAGNIOL-VILLARD
---
 crypto/digest.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
crypto/digest.c +7 -3
index c261f7e..ee1a321 100644
@@ -178,7 +178,9 @@ int digest_file_window(struct digest *d, const char *filename,
 	if (key)
 		digest_set_key(d, key, keylen);
 
-	digest_init(d);
+	ret = digest_init(d);
+	if (ret)
+		return ret;
 
 	fd = open(filename, O_RDONLY);
 	if (fd < 0) {
@@ -222,7 +224,9 @@ int digest_file_window(struct digest *d, const char *filename,
 			goto out_free;
 		}
 
-		digest_update(d, buf, now);
+		ret = digest_update(d, buf, now);
+		if (ret)
+			goto out_free;
 		size -= now;
 		len += now;
 	}
@@ -230,7 +234,7 @@ int digest_file_window(struct digest *d, const char *filename,
 	if (sig)
 		ret = digest_verify(d, sig);
 	else
-		digest_final(d, hash);
+		ret = digest_final(d, hash);
 
 out_free:
 	if (flags)
Signature · 7 lines
2.1.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw

PATCH v3 1/10 digest: add verify callback

In reply to Jean-Christophe PLAGNIOL-VILLARD

this will allow to compare a md with the original one

When calling this do not call final

For RSA_SIGN verification final does not exist only verify as final will be for signing

---
 crypto/digest.c   | 24 +++++++++++++++++++++++-
 crypto/hmac.c     |  1 +
 crypto/internal.h |  2 ++
 crypto/md5.c      |  1 +
 crypto/sha1.c     |  1 +
 crypto/sha2.c     |  2 ++
 crypto/sha4.c     |  2 ++
 include/digest.h  |  6 ++++++
 8 files changed, 38 insertions(+), 1 deletion(-)
crypto/digest.c +23 -1
index c06089d..52e8796 100644
@@ -26,6 +26,8 @@
 #include <module.h>
 #include <linux/err.h>
 
+#include "internal.h"
+
 static LIST_HEAD(digests);
 
 static struct digest_algo *digest_algo_get_by_name(const char *name);
@@ -37,9 +39,29 @@ static int dummy_init(struct digest *d)
 
 static void dummy_free(struct digest *d) {}
 
+int digest_generic_verify(struct digest *d, const unsigned char *md)
+{
+	int ret;
+	int len = digest_length(d);
+	unsigned char *tmp;
+
+	tmp = xmalloc(len);
+
+	ret = digest_final(d, tmp);
+	if (ret)
+		goto end;
+
+	ret = memcmp(md, tmp, len);
+	ret = ret ? -EINVAL : 0;
+end:
+	free(tmp);
+	return ret;
+}
+
 int digest_algo_register(struct digest_algo *d)
 {
-	if (!d || !d->name || !d->update || !d->final || d->length < 1)
+	if (!d || !d->name || !d->update || !d->final || !d->verify ||
+	    d->length < 1)
 		return -EINVAL;
 
 	if (!d->init)
crypto/hmac.c +1 -0
index 1462730..f39e4c8 100644
@@ -136,6 +136,7 @@ struct digest_algo hmac_algo = {
 	.init = digest_hmac_init,
 	.update = digest_hmac_update,
 	.final = digest_hmac_final,
+	.verify = digest_generic_verify,
 	.set_key = digest_hmac_set_key,
 	.free = digest_hmac_free,
 	.ctx_length = sizeof(struct digest_hmac),
crypto/internal.h +2 -0
index cc409d8..f482654 100644
@@ -13,3 +13,5 @@ static inline int digest_hmac_register(struct digest_algo *algo,
 	return 0;
 }
 #endif
+
+int digest_generic_verify(struct digest *d, const unsigned char *md);
crypto/md5.c +1 -0
index fe17ff5..4847b38 100644
@@ -294,6 +294,7 @@ static struct digest_algo md5 = {
 	.init = digest_md5_init,
 	.update = digest_md5_update,
 	.final = digest_md5_final,
+	.verify = digest_generic_verify,
 	.length = 16,
 	.ctx_length = sizeof(struct MD5Context),
 };
crypto/sha1.c +1 -0
index a244b5d..09dee87 100644
@@ -315,6 +315,7 @@ static struct digest_algo m = {
 	.init = digest_sha1_init,
 	.update = digest_sha1_update,
 	.final = digest_sha1_final,
+	.verify = digest_generic_verify,
 	.length = SHA1_SUM_LEN,
 	.ctx_length = sizeof(sha1_context),
 };
crypto/sha2.c +2 -0
index cb89c82..9bf6541 100644
@@ -304,6 +304,7 @@ static struct digest_algo m224 = {
 	.init = digest_sha224_init,
 	.update = digest_sha2_update,
 	.final = digest_sha2_final,
+	.verify = digest_generic_verify,
 	.length = SHA224_SUM_LEN,
 	.ctx_length = sizeof(sha2_context),
 };
@@ -335,6 +336,7 @@ static struct digest_algo m256 = {
 	.init = digest_sha256_init,
 	.update = digest_sha2_update,
 	.final = digest_sha2_final,
+	.verify = digest_generic_verify,
 	.length = SHA256_SUM_LEN,
 	.ctx_length = sizeof(sha2_context),
 };
crypto/sha4.c +2 -0
index 1c768e7..5c3097d 100644
@@ -309,6 +309,7 @@ static struct digest_algo m384 = {
 	.init = digest_sha384_init,
 	.update = digest_sha4_update,
 	.final = digest_sha4_final,
+	.verify = digest_generic_verify,
 	.length = SHA384_SUM_LEN,
 	.ctx_length = sizeof(sha4_context),
 };
@@ -341,6 +342,7 @@ static struct digest_algo m512 = {
 	.init = digest_sha512_init,
 	.update = digest_sha4_update,
 	.final = digest_sha4_final,
+	.verify = digest_generic_verify,
 	.length = SHA512_SUM_LEN,
 	.ctx_length = sizeof(sha4_context),
 };
include/digest.h +6 -0
index b890a7a..cba7814 100644
@@ -32,6 +32,7 @@ struct digest_algo {
 	int (*update)(struct digest *d, const void *data, unsigned long len);
 	int (*final)(struct digest *d, unsigned char *md);
 	int (*set_key)(struct digest *d, const unsigned char *key, unsigned int len);
+	int (*verify)(struct digest *d, const unsigned char *md);
 
 	unsigned int length;
 	unsigned int ctx_length;
@@ -80,6 +81,11 @@ static inline int digest_final(struct digest *d, unsigned char *md)
 	return d->algo->final(d, md);
 }
 
+static inline int digest_verify(struct digest *d, const unsigned char *md)
+{
+	return d->algo->verify(d, md);
+}
+
 static inline int digest_length(struct digest *d)
 {
 	return d->algo->length;
Signature · 7 lines
2.1.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

PATCH v3 2/10 command: rename digest.c to hashsum.c

as I'll add a new generic command named digest

---
 commands/Kconfig                 | 14 +++++++-------
 commands/Makefile                |  2 +-
 commands/{digest.c => hashsum.c} |  0
 3 files changed, 8 insertions(+), 8 deletions(-)
 rename commands/{digest.c => hashsum.c} (100%)
commands/Kconfig +7 -7
index 286e9ce..7e3e8b7 100644
@@ -12,7 +12,7 @@ config HAS_POWEROFF
 
 if COMMAND_SUPPORT
 
-config COMPILE_DIGEST
+config COMPILE_HASH
 	tristate
 	select DIGEST
 	help
@@ -917,7 +917,7 @@ config CMD_LS
 
 config CMD_MD5SUM
 	tristate
-	select COMPILE_DIGEST
+	select COMPILE_HASH
 	select MD5
 	prompt "md5sum"
 	help
@@ -982,7 +982,7 @@ config CMD_RMDIR
 
 config CMD_SHA1SUM
 	tristate
-	select COMPILE_DIGEST
+	select COMPILE_HASH
 	select SHA1
 	prompt "sha1sum"
 	help
@@ -994,7 +994,7 @@ config CMD_SHA1SUM
 
 config CMD_SHA224SUM
 	tristate
-	select COMPILE_DIGEST
+	select COMPILE_HASH
 	select SHA224
 	prompt "sha224sum"
 	help
@@ -1006,7 +1006,7 @@ config CMD_SHA224SUM
 
 config CMD_SHA256SUM
 	tristate
-	select COMPILE_DIGEST
+	select COMPILE_HASH
 	select SHA256
 	prompt "sha256sum"
 	help
@@ -1018,7 +1018,7 @@ config CMD_SHA256SUM
 
 config CMD_SHA384SUM
 	tristate
-	select COMPILE_DIGEST
+	select COMPILE_HASH
 	select SHA384
 	prompt "sha384sum"
 	help
@@ -1030,7 +1030,7 @@ config CMD_SHA384SUM
 
 config CMD_SHA512SUM
 	tristate
-	select COMPILE_DIGEST
+	select COMPILE_HASH
 	select SHA512
 	prompt "sha512sum"
 	help
commands/Makefile +1 -1
index 7344e01..e42662f 100644
@@ -1,5 +1,5 @@
 obj-$(CONFIG_STDDEV)		+= stddev.o
-obj-$(CONFIG_COMPILE_DIGEST)	+= digest.o
+obj-$(CONFIG_COMPILE_HASH)	+= hashsum.o
 obj-$(CONFIG_COMPILE_MEMORY)	+= mem.o
 obj-$(CONFIG_CMD_BOOTM)		+= bootm.o
 obj-$(CONFIG_CMD_UIMAGE)	+= uimage.o
commands/hashsum.c renamed from commands/digest.c +0 -0
similarity index 100%
rename from commands/digest.c
rename to commands/hashsum.c
Signature · 7 lines
2.1.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw

PATCH v3 3/10 command: allow runtime usage

In reply to Jean-Christophe PLAGNIOL-VILLARD

This will allow as example to list the currently supported digest.

---
 common/command.c  | 2 ++
 include/command.h | 3 +++
 2 files changed, 5 insertions(+)
common/command.c +2 -0
index 61191c2..dc2cb88 100644
@@ -47,6 +47,8 @@ void barebox_cmd_usage(struct command *cmdtp)
 		puts(cmdtp->help);
 		putchar('\n');
 	}
+	if (cmdtp->usage)
+		cmdtp->usage();
 #endif
 }
 EXPORT_SYMBOL(barebox_cmd_usage);
include/command.h +3 -0
index 5d5bf53..3aca1a9 100644
@@ -54,6 +54,7 @@ struct command {
 	uint32_t	group;
 #ifdef	CONFIG_LONGHELP
 	const char	*help;		/* Help  message	(long)	*/
+	void		(*usage)(void);
 #endif
 }
 #ifdef __x86_64__
@@ -115,8 +116,10 @@ static const __maybe_unused char cmd_##_name##_help[] =
 
 #ifdef CONFIG_LONGHELP
 #define BAREBOX_CMD_HELP(text)	.help = text,
+#define BAREBOX_CMD_USAGE(fn)	.usage = fn,
 #else
 #define BAREBOX_CMD_HELP(text)
+#define BAREBOX_CMD_USAGE(fn)
 #endif
 
 #define BAREBOX_CMD_GROUP(grp)	.group = grp,
Signature · 7 lines
2.1.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#4 lore raw

PATCH v3 4/10 command: add generic digest command

In reply to Jean-Christophe PLAGNIOL-VILLARD

That can be used for digest calculation and verify

---
 commands/Kconfig    |  12 +++-
 commands/Makefile   |   1 +
 commands/digest.c   | 193 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 commands/hashsum.c  |  68 ++++--------------
 commands/internal.h |   3 +
 crypto/digest.c     |  25 +++++--
 include/digest.h    |   8 ++-
 7 files changed, 248 insertions(+), 62 deletions(-)
 create mode 100644 commands/digest.c
 create mode 100644 commands/internal.h
commands/Kconfig +11 -1
index 7e3e8b7..847ff76 100644
@@ -14,7 +14,7 @@ if COMMAND_SUPPORT
 
 config COMPILE_HASH
 	tristate
-	select DIGEST
+	select CMD_DIGEST
 	help
 	  Turns on compilation of digest.c
 
@@ -842,6 +842,16 @@ config CMD_CMP
 
 	  Returns successfully if the two files are the same, return with an error if not
 
+config CMD_DIGEST
+	tristate
+	select DIGEST
+	prompt "digest"
+	help
+	  Usage: digest -a <algo> [-k <key> | -K <file>] [-s <sig> | -S <file>] FILE|AREA
+
+	  Calculate a digest over a FILE or a memory area with the possibility
+	  to checkit.
+
 config CMD_DIRNAME
 	tristate
 	prompt "dirname"
commands/Makefile +1 -0
index e42662f..b902f58 100644
@@ -1,4 +1,5 @@
 obj-$(CONFIG_STDDEV)		+= stddev.o
+obj-$(CONFIG_CMD_DIGEST)	+= digest.o
 obj-$(CONFIG_COMPILE_HASH)	+= hashsum.o
 obj-$(CONFIG_COMPILE_MEMORY)	+= mem.o
 obj-$(CONFIG_CMD_BOOTM)		+= bootm.o
commands/digest.c new file +193 -0

193 lines not on this page · raw message

commands/hashsum.c +14 -54

126 lines not on this page · raw message

commands/internal.h new file +3 -0
new file mode 100644
index 0000000..29cc656
@@ -0,0 +1,3 @@
+int __do_digest(struct digest *d, unsigned char *key, int keylen,
+		       unsigned char *sig,
+		       int argc, char *argv[]);
crypto/digest.c +20 -5
index 52e8796..9fa5bba 100644
@@ -106,6 +106,15 @@ static struct digest_algo *digest_algo_get_by_name(const char *name)
 	return NULL;
 }
 
+void digest_algo_prints(const char *prefix)
+{
+	struct digest_algo* d;
+
+	list_for_each_entry(d, &digests, list) {
+		printf("%s%s\n", prefix, d->name);
+	}
+}
+
 struct digest *digest_alloc(const char *name)
 {
 	struct digest *d;
@@ -140,6 +149,7 @@ EXPORT_SYMBOL_GPL(digest_free);
 int digest_file_window(struct digest *d, const char *filename,
 		       const unsigned char *key, size_t keylen,
 		       unsigned char *hash,
+		       unsigned char *sig,
 		       ulong start, ulong size)
 {
 	ulong len = 0;
@@ -199,7 +209,10 @@ int digest_file_window(struct digest *d, const char *filename,
 		len += now;
 	}
 
-	digest_final(d, hash);
+	if (sig)
+		ret = digest_verify(d, sig);
+	else
+		digest_final(d, hash);
 
 out_free:
 	if (flags)
@@ -213,7 +226,8 @@ EXPORT_SYMBOL_GPL(digest_file_window);
 
 int digest_file(struct digest *d, const char *filename,
 		       const unsigned char *key, size_t keylen,
-		       unsigned char *hash)
+		       unsigned char *hash,
+		       unsigned char *sig)
 {
 	struct stat st;
 	int ret;
@@ -223,13 +237,14 @@ int digest_file(struct digest *d, const char *filename,
 	if (ret < 0)
 		return ret;
 
-	return digest_file_window(d, filename, key, keylen, hash, 0, st.st_size);
+	return digest_file_window(d, filename, key, keylen, hash, sig, 0, st.st_size);
 }
 EXPORT_SYMBOL_GPL(digest_file);
 
 int digest_file_by_name(const char *algo, const char *filename,
 		       const unsigned char *key, size_t keylen,
-		       unsigned char *hash)
+		       unsigned char *hash,
+		       unsigned char *sig)
 {
 	struct digest *d;
 	int ret;
@@ -238,7 +253,7 @@ int digest_file_by_name(const char *algo, const char *filename,
 	if (!d)
 		return -EIO;
 
-	ret = digest_file(d, filename, key, keylen, hash);
+	ret = digest_file(d, filename, key, keylen, hash, sig);
 	digest_free(d);
 	return ret;
 }
include/digest.h +6 -2
index cba7814..ec904f0 100644
@@ -50,6 +50,7 @@ struct digest {
  */
 int digest_algo_register(struct digest_algo *d);
 void digest_algo_unregister(struct digest_algo *d);
+void digest_algo_prints(const char *prefix);
 
 struct digest *digest_alloc(const char *name);
 void digest_free(struct digest *d);
@@ -57,13 +58,16 @@ void digest_free(struct digest *d);
 int digest_file_window(struct digest *d, const char *filename,
 		       const unsigned char *key, size_t keylen,
 		       unsigned char *hash,
+		       unsigned char *sig,
 		       ulong start, ulong size);
 int digest_file(struct digest *d, const char *filename,
 		       const unsigned char *key, size_t keylen,
-		       unsigned char *hash);
+		       unsigned char *hash,
+		       unsigned char *sig);
 int digest_file_by_name(const char *algo, const char *filename,
 		       const unsigned char *key, size_t keylen,
-		       unsigned char *hash);
+		       unsigned char *hash,
+		       unsigned char *sig);
 
 static inline int digest_init(struct digest *d)
 {
Signature · 7 lines
2.1.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#7 lore raw

PATCH v3 5/10 digest: add digest callback

In reply to Jean-Christophe PLAGNIOL-VILLARD

Combination of @init and @update and @final. This function effectively behaves as the entire chain of operations, @init, @update and @final issued in sequence. This is added for hardware which cannot do even the @finup, but can only do the whole transformation in one run.

---
 crypto/digest.c   | 18 ++++++++++++++++++
 crypto/hmac.c     |  1 +
 crypto/internal.h |  2 ++
 crypto/md5.c      |  1 +
 crypto/sha1.c     |  1 +
 crypto/sha2.c     |  1 +
 crypto/sha4.c     |  1 +
 include/digest.h  |  8 ++++++++
 8 files changed, 33 insertions(+)
crypto/digest.c +18 -0
index 9fa5bba..c261f7e 100644
@@ -58,6 +58,24 @@ end:
 	return ret;
 }
 
+int digest_generic_digest(struct digest *d, const void *data,
+			  unsigned int len, u8 *md)
+
+{
+	int ret;
+
+	if (!data || len == 0 || !md)
+		return -EINVAL;
+
+	ret = digest_init(d);
+	if (ret)
+		return ret;
+	ret = digest_update(d, data, len);
+	if (ret)
+		return ret;
+	return digest_final(d, md);
+}
+
 int digest_algo_register(struct digest_algo *d)
 {
 	if (!d || !d->name || !d->update || !d->final || !d->verify ||
crypto/hmac.c +1 -0
index f39e4c8..b1c17af 100644
@@ -136,6 +136,7 @@ struct digest_algo hmac_algo = {
 	.init = digest_hmac_init,
 	.update = digest_hmac_update,
 	.final = digest_hmac_final,
+	.digest = digest_generic_digest,
 	.verify = digest_generic_verify,
 	.set_key = digest_hmac_set_key,
 	.free = digest_hmac_free,
crypto/internal.h +2 -0
index f482654..c6f5908 100644
@@ -15,3 +15,5 @@ static inline int digest_hmac_register(struct digest_algo *algo,
 #endif
 
 int digest_generic_verify(struct digest *d, const unsigned char *md);
+int digest_generic_digest(struct digest *d, const void *data,
+			  unsigned int len, u8 *out);
crypto/md5.c +1 -0
index 4847b38..b7ad6f2 100644
@@ -294,6 +294,7 @@ static struct digest_algo md5 = {
 	.init = digest_md5_init,
 	.update = digest_md5_update,
 	.final = digest_md5_final,
+	.digest = digest_generic_digest,
 	.verify = digest_generic_verify,
 	.length = 16,
 	.ctx_length = sizeof(struct MD5Context),
crypto/sha1.c +1 -0
index 09dee87..b108f8a 100644
@@ -315,6 +315,7 @@ static struct digest_algo m = {
 	.init = digest_sha1_init,
 	.update = digest_sha1_update,
 	.final = digest_sha1_final,
+	.digest = digest_generic_digest,
 	.verify = digest_generic_verify,
 	.length = SHA1_SUM_LEN,
 	.ctx_length = sizeof(sha1_context),
crypto/sha2.c +1 -0
index 9bf6541..375a40e 100644
@@ -336,6 +336,7 @@ static struct digest_algo m256 = {
 	.init = digest_sha256_init,
 	.update = digest_sha2_update,
 	.final = digest_sha2_final,
+	.digest = digest_generic_digest,
 	.verify = digest_generic_verify,
 	.length = SHA256_SUM_LEN,
 	.ctx_length = sizeof(sha2_context),
crypto/sha4.c +1 -0
index 5c3097d..1b91e7f 100644
@@ -342,6 +342,7 @@ static struct digest_algo m512 = {
 	.init = digest_sha512_init,
 	.update = digest_sha4_update,
 	.final = digest_sha4_final,
+	.digest = digest_generic_digest,
 	.verify = digest_generic_verify,
 	.length = SHA512_SUM_LEN,
 	.ctx_length = sizeof(sha4_context),
include/digest.h +8 -0
index ec904f0..8250ca7 100644
@@ -31,6 +31,8 @@ struct digest_algo {
 	int (*init)(struct digest *d);
 	int (*update)(struct digest *d, const void *data, unsigned long len);
 	int (*final)(struct digest *d, unsigned char *md);
+	int (*digest)(struct digest *d, const void *data,
+		      unsigned int len, u8 *out);
 	int (*set_key)(struct digest *d, const unsigned char *key, unsigned int len);
 	int (*verify)(struct digest *d, const unsigned char *md);
 
@@ -85,6 +87,12 @@ static inline int digest_final(struct digest *d, unsigned char *md)
 	return d->algo->final(d, md);
 }
 
+static inline int digest_digest(struct digest *d, const void *data,
+		      unsigned int len, u8 *md)
+{
+	return d->algo->digest(d, data, len, md);
+}
+
 static inline int digest_verify(struct digest *d, const unsigned char *md)
 {
 	return d->algo->verify(d, md);
Signature · 7 lines
2.1.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#8 lore raw

PATCH v3 6/10 crypto: add pbkdf2 hmac key generator

In reply to Jean-Christophe PLAGNIOL-VILLARD

this will allow to generate a KEY + IV based on a password and salt for AES encryption/decryption as example

or simply the key for hmac or rsa from text password

---
 crypto/Kconfig          |  5 +++
 crypto/Makefile         |  2 ++
 crypto/pbkdf2.c         | 94 +++++++++++++++++++++++++++++++++++++++++++++++++
 include/crypto/pbkdf2.h | 23 ++++++++++++
 4 files changed, 124 insertions(+)
 create mode 100644 crypto/pbkdf2.c
 create mode 100644 include/crypto/pbkdf2.h
crypto/Kconfig +5 -0
index e72b91e..b721e30 100644
@@ -34,3 +34,8 @@ config DIGEST_HMAC
 	bool "HMAC"
 
 endif
+
+config CRYPTO_PBKDF2
+	select DIGEST
+	select SHA1
+	bool
crypto/Makefile +2 -0
index ff5c289..0bb67d5 100644
@@ -9,3 +9,5 @@ obj-$(CONFIG_SHA224)	+= sha2.o
 obj-$(CONFIG_SHA256)	+= sha2.o
 obj-$(CONFIG_SHA384)	+= sha4.o
 obj-$(CONFIG_SHA512)	+= sha4.o
+
+obj-$(CONFIG_CRYPTO_PBKDF2)	+= pbkdf2.o
crypto/pbkdf2.c new file +94 -0

94 lines not on this page · raw message

include/crypto/pbkdf2.h new file +23 -0
new file mode 100644
index 0000000..fa66675
@@ -0,0 +1,23 @@
+/*
+ * (C) Copyright 2015 Jean-Christophe PLAGNIOL-VILLARD <[email protected]>
+ *
+ * Under GPLv2 Only
+ */
+
+#ifndef __PBKDF2_H__
+#define __PBKDF2_H__
+
+#include <digest.h>
+
+int pkcs5_pbkdf2_hmac_sha1(const unsigned char *pwd, size_t pwd_len,
+			   const unsigned char *salt, size_t salt_len,
+			   uint32_t iteration,
+			   uint32_t key_len, unsigned char *buf);
+
+int pkcs5_pbkdf2_hmac(struct digest* d,
+		      const unsigned char *pwd, size_t pwd_len,
+		      const unsigned char *salt, size_t salt_len,
+		      uint32_t iteration,
+		      uint32_t key_len, unsigned char *key);
+
+#endif /* __PBKDF2_H__ */
Signature · 7 lines
2.1.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#20 lore raw

PATCH v3 8/10 digest: allow algo to specify their length at runtime

In reply to Jean-Christophe PLAGNIOL-VILLARD

such as RSA as we load a DER key we will detect the key size at runtime and so the algo length.

---
 include/digest.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/digest.h +2 -1
index 8250ca7..41ad912 100644
@@ -45,6 +45,7 @@ struct digest_algo {
 struct digest {
 	struct digest_algo *algo;
 	void *ctx;
+	unsigned int length;
 };
 
 /*
@@ -100,7 +101,7 @@ static inline int digest_verify(struct digest *d, const unsigned char *md)
 
 static inline int digest_length(struct digest *d)
 {
-	return d->algo->length;
+	return d->length ? d->length : d->algo->length;
 }
 
 static inline int digest_set_key(struct digest *d, const unsigned char *key,
Signature · 7 lines
2.1.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#9 lore raw

PATCH v3 7/10 password: add pbkdf2 support

In reply to Jean-Christophe PLAGNIOL-VILLARD

We will use "barebox_password" as salt and 10000 round to generate a 64 bytes key.

---
 common/Kconfig    |  4 +++
 common/password.c | 79 +++++++++++++++++++++++++++++++++++--------------------
 2 files changed, 55 insertions(+), 28 deletions(-)
common/Kconfig +4 -0
index 96ace6b..ad8a596 100644
@@ -453,6 +453,10 @@ config PASSWD_SUM_SHA512
 	bool "SHA512"
 	select SHA512
 
+config PASSWD_CRYPTO_PBKDF2
+	bool "PBKDF2"
+	select CRYPTO_PBKDF2
+
 endchoice
 
 endif
common/password.c +51 -28

135 lines not on this page · raw message

Signature · 7 lines
2.1.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#21 lore raw

PATCH v3 9/10 crypto: hmac: use digest_digest and check the return of every digest_xxx

In reply to Jean-Christophe PLAGNIOL-VILLARD
---
 crypto/hmac.c | 49 +++++++++++++++++++++++++++++++------------------
 1 file changed, 31 insertions(+), 18 deletions(-)
crypto/hmac.c +31 -18
index b1c17af..c2195d9 100644
@@ -62,15 +62,15 @@ static int digest_hmac_set_key(struct digest *d, const unsigned char *key,
 {
 	struct digest_hmac_ctx *dh = d->ctx;
 	struct digest_hmac *hmac = to_digest_hmac(d->algo);
+	unsigned char *sum = NULL;
+	int ret;
 
 	free(dh->key);
 	if (len > hmac->pad_length) {
-		unsigned char *sum;
-
 		sum = xmalloc(digest_length(dh->d));
-		digest_init(dh->d);
-		digest_update(dh->d, dh->key, dh->keylen);
-		digest_final(dh->d, sum);
+		ret = digest_digest(dh->d, dh->key, dh->keylen, sum);
+		if (ret)
+			goto err;
 		dh->keylen = digest_length(dh->d);
 		dh->key = sum;
 	} else {
@@ -79,14 +79,17 @@ static int digest_hmac_set_key(struct digest *d, const unsigned char *key,
 		dh->keylen = len;
 	}
 
-	return 0;
+	ret = 0;
+err:
+	free(sum);
+	return ret;
 }
 
 static int digest_hmac_init(struct digest *d)
 {
 	struct digest_hmac_ctx *dh = d->ctx;
 	struct digest_hmac *hmac = to_digest_hmac(d->algo);
-	int i;
+	int i, ret;
 	unsigned char *key = dh->key;
 	unsigned int keylen = dh->keylen;
 
@@ -98,10 +101,10 @@ static int digest_hmac_init(struct digest *d)
 		dh->opad[i] = (unsigned char)(dh->opad[i] ^ key[i]);
 	}
 
-	digest_init(dh->d);
-	digest_update(dh->d, dh->ipad, hmac->pad_length);
-
-	return 0;
+	ret = digest_init(dh->d);
+	if (ret)
+		return ret;
+	return digest_update(dh->d, dh->ipad, hmac->pad_length);
 }
 
 static int digest_hmac_update(struct digest *d, const void *data,
@@ -117,18 +120,28 @@ static int digest_hmac_final(struct digest *d, unsigned char *md)
 	struct digest_hmac_ctx *dh = d->ctx;
 	struct digest_hmac *hmac = to_digest_hmac(d->algo);
 	unsigned char *tmp = NULL;
+	int ret;
 
 	tmp = xmalloc(digest_length(d));
 
-	digest_final(dh->d, tmp);
-	digest_init(dh->d);
-	digest_update(dh->d, dh->opad, hmac->pad_length);
-	digest_update(dh->d, tmp, digest_length(d));
-	digest_final(dh->d, md);
-
+	ret = digest_final(dh->d, tmp);
+	if (ret)
+		goto err;
+	ret = digest_init(dh->d);
+	if (ret)
+		goto err;
+	ret = digest_update(dh->d, dh->opad, hmac->pad_length);
+	if (ret)
+		goto err;
+	ret = digest_update(dh->d, tmp, digest_length(d));
+	if (ret)
+		goto err;
+	ret = digest_final(dh->d, md);
+
+err:
 	free(tmp);
 
-	return 0;
+	return ret;
 }
 
 struct digest_algo hmac_algo = {
Signature · 7 lines
2.1.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#10 lore raw

Re: [PATCH 07/10] password: add pbkdf2 support

In reply to Jean-Christophe PLAGNIOL-VILLARD
Quoted 2 lines · Jean-Christophe PLAGNIOL-VILLARD

We will use "barebox_password" as salt and 10000 round to generate a 64 bytes key.

The purpose of a salt is to protect a against dictionary or rainbow-table (precomputed) attacks. That means that the Salt must be randomly generated and saved with the password.

For setting a new password in barebox, even a low entropy salt will make attacks significantly more expensive. So we should add some entropy from user interaction timing in that case.

For hashing a password at compile time, we should get the salt from the host system.

Regards,
Jan

Signature · 10 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#11 lore raw

Re: [PATCH 07/10] password: add pbkdf2 support

Quoted 7 lines · Jan Lübbe
Quoted 2 lines · Jean-Christophe PLAGNIOL-VILLARD

We will use "barebox_password" as salt and 10000 round to generate a 64 bytes key.

The purpose of a salt is to protect a against dictionary or rainbow-table (precomputed) attacks. That means that the Salt must be randomly generated and saved with the password.

This will be a enough stong enven with static one to protect against reverse hack for barebox protection

Use a 32 byte pass try to do an attack agaist dictionary. it will take you more than 10 years to break it

Quoted 4 lines

For setting a new password in barebox, even a low entropy salt will make attacks significantly more expensive. So we should add some entropy from user interaction timing in that case.

yes we could do this too

Quoted 3 lines

For hashing a password at compile time, we should get the salt from the host system.

yes

do we really need it?

Best Regards,
J.

Quoted 14 lines

Regards,
Jan

Signature · 10 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#12 lore raw

Re: [PATCH 07/10] password: add pbkdf2 support

Quoted 17 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 7 lines · Jan Lübbe
Quoted 2 lines · Jean-Christophe PLAGNIOL-VILLARD

We will use "barebox_password" as salt and 10000 round to generate a 64 bytes key.

The purpose of a salt is to protect a against dictionary or rainbow-table (precomputed) attacks. That means that the Salt must be randomly generated and saved with the password.

This will be a enough stong enven with static one to protect against reverse hack for barebox protection

Use a 32 byte pass try to do an attack agaist dictionary. it will take you more than 10 years to break it

Quoted 4 lines

For setting a new password in barebox, even a low entropy salt will make attacks significantly more expensive. So we should add some entropy from user interaction timing in that case.

Quoted 7 lines

yes we could do this too

Quoted 3 lines

For hashing a password at compile time, we should get the salt from the host system.

yes

do we really need it?

Yes, definitely. We must use the algorithms as they are intended to be used.

If we try to move users away from RSA2048 because it will be vulnerable in the future, we should not go against established practice for password salts by hard-coding it.

Regards,
Jan

Signature · 10 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#13 lore raw

Re: [PATCH 07/10] password: add pbkdf2 support

Quoted 24 lines · Jan Lübbe
Quoted 23 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 7 lines · Jan Lübbe
Quoted 2 lines · Jean-Christophe PLAGNIOL-VILLARD

We will use "barebox_password" as salt and 10000 round to generate a 64 bytes key.

The purpose of a salt is to protect a against dictionary or rainbow-table (precomputed) attacks. That means that the Salt must be randomly generated and saved with the password.

This will be a enough stong enven with static one to protect against reverse hack for barebox protection

Use a 32 byte pass try to do an attack agaist dictionary. it will take you more than 10 years to break it

Quoted 4 lines

For setting a new password in barebox, even a low entropy salt will make attacks significantly more expensive. So we should add some entropy from user interaction timing in that case.

yes we could do this too

Quoted 3 lines

For hashing a password at compile time, we should get the salt from the host system.

yes

Quoted 8 lines
Quoted 1 line

do we really need it?

Yes, definitely. We must use the algorithms as they are intended to be used.

If we try to move users away from RSA2048 because it will be vulnerable in the future, we should not go against established practice for password salts by hard-coding it.

I'm not against it but with the barebox entropy did not see the point to use it.

so how do we generate the salt? what length

Personnaly I'll prefer

a random 64 bytes | sha256 | take first 32bytes. | pbkdf2 10000 round

result a 64 bytes password file <salt 32 byes><key 32 bytes>

Best Regards,
J.

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#14 lore raw

Re: [PATCH 07/10] password: add pbkdf2 support

Quoted 6 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 6 lines

Yes, definitely. We must use the algorithms as they are intended to be used.

If we try to move users away from RSA2048 because it will be vulnerable in the future, we should not go against established practice for password salts by hard-coding it.

Quoted 8 lines

I'm not against it but with the barebox entropy did not see the point to use it.

so how do we generate the salt? what length

Personnaly I'll prefer

a random 64 bytes | sha256 | take first 32bytes. | pbkdf2 10000 round

Running SHA-256 on random data is useless for security. Just get <hash-size> bytes from /dev/urandom on the host. We could generate a file with the compile-time SALT which is then included.

On the running barebox, we could use SHA to hash the old password file together with the current timer value. At least until we have something better.

Quoted 1 line

result a 64 bytes password file <salt 32 byes><key 32 bytes>

Yes. As we select the algorithm at compile time, we don't the to save it in the file.

Regards,
Jan

Signature · 10 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#5 lore raw

Re: [PATCH 04/10] command: add generic digest command

In reply to Jean-Christophe PLAGNIOL-VILLARD

commands/digest.c line 184

Quoted 10 lines · Jean-Christophe PLAGNIOL-VILLARD
(quoted diff) +2 -0
+BAREBOX_CMD_HELP_START(digest)
+BAREBOX_CMD_HELP_TEXT("Calculate a digest over a FILE or a memory

area.")

commands/digest.c new file +7 -0
+BAREBOX_CMD_HELP_TEXT("Options:")
+BAREBOX_CMD_HELP_OPT ("-a <algo>\t",  "digest to use")
+BAREBOX_CMD_HELP_OPT ("-k <key>\t",  "key as text")
+BAREBOX_CMD_HELP_OPT ("-K <file>\t",  "key file")
+BAREBOX_CMD_HELP_OPT ("-s <sig>\t",  "digest")
+BAREBOX_CMD_HELP_OPT ("-S <file>\t",  "digest flie")
+BAREBOX_CMD_HELP_END

We're mixing different terms here: digest and signature

Signature is usually used in the context of public key crypto, digest is mostly used with for hashes. The command uses both interchangeably.

How about:
-a <algo> hash or signature algorithm to use
-k <key> use supplied <key> (ASCII or hex) for MAC
-K <file> use key from <file> (binary) for MAC
-v <hex> verify data against supplied <hex> (hash, MAC or signature)
-V <file> verify data against <file> (hash, MAC or signature)

Regards,
Jan

Signature · 10 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#15 lore raw

Re: [PATCH 07/10] password: add pbkdf2 support

In reply to Jan Lübbe
Quoted 10 lines · Jan Lübbe
Quoted 9 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 6 lines

Yes, definitely. We must use the algorithms as they are intended to be used.

If we try to move users away from RSA2048 because it will be vulnerable in the future, we should not go against established practice for password salts by hard-coding it.

I'm not against it but with the barebox entropy did not see the point to use it.

Quoted 7 lines
Quoted 5 lines

so how do we generate the salt? what length

Personnaly I'll prefer

a random 64 bytes | sha256 | take first 32bytes. | pbkdf2 10000 round

Running SHA-256 on random data is useless for security.

SHA256 is to improve the entrpopy not security

Quoted 4 lines

Just get
<hash-size> bytes from /dev/urandom on the host. We could generate a file with the compile-time SALT which is then included.

Quoted 8 lines

On the running barebox, we could use SHA to hash the old password file together with the current timer value. At least until we have something better.

Quoted 1 line

result a 64 bytes password file <salt 32 byes><key 32 bytes>

Yes. As we select the algorithm at compile time, we don't the to save it in the file.

this is for barebox as we may not have any passwd file

Best Regards,
J.

Quoted 9 lines

Regards,
Jan

Signature · 4 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#16 lore raw

Re: [PATCH 07/10] password: add pbkdf2 support

Quoted 11 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 10 lines · Jan Lübbe
Quoted 9 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 6 lines

Yes, definitely. We must use the algorithms as they are intended to be used.

If we try to move users away from RSA2048 because it will be vulnerable in the future, we should not go against established practice for password salts by hard-coding it.

I'm not against it but with the barebox entropy did not see the point to use it.

Quoted 8 lines
Quoted 7 lines
Quoted 5 lines

so how do we generate the salt? what length

Personnaly I'll prefer

a random 64 bytes | sha256 | take first 32bytes. | pbkdf2 10000 round

Running SHA-256 on random data is useless for security.

SHA256 is to improve the entrpopy not security

Running a deterministic algorithm cannot increase entropy (only reduce it).

Quoted 8 lines
Quoted 8 lines

Just get
<hash-size> bytes from /dev/urandom on the host. We could generate a file with the compile-time SALT which is then included.

On the running barebox, we could use SHA to hash the old password file together with the current timer value. At least until we have something better.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

result a 64 bytes password file <salt 32 byes><key 32 bytes>

Yes. As we select the algorithm at compile time, we don't the to save it in the file.

this is for barebox as we may not have any passwd file

The same applies also to the default_passwd compiled in variable.

Currently we have:
PASSWD_FILE := $(shell cd $(srctree); find $(CONFIG_PASSWORD_DEFAULT) -type f)

cmd_pwd_h = echo -n "static const char default_passwd[] = \"" > $@; \
        cat $< | tr -d '\n' >> $@; \
        echo "\";" >> $@

include/generated/passwd.h: $(PASSWD_FILE)

        $(call if_changed,pwd_h)

This would need to run the hash/pbkdf2 and store salt+key.

Regards,
Jan

Signature · 10 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#17 lore raw

Re: [PATCH 07/10] password: add pbkdf2 support

Quoted 17 lines · Jan Lübbe
Quoted 15 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 14 lines · Jan Lübbe
Quoted 13 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 6 lines

Yes, definitely. We must use the algorithms as they are intended to be used.

If we try to move users away from RSA2048 because it will be vulnerable in the future, we should not go against established practice for password salts by hard-coding it.

I'm not against it but with the barebox entropy did not see the point to use it.

so how do we generate the salt? what length

Personnaly I'll prefer

Quoted 7 lines
Quoted 4 lines
Quoted 3 lines
Quoted 1 line

a random 64 bytes | sha256 | take first 32bytes. | pbkdf2 10000 round

Running SHA-256 on random data is useless for security.

SHA256 is to improve the entrpopy not security

Running a deterministic algorithm cannot increase entropy (only reduce it).

check the kennel algo for PRGN

and youp will see why I want to use a sha

Quoted 20 lines
Quoted 9 lines
Quoted 9 lines

Just get
<hash-size> bytes from /dev/urandom on the host. We could generate a file with the compile-time SALT which is then included.

On the running barebox, we could use SHA to hash the old password file together with the current timer value. At least until we have something better.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

result a 64 bytes password file <salt 32 byes><key 32 bytes>

Yes. As we select the algorithm at compile time, we don't the to save it in the file.

this is for barebox as we may not have any passwd file

The same applies also to the default_passwd compiled in variable.

Currently we have:
PASSWD_FILE := $(shell cd $(srctree); find $(CONFIG_PASSWORD_DEFAULT) -type f)

Quoted 8 lines
cmd_pwd_h = echo -n "static const char default_passwd[] = \"" > $@; \
        cat $< | tr -d '\n' >> $@; \
        echo "\";" >> $@

include/generated/passwd.h: $(PASSWD_FILE)

        $(call if_changed,pwd_h)

This would need to run the hash/pbkdf2 and store salt+key.

no as the current current code expect you to give the correct file format for the currently use password

so today the output of openssl

but yes we may need to do more here

Best Regards,
J.

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#18 lore raw

Re: [PATCH 07/10] password: add pbkdf2 support

Quoted 5 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 4 lines · Jan Lübbe
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

Personnaly I'll prefer

a random 64 bytes | sha256 | take first 32bytes. | pbkdf2 10000 round

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Quoted 1 line

Running SHA-256 on random data is useless for security.

SHA256 is to improve the entrpopy not security

Running a deterministic algorithm cannot increase entropy (only reduce it).

check the kennel algo for PRGN

PRNG? That is a different use case. The kernel takes sources of entropy and uses those to seed an CSPRNG:
http://www.2uo.de/myths-about-urandom/

Quoted 1 line

and youp will see why I want to use a sha

Having high entropy and appearing random are different properties. As SHA-256 is deterministic it *cannot* increase entropy:
http://en.wikipedia.org/wiki/Entropy_(information_theory)

Quoted 26 lines
Quoted 26 lines
Quoted 8 lines
Quoted 8 lines

Just get
<hash-size> bytes from /dev/urandom on the host. We could generate a file with the compile-time SALT which is then included.

On the running barebox, we could use SHA to hash the old password file together with the current timer value. At least until we have something better.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

result a 64 bytes password file <salt 32 byes><key 32 bytes>

Yes. As we select the algorithm at compile time, we don't the to save it in the file.

this is for barebox as we may not have any passwd file

The same applies also to the default_passwd compiled in variable.

Currently we have:
PASSWD_FILE := $(shell cd $(srctree); find $(CONFIG_PASSWORD_DEFAULT) -type f)

cmd_pwd_h = echo -n "static const char default_passwd[] = \"" > $@; \
        cat $< | tr -d '\n' >> $@; \
        echo "\";" >> $@

include/generated/passwd.h: $(PASSWD_FILE)

        $(call if_changed,pwd_h)
Quoted 6 lines
Quoted 1 line

This would need to run the hash/pbkdf2 and store salt+key.

no as the current current code expect you to give the correct file format for the currently use password

so today the output of openssl

Ah, sorry I misread the code here. I though that the plaintext password was in the config. CONFIG_PASSWORD_DEFAULT must be the name of a file in the srctree with the format matching the selected hash algo?

Quoted 1 line

but yes we may need to do more here

It seems there is no standard tool to create password hashes which supports all the algorithms we want to have.

So the current way is to use barebox itself to create the default password file? Should be have a host tool for that or is barebox sandbox enough?

Regards,
Jan

Signature · 10 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#19 lore raw

Re: [PATCH 07/10] password: add pbkdf2 support

Quoted 9 lines · Jan Lübbe
Quoted 8 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 7 lines · Jan Lübbe
Quoted 6 lines
Quoted 5 lines
Quoted 3 lines

Personnaly I'll prefer

a random 64 bytes | sha256 | take first 32bytes. | pbkdf2 10000 round

Running SHA-256 on random data is useless for security.

SHA256 is to improve the entrpopy not security

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Running a deterministic algorithm cannot increase entropy (only reduce it).

check the kennel algo for PRGN

PRNG? That is a different use case. The kernel takes sources of entropy and uses those to seed an CSPRNG:
http://www.2uo.de/myths-about-urandom/

I known how work urandom and random but the kernel do use SHA-1 for generating the Random numbers. I do not want to go to deep in the algo we can look at the code.

Quoted 6 lines
Quoted 2 lines

and youp will see why I want to use a sha

Having high entropy and appearing random are different properties. As SHA-256 is deterministic it *cannot* increase entropy:
http://en.wikipedia.org/wiki/Entropy_(information_theory)

I known about it

Quoted 38 lines
Quoted 27 lines
Quoted 27 lines
Quoted 9 lines
Quoted 9 lines

Just get
<hash-size> bytes from /dev/urandom on the host. We could generate a file with the compile-time SALT which is then included.

On the running barebox, we could use SHA to hash the old password file together with the current timer value. At least until we have something better.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

result a 64 bytes password file <salt 32 byes><key 32 bytes>

Yes. As we select the algorithm at compile time, we don't the to save it in the file.

this is for barebox as we may not have any passwd file

The same applies also to the default_passwd compiled in variable.

Currently we have:
PASSWD_FILE := $(shell cd $(srctree); find $(CONFIG_PASSWORD_DEFAULT) -type f)

cmd_pwd_h = echo -n "static const char default_passwd[] = \"" > $@; \
        cat $< | tr -d '\n' >> $@; \
        echo "\";" >> $@

include/generated/passwd.h: $(PASSWD_FILE)

        $(call if_changed,pwd_h)
Quoted 6 lines
Quoted 1 line

This would need to run the hash/pbkdf2 and store salt+key.

no as the current current code expect you to give the correct file format for the currently use password

so today the output of openssl

Ah, sorry I misread the code here. I though that the plaintext password was in the config. CONFIG_PASSWORD_DEFAULT must be the name of a file in the srctree with the format matching the selected hash algo?

Quoted 8 lines
Quoted 1 line

but yes we may need to do more here

It seems there is no standard tool to create password hashes which supports all the algorithms we want to have.

So the current way is to use barebox itself to create the default password file? Should be have a host tool for that or is barebox sandbox enough?

yes sandbox is enough we can create such tool but today it's just the sha of the password store in base64 so you can easly create it in shell

if we start to play we random salt yes we do need a tool

Best Regards,
J.

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#6 lore raw

Re: [PATCH 04/10] command: add generic digest command

In reply to Jan Lübbe
Quoted 19 lines · Jan Lübbe

commands/digest.c line 184

Quoted 10 lines · Jean-Christophe PLAGNIOL-VILLARD
(quoted diff) +2 -0
+BAREBOX_CMD_HELP_START(digest)
+BAREBOX_CMD_HELP_TEXT("Calculate a digest over a FILE or a memory

area.")

commands/digest.c new file +7 -0
+BAREBOX_CMD_HELP_TEXT("Options:")
+BAREBOX_CMD_HELP_OPT ("-a <algo>\t",  "digest to use")
+BAREBOX_CMD_HELP_OPT ("-k <key>\t",  "key as text")
+BAREBOX_CMD_HELP_OPT ("-K <file>\t",  "key file")
+BAREBOX_CMD_HELP_OPT ("-s <sig>\t",  "digest")
+BAREBOX_CMD_HELP_OPT ("-S <file>\t",  "digest flie")
+BAREBOX_CMD_HELP_END

We're mixing different terms here: digest and signature

Signature is usually used in the context of public key crypto, digest is mostly used with for hashes. The command uses both interchangeably.

How about:

Review

Quoted 5 lines
(quoted diff) +0 -5
-a <algo>	hash or signature algorithm to use
-k <key>	use supplied <key> (ASCII or hex) for MAC
-K <file>	use key from <file> (binary) for MAC
-v <hex>	verify data against supplied <hex> (hash, MAC or signature)
-V <file>	verify data against <file> (hash, MAC or signature)

good for me

Best Regards,
J.

Quoted 14 lines

Regards,
Jan

Signature · 10 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox