All of lore.kernel.org
 help / color / mirror / Atom feed
* [cbootimage PATCH V2] crypto: produce consistent hash for zero-length data
@ 2013-08-26 22:12 Stephen Warren
       [not found] ` <1377555170-6841-1-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Stephen Warren @ 2013-08-26 22:12 UTC (permalink / raw)
  To: swarren-3lzwWm7+Weoh9ZMKESR00Q
  Cc: treding-DDmLM1+adcrQT0dZR+AlfA,
	linux-tegra-u79uwXL29TY76Z2rM5mHXA, Stephen Warren

From: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>

In real-world use-cases, hashing zero-length data likely never happens.
However, it is relevant when testing cbootimage with a dummy zero-length
bootloader binary, e.g.:

touch u-boot.bin
cbootimage -t30 ../tamonten-ng/tegra30.img.cfg tegra30-tec-ng.img

In this scenario, it's useful to create a consistent hash, so that one
can compare the resultant images before and after applying patches, to
check for regressions.

Hence, zero out the hash data so it has consistent content if it isn't
written to.

Signed-off-by: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
---
v2: clear region using calloc at allocation time, rather than memset
    at hash-calculation time.
---
 src/crypto.c      | 2 +-
 src/data_layout.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/crypto.c b/src/crypto.c
index 88de357..99e9f08 100644
--- a/src/crypto.c
+++ b/src/crypto.c
@@ -280,7 +280,7 @@ sign_bct(build_image_context *context,
 					bct) != 0)
 		return -ENODATA;
 
-	hash_buffer = malloc(hash_size);
+	hash_buffer = calloc(1, hash_size);
 	if (hash_buffer == NULL)
 		return -ENOMEM;
 	e = sign_data_block(bct + Offset, length, hash_buffer);
diff --git a/src/data_layout.c b/src/data_layout.c
index ae62126..cae4c37 100644
--- a/src/data_layout.c
+++ b/src/data_layout.c
@@ -391,7 +391,7 @@ write_bootloaders(build_image_context *context)
 	g_soc_config->get_value(token_bootloaders_max,
 			&bootloaders_max, context->bct);
 
-	hash_buffer = malloc(hash_size);
+	hash_buffer = calloc(1, hash_size);
 	if (hash_buffer == NULL)
 		return -ENOMEM;
 
-- 
1.8.1.5

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-08-27 16:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-26 22:12 [cbootimage PATCH V2] crypto: produce consistent hash for zero-length data Stephen Warren
     [not found] ` <1377555170-6841-1-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2013-08-27  7:48   ` Thierry Reding
2013-08-27 16:05     ` Stephen Warren

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.