lib/crypto: support sha384/sha512 in x509/pkcs7
PATCH 1/1 lib/crypto: support sha384/sha512 in x509/pkcs7
Set digest_size SHA384 and SHA512 algorithms in pkcs7 and x509, (not set by ported linux code, but needed by __UBOOT__ part).
EFI_CAPSULE_AUTHENTICATE doesn't select these algos but required for correctness if certificates contain sha384WithRSAEncryption or sha512WithRSAEncryption OIDs.
--- lib/crypto/pkcs7_verify.c | 4 ++++ lib/crypto/x509_public_key.c | 4 ++++ 2 files changed, 8 insertions(+)
lib/crypto/pkcs7_verify.c +4 -0
@@ -65,6 +65,10 @@ static int pkcs7_digest(struct pkcs7_message *pkcs7,return -ENOPKG ;if (!strcmp (sinfo->sig->hash_algo,"sha256" )) sig->digest_size =SHA256_SUM_LEN ; +else if (!strcmp (sinfo->sig->hash_algo,"sha384" )) + sig->digest_size =SHA384_SUM_LEN ; +else if (!strcmp (sinfo->sig->hash_algo,"sha512" )) + sig->digest_size =SHA512_SUM_LEN ;else if (!strcmp (sinfo->sig->hash_algo,"sha1" )) sig->digest_size =SHA1_SUM_LEN ;else
lib/crypto/x509_public_key.c +4 -0
@@ -71,6 +71,10 @@ int x509_get_sig_params(struct x509_certificate *cert)return -ENOPKG ;if (!strcmp (sig->hash_algo,"sha256" )) sig->digest_size =SHA256_SUM_LEN ; +else if (!strcmp (sig->hash_algo,"sha384" )) + sig->digest_size =SHA384_SUM_LEN ; +else if (!strcmp (sig->hash_algo,"sha512" )) + sig->digest_size =SHA512_SUM_LEN ;else if (!strcmp (sig->hash_algo,"sha1" )) sig->digest_size =SHA1_SUM_LEN ;else
Signature · 1 line
2.25.1
+cc Akashi-san who initially ported those.
Quoted 8 lines · Dhananjay Phadke
Set
digest_sizeSHA384 and SHA512 algorithms in pkcs7 and x509, (not set by ported linux code, but needed by__UBOOT__part).
EFI_CAPSULE_AUTHENTICATEdoesn't select these algos but required for correctness if certificates contain sha384WithRSAEncryption or sha512WithRSAEncryption OIDs.
Does the rest of the code parse those? Or expects -ENOPKG for the unsupported certificates?
Thanks
/Ilias
Quoted 39 lines
Signed-off-by Dhananjay Phadke <[email protected]>--- lib/crypto/pkcs7_verify.c | 4 ++++ lib/crypto/x509_public_key.c | 4 ++++ 2 files changed, 8 insertions(+)lib/crypto/pkcs7_verify.c +4
-0@@ -65,6 +65,10 @@ static int pkcs7_digest(struct pkcs7_message *pkcs7,return -ENOPKG ;if (!strcmp (sinfo->sig->hash_algo,"sha256" )) sig->digest_size =SHA256_SUM_LEN ; +else if (!strcmp (sinfo->sig->hash_algo,"sha384" )) + sig->digest_size =SHA384_SUM_LEN ; +else if (!strcmp (sinfo->sig->hash_algo,"sha512" )) + sig->digest_size =SHA512_SUM_LEN ;else if (!strcmp (sinfo->sig->hash_algo,"sha1" )) sig->digest_size =SHA1_SUM_LEN ;else lib/crypto/x509_public_key.c +4
-1@@ -71,6 +71,10 @@ int x509_get_sig_params(struct x509_certificate *cert)return -ENOPKG ;if (!strcmp (sig->hash_algo,"sha256" )) sig->digest_size =SHA256_SUM_LEN ; +else if (!strcmp (sig->hash_algo,"sha384" )) + sig->digest_size =SHA384_SUM_LEN ; +else if (!strcmp (sig->hash_algo,"sha512" )) + sig->digest_size =SHA512_SUM_LEN ;else if (!strcmp (sig->hash_algo,"sha1" )) sig->digest_size =SHA1_SUM_LEN ;else --2.25.1
Quoted 9 lines · Ilias Apalodimas
+cc Akashi-san who initially ported those.
Quoted 4 lines · Dhananjay Phadke
Set
digest_sizeSHA384 and SHA512 algorithms in pkcs7 and x509, (not set by ported linux code, but needed by__UBOOT__part).
Quoted 7 lines
Quoted 4 lines
EFI_CAPSULE_AUTHENTICATEdoesn't select these algos but required for correctness if certificates contain sha384WithRSAEncryption or sha512WithRSAEncryption OIDs.Does the rest of the code parse those? Or expects
-ENOPKGfor the unsupported certificates?
Yes these OIDs are parsed by Linux code, see x509_note_pkey_algo(). U-Boot code allocates digest buf for invoking hash_calculate(), that needs this digest_size.
I've verified such certs (chain) with pkcs7_verify_one().
Thanks,
Dhananjay
Ilias Apalodimas
Reviewed-byQuoted 15 lines · Dhananjay Phadke
Quoted 14 lines · Ilias Apalodimas
+cc Akashi-san who initially ported those.
Quoted 8 lines · Dhananjay Phadke
Set
digest_sizeSHA384 and SHA512 algorithms in pkcs7 and x509, (not set by ported linux code, but needed by__UBOOT__part).
EFI_CAPSULE_AUTHENTICATEdoesn't select these algos but required for correctness if certificates contain sha384WithRSAEncryption or sha512WithRSAEncryption OIDs.
Quoted 8 lines
Quoted 2 lines
Does the rest of the code parse those? Or expects
-ENOPKGfor the unsupported certificates?Yes these OIDs are parsed by Linux code, see
x509_note_pkey_algo(). U-Boot code allocates digest buf for invokinghash_calculate(), that needs thisdigest_size.I've verified such certs (chain) with
pkcs7_verify_one().
Ah right, I probably missed that as well when I sent 8699af63b8a5 ("lib/crypto: Enable more algorithms in cert verification")
Thanks!
Quoted 3 lines
Thanks,
Dhananjay
Quoted 9 lines · Dhananjay Phadke
Set
digest_sizeSHA384 and SHA512 algorithms in pkcs7 and x509, (not set by ported linux code, but needed by__UBOOT__part).
EFI_CAPSULE_AUTHENTICATEdoesn't select these algos but required for correctness if certificates contain sha384WithRSAEncryption or sha512WithRSAEncryption OIDs.Signed-off-by Dhananjay Phadke <[email protected]>Reviewed-by Ilias Apalodimas <[email protected]>
Applied to u-boot/master, thanks!
Signature · 1 line
Tom