Optimizing ECC Operations on secp256k1 in Rust

7 replies 38 views
Posts: 1 · Reputation: 14
#1Oct 11, 2019, 09:11 PM
Hey everyone, I’m kinda new to cryptography and have been tinkering with ECC. Managed to code BSGS and kangaroo algorithms in Rust, but using the k256 crate has been kinda slow in comparison to libraries like keyhunt and cyclone. From my testing, creating public keys takes way longer than doing sha256 or ripemd160. Looks like I need to get into optimizing the core ECC operations.
4 Reply Quote Share
falcon2019Full Member
Posts: 90 · Reputation: 425
#2Oct 13, 2019, 01:44 PM
Check out libsecp256k1, best bet for fast public key generation from private keys. Seriously, avoid deriving them from private keys directly. Precompute any public keys that are fixed, and do your calculations in affine coords. If you have a bunch of (pubA, pubB) pairs, do it all in one go with a shared field inverse.
6 Reply Quote Share
shrimpNewbie
Posts: 289 · Reputation: 20
#3Oct 15, 2019, 09:25 PM
Are you talking about this repo? https://github.com/bitcoin-core/secp256k1
2 Reply Quote Share
orbit21Member
Posts: 1 · Reputation: 242
#4Oct 15, 2019, 11:21 PM
These Rust bindings for libsecp256k1 might be worth checking out. They've got potential. https://crates.io/crates/secp256k1
4 Reply Quote Share
falcon2019Full Member
Posts: 90 · Reputation: 425
#5Oct 16, 2019, 12:48 AM
The secp256k1 API isn't really low-level, those wrappers are probably not gonna cut it for raw performance. You need to expose certain functions to avoid unnecessary internal conversions, like the one from 64 bytes pubKey to a 5x52 representation. Best to write those low-level operations in C; anything else will just slow you down.
4 Reply Quote Share
ericgasFull Member
Posts: 15 · Reputation: 567
#6Oct 16, 2019, 03:08 AM
Try this repo: https://github.com/shrec/UltrafastSecp256k1. Might have what you need.
4 Reply Quote Share
GrimBitLegendary
Posts: 4 · Reputation: 5453
#7Oct 16, 2019, 07:11 AM
If I wanna use your code, should I go with Rust Cargo libraries?
4 Reply Quote Share
ericgasFull Member
Posts: 15 · Reputation: 567
#8Oct 16, 2019, 01:55 PM
Yeah, my library has Rust bindings, so you can use those directly.
5 Reply Quote Share

Related topics