forked from kimlaine/bootcamp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhash.h
44 lines (36 loc) · 1.26 KB
/
hash.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
#pragma once
#include <array>
#include "seal/util/common.h"
#include "seal/util/defines.h"
#include "seal/util/blake2.h"
namespace seal
{
namespace util
{
class HashFunction
{
public:
HashFunction() = delete;
static constexpr std::size_t hash_block_uint64_count = 4;
static constexpr std::size_t hash_block_byte_count =
hash_block_uint64_count * bytes_per_uint64;
using hash_block_type = std::array<std::uint64_t, hash_block_uint64_count>;
static constexpr hash_block_type hash_zero_block{ { 0, 0, 0, 0 } };
inline static void hash(const std::uint64_t *input, std::size_t uint64_count,
hash_block_type &destination)
{
if (blake2b(
reinterpret_cast<SEAL_BYTE*>(&destination),
hash_block_byte_count,
reinterpret_cast<const SEAL_BYTE*>(input),
uint64_count * bytes_per_uint64,
nullptr, 0) != 0)
{
throw std::runtime_error("blake2b failed");
}
}
};
}
}