Library guide · API index and notation
This page is generated from the bundled library in this checkout. Signatures and adjacent source comments are reproduced below; the linked guide explains usage, storage, failures, and platform support.
import "std/crypto/openssl"
Names used in signatures
Unqualified names denote this package’s types (including other source files in the same package), language built-ins, or generic parameters such as T. Qualified names use the import aliases below. These aliases belong to the library source; import a dependency yourself to use its alias in your program.
| Alias | Package | Source file |
|---|---|---|
crypto |
std/crypto |
openssl.dodo |
native |
std/crypto/openssl/native |
openssl.dodo |
ptr |
core/ptr |
openssl.dodo |
SHA1_BYTES
Constant · Source
Hashes, HMAC, AES-CFB8 and RSA from OpenSSL 3.5+ libcrypto. Every value owns its OpenSSL state and frees it when dropped; no call retains a caller’s buffer. Values are deliberately not Send/Sync: use each on one execution lane. Secret inputs are copied into OpenSSL during construction, so the caller may wipe its own key bytes afterwards.
pub const SHA1_BYTES: usize = 20
SHA256_BYTES
Constant · Source
pub const SHA256_BYTES: usize = 32
MD5_BYTES
Constant · Source
pub const MD5_BYTES: usize = 16
AES128_KEY_BYTES
Constant · Source
pub const AES128_KEY_BYTES: usize = 16
AES_IV_BYTES
Constant · Source
pub const AES_IV_BYTES: usize = 16
RSA_MIN_BITS
Constant · Source
pub const RSA_MIN_BITS: u32 = 1024
RSA_MAX_BITS
Constant · Source
pub const RSA_MAX_BITS: u32 = 16384
PKCS1_OVERHEAD
Constant · Source
Bytes of PKCS#1 v1.5 encryption padding; messages are at most size() - 11.
pub const PKCS1_OVERHEAD: usize = 11
Sha1
Struct · Source
Incremental SHA-1. Use it only where a protocol requires it, such as the Mojang server hash: SHA-1 is not collision resistant.
pub struct Sha1 {
// Private implementation fields omitted.
}
Sha1.new
Function · Source
pub fn new() -> Sha1!crypto.Error
Sha1.update
Function · Source
pub fn update(&mut self, data: &[u8]) -> void!crypto.Error
Sha1.finish
Function · Source
Returns the digest of everything since construction or the previous finish, and starts a new empty message.
pub fn finish(&mut self) -> [20]u8!crypto.Error
sha1
Function · Source
pub fn sha1(data: &[u8]) -> [20]u8!crypto.Error
Md5
Struct · Source
Incremental MD5. Use it only where a legacy protocol requires it, such as PostgreSQL’s md5 password authentication: MD5 is broken as a hash.
pub struct Md5 {
// Private implementation fields omitted.
}
Md5.new
Function · Source
pub fn new() -> Md5!crypto.Error
Md5.update
Function · Source
pub fn update(&mut self, data: &[u8]) -> void!crypto.Error
Md5.finish
Function · Source
Returns the digest of everything since construction or the previous finish, and starts a new empty message.
pub fn finish(&mut self) -> [16]u8!crypto.Error
md5
Function · Source
pub fn md5(data: &[u8]) -> [16]u8!crypto.Error
Sha256
Struct · Source
Incremental SHA-256.
pub struct Sha256 {
// Private implementation fields omitted.
}
Sha256.new
Function · Source
pub fn new() -> Sha256!crypto.Error
Sha256.update
Function · Source
pub fn update(&mut self, data: &[u8]) -> void!crypto.Error
Sha256.finish
Function · Source
Returns the digest of everything since construction or the previous finish, and starts a new empty message.
pub fn finish(&mut self) -> [32]u8!crypto.Error
sha256
Function · Source
pub fn sha256(data: &[u8]) -> [32]u8!crypto.Error
HmacSha256
Struct · Source
Incremental HMAC-SHA256 (RFC 2104). Keys of any length are accepted, including empty keys; keys longer than 64 bytes are hashed first.
pub struct HmacSha256 {
// Private implementation fields omitted.
}
HmacSha256.new
Function · Source
pub fn new(key: &[u8]) -> HmacSha256!crypto.Error
HmacSha256.update
Function · Source
pub fn update(&mut self, data: &[u8]) -> void!crypto.Error
HmacSha256.finish
Function · Source
Returns the tag of everything since construction or the previous finish or verify, and starts a new message under the same key.
pub fn finish(&mut self) -> [32]u8!crypto.Error
HmacSha256.verify
Function · Source
Finishes the message and compares the tag with expected in constant time. A truncated or overlong expected tag never matches.
pub fn verify(&mut self, expected: &[u8]) -> bool!crypto.Error
hmac_sha256
Function · Source
pub fn hmac_sha256(key: &[u8], data: &[u8]) -> [32]u8!crypto.Error
pbkdf2_hmac_sha256
Function · Source
PBKDF2 (RFC 8018) with HMAC-SHA256: derives output.len bytes from a password and salt with the given iteration count (at least 1), as SCRAM and many password stores require. The password is copied into OpenSSL only for the call; wipe the caller’s copy when appropriate.
pub fn pbkdf2_hmac_sha256(password: &[u8], salt: &[u8], iterations: u32, output: &mut[u8]) -> void!crypto.Error
Aes128Cfb8
Struct · Source
AES-128 in 8-bit cipher feedback mode (CFB8), as a stream: each update continues where the previous one stopped, so a message may be split at any byte. One value either encrypts or decrypts; a connection needs one of each. Minecraft protocol encryption uses the 16-byte shared secret as both key and IV.
pub struct Aes128Cfb8 {
// Private implementation fields omitted.
}
Aes128Cfb8.encryptor
Function · Source
key and iv must each be 16 bytes.
pub fn encryptor(key: &[u8], iv: &[u8]) -> Aes128Cfb8!crypto.Error
Aes128Cfb8.decryptor
Function · Source
pub fn decryptor(key: &[u8], iv: &[u8]) -> Aes128Cfb8!crypto.Error
Aes128Cfb8.update
Function · Source
Transforms input into output[..input.len]; later output bytes are left unchanged. A shorter output fails BufferTooSmall before any progress.
pub fn update(&mut self, input: &[u8], output: &mut[u8]) -> void!crypto.Error
Aes128Cfb8.update_in_place
Function · Source
pub fn update_in_place(&mut self, data: &mut[u8]) -> void!crypto.Error
RsaPrivateKey
Struct · Source
An RSA key pair with public exponent 65537.
pub struct RsaPrivateKey {
// Private implementation fields omitted.
}
RsaPrivateKey.generate
Function · Source
bits must be within RSA_MIN_BITS..=RSA_MAX_BITS. Generation draws on OpenSSL’s CSPRNG; a 1024-bit key takes milliseconds, 4096 bits seconds.
pub fn generate(bits: u32) -> RsaPrivateKey!crypto.Error
RsaPrivateKey.bits
Function · Source
pub fn bits(&self) -> u32
RsaPrivateKey.size
Function · Source
Modulus length in bytes, which is also the ciphertext length.
pub fn size(&self) -> usize
RsaPrivateKey.public_key_der
Function · Source
Writes the public key as DER SubjectPublicKeyInfo (RFC 5280), the form Minecraft’s encryption request carries, and returns its length. A shorter output fails BufferTooSmall and is left unchanged.
pub fn public_key_der(&self, output: &mut[u8]) -> usize!crypto.Error
RsaPrivateKey.public_key_der_len
Function · Source
The exact length public_key_der writes: 162 bytes for 1024-bit keys.
pub fn public_key_der_len(&self) -> usize!crypto.Error
RsaPrivateKey.decrypt_pkcs1
Function · Source
RSAES-PKCS1-v1_5 decryption (RFC 8017). ciphertext must be exactly size() bytes. Returns the message length; a shorter output fails BufferTooSmall and is left unchanged.
OpenSSL applies implicit rejection: a malformed ciphertext of the right length decrypts to a deterministic pseudorandom message instead of failing, so a padding oracle reveals nothing. Validate the plaintext, such as the expected length and a verify token, before trusting it.
pub fn decrypt_pkcs1(&self, ciphertext: &[u8], output: &mut[u8]) -> usize!crypto.Error
RsaPublicKey
Struct · Source
An RSA public key, such as a peer’s encryption key.
pub struct RsaPublicKey {
// Private implementation fields omitted.
}
RsaPublicKey.from_der
Function · Source
Parses exactly one DER SubjectPublicKeyInfo holding an RSA key of RSA_MIN_BITS..=RSA_MAX_BITS. Trailing bytes are rejected.
pub fn from_der(der: &[u8]) -> RsaPublicKey!crypto.Error
RsaPublicKey.bits
Function · Source
pub fn bits(&self) -> u32
RsaPublicKey.size
Function · Source
pub fn size(&self) -> usize
RsaPublicKey.public_key_der
Function · Source
pub fn public_key_der(&self, output: &mut[u8]) -> usize!crypto.Error
RsaPublicKey.public_key_der_len
Function · Source
pub fn public_key_der_len(&self) -> usize!crypto.Error
RsaPublicKey.encrypt_pkcs1
Function · Source
RSAES-PKCS1-v1_5 encryption with fresh random padding. message may be at most size() - PKCS1_OVERHEAD bytes; output needs size() bytes. Returns size().
pub fn encrypt_pkcs1(&self, message: &[u8], output: &mut[u8]) -> usize!crypto.Error