mirror of
https://github.com/NixOS/nix
synced 2025-06-28 22:01:15 +02:00
Add BLAKE3 hashing algorithm
This uses the single-threaded C-based routines from libblake3. This is not optimal performance-wise but should be a good starting point for nix compatibility with BLAKE3 hashing until a more performant implementation based on the multi-threaded BLAKE3 routines (written in Rust) can be developed.
This commit is contained in:
parent
a562d0b6ce
commit
1f56ea4c72
9 changed files with 89 additions and 18 deletions
|
@ -6,10 +6,52 @@
|
|||
|
||||
namespace nix {
|
||||
|
||||
class BLAKE3HashTest : public virtual ::testing::Test
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* We set these in tests rather than the regular globals so we don't have
|
||||
* to worry about race conditions if the tests run concurrently.
|
||||
*/
|
||||
ExperimentalFeatureSettings mockXpSettings;
|
||||
|
||||
private:
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
mockXpSettings.set("experimental-features", "blake3-hashes");
|
||||
}
|
||||
};
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* hashString
|
||||
* --------------------------------------------------------------------------*/
|
||||
|
||||
TEST_F(BLAKE3HashTest, testKnownBLAKE3Hashes1) {
|
||||
// values taken from: https://tools.ietf.org/html/rfc4634
|
||||
auto s = "abc";
|
||||
auto hash = hashString(HashAlgorithm::BLAKE3, s, mockXpSettings);
|
||||
ASSERT_EQ(hash.to_string(HashFormat::Base16, true),
|
||||
"blake3:6437b3ac38465133ffb63b75273a8db548c558465d79db03fd359c6cd5bd9d85");
|
||||
}
|
||||
|
||||
TEST_F(BLAKE3HashTest, testKnownBLAKE3Hashes2) {
|
||||
// values taken from: https://tools.ietf.org/html/rfc4634
|
||||
auto s = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
|
||||
auto hash = hashString(HashAlgorithm::BLAKE3, s, mockXpSettings);
|
||||
ASSERT_EQ(hash.to_string(HashFormat::Base16, true),
|
||||
"blake3:c19012cc2aaf0dc3d8e5c45a1b79114d2df42abb2a410bf54be09e891af06ff8");
|
||||
}
|
||||
|
||||
TEST_F(BLAKE3HashTest, testKnownBLAKE3Hashes3) {
|
||||
// values taken from: https://www.ietf.org/archive/id/draft-aumasson-blake3-00.txt
|
||||
auto s = "IETF";
|
||||
auto hash = hashString(HashAlgorithm::BLAKE3, s, mockXpSettings);
|
||||
ASSERT_EQ(hash.to_string(HashFormat::Base16, true),
|
||||
"blake3:83a2de1ee6f4e6ab686889248f4ec0cf4cc5709446a682ffd1cbb4d6165181e2");
|
||||
}
|
||||
|
||||
TEST(hashString, testKnownMD5Hashes1) {
|
||||
// values taken from: https://tools.ietf.org/html/rfc1321
|
||||
auto s1 = "";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue