@@ -333,7 +333,9 @@ mpt_generate_keypair(uint8_t* out_privkey, uint8_t* out_pubkey)
333333 if (secp256k1_elgamal_generate_keypair (ctx, out_privkey, &pub) != 1 )
334334 return -1 ;
335335
336- std::memcpy (out_pubkey, pub.data , kMPT_PUBKEY_SIZE );
336+ size_t output_len = kMPT_PUBKEY_SIZE ;
337+ if (secp256k1_ec_pubkey_serialize (ctx, out_pubkey, &output_len, &pub, SECP256K1_EC_COMPRESSED) != 1 )
338+ return -1 ;
337339
338340 return 0 ;
339341}
@@ -365,7 +367,8 @@ mpt_encrypt_amount(
365367 return -1 ;
366368
367369 secp256k1_pubkey c1, c2, pk;
368- std::memcpy (pk.data , pubkey, kMPT_PUBKEY_SIZE );
370+ if (secp256k1_ec_pubkey_parse (ctx, &pk, pubkey, kMPT_PUBKEY_SIZE ) != 1 )
371+ return -1 ;
369372
370373 if (!secp256k1_elgamal_encrypt (ctx, &c1, &c2, &pk, amount, blinding_factor))
371374 return -1 ;
@@ -415,7 +418,8 @@ mpt_get_convert_proof(
415418 return -1 ;
416419
417420 secp256k1_pubkey pk;
418- std::memcpy (pk.data , pubkey, kMPT_PUBKEY_SIZE );
421+ if (secp256k1_ec_pubkey_parse (ctx, &pk, pubkey, kMPT_PUBKEY_SIZE ) != 1 )
422+ return -1 ;
419423
420424 if (secp256k1_mpt_pok_sk_prove (ctx, out_proof, &pk, privkey, ctx_hash) != 1 )
421425 return -1 ;
@@ -447,7 +451,9 @@ mpt_get_pedersen_commitment(
447451 if (secp256k1_mpt_pedersen_commit (ctx, &commitment, amount, blinding_factor) != 1 )
448452 return -1 ;
449453
450- std::memcpy (out_commitment, commitment.data , kMPT_PEDERSEN_COMMIT_SIZE );
454+ size_t output_len = kMPT_PEDERSEN_COMMIT_SIZE ;
455+ if (secp256k1_ec_pubkey_serialize (ctx, out_commitment, &output_len, &commitment, SECP256K1_EC_COMPRESSED) != 1 )
456+ return -1 ;
451457
452458 return 0 ;
453459}
@@ -467,17 +473,19 @@ mpt_get_amount_linkage_proof(
467473 if (!ctx)
468474 return -1 ;
469475
470- secp256k1_pubkey c1, c2;
476+ secp256k1_pubkey c1, c2, pk, pcm ;
471477 if (!secp256k1_ec_pubkey_parse (ctx, &c1, params->encrypted_amount , kMPT_ELGAMAL_CIPHER_SIZE ))
472478 return -1 ;
473479
474480 if (!secp256k1_ec_pubkey_parse (
475481 ctx, &c2, params->encrypted_amount + kMPT_ELGAMAL_CIPHER_SIZE , kMPT_ELGAMAL_CIPHER_SIZE ))
476482 return -1 ;
477483
478- secp256k1_pubkey pk, pcm;
479- std::memcpy (pk.data , pubkey, kMPT_PUBKEY_SIZE );
480- std::memcpy (pcm.data , params->pedersen_commitment , kMPT_PEDERSEN_COMMIT_SIZE );
484+ if (secp256k1_ec_pubkey_parse (ctx, &pk, pubkey, kMPT_PUBKEY_SIZE ) != 1 )
485+ return -1 ;
486+
487+ if (secp256k1_ec_pubkey_parse (ctx, &pcm, params->pedersen_commitment , kMPT_PEDERSEN_COMMIT_SIZE ) != 1 )
488+ return -1 ;
481489
482490 if (secp256k1_elgamal_pedersen_link_prove (
483491 ctx,
@@ -512,17 +520,19 @@ mpt_get_balance_linkage_proof(
512520 if (!ctx)
513521 return -1 ;
514522
515- secp256k1_pubkey c1, c2;
523+ secp256k1_pubkey c1, c2, pk, pcm ;
516524 if (!secp256k1_ec_pubkey_parse (ctx, &c1, params->encrypted_amount , kMPT_ELGAMAL_CIPHER_SIZE ))
517525 return -1 ;
518526
519527 if (!secp256k1_ec_pubkey_parse (
520528 ctx, &c2, params->encrypted_amount + kMPT_ELGAMAL_CIPHER_SIZE , kMPT_ELGAMAL_CIPHER_SIZE ))
521529 return -1 ;
522530
523- secp256k1_pubkey pk, pcm;
524- std::memcpy (pk.data , pub, kMPT_PUBKEY_SIZE );
525- std::memcpy (pcm.data , params->pedersen_commitment , kMPT_PEDERSEN_COMMIT_SIZE );
531+ if (secp256k1_ec_pubkey_parse (ctx, &pk, pub, kMPT_PUBKEY_SIZE ) != 1 )
532+ return -1 ;
533+
534+ if (secp256k1_ec_pubkey_parse (ctx, &pcm, params->pedersen_commitment , kMPT_PEDERSEN_COMMIT_SIZE ) != 1 )
535+ return -1 ;
526536
527537 if (secp256k1_elgamal_pedersen_link_prove (
528538 ctx,
@@ -580,7 +590,9 @@ mpt_get_confidential_send_proof(
580590 ctx, &s[i], rec.encrypted_amount + kMPT_ELGAMAL_CIPHER_SIZE , kMPT_ELGAMAL_CIPHER_SIZE ))
581591 return -1 ;
582592
583- std::memcpy (pk[i].data , rec.pubkey , kMPT_PUBKEY_SIZE );
593+ if (secp256k1_ec_pubkey_parse (ctx, &pk[i], rec.pubkey , kMPT_PUBKEY_SIZE ) != 1 )
594+ return -1 ;
595+
584596 sr.insert (sr.end (), tx_blinding_factor, tx_blinding_factor + kMPT_BLINDING_FACTOR_SIZE );
585597 }
586598
@@ -609,14 +621,14 @@ mpt_get_confidential_send_proof(
609621 // Amount Linkage Proof
610622 uint8_t * amt_ptr = out_proof + size_equality;
611623 if (mpt_get_amount_linkage_proof (
612- pk [0 ].data , tx_blinding_factor, context_hash, amount_params, amt_ptr) != 0 )
624+ recipients [0 ].pubkey , tx_blinding_factor, context_hash, amount_params, amt_ptr) != 0 )
613625 {
614626 return -1 ;
615627 }
616628
617629 // Balance Linkage Proof
618630 uint8_t * bal_ptr = amt_ptr + kMPT_PEDERSEN_LINK_SIZE ;
619- if (mpt_get_balance_linkage_proof (priv, pk [0 ].data , context_hash, balance_params, bal_ptr) != 0 )
631+ if (mpt_get_balance_linkage_proof (priv, recipients [0 ].pubkey , context_hash, balance_params, bal_ptr) != 0 )
620632 {
621633 return -1 ;
622634 }
@@ -657,7 +669,8 @@ mpt_get_clawback_proof(
657669 return -1 ;
658670
659671 secp256k1_pubkey pk;
660- std::memcpy (pk.data , pub, kMPT_PUBKEY_SIZE );
672+ if (secp256k1_ec_pubkey_parse (ctx, &pk, pub, kMPT_PUBKEY_SIZE ) != 1 )
673+ return -1 ;
661674
662675 secp256k1_pubkey c1, c2;
663676 if (!mpt_make_ec_pair (encrypted_amount, c1, c2))
0 commit comments