Skip to content

Commit

Permalink
Simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
shargon committed Jun 24, 2021
1 parent d04985a commit 3ca1f0a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/neo/Cryptography/Crypto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,14 @@ public static byte[] Sign(byte[] message, byte[] prikey, byte[] pubkey)
/// <returns><see langword="true"/> if the signature is valid; otherwise, <see langword="false"/>.</returns>
public static bool VerifySignature(ReadOnlySpan<byte> message, ReadOnlySpan<byte> signature, ECC.ECPoint pubkey)
{
byte[] buffer = pubkey.EncodePoint(false);
#if OSX

This comment has been minimized.

Copy link
@Jim8y

Jim8y Jun 30, 2021

Contributor

#if OSX
this precompile command does not work on my Macbook Pro 2019. This code works:
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)){} else {}

This comment has been minimized.

Copy link
@shargon

shargon Jun 30, 2021

Author Member

We should compile with the flag, but of course we can use a constant, but it doesn't work isn't it? I try to find the bouncy castle issue...

try
{
var curve = Org.BouncyCastle.Asn1.Sec.SecNamedCurves.GetByName(pubkey.Curve == ECC.ECCurve.Secp256r1 ? "secp256r1" : "secp256k1");
var domain = new Org.BouncyCastle.Crypto.Parameters.ECDomainParameters(curve.Curve, curve.G, curve.N, curve.H);
var point = curve.Curve.DecodePoint(buffer);
var point = curve.Curve.CreatePoint(
new Org.BouncyCastle.Math.BigInteger(pubkey.X.Value.ToString()),
new Org.BouncyCastle.Math.BigInteger(pubkey.Y.Value.ToString()));
var pubKey = new Org.BouncyCastle.Crypto.Parameters.ECPublicKeyParameters("ECDSA", point, domain);
var signer = Org.BouncyCastle.Security.SignerUtilities.GetSigner("SHA-256withECDSA");

Expand All @@ -75,6 +76,7 @@ public static bool VerifySignature(ReadOnlySpan<byte> message, ReadOnlySpan<byte
}
catch { return false; }
#else
byte[] buffer = pubkey.EncodePoint(false);
ECCurve curve =
pubkey.Curve == ECC.ECCurve.Secp256r1 ? ECCurve.NamedCurves.nistP256 :
pubkey.Curve == ECC.ECCurve.Secp256k1 ? ECCurve.CreateFromFriendlyName("secP256k1") :
Expand Down

0 comments on commit 3ca1f0a

Please sign in to comment.