using System; namespace Hazel.Dtls { /// /// DTLS cipher suite interface for protection of record payload. /// public interface IRecordProtection : IDisposable { /// /// Calculate the size of an encrypted plaintext /// /// Size of plaintext in bytes /// Size of encrypted ciphertext in bytes int GetEncryptedSize(int dataSize); /// /// Calculate the size of decrypted ciphertext /// /// Size of ciphertext in bytes /// Size of decrypted plaintext in bytes int GetDecryptedSize(int dataSize); /// /// Encrypt a plaintext intput with server keys /// /// Output may overlap with input. /// /// Output ciphertext /// Input plaintext /// Parent DTLS record void EncryptServerPlaintext(ByteSpan output, ByteSpan input, ref Record record); /// /// Encrypt a plaintext intput with client keys /// /// Output may overlap with input. /// /// Output ciphertext /// Input plaintext /// Parent DTLS record void EncryptClientPlaintext(ByteSpan output, ByteSpan input, ref Record record); /// /// Decrypt a ciphertext intput with server keys /// /// Output may overlap with input. /// /// Output plaintext /// Input ciphertext /// Parent DTLS record /// True if the input was authenticated and decrypted. Otherwise false bool DecryptCiphertextFromServer(ByteSpan output, ByteSpan input, ref Record record); /// /// Decrypt a ciphertext intput with client keys /// /// Output may overlap with input. /// /// Output plaintext /// Input ciphertext /// Parent DTLS record /// True if the input was authenticated and decrypted. Otherwise false bool DecryptCiphertextFromClient(ByteSpan output, ByteSpan input, ref Record record); } /// /// Factory to create record protection from cipher suite identifiers /// public sealed class RecordProtectionFactory { public static IRecordProtection Create(CipherSuite cipherSuite, ByteSpan masterSecret, ByteSpan serverRandom, ByteSpan clientRandom) { switch (cipherSuite) { case CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256: return new Aes128GcmRecordProtection(masterSecret, serverRandom, clientRandom); default: return null; } } } }