mpt-crypto
Confidential Multi-Purpose Tokens Cryptographic Library
Loading...
Searching...
No Matches
secp256k1_mpt.h
Go to the documentation of this file.
1#ifndef SECP256K1_MPT_H
2#define SECP256K1_MPT_H
3
4#include <secp256k1.h>
5#include <stdint.h>
6
7#ifdef __cplusplus
8extern "C" {
9#endif
10
15 const secp256k1_context* ctx,
16 unsigned char* privkey,
17 secp256k1_pubkey* pubkey
18);
19
23SECP256K1_API int secp256k1_elgamal_encrypt(
24 const secp256k1_context* ctx,
25 secp256k1_pubkey* c1,
26 secp256k1_pubkey* c2,
27 const secp256k1_pubkey* pubkey_Q,
28 uint64_t amount,
29 const unsigned char* blinding_factor
30);
31
35SECP256K1_API int secp256k1_elgamal_decrypt(
36 const secp256k1_context* ctx,
37 uint64_t* amount,
38 const secp256k1_pubkey* c1,
39 const secp256k1_pubkey* c2,
40 const unsigned char* privkey
41);
42
46SECP256K1_API int secp256k1_elgamal_add(
47 const secp256k1_context* ctx,
48 secp256k1_pubkey* sum_c1,
49 secp256k1_pubkey* sum_c2,
50 const secp256k1_pubkey* a_c1,
51 const secp256k1_pubkey* a_c2,
52 const secp256k1_pubkey* b_c1,
53 const secp256k1_pubkey* b_c2
54);
55
59SECP256K1_API int secp256k1_elgamal_subtract(
60 const secp256k1_context* ctx,
61 secp256k1_pubkey* diff_c1,
62 secp256k1_pubkey* diff_c2,
63 const secp256k1_pubkey* a_c1,
64 const secp256k1_pubkey* a_c2,
65 const secp256k1_pubkey* b_c1,
66 const secp256k1_pubkey* b_c2
67);
68
69
85SECP256K1_API int generate_canonical_encrypted_zero(
86 const secp256k1_context* ctx,
87 secp256k1_pubkey* enc_zero_c1,
88 secp256k1_pubkey* enc_zero_c2,
89 const secp256k1_pubkey* pubkey,
90 const unsigned char* account_id, // 20 bytes
91 const unsigned char* mpt_issuance_id // 24 bytes
92);
93
94
95// ... (includes and previous ElGamal declarations) ...
96
97/*
98================================================================================
99| |
100| PROOF OF KNOWLEDGE OF PLAINTEXT AND RANDOMNESS |
101| (Chaum-Pedersen Equality Proof) |
102================================================================================
103*/
104
122SECP256K1_API int secp256k1_equality_plaintext_prove(
123 const secp256k1_context* ctx,
124 unsigned char* proof, // Output: 98 bytes
125 const secp256k1_pubkey* c1,
126 const secp256k1_pubkey* c2,
127 const secp256k1_pubkey* pk_recipient,
128 uint64_t amount,
129 const unsigned char* randomness_r, // Secret input
130 const unsigned char* tx_context_id // 32 bytes
131);
132
151 const secp256k1_context* ctx,
152 const unsigned char* proof, // Input: 98 bytes
153 const secp256k1_pubkey* c1,
154 const secp256k1_pubkey* c2,
155 const secp256k1_pubkey* pk_recipient,
156 uint64_t amount,
157 const unsigned char* tx_context_id // 32 bytes
158);
159
160// ... (rest of header, #endif etc.)
161
162
163/*
164================================================================================
165| |
166| PROOF OF EQUALITY OF SECRET PLAINTEXTS |
167| (Multi-Statement Chaum-Pedersen) |
168================================================================================
169*/
170
186SECP256K1_API int secp256k1_mpt_prove_same_plaintext(
187 const secp256k1_context* ctx,
188 unsigned char* proof_out, // Output: 261 bytes
189 const secp256k1_pubkey* R1, const secp256k1_pubkey* S1, const secp256k1_pubkey* P1,
190 const secp256k1_pubkey* R2, const secp256k1_pubkey* S2, const secp256k1_pubkey* P2,
191 uint64_t amount_m,
192 const unsigned char* randomness_r1,
193 const unsigned char* randomness_r2,
194 const unsigned char* tx_context_id
195);
196
209 const secp256k1_context* ctx,
210 const unsigned char* proof, // Input: 261 bytes
211 const secp256k1_pubkey* R1, const secp256k1_pubkey* S1, const secp256k1_pubkey* P1,
212 const secp256k1_pubkey* R2, const secp256k1_pubkey* S2, const secp256k1_pubkey* P2,
213 const unsigned char* tx_context_id
214);
215
216
217
221SECP256K1_API size_t secp256k1_mpt_prove_same_plaintext_multi_size(size_t n_ciphertexts);
222
240 const secp256k1_context* ctx,
241 unsigned char* proof_out,
242 size_t* proof_len,
243 uint64_t amount_m,
244 size_t n_ciphertexts,
245 const secp256k1_pubkey* R_array,
246 const secp256k1_pubkey* S_array,
247 const secp256k1_pubkey* Pk_array,
248 const unsigned char* r_array, // Flat array: r1 || r2 || ... (N * 32 bytes)
249 const unsigned char* tx_context_id
250);
251
256 const secp256k1_context* ctx,
257 const unsigned char* proof,
258 size_t proof_len,
259 size_t n_ciphertexts,
260 const secp256k1_pubkey* R_array,
261 const secp256k1_pubkey* S_array,
262 const secp256k1_pubkey* Pk_array,
263 const unsigned char* tx_context_id
264);
265
266
282 const secp256k1_context* ctx,
283 secp256k1_pubkey* commitment_C,
284 uint64_t value,
285 const unsigned char* blinding_factor,
286 const secp256k1_pubkey* pk_base
287);
288
289
291 const secp256k1_context* ctx,
292 unsigned char* proof_out,
293 size_t* proof_len,
294 uint64_t value,
295 const unsigned char* blinding_factor,
296 const secp256k1_pubkey* pk_base,
297 const unsigned char* context_id, /* <--- AND HERE */
298 unsigned int proof_type
299);
300
301
303 const secp256k1_context* ctx,
304 const secp256k1_pubkey* G_vec,
305 const secp256k1_pubkey* H_vec,
306 const unsigned char* proof,
307 size_t proof_len,
308 const secp256k1_pubkey* commitment_C,
309 const secp256k1_pubkey* pk_base, /* This is generator H */
310 const unsigned char* context_id
311);
329 const secp256k1_context* ctx,
330 unsigned char* proof,
331 const secp256k1_pubkey* c1,
332 const secp256k1_pubkey* c2,
333 const secp256k1_pubkey* pk,
334 const secp256k1_pubkey* pcm,
335 uint64_t amount,
336 const unsigned char* r,
337 const unsigned char* rho,
338 const unsigned char* context_id);
339
345 const secp256k1_context* ctx,
346 const unsigned char* proof,
347 const secp256k1_pubkey* c1,
348 const secp256k1_pubkey* c2,
349 const secp256k1_pubkey* pk,
350 const secp256k1_pubkey* pcm,
351 const unsigned char* context_id);
352
358 const secp256k1_context* ctx,
359 const secp256k1_pubkey* c1,
360 const secp256k1_pubkey* c2,
361 const secp256k1_pubkey* pubkey_Q,
362 uint64_t amount,
363 const unsigned char* blinding_factor
364);
365
368 const secp256k1_context* ctx,
369 unsigned char* proof, /* Expected size: 65 bytes */
370 const secp256k1_pubkey* pk,
371 const unsigned char* sk,
372 const unsigned char* context_id
373);
374
376 const secp256k1_context* ctx,
377 const unsigned char* proof, /* Expected size: 65 bytes */
378 const secp256k1_pubkey* pk,
379 const unsigned char* context_id
380);
381
387 const secp256k1_context* ctx,
388 secp256k1_pubkey* commitment,
389 uint64_t amount,
390 const unsigned char* blinding_factor_rho /* 32 bytes */
391);
392
394int secp256k1_mpt_get_h_generator(const secp256k1_context* ctx, secp256k1_pubkey* h);
395
400 const secp256k1_context* ctx,
401 secp256k1_pubkey* vec,
402 size_t n,
403 const unsigned char* label,
404 size_t label_len
405);
406
407void secp256k1_mpt_scalar_add(unsigned char *res, const unsigned char *a, const unsigned char *b);
408void secp256k1_mpt_scalar_mul(unsigned char *res, const unsigned char *a, const unsigned char *b);
409void secp256k1_mpt_scalar_inverse(unsigned char *res, const unsigned char *in);
410void secp256k1_mpt_scalar_negate(unsigned char *res, const unsigned char *in);
411void secp256k1_mpt_scalar_reduce32(unsigned char out32[32], const unsigned char in32[32]);
412
413
419
425 const secp256k1_context* ctx,
426 unsigned char* proof_out,
427 uint64_t amount,
428 const unsigned char* r_shared,
429 size_t n,
430 const secp256k1_pubkey* C1,
431 const secp256k1_pubkey* C2_vec,
432 const secp256k1_pubkey* Pk_vec,
433 const unsigned char* context_id
434);
435
440 const secp256k1_context* ctx,
441 const unsigned char* proof,
442 size_t n,
443 const secp256k1_pubkey* C1,
444 const secp256k1_pubkey* C2_vec,
445 const secp256k1_pubkey* Pk_vec,
446 const unsigned char* context_id
447);
448
450 const secp256k1_context* ctx,
451 unsigned char* proof_out,
452 size_t* proof_len,
453 const uint64_t* values,
454 const unsigned char* blindings_flat,
455 size_t m,
456 const secp256k1_pubkey* pk_base,
457 const unsigned char* context_id
458);
460 const secp256k1_context* ctx,
461 const secp256k1_pubkey* G_vec, /* length n = 64*m */
462 const secp256k1_pubkey* H_vec, /* length n = 64*m */
463 const unsigned char* proof,
464 size_t proof_len,
465 const secp256k1_pubkey* commitment_C_vec, /* length m */
466 size_t m,
467 const secp256k1_pubkey* pk_base,
468 const unsigned char* context_id
469);
470
471
472
473
474
475#ifdef __cplusplus
476}
477#endif
478
479#endif // SECP256K1_MPT_H
SECP256K1_API int secp256k1_elgamal_generate_keypair(const secp256k1_context *ctx, unsigned char *privkey, secp256k1_pubkey *pubkey)
Generates a new secp256k1 key pair.
Definition elgamal.c:61
size_t secp256k1_mpt_proof_equality_shared_r_size(size_t n)
int secp256k1_bulletproof_verify_agg(const secp256k1_context *ctx, const secp256k1_pubkey *G_vec, const secp256k1_pubkey *H_vec, const unsigned char *proof, size_t proof_len, const secp256k1_pubkey *commitment_C_vec, size_t m, const secp256k1_pubkey *pk_base, const unsigned char *context_id)
int secp256k1_elgamal_verify_encryption(const secp256k1_context *ctx, const secp256k1_pubkey *c1, const secp256k1_pubkey *c2, const secp256k1_pubkey *pubkey_Q, uint64_t amount, const unsigned char *blinding_factor)
Definition elgamal.c:262
void secp256k1_mpt_scalar_negate(unsigned char *res, const unsigned char *in)
Definition mpt_scalar.c:96
int secp256k1_bulletproof_verify(const secp256k1_context *ctx, const secp256k1_pubkey *G_vec, const secp256k1_pubkey *H_vec, const unsigned char *proof, size_t proof_len, const secp256k1_pubkey *commitment_C, const secp256k1_pubkey *pk_base, const unsigned char *context_id)
SECP256K1_API int secp256k1_equality_plaintext_prove(const secp256k1_context *ctx, unsigned char *proof, const secp256k1_pubkey *c1, const secp256k1_pubkey *c2, const secp256k1_pubkey *pk_recipient, uint64_t amount, const unsigned char *randomness_r, const unsigned char *tx_context_id)
Generates a proof that an ElGamal ciphertext correctly encrypts a known plaintext m and that the prov...
SECP256K1_API size_t secp256k1_mpt_prove_same_plaintext_multi_size(size_t n_ciphertexts)
Calculates the expected proof size for a given number of ciphertexts.
int secp256k1_mpt_pok_sk_prove(const secp256k1_context *ctx, unsigned char *proof, const secp256k1_pubkey *pk, const unsigned char *sk, const unsigned char *context_id)
SECP256K1_API int secp256k1_mpt_verify_same_plaintext_multi(const secp256k1_context *ctx, const unsigned char *proof, size_t proof_len, size_t n_ciphertexts, const secp256k1_pubkey *R_array, const secp256k1_pubkey *S_array, const secp256k1_pubkey *Pk_array, const unsigned char *tx_context_id)
Verifies a proof that N ciphertexts encrypt the same secret amount.
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.
SECP256K1_API int secp256k1_elgamal_decrypt(const secp256k1_context *ctx, uint64_t *amount, const secp256k1_pubkey *c1, const secp256k1_pubkey *c2, const unsigned char *privkey)
Decrypts an ElGamal ciphertext to recover the amount.
Definition elgamal.c:111
int secp256k1_mpt_get_h_generator(const secp256k1_context *ctx, secp256k1_pubkey *h)
Derives the secondary base point (H) for Pedersen commitments.
int secp256k1_mpt_pedersen_commit(const secp256k1_context *ctx, secp256k1_pubkey *commitment, uint64_t amount, const unsigned char *blinding_factor_rho)
Creates a Pedersen Commitment C = amount*G + rho*H.
SECP256K1_API int generate_canonical_encrypted_zero(const secp256k1_context *ctx, secp256k1_pubkey *enc_zero_c1, secp256k1_pubkey *enc_zero_c2, const secp256k1_pubkey *pubkey, const unsigned char *account_id, const unsigned char *mpt_issuance_id)
Generates the canonical encrypted zero for a given MPT token instance.
Definition elgamal.c:211
void secp256k1_mpt_scalar_mul(unsigned char *res, const unsigned char *a, const unsigned char *b)
Definition mpt_scalar.c:73
int secp256k1_mpt_pok_sk_verify(const secp256k1_context *ctx, const unsigned char *proof, const secp256k1_pubkey *pk, const unsigned char *context_id)
int secp256k1_bulletproof_prove_agg(const secp256k1_context *ctx, unsigned char *proof_out, size_t *proof_len, const uint64_t *values, const unsigned char *blindings_flat, size_t m, const secp256k1_pubkey *pk_base, const unsigned char *context_id)
SECP256K1_API int secp256k1_mpt_prove_same_plaintext_multi(const secp256k1_context *ctx, unsigned char *proof_out, size_t *proof_len, uint64_t amount_m, size_t n_ciphertexts, const secp256k1_pubkey *R_array, const secp256k1_pubkey *S_array, const secp256k1_pubkey *Pk_array, const unsigned char *r_array, const unsigned char *tx_context_id)
Generates a proof that N ciphertexts encrypt the same secret amount 'm'.
SECP256K1_API int secp256k1_elgamal_add(const secp256k1_context *ctx, secp256k1_pubkey *sum_c1, secp256k1_pubkey *sum_c2, const secp256k1_pubkey *a_c1, const secp256k1_pubkey *a_c2, const secp256k1_pubkey *b_c1, const secp256k1_pubkey *b_c2)
Homomorphically adds two ElGamal ciphertexts.
Definition elgamal.c:164
SECP256K1_API int secp256k1_mpt_prove_same_plaintext(const secp256k1_context *ctx, unsigned char *proof_out, const secp256k1_pubkey *R1, const secp256k1_pubkey *S1, const secp256k1_pubkey *P1, const secp256k1_pubkey *R2, const secp256k1_pubkey *S2, const secp256k1_pubkey *P2, uint64_t amount_m, const unsigned char *randomness_r1, const unsigned char *randomness_r2, const unsigned char *tx_context_id)
Generates a proof that two ciphertexts (under different keys) encrypt the same secret amount 'm'.
SECP256K1_API int secp256k1_elgamal_subtract(const secp256k1_context *ctx, secp256k1_pubkey *diff_c1, secp256k1_pubkey *diff_c2, const secp256k1_pubkey *a_c1, const secp256k1_pubkey *a_c2, const secp256k1_pubkey *b_c1, const secp256k1_pubkey *b_c2)
Homomorphically subtracts two ElGamal ciphertexts.
Definition elgamal.c:184
int secp256k1_mpt_prove_equality_shared_r(const secp256k1_context *ctx, unsigned char *proof_out, uint64_t amount, const unsigned char *r_shared, size_t n, const secp256k1_pubkey *C1, const secp256k1_pubkey *C2_vec, const secp256k1_pubkey *Pk_vec, const unsigned char *context_id)
void secp256k1_mpt_scalar_reduce32(unsigned char out32[32], const unsigned char in32[32])
Definition mpt_scalar.c:106
SECP256K1_API int secp256k1_elgamal_encrypt(const secp256k1_context *ctx, secp256k1_pubkey *c1, secp256k1_pubkey *c2, const secp256k1_pubkey *pubkey_Q, uint64_t amount, const unsigned char *blinding_factor)
Encrypts a 64-bit amount using ElGamal.
Definition elgamal.c:79
SECP256K1_API int secp256k1_mpt_verify_same_plaintext(const secp256k1_context *ctx, const unsigned char *proof, const secp256k1_pubkey *R1, const secp256k1_pubkey *S1, const secp256k1_pubkey *P1, const secp256k1_pubkey *R2, const secp256k1_pubkey *S2, const secp256k1_pubkey *P2, const unsigned char *tx_context_id)
Verifies a proof that two ciphertexts encrypt the same secret amount.
void secp256k1_mpt_scalar_add(unsigned char *res, const unsigned char *a, const unsigned char *b)
Definition mpt_scalar.c:60
SECP256K1_API int secp256k1_equality_plaintext_verify(const secp256k1_context *ctx, const unsigned char *proof, const secp256k1_pubkey *c1, const secp256k1_pubkey *c2, const secp256k1_pubkey *pk_recipient, uint64_t amount, const unsigned char *tx_context_id)
Verifies a proof of knowledge of plaintext and randomness.
int secp256k1_elgamal_pedersen_link_prove(const secp256k1_context *ctx, unsigned char *proof, const secp256k1_pubkey *c1, const secp256k1_pubkey *c2, const secp256k1_pubkey *pk, const secp256k1_pubkey *pcm, uint64_t amount, const unsigned char *r, const unsigned char *rho, const unsigned char *context_id)
Proves the link between an ElGamal ciphertext and a Pedersen commitment.
Definition proof_link.c:108
int secp256k1_bulletproof_prove(const secp256k1_context *ctx, unsigned char *proof_out, size_t *proof_len, uint64_t value, const unsigned char *blinding_factor, const secp256k1_pubkey *pk_base, const unsigned char *context_id, unsigned int proof_type)
int secp256k1_mpt_verify_equality_shared_r(const secp256k1_context *ctx, const unsigned char *proof, size_t n, const secp256k1_pubkey *C1, const secp256k1_pubkey *C2_vec, const secp256k1_pubkey *Pk_vec, const unsigned char *context_id)
int secp256k1_elgamal_pedersen_link_verify(const secp256k1_context *ctx, const unsigned char *proof, const secp256k1_pubkey *c1, const secp256k1_pubkey *c2, const secp256k1_pubkey *pk, const secp256k1_pubkey *pcm, const unsigned char *context_id)
Verifies the link proof between ElGamal and Pedersen commitments.
Definition proof_link.c:212
void secp256k1_mpt_scalar_inverse(unsigned char *res, const unsigned char *in)
Definition mpt_scalar.c:86
SECP256K1_API int secp256k1_bulletproof_create_commitment(const secp256k1_context *ctx, secp256k1_pubkey *commitment_C, uint64_t value, const unsigned char *blinding_factor, const secp256k1_pubkey *pk_base)
Computes a Pedersen Commitment: C = value*G + blinding_factor*Pk_base.