49 const secp256k1_context* ctx,
50 secp256k1_pubkey* out,
51 const unsigned char* label,
55 unsigned char hash[32];
56 unsigned char compressed[33];
59 unsigned char idx_be[4] = {
60 (
unsigned char)(index >> 24), (
unsigned char)(index >> 16),
61 (
unsigned char)(index >> 8), (
unsigned char)(index & 0xFF)
65 while (ctr < 0xFFFFFFFFu) {
66 unsigned char ctr_be[4] = {
67 (
unsigned char)(ctr >> 24), (
unsigned char)(ctr >> 16),
68 (
unsigned char)(ctr >> 8), (
unsigned char)(ctr & 0xFF)
73 SHA256_Update(&sha,
"MPT_BULLETPROOF_V1_NUMS", 23);
74 SHA256_Update(&sha,
"secp256k1", 9);
76 if (label && label_len > 0) {
77 SHA256_Update(&sha, label, label_len);
80 SHA256_Update(&sha, idx_be, 4);
81 SHA256_Update(&sha, ctr_be, 4);
82 SHA256_Final(hash, &sha);
86 memcpy(&compressed[1], hash, 32);
89 if (secp256k1_ec_pubkey_parse(ctx, out, compressed, 33) == 1) {
150 const secp256k1_context* ctx,
151 secp256k1_pubkey* commitment,
153 const unsigned char* rho
155 secp256k1_pubkey mG, rH, H;
156 unsigned char m_scalar[32] = {0};
160 if (!secp256k1_ec_seckey_verify(ctx, rho))
return 0;
167 if (!secp256k1_ec_pubkey_tweak_mul(ctx, &rH, rho))
return 0;
178 for (
int i = 0; i < 8; i++) {
179 m_scalar[31 - i] = (amount >> (i * 8)) & 0xFF;
183 if (!secp256k1_ec_pubkey_create(ctx, &mG, m_scalar))
goto cleanup;
186 const secp256k1_pubkey* points[2] = {&mG, &rH};
187 if (!secp256k1_ec_pubkey_combine(ctx, commitment, points, 2))
goto cleanup;
193 OPENSSL_cleanse(m_scalar, 32);
int secp256k1_mpt_pedersen_commit(const secp256k1_context *ctx, secp256k1_pubkey *commitment, uint64_t amount, const unsigned char *rho)
Creates a Pedersen Commitment C = amount*G + rho*H.
int secp256k1_mpt_get_generator_vector(const secp256k1_context *ctx, secp256k1_pubkey *vec, size_t n, const unsigned char *label, size_t label_len)
Generates a vector of N independent NUMS generators.
int secp256k1_mpt_hash_to_point_nums(const secp256k1_context *ctx, secp256k1_pubkey *out, const unsigned char *label, size_t label_len, uint32_t index)
Deterministically derives a NUMS (Nothing-Up-My-Sleeve) generator point.