Skip to content

Commit cd6e1af

Browse files
ziffeebonbud-macryg
authored andcommitted
gw/secp: add secp256k1_scalar_to_point
1 parent 4423051 commit cd6e1af

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

urcrypt/secp256k1.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,32 @@ urcrypt_secp_schnorr_veri(urcrypt_secp_context* context,
243243
}
244244
return true;
245245
}
246+
247+
int
248+
urcrypt_secp_point_from_scalar(urcrypt_secp_context* context,
249+
const uint8_t scalar[32],
250+
uint8_t point[65]) {
251+
urcrypt__reverse(32, scalar);
252+
secp256k1_keypair keypair;
253+
secp256k1_pubkey pubkey;
254+
255+
secp256k1_keypair_create(context->secp, &keypair, scalar);
256+
257+
secp256k1_keypair_pub(context->secp, &pubkey, &keypair);
258+
259+
size_t output_len = 65;
260+
if (1 != secp256k1_ec_pubkey_serialize(
261+
context->secp,
262+
point,
263+
&output_len,
264+
&pubkey,
265+
SECP256K1_FLAGS_TYPE_COMPRESSION)) {
266+
return -1;
267+
}
268+
269+
urcrypt__reverse(32, point + 1);
270+
urcrypt__reverse(32, point + 33);
271+
272+
return 0;
273+
}
274+

urcrypt/urcrypt.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,10 @@ void urcrypt_scrypt_pbkdf_sha256(const uint8_t *passwd,
284284
size_t outlen, // must be at most 32*(2^32-1)
285285
uint8_t *out);
286286

287+
int urcrypt_secp_point_from_scalar(urcrypt_secp_context* context,
288+
const uint8_t scalar[32],
289+
uint8_t point[65]);
290+
287291
int urcrypt_scrypt(const uint8_t *passwd,
288292
size_t passwdlen,
289293
const uint8_t *salt,

0 commit comments

Comments
 (0)