From 08cdd22301d363df28f5c5cf0f4ded3cad0069d2 Mon Sep 17 00:00:00 2001 From: Matthew Endsley Date: Wed, 13 Jan 2021 10:37:06 -0800 Subject: [PATCH] Add interface for record protection --- Hazel/Dtls/IRecordProtection.cs | 66 +++++++++++++++++++++++++++++++++ Hazel/Hazel.csproj | 1 + 2 files changed, 67 insertions(+) create mode 100644 Hazel/Dtls/IRecordProtection.cs diff --git a/Hazel/Dtls/IRecordProtection.cs b/Hazel/Dtls/IRecordProtection.cs new file mode 100644 index 0000000..1d70c6a --- /dev/null +++ b/Hazel/Dtls/IRecordProtection.cs @@ -0,0 +1,66 @@ +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); + } +} diff --git a/Hazel/Hazel.csproj b/Hazel/Hazel.csproj index e102524..0d176f3 100644 --- a/Hazel/Hazel.csproj +++ b/Hazel/Hazel.csproj @@ -80,6 +80,7 @@ + -- 2.39.5