Update to sodium 1.0.20.1 to .NET 8

This commit is contained in:
2025-03-18 12:50:30 +13:00
parent 78015046a5
commit 93108d7032
55 changed files with 3600 additions and 282 deletions

View File

@@ -0,0 +1,36 @@
using System.Security.Cryptography;
using NUnit.Framework;
using static CSSUDII.Sodium.Interop.Libsodium;
namespace CSSUDII.Sodium.Tests;
[TestFixture]
public sealed class SecretBoxTest
{
[Test]
public unsafe void Test()
{
var message = RandomNumberGenerator.GetBytes(1024);
var cipher = RandomNumberGenerator.GetBytes((int)(1024 + crypto_secretbox_MACBYTES));
var key = stackalloc byte[(int)crypto_secretbox_KEYBYTES];
var nonce = stackalloc byte[(int)crypto_secretbox_NONCEBYTES];
crypto_secretbox_keygen(key);
randombytes_buf(nonce, crypto_secretbox_NONCEBYTES);
fixed (byte* mPtr = message)
fixed (byte* cPtr = cipher)
{
crypto_secretbox_easy(cPtr, mPtr, (ulong)message.Length, nonce, key);
}
var decrypted = new byte[message.Length];
fixed (byte* dPtr = decrypted)
fixed (byte* cPtr = cipher)
{
crypto_secretbox_open_easy(dPtr, cPtr, (ulong)cipher.Length, nonce, key);
}
Assert.That(decrypted, Is.EquivalentTo(message));
}
}