Skip to main content

str0m_apple_crypto/
lib.rs

1//! Apple CommonCrypto/Security framework implementation of cryptographic functions.
2//! DTLS via dimpl with Apple CommonCrypto as crypto backend.
3
4#![allow(clippy::redundant_pub_crate)]
5#![allow(unsafe_code)]
6#![cfg(target_vendor = "apple")]
7
8mod common_crypto;
9mod dimpl_provider;
10mod dtls;
11mod sha1;
12mod sha256;
13mod srtp;
14
15use str0m_proto::crypto::CryptoProvider;
16
17use dtls::AppleCryptoDtlsProvider;
18use sha1::AppleCryptoSha1HmacProvider;
19use sha256::AppleCryptoSha256Provider;
20use srtp::AppleCryptoSrtpProvider;
21
22/// Create the default Apple CommonCrypto crypto provider.
23///
24/// This provider implements all cryptographic operations required for WebRTC:
25/// - DTLS 1.2 for secure key exchange (using dimpl protocol + Apple CommonCrypto)
26/// - SRTP for encrypted media
27/// - SHA1-HMAC for STUN message integrity
28/// - SHA-256 for certificate fingerprints
29///
30/// # Supported SRTP Profiles
31///
32/// - `SRTP_AES128_CM_SHA1_80`
33/// - `SRTP_AEAD_AES_128_GCM`
34/// - `SRTP_AEAD_AES_256_GCM`
35pub fn default_provider() -> CryptoProvider {
36    static SRTP: AppleCryptoSrtpProvider = AppleCryptoSrtpProvider;
37    static SHA1_HMAC: AppleCryptoSha1HmacProvider = AppleCryptoSha1HmacProvider;
38    static SHA256: AppleCryptoSha256Provider = AppleCryptoSha256Provider;
39    static DTLS: AppleCryptoDtlsProvider = AppleCryptoDtlsProvider;
40
41    CryptoProvider {
42        srtp_provider: &SRTP,
43        sha1_hmac_provider: &SHA1_HMAC,
44        sha256_provider: &SHA256,
45        dtls_provider: &DTLS,
46    }
47}