我想从私钥计算公钥。它必须使用 OpenCL 才能工作。似乎 hashcat 有一个不错的库,但我不知道如何使用它。
- https://github.com/hashcat/hashcat/blob/master/OpenCL/inc_ecc_secp256k1.h
- https://github.com/hashcat/hashcat/blob/master/OpenCL/inc_ecc_secp256k1.cl
其他库也是可能的。secp256k1-cl 似乎很难使用https://github.com/hhanh00/secp256k1-cl/blob/master/secp256k1.cl
请参阅下面的示例,了解它如何基于inc_ecc_secp256k1.cl工作。
我应该parse_public
在已知基点上使用G
来获取secp256k1_t
对象中的坐标吗?之后使用point_mul
我通过的随机秘密和通过的k
基点来获取公钥?G
basepoint_precalculated
r
// 8+1 to make room for the parity
#define KEY_LENGTH_WITH_PARITY 9
// (32*8 == 256)
#define PRIVATE_KEY_LENGTH 8
// the base point G in compressed form
#define SECP256K1_G0 0x00000002
#define SECP256K1_G1 0x79be667e
#define SECP256K1_G2 0xf9dcbbac
#define SECP256K1_G3 0x55a06295
#define SECP256K1_G4 0xce870b07
#define SECP256K1_G5 0x029bfcdb
#define SECP256K1_G6 0x2dce28d9
#define SECP256K1_G7 0x59f2815b
#define SECP256K1_G8 0x16f81798
__kernel void generateKeysKernel(__global u32 *r, __global const u32 *k)
{
u32 basepoint_g[KEY_LENGTH_WITH_PARITY];
u32 u32r_local[KEY_LENGTH_WITH_PARITY];
u32 u32k_local[PRIVATE_KEY_LENGTH];
secp256k1_t basepoint_precalculated;
basepoint_g[0] = SECP256K1_G0;
basepoint_g[1] = SECP256K1_G1;
basepoint_g[2] = SECP256K1_G2;
basepoint_g[3] = SECP256K1_G3;
basepoint_g[4] = SECP256K1_G4;
basepoint_g[5] = SECP256K1_G5;
basepoint_g[6] = SECP256K1_G6;
basepoint_g[7] = SECP256K1_G7;
basepoint_g[8] = SECP256K1_G8;
// global to local
u32k_local[0] = k[0];
u32k_local[1] = k[1];
u32k_local[2] = k[2];
u32k_local[3] = k[3];
u32k_local[4] = k[4];
u32k_local[5] = k[5];
u32k_local[6] = k[6];
u32k_local[7] = k[7];
parse_public(&basepoint_precalculated, basepoint_g);
point_mul(u32r_local, u32k_local, &basepoint_precalculated);
// local to global
r[0] = u32r_local[0];
r[1] = u32r_local[1];
r[2] = u32r_local[2];
r[3] = u32r_local[3];
r[4] = u32r_local[4];
r[5] = u32r_local[5];
r[6] = u32r_local[6];
r[7] = u32r_local[7];
r[8] = u32r_local[8];
}