15#include <gnutls/gnutls.h>
16#include <gnutls/crypto.h>
17#if GNUTLS_VERSION_NUMBER >= 0x020a00
18#define HAVE_GNUTLS_HASH_FUNCTIONS
25#ifdef HAVE_GNUTLS_HASH_FUNCTIONS
31#ifndef HAVE_GNUTLS_HASH_FUNCTIONS
40#ifdef HAVE_GNUTLS_HASH_FUNCTIONS
41 gnutls_hash_deinit((gnutls_hash_hd_t)
hash_data,
nullptr);
47#ifndef HAVE_GNUTLS_HASH_FUNCTIONS
48 MFEM_CONTRACT_VAR(buffer);
49 MFEM_CONTRACT_VAR(num_bytes);
51 gnutls_hash((gnutls_hash_hd_t)
hash_data, buffer, num_bytes);
55inline constexpr char to_hex(
unsigned char u)
57 return (
u < 10) ?
'0' +
u : (
u < 16) ?
'a' + (
u - 10) :
'?';
63#ifndef MFEM_USE_GNUTLS
64 hash =
"(GnuTLS is required for hashing)";
65#elif !defined (HAVE_GNUTLS_HASH_FUNCTIONS)
66 hash =
"(Old GnuTLS version: does not support hashing)";
68 constexpr unsigned max_hash_len = 64;
69 unsigned char hash_bytes[max_hash_len];
71 MFEM_VERIFY(hash_len <= max_hash_len,
"internal error");
72 hash.reserve(2*hash_len);
73 gnutls_hash_output((gnutls_hash_hd_t)
hash_data, hash_bytes);
74 for (
unsigned i = 0; i < hash_len; i++)
76 hash +=
to_hex(hash_bytes[i]/16);
77 hash +=
to_hex(hash_bytes[i]%16);
HashFunction()
Default constructor: initialize the hash function.
std::string GetHash() const
Return the hash string for the current sequence and reset (clear) the sequence.
~HashFunction()
Destructor.
void HashBuffer(const void *buffer, size_t num_bytes)
Add a sequence of bytes for hashing.
real_t u(const Vector &xvec)
constexpr gnutls_digest_algorithm_t HASH_ALGORITHM
constexpr char to_hex(unsigned char u)