* [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
* Re: [cbootimage PATCH V2] crypto: produce consistent hash for zero-length data
[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
0 siblings, 1 reply; 3+ messages in thread
From: Thierry Reding @ 2013-08-27 7:48 UTC (permalink / raw)
To: Stephen Warren
Cc: treding-DDmLM1+adcrQT0dZR+AlfA,
linux-tegra-u79uwXL29TY76Z2rM5mHXA, Stephen Warren
[-- Attachment #1: Type: text/plain, Size: 1099 bytes --]
On Mon, Aug 26, 2013 at 04:12:50PM -0600, Stephen Warren wrote:
> 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(-)
Looks good:
Reviewed-by: Thierry Reding <treding-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [cbootimage PATCH V2] crypto: produce consistent hash for zero-length data
2013-08-27 7:48 ` Thierry Reding
@ 2013-08-27 16:05 ` Stephen Warren
0 siblings, 0 replies; 3+ messages in thread
From: Stephen Warren @ 2013-08-27 16:05 UTC (permalink / raw)
To: Thierry Reding
Cc: treding-DDmLM1+adcrQT0dZR+AlfA,
linux-tegra-u79uwXL29TY76Z2rM5mHXA, Stephen Warren
On 08/27/2013 01:48 AM, Thierry Reding wrote:
> On Mon, Aug 26, 2013 at 04:12:50PM -0600, Stephen Warren wrote:
>> 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.
...
> Looks good:
>
> Reviewed-by: Thierry Reding <treding-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
Thanks. I've pushed this out.
^ permalink raw reply [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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).