Description
Background and motivation
Some implementations of RSA PSS by default use different salt length for RSA PSS than .NET and it's currently not possible to change it.
.NET currently follows https://datatracker.ietf.org/doc/html/rfc3447#section-9.1 recommendation and uses salt length equal to hash length but spec doesn't forbid other values. On OpenSSL some providers (i.e. tpm2) use different salt length making it impossible to validate such signature (interestingly signature validates on Linux<-->Linux by default uses salt length detection during validation: RSA_PSS_SALTLEN_AUTO)
We should also support typical placeholder values as well when implementing this:
- sLen=hLen - that would be equivalent to OpenSSL RSA_PSS_SALTLEN_DIGEST
- RSA_PSS_SALTLEN_MAX - max salt len
- 0 - zero salt length
and ideally detection of salt length or at least support for sLen=hLen and RSA_PSS_SALTLEN_MAX which seem to be most frequently used.
The detection should be easily implemented because after unmasking encoded message PS length can be detected by counting number of leading zeros which should be followed by 0x01. From that remainder is salt.
API Proposal
Not proposing specific APIs but for example:
public partial class RSASignaturePadding
{
// 0 is valid, so "default" has to be some other number.
public const int PssSaltLengthIsHashLength = -1;
public const int PssSaltLengthMax = -2;
public int PssSaltLangth { get; }
public static CreatePss(int saltLength);
}
API Usage
RSASignaturePadding pssWithCustomSalt = RSASignaturePadding.CreatePss(RSASignaturePadding.PSSSaltLengthMax);
// ..
rsa.VerifyData(data, sig, hashName, pssWithCustomSalt);
Alternative Designs
No response
Risks
No response