forked from cryfs/cryfs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHash.cpp
More file actions
30 lines (23 loc) · 682 Bytes
/
Hash.cpp
File metadata and controls
30 lines (23 loc) · 682 Bytes
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
#include "Hash.h"
#include <cpp-utils/random/Random.h>
#include <vendor_cryptopp/sha.h>
using cpputils::Random;
using CryptoPP::SHA512;
namespace cpputils {
namespace hash {
Hash hash(const Data& data, Salt salt) {
SHA512 hasher; // NOLINT (workaround for clang-warning in libcrypto++)
hasher.Update(static_cast<const CryptoPP::byte*>(salt.data()), Salt::BINARY_LENGTH);
hasher.Update(static_cast<const CryptoPP::byte*>(data.data()), data.size());
Digest digest = Digest::Null();
hasher.Final(static_cast<CryptoPP::byte*>(digest.data()));
return Hash{
digest,
salt
};
}
Salt generateSalt() {
return Random::PseudoRandom().getFixedSize<8>();
}
}
}