JeanLucPons / Kangaroo

Pollard's kangaroo for SECPK1
GNU General Public License v3.0
231 stars 169 forks source link

Secp256k1 library in pure assembly #124

Closed alekssolov closed 3 months ago

alekssolov commented 5 months ago

I suggest increasing the speed of the secp256k1 in Kangaroo. I found this: https://github.com/piggypiggy/secp256k1-x64 This library aims to provide the most efficient implementation of secp256k1 curve arithmetic. For example, function secp256k1_sqr_mont (the fastest, according to the developer) i suggest to use to calculate PubKey. How to implement this? All functions implemented in assembly:

/ Modular add: res = a+b mod P asm/ X64_EXPORT void secp256k1_add(BN_ULONG res[P256_LIMBS], const BN_ULONG a[P256_LIMBS], const BN_ULONG b[P256_LIMBS]); / Modular mul by 2: res = 2a mod P asm/ X64_EXPORT void secp256k1_mul_by_2(BN_ULONG res[P256_LIMBS], const BN_ULONG a[P256_LIMBS]); / Modular mul by 3: res = 3a mod P asm/ X64_EXPORT void secp256k1_mul_by_3(BN_ULONG res[P256_LIMBS], const BN_ULONG a[P256_LIMBS]); / Modular div by 2: res = a/2 mod P asm/ X64_EXPORT void secp256k1_div_by_2(BN_ULONG res[P256_LIMBS], const BN_ULONG a[P256_LIMBS]); / Modular sub: res = a-b mod P asm/ X64_EXPORT void secp256k1_sub(BN_ULONG res[P256_LIMBS], const BN_ULONG a[P256_LIMBS], const BN_ULONG b[P256_LIMBS]); / Modular neg: res = -a mod P asm/ X64_EXPORT void secp256k1_neg(BN_ULONG res[P256_LIMBS], const BN_ULONG a[P256_LIMBS]); / res = a mod P asm/ X64_EXPORT void secp256k1_reduce(BN_ULONG res[4], BN_ULONG a[P256_LIMBS]); / res = aw mod P asm/ X64_EXPORT void secp256k1_mul_word(BN_ULONG res[P256_LIMBS], const BN_ULONG a[P256_LIMBS], const BN_ULONG w); / Montgomery mul: res = ab2^-256 mod P asm/ X64_EXPORT void secp256k1_mul_mont(BN_ULONG res[P256_LIMBS], const BN_ULONG a[P256_LIMBS], const BN_ULONG b[P256_LIMBS]); / Montgomery sqr: res = aa2^-256 mod P asm/// - FASTEST X64_EXPORT void secp256k1_sqr_mont(BN_ULONG res[P256_LIMBS], const BN_ULONG a[P256_LIMBS]); / Convert a number from Montgomery domain, by multiplying with 1 asm/ X64_EXPORT void secp256k1_from_mont(BN_ULONG res[P256_LIMBS], const BN_ULONG in[P256_LIMBS]); / Convert a number to Montgomery domain, by multiplying with 2^512 mod asmP/ X64_EXPORT void secp256k1_to_mont(BN_ULONG res[P256_LIMBS], const BN_ULONG in[P256_LIMBS]); / Functions that perform constant time access to the precomputed tables asm/ X64_EXPORT void secp256k1_scatter_w5(POINT256 val, const POINT256 in_t, int idx); X64_EXPORT void secp256k1_scatter_w7(POINT256_AFFINE val, const POINT256_AFFINE in_t, int idx); / compare two points, 0 : a = b, -1 : a != b asm/ X64_EXPORT int secp256k1_point_cmp(const POINT256 a, const POINT256 b); X64_EXPORT void secp256k1_point_dbl(POINT256 r, const POINT256 a); X64_EXPORT void secp256k1_point_add(POINT256 r, const POINT256 a, const POINT256 b); X64_EXPORT void secp256k1_point_add_affine(POINT256 r, const POINT256 a, const POINT256_AFFINE *b);