diff mbox series

[2/2] fit: cipher: aes: allow to read the IV in the FIT image

Message ID 1600347707-19080-2-git-send-email-philippe.reynes@softathome.com
State Accepted
Delegated to: Tom Rini
Headers show
Series [1/2] fit: cipher: aes: allow to store the IV in the FIT image | expand

Commit Message

Philippe Reynes Sept. 17, 2020, 1:01 p.m. UTC
This commit add the support in u-boot to read the IV
in the FIT image instead of u-boot device tree.

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
---
 common/image-cipher.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

Comments

Tom Rini Oct. 13, 2020, 2:06 p.m. UTC | #1
On Thu, Sep 17, 2020 at 03:01:47PM +0200, Philippe Reynes wrote:

> This commit add the support in u-boot to read the IV
> in the FIT image instead of u-boot device tree.
> 
> Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/common/image-cipher.c b/common/image-cipher.c
index 09869f7..4ca9eec 100644
--- a/common/image-cipher.c
+++ b/common/image-cipher.c
@@ -94,9 +94,11 @@  static int fit_image_setup_decrypt(struct image_cipher_info *info,
 		return -1;
 	}
 
+	info->iv = fdt_getprop(fit, cipher_noffset, "iv", NULL);
 	info->ivname = fdt_getprop(fit, cipher_noffset, "iv-name-hint", NULL);
-	if (!info->ivname) {
-		printf("Can't get IV name\n");
+
+	if (!info->iv && !info->ivname) {
+		printf("Can't get IV or IV name\n");
 		return -1;
 	}
 
@@ -120,8 +122,12 @@  static int fit_image_setup_decrypt(struct image_cipher_info *info,
 	 * Search the cipher node in the u-boot fdt
 	 * the path should be: /cipher/key-<algo>-<key>-<iv>
 	 */
-	snprintf(node_path, sizeof(node_path), "/%s/key-%s-%s-%s",
-		 FIT_CIPHER_NODENAME, algo_name, info->keyname, info->ivname);
+	if (info->ivname)
+		snprintf(node_path, sizeof(node_path), "/%s/key-%s-%s-%s",
+			 FIT_CIPHER_NODENAME, algo_name, info->keyname, info->ivname);
+	else
+		snprintf(node_path, sizeof(node_path), "/%s/key-%s-%s",
+			 FIT_CIPHER_NODENAME, algo_name, info->keyname);
 
 	noffset = fdt_path_offset(fdt, node_path);
 	if (noffset < 0) {
@@ -137,10 +143,12 @@  static int fit_image_setup_decrypt(struct image_cipher_info *info,
 	}
 
 	/* read iv */
-	info->iv = fdt_getprop(fdt, noffset, "iv", NULL);
 	if (!info->iv) {
-		printf("Can't get IV in cipher node '%s'\n", node_path);
-		return -1;
+		info->iv = fdt_getprop(fdt, noffset, "iv", NULL);
+		if (!info->iv) {
+			printf("Can't get IV in cipher node '%s'\n", node_path);
+			return -1;
+		}
 	}
 
 	return 0;