diff options
author | vnugent <public@vaughnnugent.com> | 2023-11-23 12:44:53 -0500 |
---|---|---|
committer | vnugent <public@vaughnnugent.com> | 2023-11-23 12:44:53 -0500 |
commit | 8434d8b8ecf54c6038a7e9ad7d57084a0865500c (patch) | |
tree | 719f5ee3beb9ea99c8d9e3d8e6279092f98e11ac /back-end/libs/NVault.Crypto.Secp256k1 | |
parent | e272adcc3f32e31fe7668551453b8e34bc823c3e (diff) |
fixed signing and working note encryption!
Diffstat (limited to 'back-end/libs/NVault.Crypto.Secp256k1')
-rw-r--r-- | back-end/libs/NVault.Crypto.Secp256k1/src/ContextExtensions.cs | 23 | ||||
-rw-r--r-- | back-end/libs/NVault.Crypto.Secp256k1/src/LibSecp256k1.cs | 5 |
2 files changed, 22 insertions, 6 deletions
diff --git a/back-end/libs/NVault.Crypto.Secp256k1/src/ContextExtensions.cs b/back-end/libs/NVault.Crypto.Secp256k1/src/ContextExtensions.cs index f5327df..9931698 100644 --- a/back-end/libs/NVault.Crypto.Secp256k1/src/ContextExtensions.cs +++ b/back-end/libs/NVault.Crypto.Secp256k1/src/ContextExtensions.cs @@ -254,7 +254,7 @@ namespace NVault.Crypto.Secp256k1 { if (secretKey.Length != SecretKeySize) { - throw new ArgumentException($"Your public key buffer must be exactly {SecretKeySize} bytes long"); + throw new ArgumentException($"Your secret key buffer must be exactly {SecretKeySize} bytes long"); } //Init callback state struct @@ -265,17 +265,28 @@ namespace NVault.Crypto.Secp256k1 OutLen = data.Length }; + context.Lib.SafeLibHandle.ThrowIfClosed(); + //Stack allocated keypair and x-only public key - Secp256k1PublicKey pubKeyStruct = new(); - //Recover the x-only public key structure - MemoryUtil.CopyStruct(xOnlyPubKey, &pubKeyStruct); + Secp256k1PublicKey peerPubKey = new(); - context.Lib.SafeLibHandle.ThrowIfClosed(); + //Parse the public key from the buffer + fixed (byte* pubkeyPtr = &MemoryMarshal.GetReference(xOnlyPubKey)) + { + context.Lib._xOnlyPubkeyParse(context.Context, &peerPubKey, pubkeyPtr); + } fixed (byte* dataPtr = &MemoryMarshal.GetReference(data), secKeyPtr = &MemoryMarshal.GetReference(secretKey)) { - return context.Lib._ecdh.Invoke(context.Context, dataPtr, &pubKeyStruct, secKeyPtr, UmanagedEcdhHashFuncCallback, &state) == 1; + return context.Lib._ecdh.Invoke( + context.Context, + dataPtr, + &peerPubKey, + secKeyPtr, + UmanagedEcdhHashFuncCallback, + &state + ) == 1; } /* diff --git a/back-end/libs/NVault.Crypto.Secp256k1/src/LibSecp256k1.cs b/back-end/libs/NVault.Crypto.Secp256k1/src/LibSecp256k1.cs index 5aeed00..f3afc33 100644 --- a/back-end/libs/NVault.Crypto.Secp256k1/src/LibSecp256k1.cs +++ b/back-end/libs/NVault.Crypto.Secp256k1/src/LibSecp256k1.cs @@ -82,6 +82,9 @@ namespace NVault.Crypto.Secp256k1 [SafeMethodName("secp256k1_ec_pubkey_serialize")] internal delegate int PubKeySerialize(IntPtr ctx, byte* outPubKey, ulong* outLen, Secp256k1PublicKey* pubKey, uint flags); + [SafeMethodName("secp256k1_xonly_pubkey_parse")] + internal delegate int XOnlyPubkeyParse(IntPtr ctx, Secp256k1PublicKey* pubkey, byte* input32); + [SafeMethodName("secp256k1_ecdh")] internal delegate int Ecdh( IntPtr ctx, @@ -143,6 +146,7 @@ namespace NVault.Crypto.Secp256k1 internal readonly SecKeyVerify _secKeyVerify; internal readonly PubKeySerialize _pubKeySerialize; internal readonly Ecdh _ecdh; + internal readonly XOnlyPubkeyParse _xOnlyPubkeyParse; private readonly IRandomSource _randomSource; /// <summary> @@ -171,6 +175,7 @@ namespace NVault.Crypto.Secp256k1 _secKeyVerify = handle.DangerousGetMethod<SecKeyVerify>(); _pubKeySerialize = handle.DangerousGetMethod<PubKeySerialize>(); _ecdh = handle.DangerousGetMethod<Ecdh>(); + _xOnlyPubkeyParse = handle.DangerousGetMethod<XOnlyPubkeyParse>(); //Store random source _randomSource = randomSource; |