core::crypto::rsa
本頁內容
API 參考只有英文版,由標準函式庫原始碼中的英文文件註解產生。
RSA (RFC 8017): PKCS #1 v1.5 and PSS verification and signing (MGF1 with the message hash), moduli of 2048 to 4096 bits.
Structs
PublicKeySource
pub struct PublicKeyAn RSA public key (n, e).
Sourcepub fn new<N: AsBytes, E: AsBytes>(§n: N, e: E) throws (ValueError) -> PublicKey From 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).
Sourcepub fn from_pkcs1_der<B: AsBytes>(§der: B) throws (ValueError) -> PublicKey From a DER
RSAPublicKey ::= SEQUENCE { modulus INTEGER, publicExponent INTEGER }.The modulus length in bits.
The modulus, big-endian without leading zeros.
The public exponent, big-endian without leading zeros.
Sourcepub fn verify_pkcs1v15<M: AsBytes, S: AsBytes>(§self, hash: HashAlgorithm, msg: M, signature: S) -> bool RSASSA-PKCS1-v1_5 verification: the whole encoding is rebuilt and compared.
Sourcepub fn verify_pss<M: AsBytes, S: AsBytes>(§self, hash: HashAlgorithm, msg: M, signature: S, salt_len: usize | none = none) -> bool RSASSA-PSS verification, MGF1 with
hash; the salt issalt_lenbytes (none: the hash length).
PrivateKeySource
pub struct PrivateKeyAn RSA private key with its CRT parameters (RFC 8017 3.2, two primes), big-endian in secret storage.
Sourcepub fn from_pkcs1_der<B: AsBytes>(§der: B) throws (ValueError) -> PrivateKey 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).Overwrite the private values with zeros now (every copy shares them); signing is meaningless afterwards.
The public half.
The modulus length in bits.
Sourcepub fn sign_pss<M: AsBytes, S: AsBytes>(§self, hash: HashAlgorithm, msg: M, salt: S) 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.
Sourcepub fn sign_pkcs1v15<B: AsBytes>(§self, hash: HashAlgorithm, msg: B) throws (ValueError) -> List<u8> An RSASSA-PKCS1-v1_5 signature of
msg(deterministic: the blinding factor is derived from the message and the key).