planetarium / libplanet

Blockchain in C#/.NET for on-chain, decentralized gaming
https://docs.libplanet.io/
GNU Lesser General Public License v2.1
506 stars 142 forks source link

Replace BouncyCastle with System.Cryptography #66

Closed longfin closed 3 years ago

longfin commented 5 years ago

Currently, we use BouncyCastle as cryptographic backend. when we introduced it for the first time, we considered the .NET Framework 3.5 as the lowest version, so it was an inevitable.

However, as the project's target moves to .NET standard 2.0, we need to review it again. since .NET Standard 1.6 seems to have support for elliptic curves, we might be able to use it instead of BouncyCastle. This has the following benefits:

Using BouncyCastle directly is the Libplanet.Crypto namespace, and I don't think it would be a big problem if unit tests for these namespaces pass.

earlbread commented 5 years ago

I tried to generate keys with .NET ECDsa on mac but it seems that it does not support "secp256k1". Following code throws an exception:

var curve = ECCurve.CreateFromValue("1.3.132.0.10"); // "secP256k1"
var ecdsa = ECDsa.Create(curve);
Unhandled Exception: System.PlatformNotSupportedException: The specified curve '1.3.132.0.10' or its parameters are not valid for this platform.
   at System.Security.Cryptography.EccSecurityTransforms.GenerateKey(ECCurve curve)
   at System.Security.Cryptography.ECDsa.ECDsaImplementation.ECDsaSecurityTransforms.GenerateKey(ECCurve curve)
   at System.Security.Cryptography.ECDsa.Create(ECCurve curve)
   at console_test.Program.Main(String[] args) in /Users/earl/test/console-test/Program.cs:line 13

The exception point is below: https://github.com/dotnet/corefx/blob/master/src/Common/src/System/Security/Cryptography/EccSecurityTransforms.cs#L35

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. Thank you for your contributions.