@@ -245,30 +245,76 @@ urcrypt_secp_schnorr_veri(urcrypt_secp_context* context,
245245}
246246
247247int
248- urcrypt_secp_point_from_scalar (urcrypt_secp_context * context ,
249- const uint8_t scalar [32 ],
250- uint8_t point [ 65 ]) {
248+ urcrypt_secp_cmp_point_from_scalar (urcrypt_secp_context * context ,
249+ const uint8_t scalar [32 ],
250+ uint8_t cmp_point [ 33 ]) {
251251 urcrypt__reverse (32 , scalar );
252+
252253 secp256k1_keypair keypair ;
253254 secp256k1_pubkey pubkey ;
254255
255256 secp256k1_keypair_create (context -> secp , & keypair , scalar );
256-
257257 secp256k1_keypair_pub (context -> secp , & pubkey , & keypair );
258258
259- size_t output_len = 65 ;
259+ size_t output_len = 33 ;
260260 if (1 != secp256k1_ec_pubkey_serialize (
261261 context -> secp ,
262- point ,
262+ cmp_point ,
263263 & output_len ,
264264 & pubkey ,
265- SECP256K1_FLAGS_TYPE_COMPRESSION )) {
265+ SECP256K1_EC_COMPRESSED )) {
266266 return -1 ;
267267 }
268268
269- urcrypt__reverse (32 , point + 1 );
270- urcrypt__reverse (32 , point + 33 );
269+ urcrypt__reverse (33 , cmp_point );
270+
271+ return 0 ;
272+ }
273+
274+ int
275+ urcrypt_secp_scalar_tweak_add (urcrypt_secp_context * context ,
276+ uint8_t scalar [32 ],
277+ const uint8_t tweak [32 ]) {
278+ urcrypt__reverse (32 , scalar );
279+ urcrypt__reverse (32 , tweak );
280+
281+ if (1 != secp256k1_ec_seckey_tweak_add (context , scalar , tweak )) {
282+ return -1 ;
283+ }
284+
285+ urcrypt__reverse (32 , scalar );
271286
272287 return 0 ;
273288}
274289
290+ int
291+ urcrypt_secp_cmp_point_tweak_add (urcrypt_secp_context * context ,
292+ uint8_t cmp_point [33 ],
293+ const uint8_t tweak [32 ]) {
294+ urcrypt__reverse (33 , cmp_point );
295+ urcrypt__reverse (32 , tweak );
296+
297+ secp256k1_pubkey point ;
298+ size_t cmp_len = 33 ;
299+
300+ if (1 != secp256k1_ec_pubkey_parse (context -> secp , & point , cmp_point , cmp_len )) {
301+ return -1 ; //invalid compressed point
302+ }
303+
304+ if (1 != secp256k1_ec_pubkey_tweak_add (context -> secp , & point , tweak )) {
305+ return -2 ; //invalid tweak
306+ }
307+
308+ if (1 != secp256k1_ec_pubkey_serialize (
309+ context -> secp ,
310+ cmp_point ,
311+ & cmp_len ,
312+ & point ,
313+ SECP256K1_EC_COMPRESSED )) {
314+ return -3 ; //something is very wrong
315+ }
316+
317+ urcrypt__reverse (33 , cmp_point );
318+
319+ return 0 ;
320+ }
0 commit comments