diff --git a/src/Cryptography/AeadAlgorithm.cs b/src/Cryptography/AeadAlgorithm.cs index 03fcde95..b4eccde3 100644 --- a/src/Cryptography/AeadAlgorithm.cs +++ b/src/Cryptography/AeadAlgorithm.cs @@ -23,6 +23,8 @@ namespace NSec.Cryptography // public abstract class AeadAlgorithm : Algorithm { + private static Aegis128L? s_Aegis128L; + private static Aegis256? s_Aegis256; private static Aes256Gcm? s_Aes256Gcm; private static ChaCha20Poly1305? s_ChaCha20Poly1305; private static XChaCha20Poly1305? s_XChaCha20Poly1305; @@ -37,7 +39,7 @@ private protected AeadAlgorithm( int tagSize) { Debug.Assert(keySize > 0); - Debug.Assert(nonceSize >= 0 && nonceSize <= 24); + Debug.Assert(nonceSize >= 0 && nonceSize <= 32); Debug.Assert(tagSize >= 0 && tagSize <= 255); _keySize = keySize; @@ -45,6 +47,34 @@ private protected AeadAlgorithm( _tagSize = tagSize; } + public static Aegis128L Aegis128L + { + get + { + Aegis128L? instance = s_Aegis128L; + if (instance == null) + { + Interlocked.CompareExchange(ref s_Aegis128L, new Aegis128L(), null); + instance = s_Aegis128L; + } + return instance; + } + } + + public static Aegis256 Aegis256 + { + get + { + Aegis256? instance = s_Aegis256; + if (instance == null) + { + Interlocked.CompareExchange(ref s_Aegis256, new Aegis256(), null); + instance = s_Aegis256; + } + return instance; + } + } + public static Aes256Gcm Aes256Gcm { get diff --git a/src/Cryptography/Aegis128L.cs b/src/Cryptography/Aegis128L.cs new file mode 100644 index 00000000..fbeeed96 --- /dev/null +++ b/src/Cryptography/Aegis128L.cs @@ -0,0 +1,179 @@ +using System; +using System.Diagnostics; +using System.Threading; +using NSec.Cryptography.Formatting; +using static Interop.Libsodium; + +namespace NSec.Cryptography +{ + // + // AEGIS-128L + // + // The AEGIS-128L authenticated encryption with associated data (AEAD) + // algorithm + // + // References: + // + // draft-irtf-cfrg-aegis-aead-04 - The AEGIS Family of Authenticated + // Encryption Algorithms + // + // RFC 5116 - An Interface and Algorithms for Authenticated Encryption + // + // Parameters: + // + // Key Size - 16 bytes. + // + // Nonce Size - 16 bytes. + // + // Tag Size - 32 bytes. + // + // Plaintext Size - Between 0 and 2^61-1 bytes. (A Span can hold + // only up to 2^31-1 bytes.) + // + // Associated Data Size - Between 0 and 2^64-1 bytes. + // + // Ciphertext Size - The ciphertext always has the size of the + // plaintext plus the tag size. + // + public sealed class Aegis128L : AeadAlgorithm + { + private const uint NSecBlobHeader = 0xDE614ADE; + + private static int s_selfTest; + + public Aegis128L() : base( + keySize: crypto_aead_aegis128l_KEYBYTES, + nonceSize: crypto_aead_aegis128l_NPUBBYTES, + tagSize: crypto_aead_aegis128l_ABYTES) + { + if (s_selfTest == 0) + { + SelfTest(); + Interlocked.Exchange(ref s_selfTest, 1); + } + } + + internal override void CreateKey( + ReadOnlySpan seed, + out SecureMemoryHandle keyHandle, + out PublicKey? publicKey) + { + Debug.Assert(seed.Length == crypto_aead_aegis128l_KEYBYTES); + + publicKey = null; + keyHandle = SecureMemoryHandle.CreateFrom(seed); + } + + private protected unsafe override void EncryptCore( + SecureMemoryHandle keyHandle, + ReadOnlySpan nonce, + ReadOnlySpan associatedData, + ReadOnlySpan plaintext, + Span ciphertext) + { + Debug.Assert(keyHandle.Size == crypto_aead_aegis128l_KEYBYTES); + Debug.Assert(nonce.Length == crypto_aead_aegis128l_NPUBBYTES); + Debug.Assert(ciphertext.Length == plaintext.Length + crypto_aead_aegis128l_ABYTES); + + fixed (byte* c = ciphertext) + fixed (byte* m = plaintext) + fixed (byte* ad = associatedData) + fixed (byte* n = nonce) + { + int error = crypto_aead_aegis128l_encrypt( + c, + out ulong clen_p, + m, + (ulong)plaintext.Length, + ad, + (ulong)associatedData.Length, + null, + n, + keyHandle); + + Debug.Assert(error == 0); + Debug.Assert((ulong)ciphertext.Length == clen_p); + } + } + + internal override int GetSeedSize() + { + return crypto_aead_aegis128l_KEYBYTES; + } + + private protected unsafe override bool DecryptCore( + SecureMemoryHandle keyHandle, + ReadOnlySpan nonce, + ReadOnlySpan associatedData, + ReadOnlySpan ciphertext, + Span plaintext) + { + Debug.Assert(keyHandle.Size == crypto_aead_aegis128l_KEYBYTES); + Debug.Assert(nonce.Length == crypto_aead_aegis128l_NPUBBYTES); + Debug.Assert(plaintext.Length == ciphertext.Length - crypto_aead_aegis128l_ABYTES); + + fixed (byte* m = plaintext) + fixed (byte* c = ciphertext) + fixed (byte* ad = associatedData) + fixed (byte* n = nonce) + { + int error = crypto_aead_aegis128l_decrypt( + m, + out ulong mlen_p, + null, + c, + (ulong)ciphertext.Length, + ad, + (ulong)associatedData.Length, + n, + keyHandle); + + // libsodium clears plaintext if decryption fails + + Debug.Assert(error != 0 || (ulong)plaintext.Length == mlen_p); + return error == 0; + } + } + + internal override bool TryExportKey( + SecureMemoryHandle keyHandle, + KeyBlobFormat format, + Span blob, + out int blobSize) + { + return format switch + { + KeyBlobFormat.RawSymmetricKey => RawKeyFormatter.TryExport(keyHandle, blob, out blobSize), + KeyBlobFormat.NSecSymmetricKey => NSecKeyFormatter.TryExport(NSecBlobHeader, crypto_aead_aegis128l_KEYBYTES, crypto_aead_aegis128l_ABYTES, keyHandle, blob, out blobSize), + _ => throw Error.Argument_FormatNotSupported(nameof(format), format.ToString()), + }; + } + + internal override bool TryImportKey( + ReadOnlySpan blob, + KeyBlobFormat format, + out SecureMemoryHandle? keyHandle, + out PublicKey? publicKey) + { + publicKey = null; + + return format switch + { + KeyBlobFormat.RawSymmetricKey => RawKeyFormatter.TryImport(crypto_aead_aegis128l_KEYBYTES, blob, out keyHandle), + KeyBlobFormat.NSecSymmetricKey => NSecKeyFormatter.TryImport(NSecBlobHeader, crypto_aead_aegis128l_KEYBYTES, crypto_aead_aegis128l_ABYTES, blob, out keyHandle), + _ => throw Error.Argument_FormatNotSupported(nameof(format), format.ToString()), + }; + } + + private static void SelfTest() + { + if ((crypto_aead_aegis128l_abytes() != crypto_aead_aegis128l_ABYTES) || + (crypto_aead_aegis128l_keybytes() != crypto_aead_aegis128l_KEYBYTES) || + (crypto_aead_aegis128l_npubbytes() != crypto_aead_aegis128l_NPUBBYTES) || + (crypto_aead_aegis128l_nsecbytes() != crypto_aead_aegis128l_NSECBYTES)) + { + throw Error.InvalidOperation_InitializationFailed(); + } + } + } +} diff --git a/src/Cryptography/Aegis256.cs b/src/Cryptography/Aegis256.cs new file mode 100644 index 00000000..1a8acfa8 --- /dev/null +++ b/src/Cryptography/Aegis256.cs @@ -0,0 +1,179 @@ +using System; +using System.Diagnostics; +using System.Threading; +using NSec.Cryptography.Formatting; +using static Interop.Libsodium; + +namespace NSec.Cryptography +{ + // + // AEGIS-256 + // + // The AEGIS-256 authenticated encryption with associated data (AEAD) + // algorithm + // + // References: + // + // draft-irtf-cfrg-aegis-aead-04 - The AEGIS Family of Authenticated + // Encryption Algorithms + // + // RFC 5116 - An Interface and Algorithms for Authenticated Encryption + // + // Parameters: + // + // Key Size - 32 bytes. + // + // Nonce Size - 32 bytes. + // + // Tag Size - 32 bytes. + // + // Plaintext Size - Between 0 and 2^61-1 bytes. (A Span can hold + // only up to 2^31-1 bytes.) + // + // Associated Data Size - Between 0 and 2^64-1 bytes. + // + // Ciphertext Size - The ciphertext always has the size of the + // plaintext plus the tag size. + // + public sealed class Aegis256 : AeadAlgorithm + { + private const uint NSecBlobHeader = 0xDE614BDE; + + private static int s_selfTest; + + public Aegis256() : base( + keySize: crypto_aead_aegis256_KEYBYTES, + nonceSize: crypto_aead_aegis256_NPUBBYTES, + tagSize: crypto_aead_aegis256_ABYTES) + { + if (s_selfTest == 0) + { + SelfTest(); + Interlocked.Exchange(ref s_selfTest, 1); + } + } + + internal override void CreateKey( + ReadOnlySpan seed, + out SecureMemoryHandle keyHandle, + out PublicKey? publicKey) + { + Debug.Assert(seed.Length == crypto_aead_aegis256_KEYBYTES); + + publicKey = null; + keyHandle = SecureMemoryHandle.CreateFrom(seed); + } + + private protected unsafe override void EncryptCore( + SecureMemoryHandle keyHandle, + ReadOnlySpan nonce, + ReadOnlySpan associatedData, + ReadOnlySpan plaintext, + Span ciphertext) + { + Debug.Assert(keyHandle.Size == crypto_aead_aegis256_KEYBYTES); + Debug.Assert(nonce.Length == crypto_aead_aegis256_NPUBBYTES); + Debug.Assert(ciphertext.Length == plaintext.Length + crypto_aead_aegis256_ABYTES); + + fixed (byte* c = ciphertext) + fixed (byte* m = plaintext) + fixed (byte* ad = associatedData) + fixed (byte* n = nonce) + { + int error = crypto_aead_aegis256_encrypt( + c, + out ulong clen_p, + m, + (ulong)plaintext.Length, + ad, + (ulong)associatedData.Length, + null, + n, + keyHandle); + + Debug.Assert(error == 0); + Debug.Assert((ulong)ciphertext.Length == clen_p); + } + } + + internal override int GetSeedSize() + { + return crypto_aead_aegis256_KEYBYTES; + } + + private protected unsafe override bool DecryptCore( + SecureMemoryHandle keyHandle, + ReadOnlySpan nonce, + ReadOnlySpan associatedData, + ReadOnlySpan ciphertext, + Span plaintext) + { + Debug.Assert(keyHandle.Size == crypto_aead_aegis256_KEYBYTES); + Debug.Assert(nonce.Length == crypto_aead_aegis256_NPUBBYTES); + Debug.Assert(plaintext.Length == ciphertext.Length - crypto_aead_aegis256_ABYTES); + + fixed (byte* m = plaintext) + fixed (byte* c = ciphertext) + fixed (byte* ad = associatedData) + fixed (byte* n = nonce) + { + int error = crypto_aead_aegis256_decrypt( + m, + out ulong mlen_p, + null, + c, + (ulong)ciphertext.Length, + ad, + (ulong)associatedData.Length, + n, + keyHandle); + + // libsodium clears plaintext if decryption fails + + Debug.Assert(error != 0 || (ulong)plaintext.Length == mlen_p); + return error == 0; + } + } + + internal override bool TryExportKey( + SecureMemoryHandle keyHandle, + KeyBlobFormat format, + Span blob, + out int blobSize) + { + return format switch + { + KeyBlobFormat.RawSymmetricKey => RawKeyFormatter.TryExport(keyHandle, blob, out blobSize), + KeyBlobFormat.NSecSymmetricKey => NSecKeyFormatter.TryExport(NSecBlobHeader, crypto_aead_aegis256_KEYBYTES, crypto_aead_aegis256_ABYTES, keyHandle, blob, out blobSize), + _ => throw Error.Argument_FormatNotSupported(nameof(format), format.ToString()), + }; + } + + internal override bool TryImportKey( + ReadOnlySpan blob, + KeyBlobFormat format, + out SecureMemoryHandle? keyHandle, + out PublicKey? publicKey) + { + publicKey = null; + + return format switch + { + KeyBlobFormat.RawSymmetricKey => RawKeyFormatter.TryImport(crypto_aead_aegis256_KEYBYTES, blob, out keyHandle), + KeyBlobFormat.NSecSymmetricKey => NSecKeyFormatter.TryImport(NSecBlobHeader, crypto_aead_aegis256_KEYBYTES, crypto_aead_aegis256_ABYTES, blob, out keyHandle), + _ => throw Error.Argument_FormatNotSupported(nameof(format), format.ToString()), + }; + } + + private static void SelfTest() + { + if ((crypto_aead_aegis256_abytes() != crypto_aead_aegis256_ABYTES) || + (crypto_aead_aegis256_keybytes() != crypto_aead_aegis256_KEYBYTES) || + (crypto_aead_aegis256_npubbytes() != crypto_aead_aegis256_NPUBBYTES) || + (crypto_aead_aegis256_nsecbytes() != crypto_aead_aegis256_NSECBYTES)) + { + throw Error.InvalidOperation_InitializationFailed(); + } + } + } +} diff --git a/src/Experimental/PasswordBased/PasswordBasedKeyExporter.cs b/src/Experimental/PasswordBased/PasswordBasedKeyExporter.cs index 40f964e2..520a9d49 100644 --- a/src/Experimental/PasswordBased/PasswordBasedKeyExporter.cs +++ b/src/Experimental/PasswordBased/PasswordBasedKeyExporter.cs @@ -189,6 +189,16 @@ private static void ReadEncryptionParameters( Read(ref reader, out nonce); break; + case Aegis128L _: + Read(ref reader, 0x2004); + Read(ref reader, out nonce); + break; + + case Aegis256 _: + Read(ref reader, 0x2005); + Read(ref reader, out nonce); + break; + default: throw new NotSupportedException(); } @@ -275,6 +285,16 @@ private static void WriteEncryptionParameters( Write(ref writer, nonce); break; + case Aegis128L _: + Write(ref writer, 0x2004); + Write(ref writer, nonce); + break; + + case Aegis256 _: + Write(ref writer, 0x2005); + Write(ref writer, nonce); + break; + default: throw new NotSupportedException(); } diff --git a/src/Interop/Interop.Aead.Aegis128L.cs b/src/Interop/Interop.Aead.Aegis128L.cs new file mode 100644 index 00000000..f19e9b33 --- /dev/null +++ b/src/Interop/Interop.Aead.Aegis128L.cs @@ -0,0 +1,49 @@ +using System; +using System.Runtime.InteropServices; + +internal static partial class Interop +{ + internal static partial class Libsodium + { + internal const int crypto_aead_aegis128l_ABYTES = 32; + internal const int crypto_aead_aegis128l_KEYBYTES = 16; + internal const int crypto_aead_aegis128l_NPUBBYTES = 16; + internal const int crypto_aead_aegis128l_NSECBYTES = 0; + + [DllImport(Libraries.Libsodium, CallingConvention = CallingConvention.Cdecl)] + internal static extern nuint crypto_aead_aegis128l_abytes(); + + [DllImport(Libraries.Libsodium, CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern int crypto_aead_aegis128l_decrypt( + byte* m, + out ulong mlen_p, + byte* nsec, + byte* c, + ulong clen, + byte* ad, + ulong adlen, + byte* npub, + SecureMemoryHandle k); + + [DllImport(Libraries.Libsodium, CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern int crypto_aead_aegis128l_encrypt( + byte* c, + out ulong clen_p, + byte* m, + ulong mlen, + byte* ad, + ulong adlen, + byte* nsec, + byte* npub, + SecureMemoryHandle k); + + [DllImport(Libraries.Libsodium, CallingConvention = CallingConvention.Cdecl)] + internal static extern nuint crypto_aead_aegis128l_keybytes(); + + [DllImport(Libraries.Libsodium, CallingConvention = CallingConvention.Cdecl)] + internal static extern nuint crypto_aead_aegis128l_npubbytes(); + + [DllImport(Libraries.Libsodium, CallingConvention = CallingConvention.Cdecl)] + internal static extern nuint crypto_aead_aegis128l_nsecbytes(); + } +} diff --git a/src/Interop/Interop.Aead.Aegis256.cs b/src/Interop/Interop.Aead.Aegis256.cs new file mode 100644 index 00000000..4b22d0bb --- /dev/null +++ b/src/Interop/Interop.Aead.Aegis256.cs @@ -0,0 +1,49 @@ +using System; +using System.Runtime.InteropServices; + +internal static partial class Interop +{ + internal static partial class Libsodium + { + internal const int crypto_aead_aegis256_ABYTES = 32; + internal const int crypto_aead_aegis256_KEYBYTES = 32; + internal const int crypto_aead_aegis256_NPUBBYTES = 32; + internal const int crypto_aead_aegis256_NSECBYTES = 0; + + [DllImport(Libraries.Libsodium, CallingConvention = CallingConvention.Cdecl)] + internal static extern nuint crypto_aead_aegis256_abytes(); + + [DllImport(Libraries.Libsodium, CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern int crypto_aead_aegis256_decrypt( + byte* m, + out ulong mlen_p, + byte* nsec, + byte* c, + ulong clen, + byte* ad, + ulong adlen, + byte* npub, + SecureMemoryHandle k); + + [DllImport(Libraries.Libsodium, CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern int crypto_aead_aegis256_encrypt( + byte* c, + out ulong clen_p, + byte* m, + ulong mlen, + byte* ad, + ulong adlen, + byte* nsec, + byte* npub, + SecureMemoryHandle k); + + [DllImport(Libraries.Libsodium, CallingConvention = CallingConvention.Cdecl)] + internal static extern nuint crypto_aead_aegis256_keybytes(); + + [DllImport(Libraries.Libsodium, CallingConvention = CallingConvention.Cdecl)] + internal static extern nuint crypto_aead_aegis256_npubbytes(); + + [DllImport(Libraries.Libsodium, CallingConvention = CallingConvention.Cdecl)] + internal static extern nuint crypto_aead_aegis256_nsecbytes(); + } +} diff --git a/src/Interop/Interop.projitems b/src/Interop/Interop.projitems index 20eb0f2f..dad831ee 100644 --- a/src/Interop/Interop.projitems +++ b/src/Interop/Interop.projitems @@ -5,6 +5,8 @@ true + + diff --git a/src/Interop/Interop.yaml b/src/Interop/Interop.yaml index 3c15e981..fd4f6148 100644 --- a/src/Interop/Interop.yaml +++ b/src/Interop/Interop.yaml @@ -6,6 +6,36 @@ Interop.Core.cs: - sodium_init - sodium_set_misuse_handler +Interop.Aead.Aegis128L.cs: + include: include/sodium/crypto_aead_aegis128l.h + constants: + - crypto_aead_aegis128l_ABYTES + - crypto_aead_aegis128l_KEYBYTES + - crypto_aead_aegis128l_NPUBBYTES + - crypto_aead_aegis128l_NSECBYTES + functions: + - crypto_aead_aegis128l_abytes + - crypto_aead_aegis128l_decrypt (out ulong mlen_p, SecureMemoryHandle k) + - crypto_aead_aegis128l_encrypt (out ulong clen_p, SecureMemoryHandle k) + - crypto_aead_aegis128l_keybytes + - crypto_aead_aegis128l_npubbytes + - crypto_aead_aegis128l_nsecbytes + +Interop.Aead.Aegis256.cs: + include: include/sodium/crypto_aead_aegis256.h + constants: + - crypto_aead_aegis256_ABYTES + - crypto_aead_aegis256_KEYBYTES + - crypto_aead_aegis256_NPUBBYTES + - crypto_aead_aegis256_NSECBYTES + functions: + - crypto_aead_aegis256_abytes + - crypto_aead_aegis256_decrypt (out ulong mlen_p, SecureMemoryHandle k) + - crypto_aead_aegis256_encrypt (out ulong clen_p, SecureMemoryHandle k) + - crypto_aead_aegis256_keybytes + - crypto_aead_aegis256_npubbytes + - crypto_aead_aegis256_nsecbytes + Interop.Aead.Aes256Gcm.cs: include: include/sodium/crypto_aead_aes256gcm.h constants: diff --git a/tests/Algorithms/Aegis128LTests.cs b/tests/Algorithms/Aegis128LTests.cs new file mode 100644 index 00000000..f199c06e --- /dev/null +++ b/tests/Algorithms/Aegis128LTests.cs @@ -0,0 +1,50 @@ +using System; +using NSec.Cryptography; +using Xunit; + +namespace NSec.Tests.Algorithms +{ + public static class Aegis128LTests + { + public static readonly TheoryData PlaintextLengths = Utilities.Primes; + + #region Properties + + [Fact] + public static void Properties() + { + var a = AeadAlgorithm.Aegis128L; + + Assert.Equal(16, a.KeySize); + Assert.Equal(16, a.NonceSize); + Assert.Equal(32, a.TagSize); + } + + #endregion + + #region Encrypt/Decrypt + + [Theory] + [MemberData(nameof(PlaintextLengths))] + public static void EncryptDecrypt(int length) + { + var a = AeadAlgorithm.Aegis128L; + + using var k = new Key(a); + var n = Utilities.RandomBytes.Slice(0, a.NonceSize); + var ad = Utilities.RandomBytes.Slice(0, 100); + + var expected = Utilities.RandomBytes.Slice(0, length).ToArray(); + + var ciphertext = a.Encrypt(k, n, ad, expected); + Assert.NotNull(ciphertext); + Assert.Equal(length + a.TagSize, ciphertext.Length); + + var actual = a.Decrypt(k, n, ad, ciphertext); + Assert.NotNull(actual); + Assert.Equal(expected, actual); + } + + #endregion + } +} diff --git a/tests/Algorithms/Aegis256Tests.cs b/tests/Algorithms/Aegis256Tests.cs new file mode 100644 index 00000000..1659fab8 --- /dev/null +++ b/tests/Algorithms/Aegis256Tests.cs @@ -0,0 +1,50 @@ +using System; +using NSec.Cryptography; +using Xunit; + +namespace NSec.Tests.Algorithms +{ + public static class Aegis256Tests + { + public static readonly TheoryData PlaintextLengths = Utilities.Primes; + + #region Properties + + [Fact] + public static void Properties() + { + var a = AeadAlgorithm.Aegis256; + + Assert.Equal(32, a.KeySize); + Assert.Equal(32, a.NonceSize); + Assert.Equal(32, a.TagSize); + } + + #endregion + + #region Encrypt/Decrypt + + [Theory] + [MemberData(nameof(PlaintextLengths))] + public static void EncryptDecrypt(int length) + { + var a = AeadAlgorithm.Aegis256; + + using var k = new Key(a); + var n = Utilities.RandomBytes.Slice(0, a.NonceSize); + var ad = Utilities.RandomBytes.Slice(0, 100); + + var expected = Utilities.RandomBytes.Slice(0, length).ToArray(); + + var ciphertext = a.Encrypt(k, n, ad, expected); + Assert.NotNull(ciphertext); + Assert.Equal(length + a.TagSize, ciphertext.Length); + + var actual = a.Decrypt(k, n, ad, ciphertext); + Assert.NotNull(actual); + Assert.Equal(expected, actual); + } + + #endregion + } +} diff --git a/tests/Base/AeadAlgorithmTests.cs b/tests/Base/AeadAlgorithmTests.cs index 7a724dda..7911cc17 100644 --- a/tests/Base/AeadAlgorithmTests.cs +++ b/tests/Base/AeadAlgorithmTests.cs @@ -17,7 +17,7 @@ public static class AeadAlgorithmTests public static void Properties(AeadAlgorithm a) { Assert.True(a.KeySize > 0); - Assert.InRange(a.NonceSize, 0, 24); + Assert.InRange(a.NonceSize, 0, 32); Assert.InRange(a.TagSize, 0, 255); } diff --git a/tests/Formatting/NSecTests.cs b/tests/Formatting/NSecTests.cs index 93b0c5bb..6d67a8f9 100644 --- a/tests/Formatting/NSecTests.cs +++ b/tests/Formatting/NSecTests.cs @@ -7,6 +7,8 @@ namespace NSec.Tests.Formatting public static class NSecTests { [Theory] + [InlineData(typeof(Aegis128L), new byte[] { 0xDE, 0x61, 0x4A, 0xDE })] + [InlineData(typeof(Aegis256), new byte[] { 0xDE, 0x61, 0x4B, 0xDE })] [InlineData(typeof(Aes256Gcm), new byte[] { 0xDE, 0x61, 0x44, 0xDE })] [InlineData(typeof(ChaCha20Poly1305), new byte[] { 0xDE, 0x61, 0x43, 0xDE })] public static void Aead(Type algorithmType, byte[] blobHeader) diff --git a/tests/Registry.cs b/tests/Registry.cs index f8ccd24a..8fe26fd5 100644 --- a/tests/Registry.cs +++ b/tests/Registry.cs @@ -12,6 +12,8 @@ internal static class Registry public static readonly TheoryData AeadAlgorithms = new() { + AeadAlgorithm.Aegis128L, + AeadAlgorithm.Aegis256, AeadAlgorithm.Aes256Gcm, AeadAlgorithm.ChaCha20Poly1305, AeadAlgorithm.XChaCha20Poly1305, @@ -101,6 +103,8 @@ internal static class Registry public static readonly TheoryData SymmetricAlgorithms = new() { + AeadAlgorithm.Aegis128L, + AeadAlgorithm.Aegis256, AeadAlgorithm.Aes256Gcm, AeadAlgorithm.ChaCha20Poly1305, AeadAlgorithm.XChaCha20Poly1305, @@ -167,6 +171,10 @@ internal static class Registry public static readonly TheoryData SymmetricKeyBlobFormats = new() { + { AeadAlgorithm.Aegis128L, KeyBlobFormat.RawSymmetricKey }, + { AeadAlgorithm.Aegis128L, KeyBlobFormat.NSecSymmetricKey }, + { AeadAlgorithm.Aegis256, KeyBlobFormat.RawSymmetricKey }, + { AeadAlgorithm.Aegis256, KeyBlobFormat.NSecSymmetricKey }, { AeadAlgorithm.Aes256Gcm, KeyBlobFormat.RawSymmetricKey }, { AeadAlgorithm.Aes256Gcm, KeyBlobFormat.NSecSymmetricKey }, { MacAlgorithm.Blake2b_128, KeyBlobFormat.RawSymmetricKey },