purify
C++ Purify implementation with native circuit and BPP support
Loading...
Searching...
No Matches
bppp_bridge.h File Reference

C ABI bridging Purify C++ code to secp256k1-zkp BPPP functionality.

#include <stddef.h>
#include "purify/secp_bridge.h"

Go to the source code of this file.

Data Structures

struct  purify_bulletproof_row_view
struct  purify_bulletproof_circuit_view
struct  purify_bulletproof_assignment_view

Typedefs

typedef struct purify_bppp_backend_resources purify_bppp_backend_resources
typedef struct purify_bulletproof_row_view purify_bulletproof_row_view
typedef struct purify_bulletproof_circuit_view purify_bulletproof_circuit_view
typedef struct purify_bulletproof_assignment_view purify_bulletproof_assignment_view
typedef struct purify_bulletproof_backend_resources purify_bulletproof_backend_resources

Functions

size_t purify_bppp_required_proof_size (size_t n_vec_len, size_t c_vec_len)
 Computes the maximum serialized size of a BPPP norm proof.
int purify_bppp_base_generator (purify_secp_context *context, unsigned char out33[33])
 Serializes the secp256k1 base generator into compressed form.
int purify_bppp_value_generator_h (purify_secp_context *context, unsigned char out33[33])
 Serializes the alternate value generator used by Pedersen commitments.
int purify_bppp_create_generators (purify_secp_context *context, size_t count, unsigned char *out, size_t *out_len)
 Expands the generator list required by the BPPP prover and verifier.
purify_bppp_backend_resources * purify_bppp_backend_resources_create (purify_secp_context *context, const unsigned char *generators33, size_t generators_count)
purify_bppp_backend_resources * purify_bppp_backend_resources_clone (const purify_bppp_backend_resources *resources)
void purify_bppp_backend_resources_destroy (purify_bppp_backend_resources *resources)
int purify_bppp_commit_norm_arg (purify_secp_context *context, const unsigned char rho32[32], const unsigned char *generators33, size_t generators_count, const unsigned char *n_vec32, size_t n_vec_len, const unsigned char *l_vec32, size_t l_vec_len, const unsigned char *c_vec32, size_t c_vec_len, unsigned char commitment_out33[33])
int purify_bppp_commit_norm_arg_with_resources (purify_bppp_backend_resources *resources, const unsigned char rho32[32], const unsigned char *n_vec32, size_t n_vec_len, const unsigned char *l_vec32, size_t l_vec_len, const unsigned char *c_vec32, size_t c_vec_len, unsigned char commitment_out33[33])
int purify_bppp_commit_witness_only (purify_secp_context *context, const unsigned char *generators33, size_t generators_count, const unsigned char *n_vec32, size_t n_vec_len, const unsigned char *l_vec32, size_t l_vec_len, unsigned char commitment_out33[33])
int purify_bppp_commit_witness_only_with_resources (purify_bppp_backend_resources *resources, const unsigned char *n_vec32, size_t n_vec_len, const unsigned char *l_vec32, size_t l_vec_len, unsigned char commitment_out33[33])
int purify_bppp_offset_commitment (purify_secp_context *context, const unsigned char commitment33[33], const unsigned char scalar32[32], unsigned char commitment_out33[33])
int purify_point_scale (purify_secp_context *context, const unsigned char point33[33], const unsigned char scalar32[32], unsigned char out33[33])
int purify_point_add (purify_secp_context *context, const unsigned char lhs33[33], const unsigned char rhs33[33], unsigned char out33[33])
int purify_pedersen_commit_char (purify_secp_context *context, const unsigned char blind32[32], const unsigned char value32[32], const unsigned char value_gen33[33], const unsigned char blind_gen33[33], unsigned char commitment_out33[33])
 Computes a Pedersen commitment to an arbitrary 32-byte scalar value.
int purify_bppp_prove_norm_arg (purify_secp_context *context, const unsigned char rho32[32], const unsigned char *generators33, size_t generators_count, const unsigned char *n_vec32, size_t n_vec_len, const unsigned char *l_vec32, size_t l_vec_len, const unsigned char *c_vec32, size_t c_vec_len, unsigned char commitment_out33[33], unsigned char *proof_out, size_t *proof_len)
 Produces a standalone BPPP norm argument.
