webrtc_dtls_crypto (webrtc v0.1.0)
View SourceCryptographic building blocks for DTLS 1.2: cipher suite table, TLS 1.2 PRF (RFC 5246 §5), master secret including the extended master secret (RFC 7627), key block, Finished, exporters (RFC 5705), ECDHE and handshake signatures.
Summary
Functions
Compute the ECDHE shared secret. Invalid points are rejected; an all-zero X25519 result is rejected as required by RFC 8422 §5.11 and RFC 7748 §6.1.
Keying material exporter (RFC 5705 §4). DTLS-SRTP uses the label "EXTRACTOR-dtls_srtp" with no context (RFC 5764 §4.2).
RFC 7627 §4: the session hash covers the handshake up to and including ClientKeyExchange.
Returns {ClientKey, ServerKey, ClientIV, ServerIV} for an AEAD suite (no MAC keys).
Signature scheme to use with our own private key, chosen among the schemes the peer accepts.
Cipher suites in order of preference. RFC 8827 §6.5 requires TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256. Only AEAD suites with forward secrecy are offered (RFC 9325 §4.2).
Verify a handshake signature with the peer's certificate key. The scheme must match the key type.
Types
-type group() :: x25519 | secp256r1 | secp384r1.
-type sig_scheme() ::
ecdsa_secp256r1_sha256 | ecdsa_secp384r1_sha384 | rsa_pss_rsae_sha256 | rsa_pkcs1_sha256 |
ed25519.
-type suite() :: #{id := 0..65535, name := atom(), auth := ecdsa | rsa, cipher := aes_128_gcm | aes_256_gcm | chacha20_poly1305, key_len := pos_integer(), iv_len := pos_integer(), explicit_nonce := 0 | 8, prf := sha256 | sha384}.
Functions
-spec export(sha256 | sha384, binary(), {binary(), binary()}, binary(), binary() | no_context) -> fun((non_neg_integer()) -> binary()).
Keying material exporter (RFC 5705 §4). DTLS-SRTP uses the label "EXTRACTOR-dtls_srtp" with no context (RFC 5764 §4.2).
RFC 7627 §4: the session hash covers the handshake up to and including ClientKeyExchange.
-spec group_id(group()) -> 0..65535.
-spec group_name(0..65535) -> group() | unknown.
Returns {ClientKey, ServerKey, ClientIV, ServerIV} for an AEAD suite (no MAC keys).
-spec prf(sha256 | sha384, binary(), iodata(), non_neg_integer()) -> binary().
-spec scheme_for_key(public_key:private_key()) -> [sig_scheme()].
Signature scheme to use with our own private key, chosen among the schemes the peer accepts.
-spec sig_scheme_id(sig_scheme()) -> 0..65535.
-spec sig_scheme_name(0..65535) -> sig_scheme() | unknown.
-spec sign(sig_scheme(), iodata(), public_key:private_key()) -> binary().
-spec signature_schemes() -> [sig_scheme()].
-spec suite(0..65535) -> {ok, suite()} | error.
-spec supported_suites() -> [0..65535].
Cipher suites in order of preference. RFC 8827 §6.5 requires TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256. Only AEAD suites with forward secrecy are offered (RFC 9325 §4.2).
-spec verify(sig_scheme(), iodata(), binary(), {ecdsa | rsa | eddsa, term()}) -> boolean().
Verify a handshake signature with the peer's certificate key. The scheme must match the key type.