Skip to content

std/crypto

module crypto

Keys, signatures, MACs, password hashes and encryption. An algorithm and a key format are each named by a type, as a format is: PublicKey(text, Pem, Ed25519). A key's type carries its algorithm, so a key of one algorithm used where another is named is a check error. PrivateKey, KeyPair and SecretKey are Secret: no format writes one, == does not compare them, and each prints redacted.

  • KeyAlgorithm — An asymmetric key algorithm.
  • Signing — An asymmetric key algorithm.
  • Agreement — An asymmetric key algorithm.
  • Ed25519 — An asymmetric key algorithm.
  • P256 — An asymmetric key algorithm.
  • Rsa — An asymmetric key algorithm.
  • X25519 — An asymmetric key algorithm.
  • SecretAlgorithm — A symmetric algorithm: a Cipher encrypts, a Mac authenticates.
  • Cipher — A symmetric algorithm: a Cipher encrypts, a Mac authenticates.
  • Mac — A symmetric algorithm: a Cipher encrypts, a Mac authenticates.
  • Aes256Gcm — A symmetric algorithm: a Cipher encrypts, a Mac authenticates.
  • ChaCha20Poly1305 — A symmetric algorithm: a Cipher encrypts, a Mac authenticates.
  • HmacSha256 — A symmetric algorithm: a Cipher encrypts, a Mac authenticates.
  • HmacSha512 — A symmetric algorithm: a Cipher encrypts, a Mac authenticates.
  • Secret — The values that hold private key material: no format encodes one, == does not compare them, and each prints redacted.
  • PublicKey — A public key of algorithm A.
  • PrivateKey — A private key of algorithm A.
  • KeyPair — A private key and its public key.
  • SecretKey — A symmetric key of algorithm A.
  • KeyFormat — How one key is text.
  • Pem — How one key is text.
  • Jwk — How one key is text.
  • OpenSsh — How one key is text.
  • Age — How one key is text.
  • to_public_key — The public key self holds in format, or none.
  • to_private_key — The private key self holds in format, or none.
  • read_public_key — The public key a file holds in format.
  • read_private_key — The private key a file holds in format.
  • to_text — self written in format: key.to_text(OpenSsh) is an ssh-ed25519 AAAA… line.
  • to_der — self as SPKI DER.
  • export_private — The private key material of self written in format, encrypted under passphrase where one is given: PKCS #8 with scrypt and AES-256-CBC for Pem, bcrypt-pbkdf and AES-256-CTR for OpenSsh.
  • public — The public key of a private key.
  • thumbprint — The RFC 7638 JWK thumbprint of self: base64url, unpadded, of the SHA-256 of its canonical JWK.
  • generate_key_pair — A new key pair from the host's cryptographically secure generator.
  • generate_secret_key — A new symmetric key from the host generator: 32 octets for a cipher and HmacSha256, 64 for HmacSha512.
  • sign — The signature of the octets of self by key.
  • sign_data — The signature of canonical(self), the RFC 8785 text of the tree, so two trees equal under HQL equality have one signature.
  • verify — Whether signature is key's signature of self: false, never an error, for a signature of another key, of the wrong length or malformed.
  • verify_data — Whether signature is key's signature of canonical(self).
  • p256_signature_from_der — The r || s form of an ASN.1 DER ECDSA P-256 signature, as OpenSSL writes one, or none where self is not one.
  • mac — The HMAC tag of self under key: 32 octets for HmacSha256, 64 for HmacSha512.
  • verify_mac — Whether tag is the MAC tag of self under key, compared in time independent of where it first differs.
  • hash_password — The Argon2id hash of self under a new 16-octet salt from the host generator, as a PHC string: $argon2id$v=19$m=19456,t=2,p=1$…$….
  • verify_password — Whether self is the password hash was made from, under the hash's own parameters.
  • encrypt — The authenticated encryption of self under key, with aad bound to it and not encrypted: a new 12-octet nonce from the host generator, then the ciphertext, then the 16-octet tag.
  • decrypt — The plaintext of self under key and aad, or none where self is not an encryption of anything under them: shorter than 28 octets, a changed octet anywhere, a wrong key or a wrong aad.
  • encrypt_to — The age encryption of self to every key of recipients: any one of their private keys decrypts it.
  • decrypt_with — The plaintext of the age message self for identity, or none where it is not a message to that key or has been changed.
  • encrypt_with_passphrase — The age encryption of self under a passphrase, by age's scrypt recipient with work factor 18.
  • decrypt_with_passphrase — The plaintext of the age message self under passphrase, or none.
  • armor — The ASCII armor of an age message: -----BEGIN AGE ENCRYPTED FILE-----.
  • unarmor — The age message an armored text holds, or none.
  • EncryptedEnd — An endpoint whose writes are age-encrypted to recipients and stored in endpoint.
  • DecryptedEnd — An endpoint whose contents are those of a replayable endpoint, age-decrypted.
  • DecryptedLive — An endpoint whose contents are those of a live endpoint, age-decrypted.
  • encrypted_to — endpoint, its writes age-encrypted to recipients.
  • decrypted_with — endpoint, its contents age-decrypted with identity.