|
13 | 13 | #include <xrpl/protocol/TxFormats.h> |
14 | 14 | #include <xrpl/protocol/detail/secp256k1.h> |
15 | 15 |
|
16 | | -#include <secp256k1.h> |
| 16 | +#include <secp256k1_mpt.h> |
17 | 17 |
|
18 | 18 | namespace xrpl { |
19 | 19 |
|
@@ -438,291 +438,6 @@ verifyBalancePcmLinkage( |
438 | 438 | Slice const& pcmSlice, |
439 | 439 | uint256 const& contextHash); |
440 | 440 |
|
441 | | -// The following functions belong to the mpt-crypto library, |
442 | | -// they will be finally removed and we will use conan2 to manage the dependency. |
443 | | -/** |
444 | | - * @brief Generates a new secp256k1 key pair. |
445 | | - */ |
446 | | -SECP256K1_API int |
447 | | -secp256k1_elgamal_generate_keypair(secp256k1_context const* ctx, unsigned char* privkey, secp256k1_pubkey* pubkey); |
448 | | - |
449 | | -/** |
450 | | - * @brief Encrypts a 64-bit amount using ElGamal. |
451 | | - */ |
452 | | -SECP256K1_API int |
453 | | -secp256k1_elgamal_encrypt( |
454 | | - secp256k1_context const* ctx, |
455 | | - secp256k1_pubkey* c1, |
456 | | - secp256k1_pubkey* c2, |
457 | | - secp256k1_pubkey const* pubkey_Q, |
458 | | - uint64_t amount, |
459 | | - unsigned char const* blinding_factor); |
460 | | - |
461 | | -/** |
462 | | - * @brief Decrypts an ElGamal ciphertext to recover the amount. |
463 | | - */ |
464 | | -SECP256K1_API int |
465 | | -secp256k1_elgamal_decrypt( |
466 | | - secp256k1_context const* ctx, |
467 | | - uint64_t* amount, |
468 | | - secp256k1_pubkey const* c1, |
469 | | - secp256k1_pubkey const* c2, |
470 | | - unsigned char const* privkey); |
471 | | - |
472 | | -/** |
473 | | - * @brief Homomorphically adds two ElGamal ciphertexts. |
474 | | - */ |
475 | | -SECP256K1_API int |
476 | | -secp256k1_elgamal_add( |
477 | | - secp256k1_context const* ctx, |
478 | | - secp256k1_pubkey* sum_c1, |
479 | | - secp256k1_pubkey* sum_c2, |
480 | | - secp256k1_pubkey const* a_c1, |
481 | | - secp256k1_pubkey const* a_c2, |
482 | | - secp256k1_pubkey const* b_c1, |
483 | | - secp256k1_pubkey const* b_c2); |
484 | | - |
485 | | -/** |
486 | | - * @brief Homomorphically subtracts two ElGamal ciphertexts. |
487 | | - */ |
488 | | -SECP256K1_API int |
489 | | -secp256k1_elgamal_subtract( |
490 | | - secp256k1_context const* ctx, |
491 | | - secp256k1_pubkey* diff_c1, |
492 | | - secp256k1_pubkey* diff_c2, |
493 | | - secp256k1_pubkey const* a_c1, |
494 | | - secp256k1_pubkey const* a_c2, |
495 | | - secp256k1_pubkey const* b_c1, |
496 | | - secp256k1_pubkey const* b_c2); |
497 | | - |
498 | | -/** |
499 | | - * @brief Generates the canonical encrypted zero for a given MPT token instance. |
500 | | - * |
501 | | - * This ciphertext represents a zero balance for a specific account's holding |
502 | | - * of a token defined by its MPTokenIssuanceID. |
503 | | - * |
504 | | - * @param[in] ctx A pointer to a valid secp256k1 context. |
505 | | - * @param[out] enc_zero_c1 The C1 component of the canonical ciphertext. |
506 | | - * @param[out] enc_zero_c2 The C2 component of the canonical ciphertext. |
507 | | - * @param[in] pubkey The ElGamal public key of the account holder. |
508 | | - * @param[in] account_id A pointer to the 20-byte AccountID. |
509 | | - * @param[in] mpt_issuance_id A pointer to the 24-byte MPTokenIssuanceID. |
510 | | - * |
511 | | - * @return 1 on success, 0 on failure. |
512 | | - */ |
513 | | -SECP256K1_API int |
514 | | -generate_canonical_encrypted_zero( |
515 | | - secp256k1_context const* ctx, |
516 | | - secp256k1_pubkey* enc_zero_c1, |
517 | | - secp256k1_pubkey* enc_zero_c2, |
518 | | - secp256k1_pubkey const* pubkey, |
519 | | - unsigned char const* account_id, // 20 bytes |
520 | | - unsigned char const* mpt_issuance_id // 24 bytes |
521 | | -); |
522 | | - |
523 | | -/** |
524 | | - * Generates a cryptographically secure 32-byte scalar (private key). |
525 | | - * @return 1 on success, 0 on failure. |
526 | | - */ |
527 | | -SECP256K1_API int |
528 | | -generate_random_scalar(secp256k1_context const* ctx, unsigned char* scalar_bytes); |
529 | | - |
530 | | -/** |
531 | | - * Computes the point M = amount * G. |
532 | | - * IMPORTANT: This function MUST NOT be called with amount = 0. |
533 | | - */ |
534 | | -SECP256K1_API int |
535 | | -compute_amount_point(secp256k1_context const* ctx, secp256k1_pubkey* mG, uint64_t amount); |
536 | | - |
537 | | -/** |
538 | | - * Builds the challenge hash input for the NON-ZERO amount case. |
539 | | - * Output buffer must be 253 bytes. |
540 | | - */ |
541 | | -SECP256K1_API void |
542 | | -build_challenge_hash_input_nonzero( |
543 | | - unsigned char* hash_input, |
544 | | - secp256k1_pubkey const* c1, |
545 | | - secp256k1_pubkey const* c2, |
546 | | - secp256k1_pubkey const* pk, |
547 | | - secp256k1_pubkey const* mG, |
548 | | - secp256k1_pubkey const* T1, |
549 | | - secp256k1_pubkey const* T2, |
550 | | - unsigned char const* tx_context_id); |
551 | | - |
552 | | -/** |
553 | | - * Builds the challenge hash input for the ZERO amount case. |
554 | | - * Output buffer must be 220 bytes. |
555 | | - */ |
556 | | -SECP256K1_API void |
557 | | -build_challenge_hash_input_zero( |
558 | | - unsigned char* hash_input, |
559 | | - secp256k1_pubkey const* c1, |
560 | | - secp256k1_pubkey const* c2, |
561 | | - secp256k1_pubkey const* pk, |
562 | | - secp256k1_pubkey const* T1, |
563 | | - secp256k1_pubkey const* T2, |
564 | | - unsigned char const* tx_context_id); |
565 | | - |
566 | | -/** |
567 | | - * @brief Proves that a commitment (C1, C2) encrypts a specific plaintext |
568 | | - * 'amount'. |
569 | | - */ |
570 | | -SECP256K1_API int |
571 | | -secp256k1_equality_plaintext_prove( |
572 | | - secp256k1_context const* ctx, |
573 | | - unsigned char* proof, |
574 | | - secp256k1_pubkey const* c1, |
575 | | - secp256k1_pubkey const* c2, |
576 | | - secp256k1_pubkey const* pk_recipient, |
577 | | - uint64_t amount, |
578 | | - unsigned char const* randomness_r, |
579 | | - unsigned char const* tx_context_id); |
580 | | - |
581 | | -/** |
582 | | - * @brief Verifies the proof generated by secp256k1_equality_plaintext_prove. |
583 | | - */ |
584 | | -SECP256K1_API int |
585 | | -secp256k1_equality_plaintext_verify( |
586 | | - secp256k1_context const* ctx, |
587 | | - unsigned char const* proof, |
588 | | - secp256k1_pubkey const* c1, |
589 | | - secp256k1_pubkey const* c2, |
590 | | - secp256k1_pubkey const* pk_recipient, |
591 | | - uint64_t amount, |
592 | | - unsigned char const* tx_context_id); |
593 | | - |
594 | | -void |
595 | | -build_pok_challenge( |
596 | | - unsigned char* e, |
597 | | - secp256k1_context const* ctx, |
598 | | - secp256k1_pubkey const* pk, |
599 | | - secp256k1_pubkey const* T, |
600 | | - unsigned char const* context_id); |
601 | | - |
602 | | -/** Proof of Knowledge of Secret Key for Registration */ |
603 | | -int |
604 | | -secp256k1_mpt_pok_sk_prove( |
605 | | - secp256k1_context const* ctx, |
606 | | - unsigned char* proof, /* Expected size: 65 bytes */ |
607 | | - secp256k1_pubkey const* pk, |
608 | | - unsigned char const* sk, |
609 | | - unsigned char const* context_id); |
610 | | - |
611 | | -int |
612 | | -secp256k1_mpt_pok_sk_verify( |
613 | | - secp256k1_context const* ctx, |
614 | | - unsigned char const* proof, /* Expected size: 65 bytes */ |
615 | | - secp256k1_pubkey const* pk, |
616 | | - unsigned char const* context_id); |
617 | | - |
618 | | -/** |
619 | | - * Verifies that (c1, c2) is a valid ElGamal encryption of 'amount' |
620 | | - * for 'pubkey_Q' using the revealed 'blinding_factor'. |
621 | | - */ |
622 | | -int |
623 | | -secp256k1_elgamal_verify_encryption( |
624 | | - secp256k1_context const* ctx, |
625 | | - secp256k1_pubkey const* c1, |
626 | | - secp256k1_pubkey const* c2, |
627 | | - secp256k1_pubkey const* pubkey_Q, |
628 | | - uint64_t amount, |
629 | | - unsigned char const* blinding_factor); |
630 | | - |
631 | | -/** |
632 | | - * @brief Proves the link between an ElGamal ciphertext and a Pedersen |
633 | | - * commitment. |
634 | | - * * Formal Statement: Knowledge of (m, r, rho) such that: |
635 | | - * C1 = r*G, C2 = m*G + r*Pk, and PCm = m*G + rho*H. |
636 | | - * * @param ctx Pointer to a secp256k1 context object. |
637 | | - * @param proof [OUT] Pointer to 195-byte buffer for the proof output. |
638 | | - * @param c1 Pointer to the ElGamal C1 point (r*G). |
639 | | - * @param c2 Pointer to the ElGamal C2 point (m*G + r*Pk). |
640 | | - * @param pk Pointer to the recipient's public key. |
641 | | - * @param pcm Pointer to the Pedersen Commitment (m*G + rho*H). |
642 | | - * @param amount The plaintext amount (m). |
643 | | - * @param r The 32-byte secret ElGamal blinding factor. |
644 | | - * @param rho The 32-byte secret Pedersen blinding factor. |
645 | | - * @param context_id 32-byte unique transaction context identifier. |
646 | | - * @return 1 on success, 0 on failure. |
647 | | - */ |
648 | | -int |
649 | | -secp256k1_elgamal_pedersen_link_prove( |
650 | | - secp256k1_context const* ctx, |
651 | | - unsigned char* proof, |
652 | | - secp256k1_pubkey const* c1, |
653 | | - secp256k1_pubkey const* c2, |
654 | | - secp256k1_pubkey const* pk, |
655 | | - secp256k1_pubkey const* pcm, |
656 | | - uint64_t amount, |
657 | | - unsigned char const* r, |
658 | | - unsigned char const* rho, |
659 | | - unsigned char const* context_id); |
660 | | - |
661 | | -/** |
662 | | - * @brief Verifies the link proof between ElGamal and Pedersen commitments. |
663 | | - * * @return 1 if the proof is valid, 0 otherwise. |
664 | | - */ |
665 | | -int |
666 | | -secp256k1_elgamal_pedersen_link_verify( |
667 | | - secp256k1_context const* ctx, |
668 | | - unsigned char const* proof, |
669 | | - secp256k1_pubkey const* c1, |
670 | | - secp256k1_pubkey const* c2, |
671 | | - secp256k1_pubkey const* pk, |
672 | | - secp256k1_pubkey const* pcm, |
673 | | - unsigned char const* context_id); |
674 | | - |
675 | | -/** |
676 | | - * Compute a Pedersen Commitment: PC = m*G + rho*H |
677 | | - * Returns 1 on success, 0 on failure. |
678 | | - */ |
679 | | -int |
680 | | -secp256k1_mpt_pedersen_commit( |
681 | | - secp256k1_context const* ctx, |
682 | | - secp256k1_pubkey* commitment, |
683 | | - uint64_t amount, |
684 | | - unsigned char const* blinding_factor_rho /* 32 bytes */ |
685 | | -); |
686 | | - |
687 | | -// Multi-proof for same plaintexts |
688 | | -void |
689 | | -build_hash_input( |
690 | | - unsigned char* hash_out, // Output: 32-byte hash |
691 | | - size_t n, |
692 | | - secp256k1_pubkey const* R, |
693 | | - secp256k1_pubkey const* S, |
694 | | - secp256k1_pubkey const* Pk, |
695 | | - secp256k1_pubkey const* T_m, |
696 | | - secp256k1_pubkey const* T_rG, |
697 | | - secp256k1_pubkey const* T_rP, |
698 | | - unsigned char const* tx_id); |
699 | | - |
700 | | -size_t |
701 | | -secp256k1_mpt_prove_same_plaintext_multi_size(size_t n); |
702 | | - |
703 | | -int |
704 | | -secp256k1_mpt_prove_same_plaintext_multi( |
705 | | - secp256k1_context const* ctx, |
706 | | - unsigned char* proof_out, |
707 | | - size_t* proof_len, |
708 | | - uint64_t amount_m, |
709 | | - size_t n, |
710 | | - secp256k1_pubkey const* R, |
711 | | - secp256k1_pubkey const* S, |
712 | | - secp256k1_pubkey const* Pk, |
713 | | - unsigned char const* r_array, |
714 | | - unsigned char const* tx_id); |
715 | | - |
716 | | -int |
717 | | -secp256k1_mpt_verify_same_plaintext_multi( |
718 | | - secp256k1_context const* ctx, |
719 | | - unsigned char const* proof, |
720 | | - size_t proof_len, |
721 | | - size_t n, |
722 | | - secp256k1_pubkey const* R, |
723 | | - secp256k1_pubkey const* S, |
724 | | - secp256k1_pubkey const* Pk, |
725 | | - unsigned char const* tx_id); |
726 | 441 | } // namespace xrpl |
727 | 442 |
|
728 | 443 | #endif |
0 commit comments