diff options
| author | Jack O'Connor <[email protected]> | 2020-06-29 16:34:17 -0400 |
|---|---|---|
| committer | Jack O'Connor <[email protected]> | 2020-06-29 16:38:53 -0400 |
| commit | 2f6f56f3477321c9e4742f1c863e45f2cfcbfb5e (patch) | |
| tree | 107f5c089f356334ee4abaeeca8c31704661f37d | |
| parent | f2005678f84a8222be69c54c3d5457c6c40e87d2 (diff) | |
stop being a jerk and add the context string to test_vectors.json
| -rwxr-xr-x | c/test.py | 6 | ||||
| -rw-r--r-- | test_vectors/src/lib.rs | 21 | ||||
| -rw-r--r-- | test_vectors/test_vectors.json | 3 |
3 files changed, 15 insertions, 15 deletions
@@ -8,7 +8,6 @@ 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)) -TEST_CONTEXT = "BLAKE3 2019-12-27 16:29:52 test vectors context" def run_blake3(args, input): @@ -37,6 +36,7 @@ def main(): 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"] @@ -76,7 +76,7 @@ def main(): input_len, expected_keyed_hash_xof, line) # Test the default derive key. - test_derive_key = run_blake3(["--derive-key", TEST_CONTEXT], input) + 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( @@ -85,7 +85,7 @@ def main(): # Test the extended derive key. xof_len = len(expected_derive_key_xof) // 2 test_derive_key_xof = run_blake3( - ["--derive-key", TEST_CONTEXT, "--length", + ["--derive-key", context_string, "--length", str(xof_len)], input) for line in test_derive_key_xof.splitlines(): assert expected_derive_key_xof == line, \ diff --git a/test_vectors/src/lib.rs b/test_vectors/src/lib.rs index 671393a..b07004a 100644 --- a/test_vectors/src/lib.rs +++ b/test_vectors/src/lib.rs @@ -30,20 +30,19 @@ pub const TEST_CASES: &[usize] = &[ 100 * CHUNK_LEN, // subtrees larger than MAX_SIMD_DEGREE chunks ]; +pub const TEST_KEY: &[u8; blake3::KEY_LEN] = b"whats the Elvish word for friend"; pub const TEST_CONTEXT: &str = "BLAKE3 2019-12-27 16:29:52 test vectors context"; const COMMENT: &str = r#" Each test is an input length and three outputs, one for each of the hash, keyed_hash, and derive_key modes. The input in each case is filled with a -251-byte-long repeating pattern: 0, 1, 2, ..., 249, 250, 0, 1, ... The key used -with keyed_hash is the 32-byte ASCII string given in the 'key' field below. For -derive_key, the test input is used as the input key, and the context string is -'BLAKE3 2019-12-27 16:29:52 test vectors context'. (As good practice for -following the security requirements of derive_key, test runners should make -that context string a hardcoded constant, and we do not provided it in -machine-readable form.) Outputs are encoded as hexadecimal. Each case is an -extended output, and implementations should also check that the first 32 bytes -match their default-length output. +repeating sequence of 251 bytes: 0, 1, 2, ..., 249, 250, 0, 1, ..., and so on. +The key used with keyed_hash is the 32-byte ASCII string "whats the Elvish word +for friend", also given in the `key` field below. The context string used with +derive_key is the ASCII string "BLAKE3 2019-12-27 16:29:52 test vectors +context", also given in the `context_string` field below. Outputs are encoded +as hexadecimal. Each case is an extended output, and implementations should +also check that the first 32 bytes match their default-length output. "#; // Paint the input with a repeating byte pattern. We use a cycle length of 251, @@ -60,6 +59,7 @@ pub fn paint_test_input(buf: &mut [u8]) { pub struct Cases { pub _comment: String, pub key: String, + pub context_string: String, pub cases: Vec<Case>, } @@ -72,8 +72,6 @@ pub struct Case { } pub fn generate_json() -> String { - const TEST_KEY: &[u8; blake3::KEY_LEN] = b"whats the Elvish word for friend"; - let mut cases = Vec::new(); for &input_len in TEST_CASES { let mut input = vec![0; input_len]; @@ -108,6 +106,7 @@ pub fn generate_json() -> String { let mut json = serde_json::to_string_pretty(&Cases { _comment: COMMENT.trim().replace("\n", " "), key: std::str::from_utf8(TEST_KEY).unwrap().to_string(), + context_string: TEST_CONTEXT.to_string(), cases, }) .unwrap(); diff --git a/test_vectors/test_vectors.json b/test_vectors/test_vectors.json index a52b7e1..9f1a45c 100644 --- a/test_vectors/test_vectors.json +++ b/test_vectors/test_vectors.json @@ -1,6 +1,7 @@ { - "_comment": "Each test is an input length and three outputs, one for each of the hash, keyed_hash, and derive_key modes. The input in each case is filled with a 251-byte-long repeating pattern: 0, 1, 2, ..., 249, 250, 0, 1, ... The key used with keyed_hash is the 32-byte ASCII string given in the 'key' field below. For derive_key, the test input is used as the input key, and the context string is 'BLAKE3 2019-12-27 16:29:52 test vectors context'. (As good practice for following the security requirements of derive_key, test runners should make that context string a hardcoded constant, and we do not provided it in machine-readable form.) Outputs are encoded as hexadecimal. Each case is an extended output, and implementations should also check that the first 32 bytes match their default-length output.", + "_comment": "Each test is an input length and three outputs, one for each of the hash, keyed_hash, and derive_key modes. The input in each case is filled with a repeating sequence of 251 bytes: 0, 1, 2, ..., 249, 250, 0, 1, ..., and so on. The key used with keyed_hash is the 32-byte ASCII string \"whats the Elvish word for friend\", also given in the `key` field below. The context string used with derive_key is the ASCII string \"BLAKE3 2019-12-27 16:29:52 test vectors context\", also given in the `context_string` field below. Outputs are encoded as hexadecimal. Each case is an extended output, and implementations should also check that the first 32 bytes match their default-length output.", "key": "whats the Elvish word for friend", + "context_string": "BLAKE3 2019-12-27 16:29:52 test vectors context", "cases": [ { "input_len": 0, |
