// Copyright (C) 2024 Vaughn Nugent // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as // published by the Free Software Foundation, either version 3 of the // License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . using System; namespace VNLib.Utils.Cryptography.Noscrypt { public interface INostrCrypto { /// /// Gets a nostr public key from a secret key. /// /// A reference to the secret key to get the public key from /// A reference to the public key structure to write the recovered key to /// /// void GetPublicKey(ref readonly NCSecretKey secretKey, ref NCPublicKey publicKey); /// /// Validates a secret key is in a valid format. /// /// A readonly reference to key structure to validate /// True if the key is consiered valid against the secp256k1 curve /// /// bool ValidateSecretKey(ref readonly NCSecretKey secretKey); /// /// Signs the supplied data with the secret key and random32 nonce, then writes /// the message signature to the supplied sig64 buffer. /// /// The secret key used to sign the message /// A highly secure random nonce used to seed the signature /// A pointer to the first byte in the message to sign /// The size of the message in bytes /// A pointer to the first byte of a 64 byte buffer used to write the message signature to /// /// void SignData( ref readonly NCSecretKey secretKey, ref readonly byte random32, ref readonly byte data, uint dataSize, ref byte sig64 ); /// /// Performs cryptographic verification of the supplied data /// against the supplied public key. /// /// The signer's public key /// A pointer to the first byte in the message to sign /// The number of bytes in the message /// A pointer to the signature buffer /// True if the signature could be verified against the public key. False otherwise /// /// bool VerifyData( ref readonly NCPublicKey pubKey, ref readonly byte data, 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 ); } }