aboutsummaryrefslogtreecommitdiff
path: root/thirdparty/blake3/c/test.py
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2025-11-07 14:49:13 +0100
committerGitHub Enterprise <[email protected]>2025-11-07 14:49:13 +0100
commit24e43a913f29ac3b314354e8ce5175f135bcc64f (patch)
treeca442937ceeb63461012b33a4576e9835099f106 /thirdparty/blake3/c/test.py
parentget oplog attachments (#622) (diff)
downloadzen-24e43a913f29ac3b314354e8ce5175f135bcc64f.tar.xz
zen-24e43a913f29ac3b314354e8ce5175f135bcc64f.zip
switch to xmake for package management (#611)
This change removes our dependency on vcpkg for package management, in favour of bringing some code in-tree in the `thirdparty` folder as well as using the xmake build-in package management feature. For the latter, all the package definitions are maintained in the zen repo itself, in the `repo` folder. It should now also be easier to build the project as it will no longer depend on having the right version of vcpkg installed, which has been a common problem for new people coming in to the codebase. Now you should only need xmake to build. * Bumps xmake requirement on github runners to 2.9.9 to resolve an issue where xmake on Windows invokes cmake with `v144` toolchain which does not exist * BLAKE3 is now in-tree at `thirdparty/blake3` * cpr is now in-tree at `thirdparty/cpr` * cxxopts is now in-tree at `thirdparty/cxxopts` * fmt is now in-tree at `thirdparty/fmt` * robin-map is now in-tree at `thirdparty/robin-map` * ryml is now in-tree at `thirdparty/ryml` * sol2 is now in-tree at `thirdparty/sol2` * spdlog is now in-tree at `thirdparty/spdlog` * utfcpp is now in-tree at `thirdparty/utfcpp` * xmake package repo definitions is in `repo` * implemented support for sanitizers. ASAN is supported on windows, TSAN, UBSAN, MSAN etc are supported on Linux/MacOS though I have not yet tested it extensively on MacOS * the zencore encryption implementation also now supports using mbedTLS which is used on MacOS, though for now we still use openssl on Linux * crashpad * bumps libcurl to 8.11.0 (from 8.8.0) which should address a rare build upload bug
Diffstat (limited to 'thirdparty/blake3/c/test.py')
-rwxr-xr-xthirdparty/blake3/c/test.py97
1 files changed, 97 insertions, 0 deletions
diff --git a/thirdparty/blake3/c/test.py b/thirdparty/blake3/c/test.py
new file mode 100755
index 000000000..98b1c3dff
--- /dev/null
+++ b/thirdparty/blake3/c/test.py
@@ -0,0 +1,97 @@
+#! /usr/bin/env python3
+
+from binascii import hexlify
+import json
+from os import path
+import subprocess
+
+HERE = path.dirname(__file__)
+TEST_VECTORS_PATH = path.join(HERE, "..", "test_vectors", "test_vectors.json")
+TEST_VECTORS = json.load(open(TEST_VECTORS_PATH))
+
+
+def run_blake3(args, input):
+ output = subprocess.run([path.join(HERE, "blake3")] + args,
+ input=input,
+ stdout=subprocess.PIPE,
+ check=True)
+ return output.stdout.decode().strip()
+
+
+# Fill the input with a repeating byte pattern. We use a cycle length of 251,
+# because that's the largest prime number less than 256. This makes it unlikely
+# to swapping any two adjacent input blocks or chunks will give the same
+# answer.
+def make_test_input(length):
+ i = 0
+ buf = bytearray()
+ while len(buf) < length:
+ buf.append(i)
+ i = (i + 1) % 251
+ return buf
+
+
+def main():
+ for case in TEST_VECTORS["cases"]:
+ input_len = case["input_len"]
+ input = make_test_input(input_len)
+ hex_key = hexlify(TEST_VECTORS["key"].encode())
+ context_string = TEST_VECTORS["context_string"]
+ expected_hash_xof = case["hash"]
+ expected_hash = expected_hash_xof[:64]
+ expected_keyed_hash_xof = case["keyed_hash"]
+ expected_keyed_hash = expected_keyed_hash_xof[:64]
+ expected_derive_key_xof = case["derive_key"]
+ expected_derive_key = expected_derive_key_xof[:64]
+
+ # Test the default hash.
+ test_hash = run_blake3([], input)
+ for line in test_hash.splitlines():
+ assert expected_hash == line, \
+ "hash({}): {} != {}".format(input_len, expected_hash, line)
+
+ # Test the extended hash.
+ xof_len = len(expected_hash_xof) // 2
+ test_hash_xof = run_blake3(["--length", str(xof_len)], input)
+ for line in test_hash_xof.splitlines():
+ assert expected_hash_xof == line, \
+ "hash_xof({}): {} != {}".format(
+ input_len, expected_hash_xof, line)
+
+ # Test the default keyed hash.
+ test_keyed_hash = run_blake3(["--keyed", hex_key], input)
+ for line in test_keyed_hash.splitlines():
+ assert expected_keyed_hash == line, \
+ "keyed_hash({}): {} != {}".format(
+ input_len, expected_keyed_hash, line)
+
+ # Test the extended keyed hash.
+ xof_len = len(expected_keyed_hash_xof) // 2
+ test_keyed_hash_xof = run_blake3(
+ ["--keyed", hex_key, "--length",
+ str(xof_len)], input)
+ for line in test_keyed_hash_xof.splitlines():
+ assert expected_keyed_hash_xof == line, \
+ "keyed_hash_xof({}): {} != {}".format(
+ input_len, expected_keyed_hash_xof, line)
+
+ # Test the default derive key.
+ test_derive_key = run_blake3(["--derive-key", context_string], input)
+ for line in test_derive_key.splitlines():
+ assert expected_derive_key == line, \
+ "derive_key({}): {} != {}".format(
+ input_len, expected_derive_key, line)
+
+ # Test the extended derive key.
+ xof_len = len(expected_derive_key_xof) // 2
+ test_derive_key_xof = run_blake3(
+ ["--derive-key", context_string, "--length",
+ str(xof_len)], input)
+ for line in test_derive_key_xof.splitlines():
+ assert expected_derive_key_xof == line, \
+ "derive_key_xof({}): {} != {}".format(
+ input_len, expected_derive_key_xof, line)
+
+
+if __name__ == "__main__":
+ main()