rokdocs
v0.1

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 RsaPublicKey

An RSA public key (n, e).

  • pub fn new(n: Bytes, e: Bytes) throws (ValueError) -> RsaPublicKey

    From big-endian n and e: n odd, 2048 to 4096 bits; e odd, 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) -> RsaPublicKey

    From a DER RSAPublicKey ::= SEQUENCE { modulus INTEGER, publicExponent INTEGER }.

  • pub const fn bits(self) -> usize
  • pub 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) -> bool

    RSASSA-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) -> bool

    RSASSA-PSS verification, MGF1 with hash; the salt is salt_len bytes (none: the hash length).

RsaPrivateKey

pub struct RsaPrivateKey

An RSA private key with its CRT parameters (RFC 8017 3.2, two primes).

  • pub fn from_pkcs1_der(der: Bytes) throws (ValueError) -> RsaPrivateKey

    From 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) -> RsaPublicKey
  • pub const fn bits(self) -> usize
  • pub fn sign_pss(self, hash: HashAlgorithm, msg: Bytes, salt: Bytes) throws (ValueError) -> List<u8>

    An RSASSA-PSS signature of msg: MGF1 with hash, salt as long as the hash. salt must 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).