From e8be9ced6181db87d2d5d4ff8273f29db71772b3 Mon Sep 17 00:00:00 2001 From: Mike Mulchrone Date: Sat, 20 Jun 2026 11:39:27 -0400 Subject: [PATCH 1/2] fixing build and test errors --- cas-core-lib | 2 +- .../Asymmetric/Types/RsaKeyPairResult.cs | 4 +- .../Asymmetric/Types/RsaSignResult.cs | 4 +- cas-dotnet-sdk/Helpers/NativeString.cs | 4 +- .../Hybrid/Types/HpkeEncryptResult.cs | 10 +- .../Hybrid/Types/HpkeKeyPairResult.cs | 10 +- .../Types/X25519SecretPublicKey.cs | 8 +- .../KeyExchange/Types/X25519SharedSecret.cs | 6 +- cas-dotnet-sdk/PQC/Types/SLHDSAKeyPair.cs | 6 +- .../PasswordHashers/PasswordHasherFactory.cs | 23 +- cas-dotnet-sdk/Signatures/ED25519Wrapper.cs | 12 +- .../Types/Ed25519ByteSignatureResult.cs | 8 +- .../Signatures/Types/Ed25519KeyPairResult.cs | 8 +- .../Types/Ed25519SignatureResult.cs | 4 +- cas-dotnet-sdk/Sponges/AsconWrapper.cs | 8 +- .../Symmetric/Types/AesEncryptResult.cs | 4 +- generated/NativeMethods.g.cs | 423 ++++++++++++++++++ 17 files changed, 488 insertions(+), 56 deletions(-) create mode 100644 generated/NativeMethods.g.cs diff --git a/cas-core-lib b/cas-core-lib index 5f2db99..fd662cc 160000 --- a/cas-core-lib +++ b/cas-core-lib @@ -1 +1 @@ -Subproject commit 5f2db993e8b213bddd391029f7862c4c5eec1a6a +Subproject commit fd662cc697ae7726bae2536400eb29a719e94bd9 diff --git a/cas-dotnet-sdk/Asymmetric/Types/RsaKeyPairResult.cs b/cas-dotnet-sdk/Asymmetric/Types/RsaKeyPairResult.cs index f93df9d..4123871 100644 --- a/cas-dotnet-sdk/Asymmetric/Types/RsaKeyPairResult.cs +++ b/cas-dotnet-sdk/Asymmetric/Types/RsaKeyPairResult.cs @@ -2,7 +2,7 @@ { public class RsaKeyPairResult { - public string PublicKey { get; set; } - public string PrivateKey { get; set; } + public string PublicKey { get; set; } = string.Empty; + public string PrivateKey { get; set; } = string.Empty; } } diff --git a/cas-dotnet-sdk/Asymmetric/Types/RsaSignResult.cs b/cas-dotnet-sdk/Asymmetric/Types/RsaSignResult.cs index df220e5..82322c8 100644 --- a/cas-dotnet-sdk/Asymmetric/Types/RsaSignResult.cs +++ b/cas-dotnet-sdk/Asymmetric/Types/RsaSignResult.cs @@ -2,7 +2,7 @@ { public class RsaSignResult { - public string Signature { get; set; } - public string PublicKey { get; set; } + public string Signature { get; set; } = string.Empty; + public string PublicKey { get; set; } = string.Empty; } } diff --git a/cas-dotnet-sdk/Helpers/NativeString.cs b/cas-dotnet-sdk/Helpers/NativeString.cs index a504e7e..47693ad 100644 --- a/cas-dotnet-sdk/Helpers/NativeString.cs +++ b/cas-dotnet-sdk/Helpers/NativeString.cs @@ -18,9 +18,9 @@ public static string ReadAndFree(byte* ptr) { if (ptr == null) { - return null; + return string.Empty; } - string value = Marshal.PtrToStringUTF8((IntPtr)ptr); + string value = Marshal.PtrToStringUTF8((IntPtr)ptr) ?? string.Empty; NativeMethods.free_cstring(ptr); return value; } diff --git a/cas-dotnet-sdk/Hybrid/Types/HpkeEncryptResult.cs b/cas-dotnet-sdk/Hybrid/Types/HpkeEncryptResult.cs index 44eba0f..da25fca 100644 --- a/cas-dotnet-sdk/Hybrid/Types/HpkeEncryptResult.cs +++ b/cas-dotnet-sdk/Hybrid/Types/HpkeEncryptResult.cs @@ -1,9 +1,11 @@ -namespace CasDotnetSdk.Hybrid.Types +using System; + +namespace CasDotnetSdk.Hybrid.Types { public class HpkeEncryptResult { - public byte[] EncappedKey { get; set; } - public byte[] Ciphertext { get; set; } - public byte[] Tag { get; set; } + public byte[] EncappedKey { get; set; } = Array.Empty(); + public byte[] Ciphertext { get; set; } = Array.Empty(); + public byte[] Tag { get; set; } = Array.Empty(); } } diff --git a/cas-dotnet-sdk/Hybrid/Types/HpkeKeyPairResult.cs b/cas-dotnet-sdk/Hybrid/Types/HpkeKeyPairResult.cs index bb5778a..9b780a3 100644 --- a/cas-dotnet-sdk/Hybrid/Types/HpkeKeyPairResult.cs +++ b/cas-dotnet-sdk/Hybrid/Types/HpkeKeyPairResult.cs @@ -1,9 +1,11 @@ -namespace CasDotnetSdk.Hybrid.Types +using System; + +namespace CasDotnetSdk.Hybrid.Types { public class HpkeKeyPairResult { - public byte[] PrivateKey { get; set; } - public byte[] PublicKey { get; set; } - public byte[] InfoStr { get; set; } + public byte[] PrivateKey { get; set; } = Array.Empty(); + public byte[] PublicKey { get; set; } = Array.Empty(); + public byte[] InfoStr { get; set; } = Array.Empty(); } } diff --git a/cas-dotnet-sdk/KeyExchange/Types/X25519SecretPublicKey.cs b/cas-dotnet-sdk/KeyExchange/Types/X25519SecretPublicKey.cs index 6419abe..0902edd 100644 --- a/cas-dotnet-sdk/KeyExchange/Types/X25519SecretPublicKey.cs +++ b/cas-dotnet-sdk/KeyExchange/Types/X25519SecretPublicKey.cs @@ -1,8 +1,10 @@ -namespace CasDotnetSdk.KeyExchange.Types +using System; + +namespace CasDotnetSdk.KeyExchange.Types { public class X25519SecretPublicKey { - public byte[] SecretKey { get; set; } - public byte[] PublicKey { get; set; } + public byte[] SecretKey { get; set; } = Array.Empty(); + public byte[] PublicKey { get; set; } = Array.Empty(); } } diff --git a/cas-dotnet-sdk/KeyExchange/Types/X25519SharedSecret.cs b/cas-dotnet-sdk/KeyExchange/Types/X25519SharedSecret.cs index 82e0b19..9480e8a 100644 --- a/cas-dotnet-sdk/KeyExchange/Types/X25519SharedSecret.cs +++ b/cas-dotnet-sdk/KeyExchange/Types/X25519SharedSecret.cs @@ -1,7 +1,9 @@ -namespace CasDotnetSdk.KeyExchange.Types +using System; + +namespace CasDotnetSdk.KeyExchange.Types { public class X25519SharedSecret { - public byte[] SharedSecret { get; set; } + public byte[] SharedSecret { get; set; } = Array.Empty(); } } \ No newline at end of file diff --git a/cas-dotnet-sdk/PQC/Types/SLHDSAKeyPair.cs b/cas-dotnet-sdk/PQC/Types/SLHDSAKeyPair.cs index aabc74d..1866bd1 100644 --- a/cas-dotnet-sdk/PQC/Types/SLHDSAKeyPair.cs +++ b/cas-dotnet-sdk/PQC/Types/SLHDSAKeyPair.cs @@ -1,8 +1,10 @@ +using System; + namespace CasDotnetSdk.PQC.Types { public class SLHDSAKeyPair { - public byte[] SigningKey { get; set; } - public byte[] VerificationKey { get; set; } + public byte[] SigningKey { get; set; } = Array.Empty(); + public byte[] VerificationKey { get; set; } = Array.Empty(); } } diff --git a/cas-dotnet-sdk/PasswordHashers/PasswordHasherFactory.cs b/cas-dotnet-sdk/PasswordHashers/PasswordHasherFactory.cs index e2fa18d..3fe6aa1 100644 --- a/cas-dotnet-sdk/PasswordHashers/PasswordHasherFactory.cs +++ b/cas-dotnet-sdk/PasswordHashers/PasswordHasherFactory.cs @@ -1,4 +1,6 @@ -namespace CasDotnetSdk.PasswordHashers +using System; + +namespace CasDotnetSdk.PasswordHashers { public enum PasswordHasherType { @@ -11,20 +13,13 @@ public static class PasswordHasherFactory { public static IPasswordHasherBase Get(PasswordHasherType type) { - IPasswordHasherBase hasher = null; - switch (type) + return type switch { - case PasswordHasherType.Argon2: - hasher = new Argon2Wrapper(); - break; - case PasswordHasherType.BCrypt: - hasher = new BcryptWrapper(); - break; - case PasswordHasherType.SCrypt: - hasher = new SCryptWrapper(); - break; - } - return hasher; + PasswordHasherType.Argon2 => new Argon2Wrapper(), + PasswordHasherType.BCrypt => new BcryptWrapper(), + PasswordHasherType.SCrypt => new SCryptWrapper(), + _ => throw new ArgumentOutOfRangeException(nameof(type), type, "Unsupported password hasher type.") + }; } } } diff --git a/cas-dotnet-sdk/Signatures/ED25519Wrapper.cs b/cas-dotnet-sdk/Signatures/ED25519Wrapper.cs index d65c37f..dd7d652 100644 --- a/cas-dotnet-sdk/Signatures/ED25519Wrapper.cs +++ b/cas-dotnet-sdk/Signatures/ED25519Wrapper.cs @@ -61,15 +61,15 @@ public Ed25519ByteSignatureResult SignBytes(byte[] keyBytes, byte[] dataToSign) /// public bool VerifyBytes(byte[] keyPair, byte[] signature, byte[] dataToVerify) { - if (keyPair?.Length == 0) + if (keyPair == null || keyPair.Length == 0) { throw new Exception("You must provide allocated key pair data to Verify Bytes with ED25519-Dalek"); } - if (signature?.Length == 0) + if (signature == null || signature.Length == 0) { throw new Exception("You must provide allocated signature data to Verify Bytes with ED25519-Dalek"); } - if (dataToVerify?.Length == 0) + if (dataToVerify == null || dataToVerify.Length == 0) { throw new Exception("You must provide allocated data to Verify with ED25519-Dalek"); } @@ -89,15 +89,15 @@ public bool VerifyBytes(byte[] keyPair, byte[] signature, byte[] dataToVerify) /// public bool VerifyWithPublicKeyBytes(byte[] publicKey, byte[] signature, byte[] dataToVerify) { - if (publicKey?.Length == 0) + if (publicKey == null || publicKey.Length == 0) { throw new Exception("You must provide allocated data for the public key to verify with ED25519-Dalek"); } - if (signature?.Length == 0) + if (signature == null || signature.Length == 0) { throw new Exception("You must provide allocated data for the signature to verify with ED25519-Dalek"); } - if (dataToVerify?.Length == 0) + if (dataToVerify == null || dataToVerify.Length == 0) { throw new Exception("You must provide allocated data to verify for the signature to verify with ED25519-Dalek"); } diff --git a/cas-dotnet-sdk/Signatures/Types/Ed25519ByteSignatureResult.cs b/cas-dotnet-sdk/Signatures/Types/Ed25519ByteSignatureResult.cs index 09543c4..ba9c2a9 100644 --- a/cas-dotnet-sdk/Signatures/Types/Ed25519ByteSignatureResult.cs +++ b/cas-dotnet-sdk/Signatures/Types/Ed25519ByteSignatureResult.cs @@ -1,8 +1,10 @@ -namespace CasDotnetSdk.Signatures.Types +using System; + +namespace CasDotnetSdk.Signatures.Types { public class Ed25519ByteSignatureResult { - public byte[] Signature { get; set; } - public byte[] PublicKey { get; set; } + public byte[] Signature { get; set; } = Array.Empty(); + public byte[] PublicKey { get; set; } = Array.Empty(); } } diff --git a/cas-dotnet-sdk/Signatures/Types/Ed25519KeyPairResult.cs b/cas-dotnet-sdk/Signatures/Types/Ed25519KeyPairResult.cs index 4924f74..2d88478 100644 --- a/cas-dotnet-sdk/Signatures/Types/Ed25519KeyPairResult.cs +++ b/cas-dotnet-sdk/Signatures/Types/Ed25519KeyPairResult.cs @@ -1,8 +1,10 @@ -namespace CasDotnetSdk.Signatures.Types +using System; + +namespace CasDotnetSdk.Signatures.Types { public class Ed25519KeyPairResult { - public byte[] SigningKey { get; set; } - public byte[] VerifyingKey { get; set; } + public byte[] SigningKey { get; set; } = Array.Empty(); + public byte[] VerifyingKey { get; set; } = Array.Empty(); } } diff --git a/cas-dotnet-sdk/Signatures/Types/Ed25519SignatureResult.cs b/cas-dotnet-sdk/Signatures/Types/Ed25519SignatureResult.cs index 80b8e11..18e6377 100644 --- a/cas-dotnet-sdk/Signatures/Types/Ed25519SignatureResult.cs +++ b/cas-dotnet-sdk/Signatures/Types/Ed25519SignatureResult.cs @@ -2,7 +2,7 @@ { public class Ed25519SignatureResult { - public string Signature { get; set; } - public string PublicKey { get; set; } + public string Signature { get; set; } = string.Empty; + public string PublicKey { get; set; } = string.Empty; } } diff --git a/cas-dotnet-sdk/Sponges/AsconWrapper.cs b/cas-dotnet-sdk/Sponges/AsconWrapper.cs index f8a63e2..5eb900b 100644 --- a/cas-dotnet-sdk/Sponges/AsconWrapper.cs +++ b/cas-dotnet-sdk/Sponges/AsconWrapper.cs @@ -33,11 +33,11 @@ public byte[] Ascon128Nonce() /// public byte[] Ascon128Encrypt(byte[] nonce, byte[] key, byte[] toEncrypt) { - if (nonce?.Length == 0) + if (nonce == null || nonce.Length == 0) { throw new Exception("You must provide a nonce to encrypt with Ascon 128"); } - if (key?.Length == 0) + if (key == null || key.Length == 0) { throw new Exception("You must provide a key to encrypt with Ascon 128"); } @@ -61,11 +61,11 @@ public byte[] Ascon128Encrypt(byte[] nonce, byte[] key, byte[] toEncrypt) /// public byte[] Ascon128Decrypt(byte[] nonce, byte[] key, byte[] toDecrypt) { - if (nonce?.Length == 0) + if (nonce == null || nonce.Length == 0) { throw new Exception("You must provide a nonce to decrypt with Ascon 128"); } - if (key?.Length == 0) + if (key == null || key.Length == 0) { throw new Exception("You must provide a key to decrypt with Ascon 128"); } diff --git a/cas-dotnet-sdk/Symmetric/Types/AesEncryptResult.cs b/cas-dotnet-sdk/Symmetric/Types/AesEncryptResult.cs index f914fe8..fe0c57b 100644 --- a/cas-dotnet-sdk/Symmetric/Types/AesEncryptResult.cs +++ b/cas-dotnet-sdk/Symmetric/Types/AesEncryptResult.cs @@ -2,7 +2,7 @@ { public class AesEncryptResult { - public string Key { get; set; } - public string CipherText { get; set; } + public string Key { get; set; } = string.Empty; + public string CipherText { get; set; } = string.Empty; } } diff --git a/generated/NativeMethods.g.cs b/generated/NativeMethods.g.cs new file mode 100644 index 0000000..47bcd7d --- /dev/null +++ b/generated/NativeMethods.g.cs @@ -0,0 +1,423 @@ +// +// This code is generated by csbindgen. +// DON'T CHANGE THIS DIRECTLY. +// +#pragma warning disable CS8500 +#pragma warning disable CS8981 +using System; +using System.Runtime.InteropServices; + + +namespace CasCoreLib +{ + internal static unsafe partial class NativeMethods + { + const string __DllName = "cas_core_lib"; + + + + + + [DllImport(__DllName, EntryPoint = "aes_256_key_from_x25519_diffie_hellman_shared_secret", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern AesNonceAndKeyFromX25519DiffieHellman aes_256_key_from_x25519_diffie_hellman_shared_secret(byte* shared_secret, nuint shared_secret_length); + + [DllImport(__DllName, EntryPoint = "aes_128_key_from_x25519_diffie_hellman_shared_secret", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern AesNonceAndKeyFromX25519DiffieHellman aes_128_key_from_x25519_diffie_hellman_shared_secret(byte* shared_secret, nuint shared_secret_length); + + [DllImport(__DllName, EntryPoint = "aes_nonce", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern AesNonce aes_nonce(); + + [DllImport(__DllName, EntryPoint = "aes_256_key", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern AesKeyResult aes_256_key(); + + [DllImport(__DllName, EntryPoint = "aes_128_key", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern AesKeyResult aes_128_key(); + + [DllImport(__DllName, EntryPoint = "aes_128_encrypt_bytes_with_key", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern AesBytesEncrypt aes_128_encrypt_bytes_with_key(byte* nonce_key, nuint nonce_key_length, byte* key, nuint key_length, byte* to_encrypt, nuint to_encrypt_length); + + [DllImport(__DllName, EntryPoint = "aes_256_encrypt_bytes_with_key", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern AesBytesEncrypt aes_256_encrypt_bytes_with_key(byte* nonce_key, nuint nonce_key_length, byte* key, nuint key_length, byte* to_encrypt, nuint to_encrypt_length); + + [DllImport(__DllName, EntryPoint = "aes_128_decrypt_bytes_with_key", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern AesBytesDecrypt aes_128_decrypt_bytes_with_key(byte* nonce_key, nuint nonce_key_length, byte* key, nuint key_length, byte* to_decrypt, nuint to_decrypt_length); + + [DllImport(__DllName, EntryPoint = "aes_256_decrypt_bytes_with_key", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern AesBytesDecrypt aes_256_decrypt_bytes_with_key(byte* nonce_key, nuint nonce_key_length, byte* key, nuint key_length, byte* to_decrypt, nuint to_decrypt_length); + + [DllImport(__DllName, EntryPoint = "ascon_128_key", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern Ascon128Key ascon_128_key(); + + [DllImport(__DllName, EntryPoint = "ascon_128_nonce", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern Ascon128Nonce ascon_128_nonce(); + + [DllImport(__DllName, EntryPoint = "ascon_128_encrypt", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern Ascon128EncryptResult ascon_128_encrypt(byte* nonce_key, nuint nonce_key_length, byte* key, nuint key_length, byte* to_encrypt, nuint to_encrypt_length); + + [DllImport(__DllName, EntryPoint = "ascon_128_decrypt", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern Ascon128DecryptResult ascon_128_decrypt(byte* nonce_key, nuint nonce_key_length, byte* key, nuint key_length, byte* to_decrypt, nuint to_decrypt_length); + + [DllImport(__DllName, EntryPoint = "blake2_512_bytes", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern Blake2HashByteResult blake2_512_bytes(byte* data, nuint data_length); + + [DllImport(__DllName, EntryPoint = "blake2_512_bytes_verify", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + [return: MarshalAs(UnmanagedType.U1)] + internal static extern bool blake2_512_bytes_verify(byte* hashed_data, nuint hashed_data_length, byte* to_compare, nuint to_compare_length); + + [DllImport(__DllName, EntryPoint = "blake2_256_bytes", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern Blake2HashByteResult blake2_256_bytes(byte* data_to_hash, nuint data_to_hash_length); + + [DllImport(__DllName, EntryPoint = "blake2_256_bytes_verify", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + [return: MarshalAs(UnmanagedType.U1)] + internal static extern bool blake2_256_bytes_verify(byte* hashed_data, nuint hashed_data_length, byte* to_compare, nuint to_compare_length); + + [DllImport(__DllName, EntryPoint = "get_ed25519_key_pair_bytes", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern Ed25519KeyPairBytesResult get_ed25519_key_pair_bytes(); + + [DllImport(__DllName, EntryPoint = "sign_with_key_pair_bytes", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern Ed25519ByteSignatureResult sign_with_key_pair_bytes(byte* key_pair, nuint key_pair_length, byte* message_to_sign, nuint message_to_sign_length); + + [DllImport(__DllName, EntryPoint = "verify_with_key_pair_bytes", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern CasVerifyResult verify_with_key_pair_bytes(byte* key_pair, nuint key_pair_length, byte* signature, nuint signature_length, byte* message, nuint message_length); + + [DllImport(__DllName, EntryPoint = "verify_with_public_key_bytes", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern CasVerifyResult verify_with_public_key_bytes(byte* public_key, nuint public_key_length, byte* signature, nuint signature_length, byte* message, nuint message_length); + + [DllImport(__DllName, EntryPoint = "free_cstring", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern void free_cstring(byte* s); + + [DllImport(__DllName, EntryPoint = "free_bytes", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern void free_bytes(byte* ptr); + + [DllImport(__DllName, EntryPoint = "hmac_sign_bytes", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern HmacSignByteResult hmac_sign_bytes(byte* key, nuint key_length, byte* message, nuint message_length); + + [DllImport(__DllName, EntryPoint = "hmac_verify_bytes", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern CasVerifyResult hmac_verify_bytes(byte* key, nuint key_length, byte* message, nuint message_length, byte* signature, nuint signature_length); + + [DllImport(__DllName, EntryPoint = "hpke_generate_keypair", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern HpkeKeyPair hpke_generate_keypair(); + + [DllImport(__DllName, EntryPoint = "hpke_encrypt", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern HpkeEncrypt hpke_encrypt(byte* plaintext, nuint plaintext_length, byte* public_key, nuint public_keylength, byte* info_str, nuint info_str_length); + + [DllImport(__DllName, EntryPoint = "hpke_decrypt", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern HpkeDecrypt hpke_decrypt(byte* ciphertext, nuint ciphertext_length, byte* private_key, nuint private_keylength, byte* encapped_key, nuint encapped_key_length, byte* tag, nuint tag_length, byte* info_str, nuint info_str_length); + + [DllImport(__DllName, EntryPoint = "argon2_hash_password_parameters", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern CasStringResult argon2_hash_password_parameters(uint memory_cost, uint iterations, uint parallelism, byte* password_to_hash); + + [DllImport(__DllName, EntryPoint = "argon2_derive_aes_128_key", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern Argon2KDFAes128 argon2_derive_aes_128_key(byte* hashed_password); + + [DllImport(__DllName, EntryPoint = "argon2_derive_aes_256_key", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern Argon2KDFAes128 argon2_derive_aes_256_key(byte* hashed_password); + + [DllImport(__DllName, EntryPoint = "argon2_verify", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern CasVerifyResult argon2_verify(byte* hashed_pass, byte* password); + + [DllImport(__DllName, EntryPoint = "argon2_hash", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern CasStringResult argon2_hash(byte* pass_to_hash); + + [DllImport(__DllName, EntryPoint = "bcrypt_hash_with_parameters", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern CasStringResult bcrypt_hash_with_parameters(byte* pass_to_hash, uint cost); + + [DllImport(__DllName, EntryPoint = "bcrypt_hash", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern CasStringResult bcrypt_hash(byte* pass_to_hash); + + [DllImport(__DllName, EntryPoint = "bcrypt_verify", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern CasVerifyResult bcrypt_verify(byte* pass, byte* hash); + + [DllImport(__DllName, EntryPoint = "scrypt_hash_with_parameters", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern CasStringResult scrypt_hash_with_parameters(byte* pass_to_hash, byte cpu_memory_cost, uint block_size, uint parallelism); + + [DllImport(__DllName, EntryPoint = "scrypt_hash", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern CasStringResult scrypt_hash(byte* pass_to_hash); + + [DllImport(__DllName, EntryPoint = "scrypt_verify", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern CasVerifyResult scrypt_verify(byte* hash_to_check, byte* pass_to_check); + + [DllImport(__DllName, EntryPoint = "slh_dsa_generate_signing_and_verification_key", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern SlhDsaKeyPairResult slh_dsa_generate_signing_and_verification_key(); + + [DllImport(__DllName, EntryPoint = "slh_dsa_sign_message", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern SlhDsaSignature slh_dsa_sign_message(byte* signing_key, nuint signing_key_length, byte* message, nuint message_length); + + [DllImport(__DllName, EntryPoint = "slh_dsa_verify_signature", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern CasVerifyResult slh_dsa_verify_signature(byte* verification_key, nuint verification_key_length, byte* signature, nuint signature_length, byte* message, nuint message_length); + + [DllImport(__DllName, EntryPoint = "get_key_pair", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern RsaKeyPair get_key_pair(nuint key_size); + + [DllImport(__DllName, EntryPoint = "rsa_sign_with_key_bytes", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern RsaSignBytesResults rsa_sign_with_key_bytes(byte* private_key, byte* data_to_sign, nuint data_to_sign_length); + + [DllImport(__DllName, EntryPoint = "rsa_verify_bytes", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern CasVerifyResult rsa_verify_bytes(byte* public_key, byte* data_to_verify, nuint data_to_verify_length, byte* signature, nuint signature_length); + + [DllImport(__DllName, EntryPoint = "sha512_bytes", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern SHAHashByteResult sha512_bytes(byte* data_to_hash, nuint data_len); + + [DllImport(__DllName, EntryPoint = "sha512_bytes_verify", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + [return: MarshalAs(UnmanagedType.U1)] + internal static extern bool sha512_bytes_verify(byte* data_to_hash, nuint data_len, byte* data_to_verify, nuint data_to_verify_len); + + [DllImport(__DllName, EntryPoint = "sha256_bytes", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern SHAHashByteResult sha256_bytes(byte* data_to_hash, nuint data_len); + + [DllImport(__DllName, EntryPoint = "sha256_bytes_verify", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + [return: MarshalAs(UnmanagedType.U1)] + internal static extern bool sha256_bytes_verify(byte* data_to_hash, nuint data_len, byte* data_to_verify, nuint data_to_verify_len); + + [DllImport(__DllName, EntryPoint = "generate_secret_and_public_key", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern x25519SecretPublicKeyResult generate_secret_and_public_key(); + + [DllImport(__DllName, EntryPoint = "diffie_hellman", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern x25519SharedSecretResult diffie_hellman(byte* secret_key, nuint secret_key_length, byte* other_user_public_key, nuint other_user_public_key_length); + + [DllImport(__DllName, EntryPoint = "decompress", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern ZstdCompressResult decompress(byte* data_to_decompress, nuint data_to_decompress_length); + + [DllImport(__DllName, EntryPoint = "compress", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern ZstdCompressResult compress(byte* data_to_compress, nuint data_to_compress_length, nuint level); + + + } + + [StructLayout(LayoutKind.Sequential)] + internal unsafe partial struct AesNonce + { + public byte* nonce; + public nuint length; + } + + [StructLayout(LayoutKind.Sequential)] + internal unsafe partial struct AesKeyResult + { + public byte* key; + public nuint length; + } + + [StructLayout(LayoutKind.Sequential)] + internal unsafe partial struct AesBytesEncrypt + { + public byte* ciphertext; + public nuint length; + public int error_code; + } + + [StructLayout(LayoutKind.Sequential)] + internal unsafe partial struct AesBytesDecrypt + { + public byte* plaintext; + public nuint length; + public int error_code; + } + + [StructLayout(LayoutKind.Sequential)] + internal unsafe partial struct AesNonceAndKeyFromX25519DiffieHellman + { + public byte* aes_key_ptr; + public nuint aes_key_ptr_length; + public int error_code; + } + + [StructLayout(LayoutKind.Sequential)] + internal unsafe partial struct Ascon128EncryptResult + { + public byte* ciphertext; + public nuint length; + public int error_code; + } + + [StructLayout(LayoutKind.Sequential)] + internal unsafe partial struct Ascon128DecryptResult + { + public byte* plaintext; + public nuint length; + public int error_code; + } + + [StructLayout(LayoutKind.Sequential)] + internal unsafe partial struct Ascon128Key + { + public byte* key; + public nuint length; + } + + [StructLayout(LayoutKind.Sequential)] + internal unsafe partial struct Ascon128Nonce + { + public byte* nonce; + public nuint length; + } + + [StructLayout(LayoutKind.Sequential)] + internal unsafe partial struct Blake2HashByteResult + { + public byte* result_bytes_ptr; + public nuint length; + } + + [StructLayout(LayoutKind.Sequential)] + internal unsafe partial struct Ed25519KeyPairBytesResult + { + public byte* signing_key; + public nuint signing_key_length; + public byte* verifying_key; + public nuint verifying_key_length; + } + + [StructLayout(LayoutKind.Sequential)] + internal unsafe partial struct Ed25519ByteSignatureResult + { + public byte* signature_byte_ptr; + public nuint signature_length; + public byte* public_key; + public nuint public_key_length; + public int error_code; + } + + /// + /// Result of a verification (`verify`-style) FFI call. + /// + /// cas-lib's verify operations now return `CasResult<bool>`, so a plain `bool` + /// can no longer distinguish "signature did not match" (`is_valid == false`, + /// `error_code == 0`) from "the inputs were malformed" (`is_valid == false`, + /// `error_code != 0`). This struct carries both across the boundary. + /// + [StructLayout(LayoutKind.Sequential)] + internal unsafe partial struct CasVerifyResult + { + [MarshalAs(UnmanagedType.U1)] public bool is_valid; + public int error_code; + } + + /// + /// Result of an FFI call that hands back a C string (e.g. a password hash). + /// + /// `value` is null when `error_code` is non-zero. The caller still frees a + /// non-null `value` with [`free_cstring`]. + /// + [StructLayout(LayoutKind.Sequential)] + internal unsafe partial struct CasStringResult + { + public byte* value; + public int error_code; + } + + [StructLayout(LayoutKind.Sequential)] + internal unsafe partial struct HmacSignByteResult + { + public byte* result_bytes_ptr; + public nuint length; + public int error_code; + } + + [StructLayout(LayoutKind.Sequential)] + internal unsafe partial struct HpkeKeyPair + { + public byte* private_key_ptr; + public nuint private_key_ptr_length; + public byte* public_key_ptr; + public nuint public_key_ptr_length; + public byte* info_str_ptr; + public nuint info_str_ptr_length; + } + + [StructLayout(LayoutKind.Sequential)] + internal unsafe partial struct HpkeEncrypt + { + public byte* encapped_key_ptr; + public nuint encapped_key_ptr_length; + public byte* ciphertext_ptr; + public nuint ciphertext_ptr_length; + public byte* tag_ptr; + public nuint tag_ptr_length; + public int error_code; + } + + [StructLayout(LayoutKind.Sequential)] + internal unsafe partial struct HpkeDecrypt + { + public byte* plaintext_ptr; + public nuint plaintext_ptr_length; + public int error_code; + } + + [StructLayout(LayoutKind.Sequential)] + internal unsafe partial struct Argon2KDFAes128 + { + public byte* key; + public nuint length; + public int error_code; + } + + [StructLayout(LayoutKind.Sequential)] + internal unsafe partial struct SlhDsaKeyPairResult + { + public byte* signing_key_ptr; + public nuint signing_key_length; + public byte* verification_key_ptr; + public nuint verification_key_length; + } + + [StructLayout(LayoutKind.Sequential)] + internal unsafe partial struct SlhDsaSignature + { + public byte* signature_ptr; + public nuint signature_length; + public int error_code; + } + + [StructLayout(LayoutKind.Sequential)] + internal unsafe partial struct RsaKeyPair + { + public byte* pub_key; + public byte* priv_key; + public int error_code; + } + + [StructLayout(LayoutKind.Sequential)] + internal unsafe partial struct RsaSignBytesResults + { + public byte* signature_raw_ptr; + public nuint length; + public int error_code; + } + + [StructLayout(LayoutKind.Sequential)] + internal unsafe partial struct SHAHashByteResult + { + public byte* result_bytes_ptr; + public nuint length; + } + + [StructLayout(LayoutKind.Sequential)] + internal unsafe partial struct x25519SecretPublicKeyResult + { + public byte* secret_key; + public nuint secret_key_length; + public byte* public_key; + public nuint public_key_length; + } + + [StructLayout(LayoutKind.Sequential)] + internal unsafe partial struct x25519SharedSecretResult + { + public byte* shared_secret; + public nuint shared_secret_length; + public int error_code; + } + + [StructLayout(LayoutKind.Sequential)] + internal unsafe partial struct ZstdCompressResult + { + public byte* data; + public nuint length; + public int error_code; + } + + + +} From bd9bf955939ff8fb6ab9f94b573c838f1bf601d0 Mon Sep 17 00:00:00 2001 From: Mike Mulchrone Date: Sat, 20 Jun 2026 11:39:44 -0400 Subject: [PATCH 2/2] version bump --- cas-dotnet-sdk/cas-dotnet-sdk.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cas-dotnet-sdk/cas-dotnet-sdk.csproj b/cas-dotnet-sdk/cas-dotnet-sdk.csproj index 7b5628c..8ba1983 100644 --- a/cas-dotnet-sdk/cas-dotnet-sdk.csproj +++ b/cas-dotnet-sdk/cas-dotnet-sdk.csproj @@ -9,7 +9,7 @@ true cas-dotnet-sdk icon.jpeg - 1.9.76 + 1.9.77 Mike Mulchrone A Nuget package that provides a implementation of the RustCrypto suite of cryptographic algorithms. https://github.com/Cryptographic-API-Services/cas-dotnet-sdk