lib: rsa: function to verify a signature against a hash
PATCH 1/1 lib: rsa: function to verify a signature against a hash
From: Heiko Stuebner <[email protected]>
rsa_verify() expects a memory region and wants to do the hashing itself, but there may be cases where the hashing is done via other means, like hashing a squashfs rootfs.
So add rsa_verify_hash() to allow verifiying a signature against an existing hash. As this entails the same verification routines we can just move the relevant code over from rsa_verify() and also call rsa_verify_hash() from there.
---
Patch depends on at least
lib: rsa: take spl/non-spl into account when building rsa_verify_with_pkey()
include/u-boot/rsa.h | 21 +++++++++++++++++ lib/rsa/rsa-verify.c | 56 +++++++++++++++++++++++++------------------- 2 files changed, 53 insertions(+), 24 deletions(-)
include/u-boot/rsa.h +21 -0
@@ -82,6 +82,20 @@ static inline int rsa_add_verify_data(struct image_sign_info *info,#endif #if IMAGE_ENABLE_VERIFY +/** +* rsa_verify_hash() - Verify a signature against a hash +* +* Verify a RSA PKCS1.5 signature against an expected hash. +* +* @info: Specifies key and FIT information +* @hash: Hash according to algorithm specified in @info +* @sig: Signature +* @sig_len: Number of bytes in signature +* @return 0 if verified, -ve on error +*/ +int rsa_verify_hash (struct image_sign_info *info, +const uint8_t *hash,uint8_t *sig,uint sig_len); +/** * rsa_verify() - Verify a signature against some data *
@@ -108,6 +122,13 @@ int padding_pss_verify(struct image_sign_info *info, const uint8_t *hash, int hash_len);#endif /* CONFIG_FIT_ENABLE_RSASSA_PSS_SUPPORT */ #else +static inline int rsa_verify_hash (struct image_sign_info *info, +const uint8_t *hash, +uint8_t *sig,uint sig_len) +{ +return -ENXIO ; +} +static inline int rsa_verify (struct image_sign_info *info,const struct image_region region[],int region_count,uint8_t *sig,uint sig_len)
lib/rsa/rsa-verify.c +32 -24
68 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH 1/1 lib: rsa: function to verify a signature against a hash
Quoted 6 lines · Heiko Stuebner
From: Heiko Stuebner <[email protected]>
rsa_verify()expects a memory region and wants to do the hashing itself, but there may be cases where the hashing is done via other means, like hashing a squashfs rootfs.
Quoted 6 lines
So add
rsa_verify_hash()to allow verifiying a signature against an existing hash. As this entails the same verification routines we can just move the relevant code over fromrsa_verify()and also callrsa_verify_hash()from there.Signed-off-by Heiko Stuebner <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200708/c740d719/attachment.sig>