Closed kevaundray closed 6 years ago
I really liked this library as well. 30 seconds seems like something is leaking memory or not optimised. iOS has secure enclave which uses secp256r1, so it could be the implementation?
Yea, this library is not optimized at all. It's not using iOS native secp256r1 implementation. I wrote everything in Swift.
You can check hyu2018/UInt256 for my implementation of big number multiplication algo. UInt256's performance tests take a long time to run, especially the division algo -- because everything is written in Swift, even though I've already implemented fast multiplication/division algos. If I rewrite it in C, then it could be usable.
I would have no idea where to start haha. I am still impressed that you managed to code the whole thing.
Good luck in your endeavours!
May I ask where you got the knowledge to create this library? Is there some sort of guide online?
I highly recommend Jimmy Song's Programming Blockchain course. Andreas Antonopoulos's book is a must for sure.
I also think this library is a good starting point. 😁 I tried to structure everything properly. Reading through the code can give you a basic idea of how elliptic curve cryptography works.
haha I meant the Uint256 library. You believe that this is the problem with the library right?
oh yes. I believe the fast algos in that library can be found in major computer arithmetic textbooks. I only wrote basic ones, maybe there are better ones that I'm not aware of... but I believe the major improvement will be in rewriting them in C. (which is counter-productive, since we already have libsecp256k1)
here is a reference book: https://members.loria.fr/PZimmermann/mca/mca-cup-0.5.9.pdf
Thanks for the link, have you done any tests using apple's instruments as to what is wrong with the code?
from preliminary results, I think it's just that the 256bit multiplications in Swift are slow, because everything else is based on it. You can dive in to the stack and see for the details. If there is actually something wrong with my implementation, I'm happy to see pull requests that'll address it and solve the usability issue.
I would need to read up on quite a few of these topics. I will see what I can do, thanks for the links and information.
hi there,
thanks for your interest. this library is very slow, because everything is written in Swift. even generating a public key takes about 30 seconds. :/