Skip to content

Commit

Permalink
CryptoPkg: BaseCryptLib: Update Salt length requirement for RSA-PSS s…
Browse files Browse the repository at this point in the history
…cheme.

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3455

Enforce salt length to be equal to digest length for RSA-PSS
encoding scheme.

Cc: Jiewen Yao <[email protected]>
Cc: Jian J Wang <[email protected]>
Cc: Xiaoyu Lu <[email protected]>
Cc: Guomin Jiang <[email protected]>

Signed-off-by: Sachin Agrawal <[email protected]>
Reviewed-by: Jiewen Yao <[email protected]>
  • Loading branch information
sagraw2 authored and mergify[bot] committed Jun 23, 2021
1 parent 7471751 commit 20ca528
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 13 deletions.
4 changes: 2 additions & 2 deletions CryptoPkg/Include/Library/BaseCryptLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -1376,7 +1376,7 @@ RsaPkcs1Verify (
If Message is NULL, then return FALSE.
If MsgSize is zero or > INT_MAX, then return FALSE.
If DigestLen is NOT 32, 48 or 64, return FALSE.
If SaltLen is < DigestLen, then return FALSE.
If SaltLen is not equal to DigestLen, then return FALSE.
If SigSize is large enough but Signature is NULL, then return FALSE.
If this interface is not supported, then return FALSE.
Expand Down Expand Up @@ -1411,7 +1411,7 @@ RsaPssSign (
Verifies the RSA signature with RSASSA-PSS signature scheme defined in RFC 8017.
Implementation determines salt length automatically from the signature encoding.
Mask generation function is the same as the message digest algorithm.
Salt length should atleast be equal to digest length.
Salt length should be equal to digest length.
@param[in] RsaContext Pointer to RSA context for signature verification.
@param[in] Message Pointer to octet message to be verified.
Expand Down
4 changes: 2 additions & 2 deletions CryptoPkg/Library/BaseCryptLib/Pk/CryptRsaPss.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ GetEvpMD (
Verifies the RSA signature with RSASSA-PSS signature scheme defined in RFC 8017.
Implementation determines salt length automatically from the signature encoding.
Mask generation function is the same as the message digest algorithm.
Salt length should atleast be equal to digest length.
Salt length should be equal to digest length.
@param[in] RsaContext Pointer to RSA context for signature verification.
@param[in] Message Pointer to octet message to be verified.
Expand Down Expand Up @@ -97,7 +97,7 @@ RsaPssVerify (
if (Signature == NULL || SigSize == 0 || SigSize > INT_MAX) {
return FALSE;
}
if (SaltLen < DigestLen) {
if (SaltLen != DigestLen) {
return FALSE;
}

Expand Down
2 changes: 1 addition & 1 deletion CryptoPkg/Library/BaseCryptLib/Pk/CryptRsaPssNull.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
Verifies the RSA signature with RSASSA-PSS signature scheme defined in RFC 8017.
Implementation determines salt length automatically from the signature encoding.
Mask generation function is the same as the message digest algorithm.
Salt length should atleast be equal to digest length.
Salt length should be equal to digest length.
@param[in] RsaContext Pointer to RSA context for signature verification.
@param[in] Message Pointer to octet message to be verified.
Expand Down
4 changes: 2 additions & 2 deletions CryptoPkg/Library/BaseCryptLib/Pk/CryptRsaPssSign.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ GetEvpMD (
If Message is NULL, then return FALSE.
If MsgSize is zero or > INT_MAX, then return FALSE.
If DigestLen is NOT 32, 48 or 64, return FALSE.
If SaltLen is < DigestLen, then return FALSE.
If SaltLen is not equal to DigestLen, then return FALSE.
If SigSize is large enough but Signature is NULL, then return FALSE.
If this interface is not supported, then return FALSE.
Expand Down Expand Up @@ -120,7 +120,7 @@ RsaPssSign (
return FALSE;
}

if (SaltLen < DigestLen) {
if (SaltLen != DigestLen) {
return FALSE;
}

Expand Down
2 changes: 1 addition & 1 deletion CryptoPkg/Library/BaseCryptLib/Pk/CryptRsaPssSignNull.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
If Message is NULL, then return FALSE.
If MsgSize is zero or > INT_MAX, then return FALSE.
If DigestLen is NOT 32, 48 or 64, return FALSE.
If SaltLen is < DigestLen, then return FALSE.
If SaltLen is not equal to DigestLen, then return FALSE.
If SigSize is large enough but Signature is NULL, then return FALSE.
If this interface is not supported, then return FALSE.
Expand Down
2 changes: 1 addition & 1 deletion CryptoPkg/Library/BaseCryptLibNull/Pk/CryptRsaPssNull.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
Verifies the RSA signature with RSASSA-PSS signature scheme defined in RFC 8017.
Implementation determines salt length automatically from the signature encoding.
Mask generation function is the same as the message digest algorithm.
Salt length should atleast be equal to digest length.
Salt length should be equal to digest length.
@param[in] RsaContext Pointer to RSA context for signature verification.
@param[in] Message Pointer to octet message to be verified.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
If Message is NULL, then return FALSE.
If MsgSize is zero or > INT_MAX, then return FALSE.
If DigestLen is NOT 32, 48 or 64, return FALSE.
If SaltLen is < DigestLen, then return FALSE.
If SaltLen is not equal to DigestLen, then return FALSE.
If SigSize is large enough but Signature is NULL, then return FALSE.
If this interface is not supported, then return FALSE.
Expand Down
10 changes: 9 additions & 1 deletion CryptoPkg/Library/BaseCryptLibOnProtocolPpi/CryptLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1556,7 +1556,7 @@ RsaPkcs1Verify (
Verifies the RSA signature with RSASSA-PSS signature scheme defined in RFC 8017.
Implementation determines salt length automatically from the signature encoding.
Mask generation function is the same as the message digest algorithm.
Salt length should atleast be equal to digest length.
Salt length should be equal to digest length.
@param[in] RsaContext Pointer to RSA context for signature verification.
@param[in] Message Pointer to octet message to be verified.
Expand Down Expand Up @@ -1592,6 +1592,14 @@ RsaPssVerify (
If the Signature buffer is too small to hold the contents of signature, FALSE
is returned and SigSize is set to the required buffer size to obtain the signature.
If RsaContext is NULL, then return FALSE.
If Message is NULL, then return FALSE.
If MsgSize is zero or > INT_MAX, then return FALSE.
If DigestLen is NOT 32, 48 or 64, return FALSE.
If SaltLen is not equal to DigestLen, then return FALSE.
If SigSize is large enough but Signature is NULL, then return FALSE.
If this interface is not supported, then return FALSE.
@param[in] RsaContext Pointer to RSA context for signature generation.
@param[in] Message Pointer to octet message to be signed.
@param[in] MsgSize Size of the message in bytes.
Expand Down
4 changes: 2 additions & 2 deletions CryptoPkg/Private/Protocol/Crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -3421,7 +3421,7 @@ EFI_STATUS
If Message is NULL, then return FALSE.
If MsgSize is zero or > INT_MAX, then return FALSE.
If DigestLen is NOT 32, 48 or 64, return FALSE.
If SaltLen is < DigestLen, then return FALSE.
If SaltLen is not equal to DigestLen, then return FALSE.
If SigSize is large enough but Signature is NULL, then return FALSE.
If this interface is not supported, then return FALSE.
Expand Down Expand Up @@ -3456,7 +3456,7 @@ BOOLEAN
Verifies the RSA signature with RSASSA-PSS signature scheme defined in RFC 8017.
Implementation determines salt length automatically from the signature encoding.
Mask generation function is the same as the message digest algorithm.
Salt length should atleast be equal to digest length.
Salt length should be equal to digest length.
@param[in] RsaContext Pointer to RSA context for signature verification.
@param[in] Message Pointer to octet message to be verified.
Expand Down

0 comments on commit 20ca528

Please sign in to comment.