I'ld like to calculate a public key from a private key. It must work using OpenCL. It seems hashcat has a nice library but I'm not sure how to use it.
- https://github.com/hashcat/hashcat/blob/master/OpenCL/inc_ecc_secp256k1.h
- https://github.com/hashcat/hashcat/blob/master/OpenCL/inc_ecc_secp256k1.cl
Other libararies are also possible. secp256k1-cl seems to be very difficult to use https://github.com/hhanh00/secp256k1-cl/blob/master/secp256k1.cl
See below an example of how it might work based on inc_ecc_secp256k1.cl.
Should I use parse_public
on the known base point G
to get the coordinates in a secp256k1_t
object?
Afterwards use point_mul
with my random secret passed via k
and the base point G
passed via basepoint_precalculated
to get the pubkey in 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];
}