Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ECDsa.VerifyData Performance Slow on Mac #36107

Closed
@Ashuaidehao

Description

@Ashuaidehao

Hi, I have got performance issue when use ECDsa.VerifyData() onMac, it's almost 10 times slower than on windows, which cause my app running very slow on Mac.
The runtime isdotnet core 3.1.
Here mytest code:

privatestaticX9ECParameters_ecParams=NistNamedCurves.GetByName("P-256");privatestaticECDomainParameters_domainParameters=newECDomainParameters(_ecParams.Curve,_ecParams.G,_ecParams.N,_ecParams.H,_ecParams.GetSeed());privatestaticOrg.BouncyCastle.Math.EC.ECCurve_curve=_ecParams.Curve;staticvoidMain(string[]args){varpublicKey="77d28f103c37eb03d62decd4fdbda01dd69fea878325bc1bebc5074a876455eb9d2f4e719ba0a0838df3b07479ed2179358f711fe9d004b693c62922e95772d0".HexToBytes();varsignature="61516a23f99962b4417c87d26592b52060b19c5b7481a2318c665af540ae721c69611c073c6e34a358343e9ad43b4966ce0f9a8914c5e77f2cb3fe28ae2bf4d0".HexToBytes();varmessage="38900d0000000000bd3bde894f6ddb7e5ae89e7d7c1eef5c271875c5a2bd6b75faba07c8c8423902e8c4d7a4ebf3542d7d8eee65a996bb45211e546bd995ae5b1d099a90464886981b9e479971010000214e0000bf1740f6c1e1f913d2f307b29b8082551ba9a5c5".HexToBytes();varv=VerifyData(message,signature,publicKey);varv2=VerifyDataBouncy(message,signature,publicKey);Console.WriteLine($"{v},{v2}");intcount=1000;varsw=newStopwatch();sw.Start();for(inti=0;i<count;i++){VerifyData(message,signature,publicKey);}sw.Stop();Console.WriteLine($"VerifyData :{sw.Elapsed.TotalSeconds} s");sw.Restart();for(inti=0;i<count;i++){VerifyDataBouncy(message,signature,publicKey);}sw.Stop();Console.WriteLine($"VerifyDataBouncy :{sw.Elapsed.TotalSeconds} s");Console.ReadLine();}staticboolVerifyData(ReadOnlySpan<byte>message,ReadOnlySpan<byte>signature,ReadOnlySpan<byte>pubkey){usingvarecdsa=ECDsa.Create(newECParameters{Curve=ECCurve.NamedCurves.nistP256,Q=newECPoint{X=pubkey[..32].ToArray(),Y=pubkey[32..].ToArray()}});returnecdsa.VerifyData(message,signature,HashAlgorithmName.SHA256);}staticboolVerifyDataBouncy(byte[]message,byte[]signature,byte[]pubkey){BigIntegerx=newBigInteger(1,pubkey.Take(32).ToArray());BigIntegery=newBigInteger(1,pubkey.Skip(32).ToArray());varderSignature=newDerSequence(// first 32 bytes is "r" numbernewDerInteger(newBigInteger(1,signature.Take(32).ToArray())),// last 32 bytes is "s" numbernewDerInteger(newBigInteger(1,signature.Skip(32).ToArray()))).GetDerEncoded();Org.BouncyCastle.Math.EC.ECPointq=_curve.CreatePoint(x,y);ECPublicKeyParameterspubkeyParam=newECPublicKeyParameters(q,_domainParameters);varverifier=SignerUtilities.GetSigner("SHA-256withECDSA");verifier.Init(false,pubkeyParam);verifier.BlockUpdate(message,0,message.Length);returnverifier.VerifySignature(derSignature);}

on Win10:
win10

on Mac:
Mac

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp