diff --git a/NBitcoin.Tests/Secp256k1Tests.cs b/NBitcoin.Tests/Secp256k1Tests.cs index 533be646d..6b2aa78c0 100644 --- a/NBitcoin.Tests/Secp256k1Tests.cs +++ b/NBitcoin.Tests/Secp256k1Tests.cs @@ -2911,65 +2911,6 @@ public void test_ecdsa_recovery_end_to_end() pubkey != recpubkey); } - [Fact] - [Trait("UnitTest", "UnitTest")] - public void test_schnorrsig_bip_vectors() - { - { - /* Test vector 1 */ - byte[] sk1 = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 - }; - byte[] pk1 = { - 0x02, 0x79, 0xBE, 0x66, 0x7E, 0xF9, 0xDC, 0xBB, - 0xAC, 0x55, 0xA0, 0x62, 0x95, 0xCE, 0x87, 0x0B, - 0x07, 0x02, 0x9B, 0xFC, 0xDB, 0x2D, 0xCE, 0x28, - 0xD9, 0x59, 0xF2, 0x81, 0x5B, 0x16, 0xF8, 0x17, - 0x98 - }; - byte[] msg1 = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - }; - byte[] sig1 = { - 0x78, 0x7A, 0x84, 0x8E, 0x71, 0x04, 0x3D, 0x28, - 0x0C, 0x50, 0x47, 0x0E, 0x8E, 0x15, 0x32, 0xB2, - 0xDD, 0x5D, 0x20, 0xEE, 0x91, 0x2A, 0x45, 0xDB, - 0xDD, 0x2B, 0xD1, 0xDF, 0xBF, 0x18, 0x7E, 0xF6, - 0x70, 0x31, 0xA9, 0x88, 0x31, 0x85, 0x9D, 0xC3, - 0x4D, 0xFF, 0xEE, 0xDD, 0xA8, 0x68, 0x31, 0x84, - 0x2C, 0xCD, 0x00, 0x79, 0xE1, 0xF9, 0x2A, 0xF1, - 0x77, 0xF7, 0xF2, 0x2C, 0xC1, 0xDC, 0xED, 0x05 - }; - test_schnorrsig_bip_vectors_check_verify(pk1, msg1, sig1, true); - } - } - - void test_schnorrsig_bip_vectors_check_verify(byte[] pk_serialized, byte[] msg32, byte[] sig_serialized, bool expected) - { - var ctx = Context.Instance; - //const unsigned char* msg_arr[1]; - //const secp256k1_schnorrsig* sig_arr[1]; - //const secp256k1_pubkey* pk_arr[1]; - ECPubKey pk; - SecpSchnorrSignature sig; - - Assert.True(ctx.TryCreatePubKey(pk_serialized, out pk)); - Assert.True(SecpSchnorrSignature.TryCreate(sig_serialized, out sig)); - - //sig_arr[0] = &sig; - //msg_arr[0] = msg32; - //pk_arr[0] = &pk; - - Assert.Equal(expected, pk.SigVerifySchnorr(sig, msg32)); - //CHECK(expected == secp256k1_schnorrsig_verify_batch(ctx, scratch, sig_arr, msg_arr, pk_arr, 1)); - } - /* Tests several edge cases. */ [Fact] [Trait("UnitTest", "UnitTest")] diff --git a/NBitcoin/Secp256k1/Schnorr/ECPubKey.cs b/NBitcoin/Secp256k1/Schnorr/ECPubKey.cs deleted file mode 100644 index 72a23f7b2..000000000 --- a/NBitcoin/Secp256k1/Schnorr/ECPubKey.cs +++ /dev/null @@ -1,75 +0,0 @@ -#if HAS_SPAN -#nullable enable -using System; -using System.Collections.Generic; -using System.Security.Cryptography; -using System.Text; - -namespace NBitcoin.Secp256k1 -{ -#if SECP256K1_LIB - public -#else - internal -#endif - partial class ECPubKey - { - [Obsolete("Use SigVerifySchnorr instead")] - public bool SigVerify(SecpSchnorrSignature signature, ReadOnlySpan msg32) - { - return SigVerifySchnorr(signature, msg32); - } - - public bool SigVerifySchnorr(SecpSchnorrSignature signature, ReadOnlySpan msg32) - { - if (msg32.Length != 32) - return false; - if (signature is null) - return false; - ref readonly Scalar s = ref signature.s; - Scalar e; - GEJ rj; - ref readonly FE rx = ref signature.rx; - - using var sha = new Secp256k1.SHA256(); - Span buf = stackalloc byte[33]; - signature.rx.WriteToSpan(buf); - sha.Write(buf.Slice(0, 32)); - this.WriteToSpan(true, buf, out _); - sha.Write(buf); - msg32.CopyTo(buf); - sha.Write(buf.Slice(0, 32)); - sha.GetHash(buf); - e = new Scalar(buf, out _); - - if (!secp256k1_schnorrsig_real_verify(ctx, s, e, this.Q, out rj) - || !rj.HasQuadYVariable /* fails if rj is infinity */ - || !rx.EqualsXVariable(rj)) - { - return false; - } - - return true; - } - - private bool secp256k1_schnorrsig_real_verify(Context ctx, Scalar s, Scalar e, GE pkp, out GEJ rj) - { - Scalar nege; - //GroupElement pkp; - GEJ pkj; - - nege = e.Negate(); - - //if (!secp256k1_pubkey_load(ctx, &pkp, pk)) - //{ - // return false; - //} - pkj = pkp.ToGroupElementJacobian(); - - /* rj = s*G + (-e)*pkj */ - rj = ctx.EcMultContext.Mult(pkj, nege, s); - return true; - } - } -} -#endif