int purify_bppp_prove_norm_arg_with_resources (purify_bppp_backend_resources *resources, const unsigned char rho32[32], const unsigned char *n_vec32, size_t n_vec_len, const unsigned char *l_vec32, size_t l_vec_len, const unsigned char *c_vec32, size_t c_vec_len, unsigned char commitment_out33[33], unsigned char *proof_out, size_t *proof_len)
int purify_bppp_prove_norm_arg_to_commitment (purify_secp_context *context, const unsigned char rho32[32], const unsigned char *generators33, size_t generators_count, const unsigned char *n_vec32, size_t n_vec_len, const unsigned char *l_vec32, size_t l_vec_len, const unsigned char *c_vec32, size_t c_vec_len, const unsigned char commitment33[33], unsigned char *proof_out, size_t *proof_len)
int purify_bppp_prove_norm_arg_to_commitment_with_resources (purify_bppp_backend_resources *resources, const unsigned char rho32[32], const unsigned char *n_vec32, size_t n_vec_len, const unsigned char *l_vec32, size_t l_vec_len, const unsigned char *c_vec32, size_t c_vec_len, const unsigned char commitment33[33], unsigned char *proof_out, size_t *proof_len)
int purify_bppp_verify_norm_arg (purify_secp_context *context, const unsigned char rho32[32], const unsigned char *generators33, size_t generators_count, const unsigned char *c_vec32, size_t c_vec_len, size_t n_vec_len, const unsigned char commitment33[33], const unsigned char *proof, size_t proof_len)
 Verifies a standalone BPPP norm argument.
int purify_bppp_verify_norm_arg_with_resources (purify_bppp_backend_resources *resources, const unsigned char rho32[32], const unsigned char *c_vec32, size_t c_vec_len, size_t n_vec_len, const unsigned char commitment33[33], const unsigned char *proof, size_t proof_len)
size_t purify_bulletproof_required_proof_size (size_t n_gates)
purify_bulletproof_backend_resources * purify_bulletproof_backend_resources_create (purify_secp_context *context, size_t n_gates)
purify_bulletproof_backend_resources * purify_bulletproof_backend_resources_clone (const purify_bulletproof_backend_resources *resources)
void purify_bulletproof_backend_resources_destroy (purify_bulletproof_backend_resources *resources)
int purify_bulletproof_prove_circuit (purify_secp_context *context, const purify_bulletproof_circuit_view *circuit, const purify_bulletproof_assignment_view *assignment, const unsigned char *blind32, const unsigned char value_gen33[33], const unsigned char nonce32[32], const unsigned char *extra_commit, size_t extra_commit_len, unsigned char commitment_out33[33], unsigned char *proof_out, size_t *proof_len)
int purify_bulletproof_prove_circuit_with_resources (purify_bulletproof_backend_resources *resources, const purify_bulletproof_circuit_view *circuit, const purify_bulletproof_assignment_view *assignment, const unsigned char *blind32, const unsigned char value_gen33[33], const unsigned char nonce32[32], const unsigned char *extra_commit, size_t extra_commit_len, unsigned char commitment_out33[33], unsigned char *proof_out, size_t *proof_len)
int purify_bulletproof_prove_circuit_assume_valid (purify_secp_context *context, const purify_bulletproof_circuit_view *circuit, const purify_bulletproof_assignment_view *assignment, const unsigned char *blind32, const unsigned char value_gen33[33], const unsigned char nonce32[32], const unsigned char *extra_commit, size_t extra_commit_len, unsigned char commitment_out33[33], unsigned char *proof_out, size_t *proof_len)
int purify_bulletproof_prove_circuit_assume_valid_with_resources (purify_bulletproof_backend_resources *resources, const purify_bulletproof_circuit_view *circuit, const purify_bulletproof_assignment_view *assignment, const unsigned char *blind32, const unsigned char value_gen33[33], const unsigned char nonce32[32], const unsigned char *extra_commit, size_t extra_commit_len, unsigned char commitment_out33[33], unsigned char *proof_out, size_t *proof_len)
int purify_bulletproof_verify_circuit (purify_secp_context *context, const purify_bulletproof_circuit_view *circuit, const unsigned char commitment33[33], const unsigned char value_gen33[33], const unsigned char *extra_commit, size_t extra_commit_len, const unsigned char *proof, size_t proof_len)
int purify_bulletproof_verify_circuit_with_resources (purify_bulletproof_backend_resources *resources, const purify_bulletproof_circuit_view *circuit, const unsigned char commitment33[33], const unsigned char value_gen33[33], const unsigned char *extra_commit, size_t extra_commit_len, const unsigned char *proof, size_t proof_len)

