diff options
| -rw-r--r-- | c/blake3_c_rust_bindings/src/test.rs | 7 | ||||
| -rw-r--r-- | c/main.c | 19 | ||||
| -rw-r--r-- | src/test.rs | 7 | ||||
| -rw-r--r-- | test_vectors/src/lib.rs | 5 | ||||
| -rw-r--r-- | test_vectors/test_vectors.json | 6 |
5 files changed, 33 insertions, 11 deletions
diff --git a/c/blake3_c_rust_bindings/src/test.rs b/c/blake3_c_rust_bindings/src/test.rs index 21b5745..abfab42 100644 --- a/c/blake3_c_rust_bindings/src/test.rs +++ b/c/blake3_c_rust_bindings/src/test.rs @@ -36,11 +36,12 @@ pub const TEST_CASES: &[usize] = &[ 7 * CHUNK_LEN + 1, 8 * CHUNK_LEN, 8 * CHUNK_LEN + 1, - 16 * CHUNK_LEN, // AVX512's bandwidth - 31 * CHUNK_LEN, // 16 + 8 + 4 + 2 + 1 + 16 * CHUNK_LEN, // AVX512's bandwidth + 31 * CHUNK_LEN, // 16 + 8 + 4 + 2 + 1 + 100 * CHUNK_LEN, // subtrees larger than MAX_SIMD_DEGREE chunks ]; -pub const TEST_CASES_MAX: usize = 31 * CHUNK_LEN; +pub const TEST_CASES_MAX: usize = 100 * CHUNK_LEN; // There's a test to make sure these two are equal below. pub const TEST_KEY: [u8; 32] = *b"whats the Elvish word for friend"; @@ -103,8 +103,21 @@ int main(int argc, char **argv) { argv += 2; } - uint8_t buf[65536] = {0}; - size_t n = fread(buf, 1, sizeof(buf), stdin); + // We're going to hash the input multiple times, so we need to buffer it all. + // This is just for test cases, so go ahead and assume that the input is less + // than 1 MiB. + size_t buf_capacity = 1 << 20; + uint8_t *buf = malloc(buf_capacity); + assert(buf != NULL); + size_t buf_len = 0; + while (1) { + size_t n = fread(&buf[buf_len], 1, buf_capacity - buf_len, stdin); + if (n == 0) { + break; + } + buf_len += n; + assert(buf_len < buf_capacity); + } const int mask = get_cpu_features(); int feature = 0; @@ -126,7 +139,7 @@ int main(int argc, char **argv) { abort(); } - blake3_hasher_update(&hasher, buf, n); + blake3_hasher_update(&hasher, buf, buf_len); // TODO: An incremental output reader API to avoid this allocation. uint8_t *out = malloc(out_len); diff --git a/src/test.rs b/src/test.rs index 897a09a..31307ab 100644 --- a/src/test.rs +++ b/src/test.rs @@ -25,11 +25,12 @@ pub const TEST_CASES: &[usize] = &[ 7 * CHUNK_LEN + 1, 8 * CHUNK_LEN, 8 * CHUNK_LEN + 1, - 16 * CHUNK_LEN, // AVX512's bandwidth - 31 * CHUNK_LEN, // 16 + 8 + 4 + 2 + 1 + 16 * CHUNK_LEN, // AVX512's bandwidth + 31 * CHUNK_LEN, // 16 + 8 + 4 + 2 + 1 + 100 * CHUNK_LEN, // subtrees larger than MAX_SIMD_DEGREE chunks ]; -pub const TEST_CASES_MAX: usize = 31 * CHUNK_LEN; +pub const TEST_CASES_MAX: usize = 100 * CHUNK_LEN; // There's a test to make sure these two are equal below. pub const TEST_KEY: CVBytes = *b"whats the Elvish word for friend"; diff --git a/test_vectors/src/lib.rs b/test_vectors/src/lib.rs index ce087b1..671393a 100644 --- a/test_vectors/src/lib.rs +++ b/test_vectors/src/lib.rs @@ -25,8 +25,9 @@ pub const TEST_CASES: &[usize] = &[ 7 * CHUNK_LEN + 1, 8 * CHUNK_LEN, 8 * CHUNK_LEN + 1, - 16 * CHUNK_LEN, // AVX512's bandwidth - 31 * CHUNK_LEN, // 16 + 8 + 4 + 2 + 1 + 16 * CHUNK_LEN, // AVX512's bandwidth + 31 * CHUNK_LEN, // 16 + 8 + 4 + 2 + 1 + 100 * CHUNK_LEN, // subtrees larger than MAX_SIMD_DEGREE chunks ]; pub const TEST_CONTEXT: &str = "BLAKE3 2019-12-27 16:29:52 test vectors context"; diff --git a/test_vectors/test_vectors.json b/test_vectors/test_vectors.json index f771ee8..a52b7e1 100644 --- a/test_vectors/test_vectors.json +++ b/test_vectors/test_vectors.json @@ -127,6 +127,12 @@ "hash": "62b6960e1a44bcc1eb1a611a8d6235b6b4b78f32e7abc4fb4c6cdcce94895c47860cc51f2b0c28a7b77304bd55fe73af663c02d3f52ea053ba43431ca5bab7bfea2f5e9d7121770d88f70ae9649ea713087d1914f7f312147e247f87eb2d4ffef0ac978bf7b6579d57d533355aa20b8b77b13fd09748728a5cc327a8ec470f4013226f", "keyed_hash": "efa53b389ab67c593dba624d898d0f7353ab99e4ac9d42302ee64cbf9939a4193a7258db2d9cd32a7a3ecfce46144114b15c2fcb68a618a976bd74515d47be08b628be420b5e830fade7c080e351a076fbc38641ad80c736c8a18fe3c66ce12f95c61c2462a9770d60d0f77115bbcd3782b593016a4e728d4c06cee4505cb0c08a42ec", "derive_key": "39772aef80e0ebe60596361e45b061e8f417429d529171b6764468c22928e28e9759adeb797a3fbf771b1bcea30150a020e317982bf0d6e7d14dd9f064bc11025c25f31e81bd78a921db0174f03dd481d30e93fd8e90f8b2fee209f849f2d2a52f31719a490fb0ba7aea1e09814ee912eba111a9fde9d5c274185f7bae8ba85d300a2b" + }, + { + "input_len": 102400, + "hash": "bc3e3d41a1146b069abffad3c0d44860cf664390afce4d9661f7902e7943e085e01c59dab908c04c3342b816941a26d69c2605ebee5ec5291cc55e15b76146e6745f0601156c3596cb75065a9c57f35585a52e1ac70f69131c23d611ce11ee4ab1ec2c009012d236648e77be9295dd0426f29b764d65de58eb7d01dd42248204f45f8e", + "keyed_hash": "1c35d1a5811083fd7119f5d5d1ba027b4d01c0c6c49fb6ff2cf75393ea5db4a7f9dbdd3e1d81dcbca3ba241bb18760f207710b751846faaeb9dff8262710999a59b2aa1aca298a032d94eacfadf1aa192418eb54808db23b56e34213266aa08499a16b354f018fc4967d05f8b9d2ad87a7278337be9693fc638a3bfdbe314574ee6fc4", + "derive_key": "4652cff7a3f385a6103b5c260fc1593e13c778dbe608efb092fe7ee69df6e9c6d83a3e041bc3a48df2879f4a0a3ed40e7c961c73eff740f3117a0504c2dff4786d44fb17f1549eb0ba585e40ec29bf7732f0b7e286ff8acddc4cb1e23b87ff5d824a986458dcc6a04ac83969b80637562953df51ed1a7e90a7926924d2763778be8560" } ] } |
