12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- #include "proof.hpp"
- /* Altered from answer at
- * https://stackoverflow.com/questions/51144505/generate-sha-3-hash-in-c-using-openssl-library
- */
- // Convert the bytes to a single integer, then make that a Scalar
- Scalar bytes_to_scalar(const std::vector<uint8_t>& bytes)
- {
- std::stringstream stream;
- for (uint8_t b : bytes)
- {
- stream << std::setw(2)
- << std::setfill('0')
- << std::hex
- << static_cast<int>(b);
- }
- mpz_class value;
- value.set_str(stream.str(), 16);
- return Scalar(value);
- }
- // Random Oracle (i.e. SHA3_256)
- Scalar oracle(const std::string& input)
- {
- uint32_t digest_length = SHA256_DIGEST_LENGTH;
- const EVP_MD* algorithm = EVP_sha3_256();
- uint8_t* digest = static_cast<uint8_t*>(OPENSSL_malloc(digest_length));
-
- EVP_MD_CTX* context = EVP_MD_CTX_new();
- EVP_DigestInit_ex(context, algorithm, NULL);
- EVP_DigestUpdate(context, input.c_str(), input.size());
- EVP_DigestFinal_ex(context, digest, &digest_length);
- EVP_MD_CTX_destroy(context);
- std::vector<uint8_t> digestBytes(digest, digest + digest_length);
- Scalar output = bytes_to_scalar(digestBytes);
- OPENSSL_free(digest);
- return output;
- }
- Proof::Proof()
- { /* Do nothing */ }
- Proof::Proof(std::string hbc)
- : hbc(hbc)
- { /* Do nothing */ }
|