Typedef Documentation

◆ purify_bppp_backend_resources

typedef struct purify_bppp_backend_resources purify_bppp_backend_resources

Definition at line 20 of file bppp_bridge.h.

◆ purify_bulletproof_assignment_view

typedef struct purify_bulletproof_assignment_view purify_bulletproof_assignment_view

◆ purify_bulletproof_backend_resources

typedef struct purify_bulletproof_backend_resources purify_bulletproof_backend_resources

Definition at line 189 of file bppp_bridge.h.

◆ purify_bulletproof_circuit_view

typedef struct purify_bulletproof_circuit_view purify_bulletproof_circuit_view

◆ purify_bulletproof_row_view

typedef struct purify_bulletproof_row_view purify_bulletproof_row_view

Function Documentation

◆ purify_bppp_backend_resources_clone()

◆ purify_bppp_backend_resources_create()

◆ purify_bppp_backend_resources_destroy()

◆ purify_bppp_base_generator()

int purify_bppp_base_generator ( purify_secp_context * context,
unsigned char out33[33] )

Definition at line 1618 of file bppp_bridge.c.

References purify_context_handle().

Referenced by purify::bppp::base_generator().

◆ purify_bppp_commit_norm_arg()

int purify_bppp_commit_norm_arg ( purify_secp_context * context,
const unsigned char rho32[32],
const unsigned char * generators33,
size_t generators_count,
const unsigned char * n_vec32,
size_t n_vec_len,
const unsigned char * l_vec32,
size_t l_vec_len,
const unsigned char * c_vec32,
size_t c_vec_len,
unsigned char commitment_out33[33] )

◆ purify_bppp_commit_norm_arg_with_resources()

int purify_bppp_commit_norm_arg_with_resources ( purify_bppp_backend_resources * resources,
const unsigned char rho32[32],
const unsigned char * n_vec32,
size_t n_vec_len,
const unsigned char * l_vec32,
size_t l_vec_len,
const unsigned char * c_vec32,
size_t c_vec_len,
unsigned char commitment_out33[33] )

◆ purify_bppp_commit_witness_only()

int purify_bppp_commit_witness_only ( purify_secp_context * context,
const unsigned char * generators33,
size_t generators_count,
const unsigned char * n_vec32,
size_t n_vec_len,
const unsigned char * l_vec32,
size_t l_vec_len,
unsigned char commitment_out33[33] )

Definition at line 1860 of file bppp_bridge.c.

References purify_bppp_commit_witness_only_impl().

◆ purify_bppp_commit_witness_only_with_resources()

int purify_bppp_commit_witness_only_with_resources ( purify_bppp_backend_resources * resources,
const unsigned char * n_vec32,
size_t n_vec_len,
const unsigned char * l_vec32,
size_t l_vec_len,
unsigned char commitment_out33[33] )

◆ purify_bppp_create_generators()

int purify_bppp_create_generators ( purify_secp_context * context,
size_t count,
unsigned char * out,
size_t * out_len )
Parameters
countNumber of generators requested.
outOutput buffer for count compressed points.
out_lenIn/out serialized byte length.
Returns
Nonzero on success.

Definition at line 1643 of file bppp_bridge.c.

References purify_bridge_checked_mul_size(), and purify_context_handle().

Referenced by purify::bppp::create_generators().

◆ purify_bppp_offset_commitment()

int purify_bppp_offset_commitment ( purify_secp_context * context,
const unsigned char commitment33[33],
const unsigned char scalar32[32],
unsigned char commitment_out33[33] )

◆ purify_bppp_prove_norm_arg()

int purify_bppp_prove_norm_arg ( purify_secp_context * context,
const unsigned char rho32[32],
const unsigned char * generators33,
size_t generators_count,
const unsigned char * n_vec32,
size_t n_vec_len,
const unsigned char * l_vec32,
size_t l_vec_len,
const unsigned char * c_vec32,
size_t c_vec_len,
unsigned char commitment_out33[33],
unsigned char * proof_out,
size_t * proof_len )
Parameters
rho32Fiat-Shamir seed.
generators33Serialized generator list.
generators_countNumber of generators in generators33.
n_vec32Serialized n vector.
n_vec_lenLength of the n vector.
l_vec32Serialized l vector.
l_vec_lenLength of the l vector.
c_vec32Serialized c vector.
c_vec_lenLength of the c vector.
commitment_out33Commitment output used by the proof.
proof_outOutput buffer for the serialized proof.
proof_lenIn/out proof buffer length.
Returns
Nonzero on success.

