Post
Topic
Board Development & Technical Discussion
Re: Source code for ECDSA operations (key generation, signing, verifying, etc)
by
schalk
on 11/04/2014, 20:13:46 UTC
I have been in the process of implementing ECDSA using Secp256k1 in C# the last few days. I haven't done much testing yet (still need to write some automated tests!), nor have I had the code reviewed by anyone, so I would strongly advice against using this in production code.

Once I have refactored and tidied up a lot of my code, I plan on creating a github repository for it. I would also still like to make this code more separated with different layers of abstraction to allow for better code testability.

Performance
I haven't done much testing in the way of performance, but I have measured it to be about twice the speed of BouncyCastle.NET on a single thread for EC Multiplication and ECDSA Signing/Verifing. When using multithreading it was an even more significant performance increase in comparison to BouncyCastle.NET (I haven't the figures on me sorry).

A lot of the performance is based on how fast the BigInteger class is. I have been using System.Numerics.BigInteger which is a lot slower than the likes of gmp. One thing to also keep in mind is that unlike BouncyCastle.NET's BigInteger, System.Numerics.BigInteger is Little Endian.

Includes
ECdsaSigner (signing/verification/recovery)
ECELGamal (public/private key encryption - well key generation)
ECEncryption (this is my non standard implementation of encryption with a public key, decryption with a private key. Using AES as the asymmetric cipher and ElGamal as the key generation)
ECPoint (does all your ECPoint math)

Download
https://mega.co.nz/#!Ao1H1IYJ!JgCnLuWhMy0MYrldjV5A4H7pg9seICnJZYIj30Y-eXM

I have also implemented BIP32 (Hierarchical Deterministic Wallets) in a separate project (this uses BouncyCastle), so let me know if you are also in need of that.

If you're feeling a bit generous:
15Xi4QCp9wwbXhCniDB2DkgzLjSw49g619