AirPlay 2 cryptographic helpers.
This module intentionally stays small: HKDF-SHA512, ChaCha20-Poly1305 and AP2 audio packet encryption. Pairing and RTSP framing build on these primitives.
Summary
Functions
Decrypt an AP2 RTP audio payload encrypted by audio_encrypt/3.
Encrypt an AP2 RTP audio payload using fields parsed from a 12-byte RTP header.
Encrypt an AP2 RTP audio payload.
Decrypt with ChaCha20-Poly1305. Returns {:ok, plaintext} or :error.
Encrypt with ChaCha20-Poly1305. Returns {ciphertext, tag}.
Compatibility wrapper for ChaCha20-Poly1305 decryption.
Compatibility wrapper for ChaCha20-Poly1305 encryption.
Generate an Ed25519 keypair as {public_key, private_key}.
Sign a message with Ed25519.
Verify an Ed25519 signature.
Compatibility wrapper for HKDF-SHA512 using (ikm, salt, info, len) argument order.
HKDF-SHA512 derive len bytes from input keying material.
Generate an X25519 keypair as {public_key, private_key}.
Compute an X25519 shared secret.
Functions
Decrypt an AP2 RTP audio payload encrypted by audio_encrypt/3.
Encrypt an AP2 RTP audio payload using fields parsed from a 12-byte RTP header.
@spec audio_encrypt( binary(), non_neg_integer(), non_neg_integer(), non_neg_integer(), binary() ) :: binary()
Encrypt an AP2 RTP audio payload.
The wire format matches owntone and airplay2-rs:
- nonce =
<<0::32, seq::little-16, 0::48>> - transmitted nonce suffix =
<<seq::little-16, 0::48>> - AAD =
<<rtp_timestamp::32, ssrc::32>> - packet trailer =
tag16 <> nonce8
The receiver reconstructs the 12-byte nonce by prefixing four zero bytes to the transmitted eight-byte suffix.
@spec chacha20_poly1305_decrypt(binary(), binary(), binary(), binary(), binary()) :: {:ok, binary()} | :error
Decrypt with ChaCha20-Poly1305. Returns {:ok, plaintext} or :error.
Encrypt with ChaCha20-Poly1305. Returns {ciphertext, tag}.
Compatibility wrapper for ChaCha20-Poly1305 decryption.
Compatibility wrapper for ChaCha20-Poly1305 encryption.
Generate an Ed25519 keypair as {public_key, private_key}.
Sign a message with Ed25519.
Verify an Ed25519 signature.
@spec hkdf(binary(), binary(), binary(), non_neg_integer()) :: binary()
Compatibility wrapper for HKDF-SHA512 using (ikm, salt, info, len) argument order.
@spec hkdf_sha512(binary(), non_neg_integer(), binary(), binary()) :: binary()
HKDF-SHA512 derive len bytes from input keying material.
Generate an X25519 keypair as {public_key, private_key}.