RSA
RSA PKCS#1 v1.5 signature verification implementation according to https://datatracker.ietf.org/doc/html/rfc8017[RFC8017]. This library supports PKCS#1 v1.5 padding to avoid malleability via chosen plaintext attacks in practical implementations. The padding follows the EMSA-PKCS1-v1_5-ENCODE encoding definition as per section 9.2 of the RFC. This padding makes RSA semantically secure for signing messages. Inspired by https://github.com/adria0/SolRsaVerify/blob/79c6182cabb9102ea69d4a2e996816091d5f1cd1[Adrià Massanet's work] (GNU General Public License v3.0). Available since v5.1.
Functions
pkcs1Sha256
Same as pkcs1Sha256 but using SHA256 to calculate the digest of data.
function pkcs1Sha256(bytes memory data, bytes memory s, bytes memory e, bytes memory n) internal view returns (bool);
pkcs1Sha256
Verifies a PKCSv1.5 signature given a digest according to the verification
method described in https://datatracker.ietf.org/doc/html/rfc8017#section-8.2.2[section 8.2.2 of RFC8017] with
support for explicit or implicit NULL parameters in the DigestInfo (no other optional parameters are supported).
IMPORTANT: For security reason, this function requires the signature and modulus to have a length of at least
2048 bits. If you use a smaller key, consider replacing it with a larger, more secure, one.
WARNING: This verification algorithm doesn't prevent replayability. If called multiple times with the same
digest, public key and (valid signature), it will return true every time. Consider including an onchain nonce
or unique identifier in the message to prevent replay attacks.
WARNING: This verification algorithm supports any exponent. NIST recommends using 65537 (or higher).
That is the default value many libraries use, such as OpenSSL. Developers may choose to reject public keys
using a low exponent out of security concerns.
function pkcs1Sha256(bytes32 digest, bytes memory s, bytes memory e, bytes memory n) internal view returns (bool);
Parameters
| Name | Type | Description |
|---|---|---|
digest | bytes32 | the digest to verify |
s | bytes | is a buffer containing the signature |
e | bytes | is the exponent of the public key |
n | bytes | is the modulus of the public key |
_unsafeReadBytes32
Reads a bytes32 from a bytes array without bounds checking.
function _unsafeReadBytes32(bytes memory array, uint256 offset) private pure returns (bytes32 result);