fit: use constants for the cipher property names
cover fit: use constants for the cipher property names
The image-data series [1] added FIT_IV_HINT, FIT_IV_PROP and FIT_DATA_SIZE_UNCIPHERED_PROP to include/image.h. It was on the list at the same time as the series that converted the remaining FIT property literals in mkimage, boot and SPL [2], which was written before these constants existed, so the cipher code still spells the three names out. This series converts them: patch 1 the iv-name-hint and iv properties, patch 2 data-size-unciphered. The two patches touch different files and do not depend on each other.
Patch 1 also uses FIT_IV_PROP for the iv property of the key node that mkimage adds to the U-Boot device tree. That node is not part of the FIT, but lib/rsa/rsa-sign.c already uses the FIT_* constants for the properties of the key node it writes.
No functional change is intended. Built for sandbox and sandbox_spl (U-Boot proper, SPL and host tools), the objects of all touched files are identical before and after the series once debug info is stripped and the embedded version string is held fixed. Each patch builds for both boards, and the sandbox FIT, vboot, mkimage and dm-verity pytests, the fit_cipher unit tests and the binman encrypted-FIT tests pass.
[1] https://lore.kernel.org/r/[email protected]
[2] https://lore.kernel.org/r/[email protected]
Aristo Chen (2):
fit: use FIT_IV_PROP and FIT_IV_HINT for the iv properties
fit: use FIT_DATA_SIZE_UNCIPHERED_PROP for data-size-unciphered
boot/image-cipher.c | 6 +++--- boot/image-fit.c | 2 +- lib/aes/aes-encrypt.c | 6 +++--- tools/image-host.c | 6 ++++-- 4 files changed, 11 insertions(+), 9 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/2 fit: use FIT_IV_PROP and FIT_IV_HINT for the iv properties
Commit d0215d8718da ("tools: mkimage: use an explicit iv from the cipher node when encrypting") added FIT_IV_HINT and FIT_IV_PROP but did not convert the other places that spell the iv-name-hint and iv property names out: fit_image_setup_decrypt() on the boot side and image_aes_add_cipher_data() in mkimage, which stores the IV. Use the constants there as well.
This includes the iv property of the key node that mkimage adds to the U-Boot device tree and U-Boot reads back. That node is not part of the FIT, but lib/rsa/rsa-sign.c already uses FIT_KEY_HINT, FIT_ALGO_PROP and FIT_KEY_REQUIRED for the properties of the key node it writes.
No functional change intended.
--- boot/image-cipher.c | 6 +++--- lib/aes/aes-encrypt.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-)
boot/image-cipher.c +3 -3
@@ -94,8 +94,8 @@ 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 ); + info->iv =fdt_getprop (fit, cipher_noffset,FIT_IV_PROP ,NULL ); + info->ivname =fdt_getprop (fit, cipher_noffset,FIT_IV_HINT ,NULL );if (!info->iv && !info->ivname) {printf ("Can't get IV or IV name\n" );
@@ -144,7 +144,7 @@ static int fit_image_setup_decrypt(struct image_cipher_info *info,/* read iv */ if (!info->iv) { - info->iv =fdt_getprop (fdt, noffset,"iv" ,NULL ); + info->iv =fdt_getprop (fdt, noffset,FIT_IV_PROP ,NULL );if (!info->iv) {printf ("Can't get IV in cipher node '%s'\n" , node_path);return -1 ;
lib/aes/aes-encrypt.c +3 -3
@@ -86,7 +86,7 @@ int image_aes_add_cipher_data(struct image_cipher_info *info, void *keydest,if (!keydest && !info->ivname) {/* At least, store the IV in the FIT image */ - ret =fdt_setprop (fit, node_noffset,"iv" , + ret =fdt_setprop (fit, node_noffset,FIT_IV_PROP , info->iv, info->cipher->iv_len); goto done; }
@@ -137,11 +137,11 @@ int image_aes_add_cipher_data(struct image_cipher_info *info, void *keydest,if (info->ivname)/* Store the IV in the u-boot device tree */ - ret =fdt_setprop (keydest, node,"iv" , + ret =fdt_setprop (keydest, node,FIT_IV_PROP , info->iv, info->cipher->iv_len);else /* Store the IV in the FIT image */ - ret =fdt_setprop (fit, node_noffset,"iv" , + ret =fdt_setprop (fit, node_noffset,FIT_IV_PROP , info->iv, info->cipher->iv_len);if (!ret)
Signature · 1 line
2.43.0
Re: [PATCH v1 1/2] fit: use FIT_IV_PROP and FIT_IV_HINT for the iv properties
Quoted 14 lines · Aristo Chen
fit: use
FIT_IV_PROPandFIT_IV_HINTfor the iv propertiesCommit
d0215d8718da("tools: mkimage: use an explicit iv from the cipher node when encrypting") addedFIT_IV_HINTandFIT_IV_PROPbut did not convert the other places that spell the iv-name-hint and iv property names out:fit_image_setup_decrypt()on the boot side andimage_aes_add_cipher_data()in mkimage, which stores the IV. Use the constants there as well.This includes the iv property of the key node that mkimage adds to the U-Boot device tree and U-Boot reads back. That node is not part of the FIT, but
lib/rsa/rsa-sign.calready usesFIT_KEY_HINT,FIT_ALGO_PROPandFIT_KEY_REQUIREDfor the properties of the key node it writes.
Quoted 7 lines
No functional change intended.
Signed-off-by Aristo Chen <[email protected]>
boot/image-cipher.c| 6 +++---lib/aes/aes-encrypt.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-)
PATCH 2/2 fit: use FIT_DATA_SIZE_UNCIPHERED_PROP for data-size-unciphered
In reply to Aristo ChenCommit 195f273b6c86 ("tools: mkimage: resolve image-data references between FIT images") added FIT_DATA_SIZE_UNCIPHERED_PROP but did not convert the existing code that spells the property name out:fit_image_get_data_size_unciphered() on the boot side, and in mkimage fit_image_write_cipher(), which adds the property, and fit_image_cipher_data(), which checks for it to avoid encrypting the data twice. Use the constant there as well.
No functional change intended.
--- boot/image-fit.c | 2 +- tools/image-host.c | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-)
boot/image-fit.c +1 -1
@@ -1044,7 +1044,7 @@ int fit_image_get_data_size_unciphered(const void *fit, int noffset,const fdt32_t *val;int len; - val =fdt_getprop (fit, noffset,"data-size-unciphered" , &len); + val =fdt_getprop (fit, noffset,FIT_DATA_SIZE_UNCIPHERED_PROP , &len);if (!val)return -ENOENT ;
tools/image-host.c +4 -2
@@ -529,7 +529,8 @@ int fit_image_write_cipher(void *fit, int image_noffset, int noffset, }/* add non ciphered data size */ - ret =fdt_setprop_u32 (fit, image_noffset,"data-size-unciphered" , size); + ret =fdt_setprop_u32 (fit, image_noffset, +FIT_DATA_SIZE_UNCIPHERED_PROP , size);if (ret == -FDT_ERR_NOSPACE ) { ret = -ENOSPC ; goto out;
@@ -623,7 +624,8 @@ int fit_image_cipher_data(const char *keydir, void *keydest,* image is already encrypted. This is important as 'mkimage -F' can be * run multiple times on a FIT image. */ -if (fdt_getprop (fit, image_noffset,"data-size-unciphered" , &len)) +if (fdt_getprop (fit, image_noffset, +FIT_DATA_SIZE_UNCIPHERED_PROP , &len))return 0 ;if (len != -FDT_ERR_NOTFOUND ) {fprintf (stderr,"Failure testing for data-size-unciphered\n" );
Signature · 1 line
2.43.0
Re: [PATCH v1 2/2] fit: use FIT_DATA_SIZE_UNCIPHERED_PROP for data-size-unciphered
Hi Aristo,
Quoted 20 lines · Aristo Chen
fit: use
FIT_DATA_SIZE_UNCIPHERED_PROPfor data-size-uncipheredCommit
195f273b6c86("tools: mkimage: resolve image-data references between FIT images") addedFIT_DATA_SIZE_UNCIPHERED_PROPbut did not convert the existing code that spells the property name out:fit_image_get_data_size_unciphered()on the boot side, and in mkimagefit_image_write_cipher(), which adds the property, andfit_image_cipher_data(), which checks for it to avoid encrypting the data twice. Use the constant there as well.No functional change intended.
Signed-off-by Aristo Chen <[email protected]>
boot/image-fit.c| 2 +-tools/image-host.c | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-)
tools/image-host.c int fit_image_cipher_data(const char *keydir, void *keydest, · line 610
Quoted 3 lines
tools/image-host.c +2
-1@@ -608,7 +609,8 @@ int fit_image_cipher_data(const char *keydir, void *keydest, -if (fdt_getprop (fit, image_noffset,"data-size-unciphered" , &len)) +if (fdt_getprop (fit, image_noffset, +FIT_DATA_SIZE_UNCIPHERED_PROP , &len))
BTW, test/boot/fit_cipher.c still spells out data-size-unciphered in the two fdt_setprop() calls in fit_cipher_test_data_size_unciphered_len().
Regards,
Simon
v2 cover fit: use constants for the cipher property names
In reply to Aristo ChenThe image-data series [1] added FIT_IV_HINT, FIT_IV_PROP and FIT_DATA_SIZE_UNCIPHERED_PROP to include/image.h. It was on the list at the same time as the series that converted the remaining FIT property literals in mkimage, boot and SPL [2], which was written before these constants existed, so the cipher code still spells the three names out. This series converts them: patch 1 the iv-name-hint and iv properties, patch 2 data-size-unciphered, including the fit_cipher unit test that sets it. The two patches touch different files and do not depend on each other.
Patch 1 also uses FIT_IV_PROP for the iv property of the key node that mkimage adds to the U-Boot device tree. That node is not part of the FIT, but lib/rsa/rsa-sign.c already uses the FIT_* constants for the properties of the key node it writes.
No functional change is intended. Built for sandbox and sandbox_spl (U-Boot proper, SPL and host tools), the objects of all touched files are identical before and after the series once debug info is stripped and the embedded version string is held fixed. Each patch builds for both boards, and the sandbox FIT, vboot, mkimage and dm-verity pytests, the fit_cipher unit tests and the binman encrypted-FIT tests pass.
The series is based on main, where these constants are; next does not have them yet.
[1] https://lore.kernel.org/r/[email protected]
[2] https://lore.kernel.org/r/[email protected]
Link to v1:
https://lore.kernel.org/u-boot/[email protected]/
Changes in v2:
- Patch 2 also converts the two literals in test/boot/fit_cipher.c (Simon)
- Collected Simon's Reviewed-by on both patches; patch 1 is unchanged
Aristo Chen (2):
fit: use FIT_IV_PROP and FIT_IV_HINT for the iv properties
fit: use FIT_DATA_SIZE_UNCIPHERED_PROP for data-size-unciphered
boot/image-cipher.c | 6 +++--- boot/image-fit.c | 2 +- lib/aes/aes-encrypt.c | 6 +++--- test/boot/fit_cipher.c | 4 ++-- tools/image-host.c | 6 ++++-- 5 files changed, 13 insertions(+), 11 deletions(-)
Signature · 1 line
2.43.0
PATCH v2 1/2 fit: use FIT_IV_PROP and FIT_IV_HINT for the iv properties
Commit d0215d8718da ("tools: mkimage: use an explicit iv from the cipher node when encrypting") added FIT_IV_HINT and FIT_IV_PROP but did not convert the other places that spell the iv-name-hint and iv property names out: fit_image_setup_decrypt() on the boot side and image_aes_add_cipher_data() in mkimage, which stores the IV. Use the constants there as well.
This includes the iv property of the key node that mkimage adds to the U-Boot device tree and U-Boot reads back. That node is not part of the FIT, but lib/rsa/rsa-sign.c already uses FIT_KEY_HINT, FIT_ALGO_PROP and FIT_KEY_REQUIRED for the properties of the key node it writes.
No functional change intended.
---
v2: no code changes, collected Reviewed-by
boot/image-cipher.c | 6 +++--- lib/aes/aes-encrypt.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-)
boot/image-cipher.c +3 -3
@@ -94,8 +94,8 @@ 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 ); + info->iv =fdt_getprop (fit, cipher_noffset,FIT_IV_PROP ,NULL ); + info->ivname =fdt_getprop (fit, cipher_noffset,FIT_IV_HINT ,NULL );if (!info->iv && !info->ivname) {printf ("Can't get IV or IV name\n" );
@@ -144,7 +144,7 @@ static int fit_image_setup_decrypt(struct image_cipher_info *info,/* read iv */ if (!info->iv) { - info->iv =fdt_getprop (fdt, noffset,"iv" ,NULL ); + info->iv =fdt_getprop (fdt, noffset,FIT_IV_PROP ,NULL );if (!info->iv) {printf ("Can't get IV in cipher node '%s'\n" , node_path);return -1 ;
lib/aes/aes-encrypt.c +3 -3
@@ -86,7 +86,7 @@ int image_aes_add_cipher_data(struct image_cipher_info *info, void *keydest,if (!keydest && !info->ivname) {/* At least, store the IV in the FIT image */ - ret =fdt_setprop (fit, node_noffset,"iv" , + ret =fdt_setprop (fit, node_noffset,FIT_IV_PROP , info->iv, info->cipher->iv_len); goto done; }
@@ -137,11 +137,11 @@ int image_aes_add_cipher_data(struct image_cipher_info *info, void *keydest,if (info->ivname)/* Store the IV in the u-boot device tree */ - ret =fdt_setprop (keydest, node,"iv" , + ret =fdt_setprop (keydest, node,FIT_IV_PROP , info->iv, info->cipher->iv_len);else /* Store the IV in the FIT image */ - ret =fdt_setprop (fit, node_noffset,"iv" , + ret =fdt_setprop (fit, node_noffset,FIT_IV_PROP , info->iv, info->cipher->iv_len);if (!ret)
Signature · 1 line
2.43.0
PATCH v2 2/2 fit: use FIT_DATA_SIZE_UNCIPHERED_PROP for data-size-unciphered
In reply to Aristo ChenCommit 195f273b6c86 ("tools: mkimage: resolve image-data references between FIT images") added FIT_DATA_SIZE_UNCIPHERED_PROP but did not convert the existing code that spells the property name out:fit_image_get_data_size_unciphered() on the boot side, and in mkimage fit_image_write_cipher(), which adds the property, and fit_image_cipher_data(), which checks for it to avoid encrypting the data twice. Use the constant there as well, and in the fit_cipher unit test that creates the property.
No functional change intended.
---
v2: also convert the two literals in test/boot/fit_cipher.c, as suggested by Simon, no other changes, Reviewed-by kept
boot/image-fit.c | 2 +- test/boot/fit_cipher.c | 4 ++-- tools/image-host.c | 6 ++++-- 3 files changed, 7 insertions(+), 5 deletions(-)
boot/image-fit.c +1 -1
@@ -1044,7 +1044,7 @@ int fit_image_get_data_size_unciphered(const void *fit, int noffset,const fdt32_t *val;int len; - val =fdt_getprop (fit, noffset,"data-size-unciphered" , &len); + val =fdt_getprop (fit, noffset,FIT_DATA_SIZE_UNCIPHERED_PROP , &len);if (!val)return -ENOENT ;
test/boot/fit_cipher.c +2 -2
@@ -96,14 +96,14 @@ static int fit_cipher_test_data_size_unciphered_len(struct unit_test_state *uts) img =fdt_add_subnode (fit, images,"kernel" );ut_assert (img >=0 ); -ut_assertok (fdt_setprop (fit, img,"data-size-unciphered" , +ut_assertok (fdt_setprop (fit, img,FIT_DATA_SIZE_UNCIPHERED_PROP , &truncated,sizeof (truncated))); ret =fit_image_get_data_size_unciphered (fit, img, &data_size);ut_asserteq (-EINVAL , ret);/* a correctly sized property still works */ -ut_assertok (fdt_setprop (fit, img,"data-size-unciphered" , +ut_assertok (fdt_setprop (fit, img,FIT_DATA_SIZE_UNCIPHERED_PROP , &valid,sizeof (valid)));ut_assertok (fit_image_get_data_size_unciphered (fit, img, &data_size));ut_asserteq (0x100 , data_size);
tools/image-host.c +4 -2
@@ -529,7 +529,8 @@ int fit_image_write_cipher(void *fit, int image_noffset, int noffset, }/* add non ciphered data size */ - ret =fdt_setprop_u32 (fit, image_noffset,"data-size-unciphered" , size); + ret =fdt_setprop_u32 (fit, image_noffset, +FIT_DATA_SIZE_UNCIPHERED_PROP , size);if (ret == -FDT_ERR_NOSPACE ) { ret = -ENOSPC ; goto out;
@@ -623,7 +624,8 @@ int fit_image_cipher_data(const char *keydir, void *keydest,* image is already encrypted. This is important as 'mkimage -F' can be * run multiple times on a FIT image. */ -if (fdt_getprop (fit, image_noffset,"data-size-unciphered" , &len)) +if (fdt_getprop (fit, image_noffset, +FIT_DATA_SIZE_UNCIPHERED_PROP , &len))return 0 ;if (len != -FDT_ERR_NOTFOUND ) {fprintf (stderr,"Failure testing for data-size-unciphered\n" );
Signature · 1 line
2.43.0
Quoted 11 lines · Aristo Chen
The image-data series [1] added
FIT_IV_HINT,FIT_IV_PROPandFIT_DATA_SIZE_UNCIPHERED_PROPtoinclude/image.h. It was on the list at the same time as the series that converted the remaining FIT property literals in mkimage, boot and SPL [2], which was written before these constants existed, so the cipher code still spells the three names out. This series converts them: patch 1 the iv-name-hint and iv properties, patch 2 data-size-unciphered, including thefit_cipherunit test that sets it. The two patches touch different files and do not depend on each other.[...]
Applied to u-boot/main, thanks!
[1/2] fit: use FIT_IV_PROP and FIT_IV_HINT for the iv properties
commit: 507deb152bdd0d5803fba29579dc8810e1cff4be
[2/2] fit: use FIT_DATA_SIZE_UNCIPHERED_PROP for data-size-unciphered
commit: dc866ade7516b351f0181663875393b8813aba17Signature · 1 line
Tom