18constexpr std::array<std::uint32_t, 64> kRound = {
19 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1,
20 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
21 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786,
22 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
23 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147,
24 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
25 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b,
26 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
27 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a,
28 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
29 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2};
31inline std::uint32_t rotr(std::uint32_t
x,
int n)
33 return (
x >> n) | (
x << (32 - n));
36void compress(std::array<std::uint32_t, 8>& h,
const std::uint8_t* block)
38 std::array<std::uint32_t, 64> w{};
39 for (
int i = 0; i < 16; ++i) {
40 w[i] = (std::uint32_t(block[4 * i]) << 24) |
41 (std::uint32_t(block[4 * i + 1]) << 16) |
42 (std::uint32_t(block[4 * i + 2]) << 8) |
43 std::uint32_t(block[4 * i + 3]);
45 for (
int i = 16; i < 64; ++i) {
46 const std::uint32_t s0 =
47 rotr(w[i - 15], 7) ^ rotr(w[i - 15], 18) ^ (w[i - 15] >> 3);
48 const std::uint32_t s1 =
49 rotr(w[i - 2], 17) ^ rotr(w[i - 2], 19) ^ (w[i - 2] >> 10);
50 w[i] = w[i - 16] + s0 + w[i - 7] + s1;
53 for (
int i = 0; i < 64; ++i) {
54 const std::uint32_t s1 =
55 rotr(v[4], 6) ^ rotr(v[4], 11) ^ rotr(v[4], 25);
56 const std::uint32_t ch = (v[4] & v[5]) ^ (~v[4] & v[6]);
57 const std::uint32_t t1 = v[7] + s1 + ch + kRound[i] + w[i];
58 const std::uint32_t s0 =
59 rotr(v[0], 2) ^ rotr(v[0], 13) ^ rotr(v[0], 22);
60 const std::uint32_t maj = (v[0] & v[1]) ^ (v[0] & v[2]) ^ (v[1] & v[2]);
61 const std::uint32_t t2 = s0 + maj;
71 for (
int i = 0; i < 8; ++i)
77 void update(
const std::uint8_t* data, std::size_t size)
81 const std::size_t take = std::min(size, std::size_t(64) - fill_);
82 std::memcpy(buffer_.data() + fill_, data, take);
87 compress(h_, buffer_.data());
95 const std::uint64_t bits = total_ * 8;
96 const std::uint8_t pad = 0x80;
98 const std::uint8_t zero = 0;
101 std::array<std::uint8_t, 8> length{};
102 for (
int i = 0; i < 8; ++i) {
103 length[i] =
static_cast<std::uint8_t
>(bits >> (56 - 8 * i));
105 update(length.data(), 8);
106 static const char* digits =
"0123456789abcdef";
108 for (
const std::uint32_t word: h_) {
109 for (
int shift = 28; shift >= 0; shift -= 4) {
110 out.push_back(digits[(word >> shift) & 0xf]);
117 std::array<std::uint32_t, 8> h_ = {0x6a09e667, 0xbb67ae85, 0x3c6ef372,
118 0xa54ff53a, 0x510e527f, 0x9b05688c,
119 0x1f83d9ab, 0x5be0cd19};
120 std::array<std::uint8_t, 64> buffer_{};
121 std::size_t fill_ = 0;
122 std::uint64_t total_ = 0;
127std::string
sha256Hex(
const void* data, std::size_t size)
130 hasher.update(
static_cast<const std::uint8_t*
>(data), size);
131 return hasher.finish();
136 std::ifstream in(path, std::ios::binary);
139 std::vector<std::uint8_t> chunk(1 << 20);
141 in.read(
reinterpret_cast<char*
>(chunk.data()),
142 static_cast<std::streamsize
>(chunk.size()));
143 hasher.update(chunk.data(),
static_cast<std::size_t
>(in.gcount()));
145 return in.eof() ? hasher.finish() : std::string();
eon_relax_band_t eon_relax_surface_fn void eon_relax_outcome_t * out
Gaussian-process regression, kernels, priors, and the searches that run on the surrogate.
std::string sha256Hex(const void *data, std::size_t size)
Lowercase hexadecimal SHA-256 digest of a byte range (FIPS 180-4).
std::string sha256File(const std::string &path)
Digest of a file's contents; empty when the file cannot be read.
Panel finish(Real left, Real right, const Value &k, const Value &g, const Value &absolute)