Added EllieBot.Voice
This commit is contained in:
parent
e9e7fd23af
commit
dac6e283e8
18 changed files with 1339 additions and 13 deletions
src/EllieBot.Voice
32
src/EllieBot.Voice/LibSodium.cs
Normal file
32
src/EllieBot.Voice/LibSodium.cs
Normal file
|
@ -0,0 +1,32 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace EllieBot.Voice
|
||||
{
|
||||
internal static unsafe class Sodium
|
||||
{
|
||||
private const string SODIUM = "data/lib/libsodium";
|
||||
|
||||
[DllImport(SODIUM, EntryPoint = "crypto_secretbox_easy", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern int SecretBoxEasy(byte* output, byte* input, long inputLength, byte* nonce, byte* secret);
|
||||
[DllImport(SODIUM, EntryPoint = "crypto_secretbox_open_easy", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern int SecretBoxOpenEasy(byte* output, byte* input, ulong inputLength, byte* nonce, byte* secret);
|
||||
|
||||
public static int Encrypt(byte[] input, int inputOffset, long inputLength, byte[] output, int outputOffset, in ReadOnlySpan<byte> nonce, byte[] secret)
|
||||
{
|
||||
fixed (byte* inPtr = input)
|
||||
fixed (byte* outPtr = output)
|
||||
fixed (byte* noncePtr = nonce)
|
||||
fixed (byte* secretPtr = secret)
|
||||
return SecretBoxEasy(outPtr + outputOffset, inPtr + inputOffset, inputLength - inputOffset, noncePtr, secretPtr);
|
||||
}
|
||||
public static int Decrypt(byte[] input, ulong inputLength, byte[] output, in ReadOnlySpan<byte> nonce, byte[] secret)
|
||||
{
|
||||
fixed (byte* outPtr = output)
|
||||
fixed (byte* inPtr = input)
|
||||
fixed (byte* noncePtr = nonce)
|
||||
fixed (byte* secretPtr = secret)
|
||||
return SecretBoxOpenEasy(outPtr, inPtr, inputLength, noncePtr, secretPtr);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue