Secp256k1 library in pure assembly
alekssolov opened this issue · 3 comments
I suggest increasing the speed of the secp256k1 in KeyHunt.
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 in SECP256K1.cpp:
Point Secp256K1::ComputePublicKey(Int privKey) {
Point Q;
long long unsigned int x[4]; //result of the montgomery square
Int result;
Q.Clear();
secp256k1_sqr_mont(x, (const long long unsigned int)(&(privKey->bits64)));
result.Set32Bytes((unsigned char*)x); // Set the result
??????????? result to Q ???????????
Q.Reduce();
return Q;
The question is how convert Int to Point?
Does anyone have any ideas?
In this topic discuss similar functions: [https://github.com/USTC-Hackergame/hackergame2022-writeups/blob/1edd745c0ce89a8ce11d451e816863358c74c662/official/小%20Z%20的靓号钱包/README.md]
There is no way to conver a single value ( array of long long unsigned int x[4]
) to a point you need at least two values x and y and i don't see how to use it.
To be honest keyhunt doesn't relay on ComputePublicKey too much, it is only called a few times to conver the intermediate Base keys into publickeys, but 99.9999% part of the remaning process depends only of public key point addition and some other shortcuts.
To albertobsd.
You wrote: "There is no way to conver a single value ( array of long long unsigned int x[4] ) to a point you need at least two values x and y and i don't see how to use it."
Answer:
#define P256_LIMBS 4
typedef struct {
BN_ULONG X[P256_LIMBS];
BN_ULONG Y[P256_LIMBS];
BN_ULONG Z[P256_LIMBS];
} POINT256;
POINT256 point;
BN_ULONG seckey[P256_LIMBS];
BN_ULONG x[P256_LIMBS];
BN_ULONG y[P256_LIMBS];
secp256k1_scalar_mul_gen(&point, seckey);
secp256k1_point_get_affine(x, y, &point);
Next questions:
Is it possible to convert now x & y to your class "Point"?
and
Is it possible to convert x & y from your class "Int" to your class "Point"?
as you see the point need at least X and Y to work some other classes and algorithms use Z for some calculations that are optimized.
So if you only have X with the secp256k1_sqr_mont then I don't know how to use it and to be honest i don't have any motivation to include it.
Why? Because keyhunt doesn't relay much on the ComputePublicKey as I mention before. So even if you increment the speed of that function 10 times more the current speed, it will not change the overall speed of the program.