|
mpt-crypto
Confidential Multi-Purpose Tokens Cryptographic Library
|
EC-ElGamal Encryption for Confidential Balances. More...
#include "secp256k1_mpt.h"#include <openssl/rand.h>#include <openssl/sha.h>#include <string.h>#include <stdlib.h>
Go to the source code of this file.
Functions | |
| static int | pubkey_equal (const secp256k1_context *ctx, const secp256k1_pubkey *pk1, const secp256k1_pubkey *pk2) |
| static int | compute_amount_point (const secp256k1_context *ctx, secp256k1_pubkey *mG, uint64_t amount) |
| int | secp256k1_elgamal_generate_keypair (const secp256k1_context *ctx, unsigned char *privkey, secp256k1_pubkey *pubkey) |
| Generates a new secp256k1 key pair. | |
| 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. | |
| 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. | |
| 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. | |
| 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. | |
| 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. | |
| 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) |
EC-ElGamal Encryption for Confidential Balances.
This module implements additive homomorphic encryption using the ElGamal scheme over the secp256k1 elliptic curve. It provides the core mechanism for representing confidential balances and transferring value on the ledger.
Encryption Scheme: Given a public key \( Q = sk \cdot G \) and a plaintext amount \( m \), encryption with randomness \( r \) produces a ciphertext pair \( (C_1, C_2) \):
Homomorphism: The scheme is additively homomorphic:
\[ Enc(m_1) + Enc(m_2) = (C_{1,1}+C_{1,2}, C_{2,1}+C_{2,2}) = Enc(m_1 + m_2) \]
This allows validators to update balances (e.g., add incoming transfers) without decrypting them.
Decryption (Discrete Logarithm): Decryption involves two steps:
Canonical Zero: To ensure deterministic ledger state for empty accounts, a "Canonical Encrypted Zero" is defined using randomness derived deterministically from the account ID and token ID.
Definition in file elgamal.c.
|
static |
| 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.
This ciphertext represents a zero balance for a specific account's holding of a token defined by its MPTokenIssuanceID.
| [in] | ctx | A pointer to a valid secp256k1 context. |
| [out] | enc_zero_c1 | The C1 component of the canonical ciphertext. |
| [out] | enc_zero_c2 | The C2 component of the canonical ciphertext. |
| [in] | pubkey | The ElGamal public key of the account holder. |
| [in] | account_id | A pointer to the 20-byte AccountID. |
| [in] | mpt_issuance_id | A pointer to the 24-byte MPTokenIssuanceID. |
Definition at line 211 of file elgamal.c.

|
static |
| 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 ) |
| int secp256k1_elgamal_decrypt | ( | const secp256k1_context * | ctx, |
| uint64_t * | amount, | ||
| const secp256k1_pubkey * | c1, | ||
| const secp256k1_pubkey * | c2, | ||
| const unsigned char * | privkey ) |
| 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 ) |
| int secp256k1_elgamal_generate_keypair | ( | const secp256k1_context * | ctx, |
| unsigned char * | privkey, | ||
| secp256k1_pubkey * | pubkey ) |
| 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 ) |
| 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 ) |