Skip to main content

𓍯𓂃 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:​
NameTypeDescription
paramsstruct RSASSAPSS.ParametersThe parameters to specify the hash length, salt length, and hash function of choice
messagebytesThe arbitrary message to be verified
sbytesThe "encrypted" signature
ebytesThe public key exponent. 65537 is a recommended value
nbytesThe modulus of a public key
Where RSASSAPSS.Parameters consist of:​
NameTypeDescription
hashLengthuint256The hash function output length in bytes
saltLengthuint256The pss encoding salt length in bytes
hasherfunction (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_);
}