TZH-nh/moonwire/crypto does not have a README file

    CryptoError

    pub(all) suberror CryptoError {
    InvalidKeyLength(expected~ : Int, actual~ : Int)
    InvalidNonceLength(expected~ : Int, actual~ : Int)
    InvalidOutputLength(actual~ : Int)
    AuthenticationFailed
    LowOrderPoint
    InvalidHex(String)
    InvalidBase64(String)
    } derive(Eq,
    Debug
    )

    Errors raised by cryptographic operations and key/encoding parsers.

    Blake2s

    pub struct Blake2s {
    // private fields
    }

    Incremental BLAKE2s hash / MAC state (RFC 7693).

    Blake2s::finalize

    fn Blake2s::finalize(self : Blake2s) -> Bytes

    Finalize the BLAKE2s state and return the digest of length out_len.

    Blake2s::new

    fn Blake2s::new(out_len? : Int, key? : BytesView) -> Blake2s raise CryptoError

    Initialize a BLAKE2s context with output length out_len (1..=32) and optional key (0..=32 bytes).

    Blake2s::update

    fn Blake2s::update(self : Blake2s, data : BytesView) -> Unit

    Feed input bytes into the BLAKE2s state.

    blake2s

    fn blake2s(data : BytesView, out_len? : Int, key? : BytesView) -> Bytes raise CryptoError

    Compute a single-shot BLAKE2s digest (default 32 bytes, unkeyed).

    blake2s_256

    fn blake2s_256(data : BytesView) -> Bytes

    Unkeyed 32-byte BLAKE2s hash (Hash(input) in WireGuard §5.4).

    blake2s_256_pair

    fn blake2s_256_pair(a : BytesView, b : BytesView) -> Bytes

    Unkeyed 32-byte BLAKE2s hash over the concatenation a || b.

    chacha20_poly1305_open

    fn chacha20_poly1305_open(key : BytesView, nonce12 : BytesView, ciphertext_and_tag : BytesView, aad : BytesView) -> Bytes raise CryptoError

    IETF ChaCha20-Poly1305 AEAD open (RFC 8439 §2.8): verifies 16-byte tag in constant time before decrypting.

    chacha20_poly1305_seal

    fn chacha20_poly1305_seal(key : BytesView, nonce12 : BytesView, plaintext : BytesView, aad : BytesView) -> Bytes raise CryptoError

    IETF ChaCha20-Poly1305 AEAD seal (RFC 8439 §2.8): returns ciphertext || tag16.

    chacha20_xor

    fn chacha20_xor(key : BytesView, counter : UInt, nonce12 : BytesView, input : BytesView) -> Bytes raise CryptoError

    IETF ChaCha20 XOR stream cipher (RFC 8439 §2.4).

    clamp_x25519_private_key

    fn clamp_x25519_private_key(raw32 : BytesView) -> Bytes raise CryptoError

    Clamp a 32-byte random secret into a canonical X25519 private scalar (RFC 7748 §5).

    concat2

    fn concat2(a : BytesView, b : BytesView) -> Bytes

    Concatenate two byte views into a newly allocated Bytes.

    ct_eq

    fn ct_eq(a : BytesView, b : BytesView) -> Bool

    Constant-time equality comparison for two byte slices. Returns false immediately only when lengths differ; otherwise inspects every byte without branching.

    ct_is_zero

    fn ct_is_zero(data : BytesView) -> Bool

    Constant-time check for whether all bytes in a slice are zero.

    from_base64

    fn from_base64(input : StringView) -> Bytes raise CryptoError

    Decode standard RFC 4648 Base64 string into Bytes.

    from_hex

    fn from_hex(hex : StringView) -> Bytes raise CryptoError

    Decode hexadecimal string (whitespace ignored) into Bytes.

    hchacha20

    fn hchacha20(key : BytesView, nonce16 : BytesView) -> Bytes raise CryptoError

    HChaCha20 subkey derivation (draft-irtf-cfrg-xchacha §2.2): 32-byte key + 16-byte nonce -> 32-byte subkey.

    hmac_blake2s

    fn hmac_blake2s(key : BytesView, data : BytesView) -> Bytes

    RFC 2104 HMAC-BLAKE2s-256 (64-byte block size, 32-byte output).

    kdf1

    fn kdf1(key : BytesView, input : BytesView) -> Bytes

    WireGuard Kdf1(key, input) (§5.4): single 32-byte HKDF-BLAKE2s output.

    kdf2

    fn kdf2(key : BytesView, input : BytesView) -> (Bytes, Bytes)

    WireGuard Kdf2(key, input) (§5.4): two 32-byte HKDF-BLAKE2s outputs.

    kdf3

    fn kdf3(key : BytesView, input : BytesView) -> (Bytes, Bytes, Bytes)

    WireGuard Kdf3(key, input) (§5.4): three 32-byte HKDF-BLAKE2s outputs.

    poly1305_mac

    fn poly1305_mac(key32 : BytesView, msg : BytesView) -> Bytes raise CryptoError

    One-time Poly1305 MAC (RFC 8439 §2.5) with a 32-byte key (r || s).

    read_u32_le

    fn read_u32_le(data : BytesView, offset : Int) -> UInt

    Read a 32-bit unsigned integer in little-endian order at offset.

    read_u64_le

    fn read_u64_le(data : BytesView, offset : Int) -> UInt64

    Read a 64-bit unsigned integer in little-endian order at offset.

    siphash24

    fn siphash24(key16 : BytesView, msg : BytesView) -> UInt64 raise CryptoError

    SipHash-2-4 pseudorandom function: 16-byte key + arbitrary message -> 64-bit MAC.

    to_base64

    fn to_base64(data : BytesView) -> String

    Encode bytes using standard RFC 4648 Base64 with = padding (WireGuard key format).

    to_hex

    fn to_hex(data : BytesView) -> String

    Encode bytes as lowercase hexadecimal string.

    wg_aead_open

    fn wg_aead_open(key : BytesView, counter : UInt64, ciphertext_and_tag : BytesView, aad : BytesView) -> Bytes raise CryptoError

    WireGuard AEAD^-1(key, counter, cipher, authtext) (§5.4).

    wg_aead_seal

    fn wg_aead_seal(key : BytesView, counter : UInt64, plaintext : BytesView, aad : BytesView) -> Bytes raise CryptoError

    WireGuard AEAD(key, counter, plain, authtext) (§5.4): 12-byte nonce 0x00000000 || le64(counter).

    wg_mac

    fn wg_mac(key : BytesView, input : BytesView) -> Bytes raise CryptoError

    WireGuard Mac(key, input) (§5.4.4 / §5.4.7): 16-byte keyed BLAKE2s.

    write_u32_le

    fn write_u32_le(out : FixedArray[Byte], offset : Int, v : UInt) -> Unit

    Write a 32-bit unsigned integer in little-endian order into out starting at offset.

    write_u64_le

    fn write_u64_le(out : FixedArray[Byte], offset : Int, v : UInt64) -> Unit

    Write a 64-bit unsigned integer in little-endian order into out starting at offset.

    x25519_dh

    fn x25519_dh(private_key32 : BytesView, peer_public_key32 : BytesView) -> Bytes raise CryptoError

    WireGuard X25519 Diffie-Hellman shared secret derivation (rejects low-order/all-zero shared secrets per RFC 7748 §6.1).

    x25519_public_key

    fn x25519_public_key(private_key32 : BytesView) -> Bytes raise CryptoError

    Derive a 32-byte X25519 public key from a 32-byte private key using the basepoint u = 9.

    x25519_raw

    fn x25519_raw(scalar32 : BytesView, u_coord32 : BytesView) -> Bytes raise CryptoError

    Raw RFC 7748 X25519(k, u) Montgomery ladder (does not reject all-zero output).

    xchacha20_poly1305_open

    fn xchacha20_poly1305_open(key : BytesView, nonce24 : BytesView, ciphertext_and_tag : BytesView, aad : BytesView) -> Bytes raise CryptoError

    XChaCha20-Poly1305 AEAD open (XAEAD^-1 in WireGuard §5.4.7, 24-byte nonce).

    xchacha20_poly1305_seal

    fn xchacha20_poly1305_seal(key : BytesView, nonce24 : BytesView, plaintext : BytesView, aad : BytesView) -> Bytes raise CryptoError

    XChaCha20-Poly1305 AEAD seal (XAEAD in WireGuard §5.4.7, 24-byte nonce).