Definition at line 2044 of file bppp_bridge.c.

References purify_bppp_prove_norm_arg_impl().

◆ purify_bppp_prove_norm_arg_to_commitment()

int purify_bppp_prove_norm_arg_to_commitment ( purify_secp_context * context,
const unsigned char rho32[32],
const unsigned char * generators33,
size_t generators_count,
const unsigned char * n_vec32,
size_t n_vec_len,
const unsigned char * l_vec32,
size_t l_vec_len,
const unsigned char * c_vec32,
size_t c_vec_len,
const unsigned char commitment33[33],
unsigned char * proof_out,
size_t * proof_len )

◆ purify_bppp_prove_norm_arg_to_commitment_with_resources()

int purify_bppp_prove_norm_arg_to_commitment_with_resources ( purify_bppp_backend_resources * resources,
const unsigned char rho32[32],
const unsigned char * n_vec32,
size_t n_vec_len,
const unsigned char * l_vec32,
size_t l_vec_len,
const unsigned char * c_vec32,
size_t c_vec_len,
const unsigned char commitment33[33],
unsigned char * proof_out,
size_t * proof_len )

◆ purify_bppp_prove_norm_arg_with_resources()

int purify_bppp_prove_norm_arg_with_resources ( purify_bppp_backend_resources * resources,
const unsigned char rho32[32],
const unsigned char * n_vec32,
size_t n_vec_len,
const unsigned char * l_vec32,
size_t l_vec_len,
const unsigned char * c_vec32,
size_t c_vec_len,
unsigned char commitment_out33[33],
unsigned char * proof_out,
size_t * proof_len )

◆ purify_bppp_required_proof_size()

size_t purify_bppp_required_proof_size ( size_t n_vec_len,
size_t c_vec_len )
Parameters
n_vec_lenLength of the n vector.
c_vec_lenLength of the c vector.
Returns
Required output buffer size in bytes.

Definition at line 1603 of file bppp_bridge.c.

References purify_bridge_checked_add_size(), and purify_bridge_checked_mul_size().

Referenced by purify::bppp::prove_norm_arg_to_commitment_with_cache(), purify_bppp_prove_norm_arg_impl(), and purify_bppp_prove_norm_arg_to_commitment_impl().

◆ purify_bppp_value_generator_h()

int purify_bppp_value_generator_h ( purify_secp_context * context,
unsigned char out33[33] )

Definition at line 1632 of file bppp_bridge.c.

References purify_context_handle().

Referenced by purify::bppp::value_generator_h().

◆ purify_bppp_verify_norm_arg()

int purify_bppp_verify_norm_arg ( purify_secp_context * context,
const unsigned char rho32[32],
const unsigned char * generators33,
size_t generators_count,
const unsigned char * c_vec32,
size_t c_vec_len,
size_t n_vec_len,
const unsigned char commitment33[33],
const unsigned char * proof,
size_t proof_len )
Parameters
rho32Fiat-Shamir seed.
generators33Serialized generator list.
generators_countNumber of generators in generators33.
c_vec32Serialized c vector.
c_vec_lenLength of the c vector.
n_vec_lenLength of the hidden n vector.
commitment33Serialized compressed commitment point.
proofSerialized proof bytes.
proof_lenProof length in bytes.
Returns
Nonzero on success.

Definition at line 2247 of file bppp_bridge.c.

References purify_bppp_verify_norm_arg_impl().

Referenced by purify::bppp::verify_norm_arg_with_cache().

◆ purify_bppp_verify_norm_arg_with_resources()

int purify_bppp_verify_norm_arg_with_resources ( purify_bppp_backend_resources * resources,
const unsigned char rho32[32],
const unsigned char * c_vec32,
size_t c_vec_len,
size_t n_vec_len,
const unsigned char commitment33[33],
const unsigned char * proof,
size_t proof_len )

◆ purify_bulletproof_backend_resources_clone()

◆ purify_bulletproof_backend_resources_create()

◆ purify_bulletproof_backend_resources_destroy()

◆ purify_bulletproof_prove_circuit()

