summaryrefslogtreecommitdiff
path: root/src/crypto.c
diff options
context:
space:
mode:
authorJimmy Zhang <jimmzhang@nvidia.com>2015-10-19 16:01:56 -0700
committerStephen Warren <swarren@nvidia.com>2015-10-19 17:33:29 -0600
commitaa869ed597435ec05d5b9f55de64d01a52cc5ea8 (patch)
treeb0877072b080178156aecba4c90857a606d9bfa4 /src/crypto.c
parent3c3b992a68147981792c4f4fe0f3df5633b13076 (diff)
downloadnvidia-cbootimage-aa869ed597435ec05d5b9f55de64d01a52cc5ea8.tar.gz
Add new configuration keyword "RehashBl"
This feature is needed in case an image is updated at later stage after bootimage has been created. How to use: Add keyword "RehashBl" to configuration file, for example, update.cfg: RehashBl; Invoke cbootimage to re-calculate bootloader aes hash, for example, for bootimage bootloader.bin: $ cbootimage -s tegra210 --update update.cfg bootloader.bin bootloader.bin-resigned Where bootloader.bin-resigned is the resigned bootimage bootloader.bin Signed-off-by: Jimmy Zhang <jimmzhang@nvidia.com> Signed-off-by: Stephen Warren <swarren@nvidia.com>
Diffstat (limited to 'src/crypto.c')
-rw-r--r--src/crypto.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/crypto.c b/src/crypto.c
index 039be0a..5438a53 100644
--- a/src/crypto.c
+++ b/src/crypto.c
@@ -326,3 +326,37 @@ reverse_byte_order(
if (size % 2)
out[size / 2] = in[size / 2];
}
+
+int
+sign_bl(build_image_context *context,
+ u_int8_t *bootloader,
+ u_int32_t length,
+ u_int32_t image_instance)
+{
+ int e = 0;
+ u_int8_t *hash_buffer;
+ u_int32_t hash_size;
+
+ g_soc_config->get_value(token_hash_size,
+ &hash_size, context->bct);
+
+ hash_buffer = calloc(1, hash_size);
+ if (hash_buffer == NULL)
+ return -ENOMEM;
+
+ /* Encrypt and compute hash */
+ if ((e = sign_data_block(bootloader,
+ length,
+ hash_buffer)) != 0)
+ goto fail;
+
+ if ((e = g_soc_config->setbl_param(image_instance,
+ token_bl_crypto_hash,
+ (u_int32_t*)hash_buffer,
+ context->bct)) != 0)
+ goto fail;
+
+ fail:
+ free(hash_buffer);
+ return e;
+}