|
| 1 | +#include "c_wrapper.h" |
| 2 | +#include <vector> |
| 3 | +#include <gmpxx.h> |
| 4 | +#include "../verifier.h" |
| 5 | +#include "../prover_slow.h" |
| 6 | + |
| 7 | +extern "C" { |
| 8 | + // C wrapper function |
| 9 | + const char* create_discriminant_wrapper(const uint8_t* seed, size_t seed_size, int length) { |
| 10 | + std::vector<uint8_t> seedVector(seed, seed + seed_size); |
| 11 | + integer result = CreateDiscriminant(seedVector, length); |
| 12 | + |
| 13 | + // Serialize the 'result' to a string |
| 14 | + std::string resultStr = result.to_string(); |
| 15 | + |
| 16 | + // Allocate a new C-string to hold the serialized result |
| 17 | + char* cResultStr = new char[resultStr.length() + 1]; |
| 18 | + std::strcpy(cResultStr, resultStr.c_str()); |
| 19 | + |
| 20 | + return cResultStr; // Return the C-string |
| 21 | + } |
| 22 | + |
| 23 | + ByteArray prove_wrapper(const uint8_t* challenge_hash, size_t challenge_size, const uint8_t* x_s, size_t x_s_size, int discriminant_size_bits, uint64_t num_iterations) { |
| 24 | + std::vector<uint8_t> challenge_hash_bytes(challenge_hash, challenge_hash + challenge_size); |
| 25 | + integer D = CreateDiscriminant(challenge_hash_bytes, discriminant_size_bits); |
| 26 | + form x = DeserializeForm(D, (const uint8_t*)x_s, x_s_size); |
| 27 | + std::vector<uint8_t> result = ProveSlow(D, x, num_iterations); |
| 28 | + |
| 29 | + // Allocate memory for the result and copy data |
| 30 | + uint8_t* resultData = new uint8_t[result.size()]; |
| 31 | + std::copy(result.begin(), result.end(), resultData); |
| 32 | + |
| 33 | + // Create and return a ByteArray struct |
| 34 | + ByteArray resultArray = { resultData, result.size() }; |
| 35 | + return resultArray; |
| 36 | + } |
| 37 | + |
| 38 | + int verify_n_wesolowski_wrapper(const char* discriminant_str, size_t discriminant_size, const char* x_s, size_t x_s_size, const char* proof_blob, size_t proof_blob_size, uint64_t num_iterations, uint64_t disc_size_bits, uint64_t recursion) { |
| 39 | + std::vector<uint8_t> x_s_v(x_s, x_s + x_s_size); |
| 40 | + std::vector<uint8_t> proof_blob_v(proof_blob, proof_blob + proof_blob_size); |
| 41 | + |
| 42 | + bool result = CheckProofOfTimeNWesolowski(integer(discriminant_str), x_s_v.data(), proof_blob_v.data(), proof_blob_v.size(), num_iterations, disc_size_bits, recursion); |
| 43 | + |
| 44 | + return result ? 1 : 0; |
| 45 | + } |
| 46 | +} |
0 commit comments