𓍯𓂃 RSASSAPSS
Introduction
The RSASSAPSS library provides functionality to verify RSASSA-PSS signatures with MGF1 mask generation function.
Users may provide custom hash functions via Parameters struct. However, the usage of sha256 is recommended.
The RSASSA-PSS signature verification costs ~340k gas.
Learn more about the algorithm here.
Functions
To use the RSASSAPSS library, you need to import it.
import "@solarity/solidity-lib/libs/crypto/RSASSAPSS.sol";
And optionally bind it to the type with the using statement.
using RSASSAPSS for *;
verifySha256
function verifySha256(
bytes memory message_,
bytes memory s_,
bytes memory e_,
bytes memory n_
) internal view returns (bool);
Description
Same as verify but with sha256 hash function preconfiguration.
verify
function verify(
RSASSAPSS.Parameters memory params_,
bytes memory message_,
bytes memory s_,
bytes memory e_,
bytes memory n_
) internal view returns (bool);
Description
Verifies RSAPSS-SSA signature with custom parameters.
Parameters:
| Name | Type | Description |
|---|---|---|
params | struct RSASSAPSS.Parameters | The parameters to specify the hash length, salt length, and hash function of choice |
message | bytes | The arbitrary message to be verified |
s | bytes | The "encrypted" signature |
e | bytes | The public key exponent. 65537 is a recommended value |
n | bytes | The modulus of a public key |
Where RSASSAPSS.Parameters consist of:
| Name | Type | Description |
|---|---|---|
hashLength | uint256 | The hash function output length in bytes |
saltLength | uint256 | The pss encoding salt length in bytes |
hasher | function (bytes) pure returns (bytes) | The function-pointer to a custom hash function |
Example
function verifySha256(
bytes calldata message_,
bytes calldata s_,
bytes calldata e_,
bytes calldata n_
) external view returns (bool) {
return message_.verifySha256(s_, e_, n_);
}