rok::core::crypto::rsa
RSA (RFC 8017): PKCS #1 v1.5 and PSS verification and signing (MGF1 with the message hash), moduli of 2048 to 4096 bits.
Structs
RsaPublicKey
pub struct RsaPublicKeyAn RSA public key (n, e).
pub fn new(n: Bytes, e: Bytes) throws (ValueError) -> RsaPublicKeyFrom big-endian
nande:nodd, 2048 to 4096 bits;eodd,3 <= e < 2^33(verification costs a square and a multiply per exponent bit; a peer's certificate must not choose that).pub fn from_pkcs1_der(der: Bytes) throws (ValueError) -> RsaPublicKeyFrom a DER
RSAPublicKey ::= SEQUENCE { modulus INTEGER, publicExponent INTEGER }.pub const fn bits(self) -> usizepub const fn modulus(self) -> List<u8>The modulus, big-endian without leading zeros.
pub const fn exponent(self) -> List<u8>The public exponent, big-endian without leading zeros.
pub fn verify_pkcs1v15(self, hash: HashAlgorithm, msg: Bytes, signature: Bytes) -> boolRSASSA-PKCS1-v1_5 verification: the whole encoding is rebuilt and compared.
pub fn verify_pss(self, hash: HashAlgorithm, msg: Bytes, signature: Bytes, salt_len: usize | none = none) -> boolRSASSA-PSS verification, MGF1 with
hash; the salt issalt_lenbytes (none: the hash length).
RsaPrivateKey
pub struct RsaPrivateKeyAn RSA private key with its CRT parameters (RFC 8017 3.2, two primes).
pub fn from_pkcs1_der(der: Bytes) throws (ValueError) -> RsaPrivateKeyFrom a DER
RSAPrivateKey(RFC 8017 A.1.2, version 0: n, e, d, p, q, d mod (p - 1), d mod (q - 1), q^-1 mod p).pub const fn public_key(self) -> RsaPublicKeypub const fn bits(self) -> usizepub fn sign_pss(self, hash: HashAlgorithm, msg: Bytes, salt: Bytes) throws (ValueError) -> List<u8>An RSASSA-PSS signature of
msg: MGF1 withhash,saltas long as the hash.saltmust be fresh random bytes; the blinding factor is derived from it, the message and the key.pub fn sign_pkcs1v15(self, hash: HashAlgorithm, msg: Bytes) throws (ValueError) -> List<u8>An RSASSA-PKCS1-v1_5 signature of
msg(deterministic: the blinding factor is derived from the message and the key).