int purify_bulletproof_prove_circuit ( purify_secp_context * context,
const purify_bulletproof_circuit_view * circuit,
const purify_bulletproof_assignment_view * assignment,
const unsigned char * blind32,
const unsigned char value_gen33[33],
const unsigned char nonce32[32],
const unsigned char * extra_commit,
size_t extra_commit_len,
unsigned char commitment_out33[33],
unsigned char * proof_out,
size_t * proof_len )

Definition at line 1322 of file bppp_bridge.c.

References purify_bulletproof_prove_circuit_impl().

◆ purify_bulletproof_prove_circuit_assume_valid()

int purify_bulletproof_prove_circuit_assume_valid ( purify_secp_context * context,
const purify_bulletproof_circuit_view * circuit,
const purify_bulletproof_assignment_view * assignment,
const unsigned char * blind32,
const unsigned char value_gen33[33],
const unsigned char nonce32[32],
const unsigned char * extra_commit,
size_t extra_commit_len,
unsigned char commitment_out33[33],
unsigned char * proof_out,
size_t * proof_len )

Definition at line 1354 of file bppp_bridge.c.

References purify_bulletproof_prove_circuit_impl().

◆ purify_bulletproof_prove_circuit_assume_valid_with_resources()

int purify_bulletproof_prove_circuit_assume_valid_with_resources ( purify_bulletproof_backend_resources * resources,
const purify_bulletproof_circuit_view * circuit,
const purify_bulletproof_assignment_view * assignment,
const unsigned char * blind32,
const unsigned char value_gen33[33],
const unsigned char nonce32[32],
const unsigned char * extra_commit,
size_t extra_commit_len,
unsigned char commitment_out33[33],
unsigned char * proof_out,
size_t * proof_len )

Definition at line 1370 of file bppp_bridge.c.

References purify_bulletproof_prove_circuit_impl().

◆ purify_bulletproof_prove_circuit_with_resources()

int purify_bulletproof_prove_circuit_with_resources ( purify_bulletproof_backend_resources * resources,
const purify_bulletproof_circuit_view * circuit,
const purify_bulletproof_assignment_view * assignment,
const unsigned char * blind32,
const unsigned char value_gen33[33],
const unsigned char nonce32[32],
const unsigned char * extra_commit,
size_t extra_commit_len,
unsigned char commitment_out33[33],
unsigned char * proof_out,
size_t * proof_len )

Definition at line 1338 of file bppp_bridge.c.

References purify_bulletproof_prove_circuit_impl().

◆ purify_bulletproof_required_proof_size()

size_t purify_bulletproof_required_proof_size ( size_t n_gates)

◆ purify_bulletproof_verify_circuit()

int purify_bulletproof_verify_circuit ( purify_secp_context * context,
const purify_bulletproof_circuit_view * circuit,
const unsigned char commitment33[33],
const unsigned char value_gen33[33],
const unsigned char * extra_commit,
size_t extra_commit_len,
const unsigned char * proof,
size_t proof_len )

◆ purify_bulletproof_verify_circuit_with_resources()

int purify_bulletproof_verify_circuit_with_resources ( purify_bulletproof_backend_resources * resources,
const purify_bulletproof_circuit_view * circuit,
const unsigned char commitment33[33],
const unsigned char value_gen33[33],
const unsigned char * extra_commit,
size_t extra_commit_len,
const unsigned char * proof,
size_t proof_len )

◆ purify_pedersen_commit_char()

int purify_pedersen_commit_char ( purify_secp_context * context,
const unsigned char blind32[32],
const unsigned char value32[32],
const unsigned char value_gen33[33],
const unsigned char blind_gen33[33],
unsigned char commitment_out33[33] )
Parameters
blind32Blinding factor in big-endian scalar form.
value32Committed value in big-endian scalar form.
value_gen33Compressed generator for the value term.
blind_gen33Compressed generator for the blind term.
commitment_out33Serialized compressed commitment output.
Returns
Nonzero on success.

Definition at line 1669 of file bppp_bridge.c.

References purify_context_handle(), purify_parse_scalar(), and purify_serialize_point().

Referenced by purify::bppp::pedersen_commit_char().

◆ purify_point_add()

int purify_point_add ( purify_secp_context * context,
const unsigned char lhs33[33],
const unsigned char rhs33[33],
unsigned char out33[33] )

◆ purify_point_scale()

int purify_point_scale ( purify_secp_context * context,
const unsigned char point33[33],
const unsigned char scalar32[32],
unsigned char out33[33] )