From 2162178cb7e209e9f060748842e1c4782a2ab852 Mon Sep 17 00:00:00 2001 From: vnugent Date: Sat, 17 Aug 2024 21:33:23 -0400 Subject: refactor: cipher utils update and simplify --- .../src/INostrCrypto.cs | 96 +++------------------- 1 file changed, 10 insertions(+), 86 deletions(-) (limited to 'wrappers/dotnet/VNLib.Utils.Cryptography.Noscrypt/src/INostrCrypto.cs') diff --git a/wrappers/dotnet/VNLib.Utils.Cryptography.Noscrypt/src/INostrCrypto.cs b/wrappers/dotnet/VNLib.Utils.Cryptography.Noscrypt/src/INostrCrypto.cs index 49c0cc0..9b4d36c 100644 --- a/wrappers/dotnet/VNLib.Utils.Cryptography.Noscrypt/src/INostrCrypto.cs +++ b/wrappers/dotnet/VNLib.Utils.Cryptography.Noscrypt/src/INostrCrypto.cs @@ -15,6 +15,8 @@ using System; +using VNLib.Utils.Cryptography.Noscrypt.Encryption; + namespace VNLib.Utils.Cryptography.Noscrypt { public interface INostrCrypto @@ -38,6 +40,14 @@ namespace VNLib.Utils.Cryptography.Noscrypt /// bool ValidateSecretKey(ref readonly NCSecretKey secretKey); + /// + /// Allocates a new cipher instance with the supplied options. + /// + /// The cipher specification version + /// The cipher initialziation flags + /// The cipher instance + NoscryptCipher AllocCipher(NoscryptCipherVersion version, NoscryptCipherFlags flags); + /// /// Signs the supplied data with the secret key and random32 nonce, then writes /// the message signature to the supplied sig64 buffer. @@ -74,91 +84,5 @@ namespace VNLib.Utils.Cryptography.Noscrypt uint dataSize, ref readonly byte sig64 ); - - /// - /// Computes a nip44 message authentication code (MAC) using the supplied key and payload. - /// - /// The key returned during a - /// - /// - /// A pointer to a buffer - /// The size of the buffer to compute the mac of, in bytes - /// A pointer to the 32byte buffer to write the mac to - /// - /// - void ComputeMac( - ref readonly byte hmacKey32, - ref readonly byte payload, - uint payloadSize, - ref byte hmacOut32 - ); - - /// - /// Verifies a nip44 message authentication code (MAC) against the supplied key and payload. - /// - /// A pointer to the receiver's secret key - /// A pointer to senders the public key - /// A pointer to the 32byte nonce buffer - /// A pointer to the 32byte message buffer - /// A pointer to the message buffer - /// The size in bytes of the payload buffer - /// True if the message authentication code (MAC) matches, false otherwise - /// - /// - bool VerifyMac( - ref readonly NCSecretKey secretKey, - ref readonly NCPublicKey publicKey, - ref readonly byte nonce32, - ref readonly byte mac32, - ref readonly byte payload, - uint payloadSize - ); - - /// - /// Encrypts a message using the supplied secret key, public key, and nonce. When this function - /// returns, the cipherText buffer will contain the encrypted message, and the hmacKeyOut32 buffer - /// will contain the key used to compute the message authentication code (MAC). - /// - /// NOTE: The cipherText buffer must be at least as large as the plaintext buffer. The - /// size parameter must be the size of the number of bytes to encrypt. - /// - /// - /// A pointer to the receiver's secret key - /// A pointer to senders the public key - /// A pointer to the 32byte nonce used for message encryption - /// A pointer to the plaintext buffer to encrypt - /// A pointer to the cyphertext buffer to write encrypted data to (must be as large or larger than the plaintext buffer) - /// The size of the data to encrypt - /// - /// - /// - void EncryptNip44( - ref readonly NCSecretKey secretKey, - ref readonly NCPublicKey publicKey, - ref readonly byte nonce32, - ref readonly byte plainText, - ref byte cipherText, - uint size, - ref byte hmacKeyOut32 - ); - - /// - /// Decrypts a message using the supplied secret key, public key, and the original message - /// nonce. - /// - /// A pointer to the receiver's secret key - /// A pointer to senders the public key - /// A pointer to the 32byte nonce used for message encryption - /// A pointer to the plaintext buffer to write plaintext data to (must be as large or larger than the ciphertext buffer) - /// A pointer to the cyphertext buffer to read encrypted data from - /// The size of the buffer to decrypt - void DecryptNip44( - ref readonly NCSecretKey secretKey, - ref readonly NCPublicKey publicKey, - ref readonly byte nonce32, - ref readonly byte cipherText, - ref byte plainText, - uint size - ); } } -- cgit