secubox-openwrt/package/secubox/zkp-hamiltonian/include/zkp_graph.h
CyberMind-FR 6553936886 feat(zkp-hamiltonian): Add Zero-Knowledge Proof library based on Hamiltonian Cycle
Implements NIZK (Non-Interactive Zero-Knowledge) proof protocol using
Blum's Hamiltonian Cycle construction with Fiat-Shamir transformation.

Features:
- Complete C99 library with SHA3-256 commitments (via OpenSSL)
- Graph generation with embedded trapdoor (Hamiltonian cycle)
- NIZK proof generation and verification
- Binary serialization for proofs, graphs, and cycles
- CLI tools: zkp_keygen, zkp_prover, zkp_verifier
- Comprehensive test suite (41 tests)

Security properties:
- Completeness: honest prover always convinces verifier
- Soundness: cheater fails with probability >= 1 - 2^(-128)
- Zero-Knowledge: verifier learns nothing about the secret cycle

Target: OpenWrt ARM (SecuBox authentication module)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-24 09:59:16 +01:00

120 lines
2.8 KiB
C

/**
* @file zkp_graph.h
* @brief Graph operations for ZKP Hamiltonian protocol
* @version 1.0
*
* Provides graph manipulation, cycle validation, and trapdoor generation.
*/
#ifndef ZKP_GRAPH_H
#define ZKP_GRAPH_H
#include "zkp_types.h"
/**
* @brief Initialize an empty graph
*
* @param G Graph to initialize
* @param n Number of nodes
*/
void zkp_graph_init(Graph *G, uint8_t n);
/**
* @brief Add undirected edge (u, v) to graph
*
* @param G Graph to modify
* @param u First node
* @param v Second node
*/
void zkp_graph_add_edge(Graph *G, uint8_t u, uint8_t v);
/**
* @brief Check if edge (u, v) exists in graph
*
* @param G Graph to query
* @param u First node
* @param v Second node
* @return true if edge exists
*/
bool zkp_graph_has_edge(const Graph *G, uint8_t u, uint8_t v);
/**
* @brief Validate that H is a valid Hamiltonian cycle in G
*
* Checks:
* - H has exactly n nodes
* - All nodes are distinct
* - All cycle edges exist in G
*
* @param G Graph
* @param H Cycle to validate
* @return true if H is a valid Hamiltonian cycle in G
*/
bool zkp_validate_hamiltonian_cycle(const Graph *G, const HamiltonianCycle *H);
/**
* @brief Check if graph is connected (BFS)
*
* @param G Graph to check
* @return true if graph is connected
*/
bool zkp_graph_is_connected(const Graph *G);
/**
* @brief Apply permutation to graph: out = π(G)
*
* @param G Input graph
* @param perm Permutation array
* @param out Output permuted graph
*/
void zkp_graph_permute(const Graph *G, const uint8_t perm[ZKP_MAX_N], Graph *out);
/**
* @brief Apply permutation to cycle: out = π(H)
*
* @param H Input cycle
* @param perm Permutation array
* @param out Output permuted cycle
*/
void zkp_cycle_permute(const HamiltonianCycle *H, const uint8_t perm[ZKP_MAX_N],
HamiltonianCycle *out);
/**
* @brief Generate graph with embedded Hamiltonian cycle (trapdoor)
*
* Creates a graph G containing a hidden Hamiltonian cycle H.
* Additional edges are added as decoys.
*
* @param n Number of nodes (recommended: 50-80)
* @param extra_ratio Ratio of extra edges to n (recommended: 0.5-1.5)
* @param out_graph Output graph
* @param out_cycle Output Hamiltonian cycle (trapdoor)
* @return ZKP_OK on success
*/
ZKPResult zkp_generate_graph(uint8_t n, double extra_ratio,
Graph *out_graph, HamiltonianCycle *out_cycle);
/**
* @brief Count edges in graph
*
* @param G Graph
* @return Number of edges
*/
uint32_t zkp_graph_edge_count(const Graph *G);
/**
* @brief Print graph (debug, only in tools/tests)
*
* @param G Graph to print
*/
void zkp_graph_print(const Graph *G);
/**
* @brief Print cycle (debug, only in tools/tests)
*
* @param H Cycle to print
*/
void zkp_cycle_print(const HamiltonianCycle *H);
#endif /* ZKP_GRAPH_H */