pub struct KeyPair { /* private fields */ }Expand description
A signature key pair, held once: the module’s parsed key and its raw public key, never the key’s
encoding (decision 0012). Not Clone.
Implementations§
Source§impl KeyPair
impl KeyPair
Sourcepub fn generate(admitted: &Admitted, a: S) -> Result<KeyPair, CryptoError>
pub fn generate(admitted: &Admitted, a: S) -> Result<KeyPair, CryptoError>
A new key pair of algorithm a. Refuses an algorithm admitted’s profile does not admit
outside TLS, or its module line lacks (Admitted::admit_signature).
Sourcepub fn from_pkcs8_der(
admitted: &Admitted,
a: S,
der: &[u8],
) -> Result<KeyPair, CryptoError>
pub fn from_pkcs8_der( admitted: &Admitted, a: S, der: &[u8], ) -> Result<KeyPair, CryptoError>
Imports a DER RFC 5958 §2 OneAsymmetricKey of algorithm a. Refuses, in this order, an
algorithm admitted’s profile does not admit outside TLS, or its module line lacks
(Admitted::admit_signature); then any structure its RFCs do not define, before the module
parses the key; then a key the module refuses, or one whose carried publicKey or
expandedKey is not its own (CryptoError::SignaturePrivateKey). The structure:
- ECDSA: version v1,
id-ecPublicKeywitha’s namedCurve (RFC 5480 §2.1.1), privateKey an RFC 5915 §3ECPrivateKeywith a scalar of the curve’s length, optional parameters naming the same curve and an optional uncompressed publicKey; - Ed25519:
id-Ed25519without parameters, privateKey the 32-byteCurvePrivateKey(RFC 8410 §3, §7), version v1, or v2 with the 32-byte publicKey; - RSA: version v1,
rsaEncryptionwith NULL parameters, privateKey a two-prime RFC 8017 A.1.2RSAPrivateKeyof version 0, then eight positive, minimal INTEGERs, the modulus exactlya’s bit length and the public exponent 65537; - ML-DSA-87:
id-ml-dsa-87without parameters, privateKey the seed or both the seed and the expanded key (RFC 9881 §6), version v1, or v2 with the 2,592-byte publicKey. The expanded key alone is refused: the module cannot export such a key again. In thebothform the expanded key must be byte for byte the seed’s (RFC 9881 §8.2), and the key held is the seed’s.
Each takes optional [0] attributes in X.690 §11.6 order, and nothing after the key. The key
is held parsed; KeyPair::to_pkcs8_der encodes it again.
Sourcepub fn to_pkcs8_der(&self) -> Result<Zeroizing<Vec<u8>>, CryptoError>
pub fn to_pkcs8_der(&self) -> Result<Zeroizing<Vec<u8>>, CryptoError>
The key’s PKCS#8 encoding, made by the module on each call into a buffer the caller owns and that is wiped on drop: the canonical encoding, not the bytes the key was imported from. ECDSA, RSA and ML-DSA-87 (the seed form) are version v1; Ed25519 is version v2 with its public key (RFC 8410 §7).
Sourcepub fn public_key(&self) -> &[u8] ⓘ
pub fn public_key(&self) -> &[u8] ⓘ
The raw public key: the bytes of the SubjectPublicKeyInfo subjectPublicKey BIT STRING.