crypto: produce consistent hash for zero-length data

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@nvidia.com>
Reviewed-by: Thierry Reding <treding@nvidia.com>
This commit is contained in:
Stephen Warren
2013-08-23 11:59:12 -06:00
parent 902a58b463
commit ce1847a2b3
2 changed files with 2 additions and 2 deletions

View File

@@ -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);

View File

@@ -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;