| ... | ... | @@ -395,6 +395,20 @@ pub const Blake3 = struct { |
| 395 | 395 | } |
| 396 | 396 | }; |
| 397 | 397 | |
| 398 | // Use named type declarations to workaround crash with anonymous structs (issue #4373). |
| 399 | const ReferenceTest = struct { |
| 400 | key: *const [KEY_LEN]u8, |
| 401 | context_string: []const u8, |
| 402 | cases: []const ReferenceTestCase, |
| 403 | }; |
| 404 | |
| 405 | const ReferenceTestCase = struct { |
| 406 | input_len: usize, |
| 407 | hash: *const [262]u8, |
| 408 | keyed_hash: *const [262]u8, |
| 409 | derive_key: *const [262]u8, |
| 410 | }; |
| 411 | |
| 398 | 412 | // Each test is an input length and three outputs, one for each of the `hash`, `keyed_hash`, and |
| 399 | 413 | // `derive_key` modes. The input in each case is filled with a 251-byte-long repeating pattern: |
| 400 | 414 | // 0, 1, 2, ..., 249, 250, 0, 1, ... The key used with `keyed_hash` is the 32-byte ASCII string |
| ... | ... | @@ -406,15 +420,10 @@ pub const Blake3 = struct { |
| 406 | 420 | // that the first 32 bytes match their default-length output. |
| 407 | 421 | // |
| 408 | 422 | // Source: https://github.com/BLAKE3-team/BLAKE3/blob/92d421dea1a89e2f079f4dbd93b0dab41234b279/test_vectors/test_vectors.json |
| 409 | | const reference_test = .{ |
| 423 | const reference_test = ReferenceTest{ |
| 410 | 424 | .key = "whats the Elvish word for friend", |
| 411 | 425 | .context_string = "BLAKE3 2019-12-27 16:29:52 test vectors context", |
| 412 | | .cases = [_]struct { |
| 413 | | input_len: usize, |
| 414 | | hash: *const [262]u8, |
| 415 | | keyed_hash: *const [262]u8, |
| 416 | | derive_key: *const [262]u8, |
| 417 | | }{ |
| 426 | .cases = &[_]ReferenceTestCase{ |
| 418 | 427 | .{ |
| 419 | 428 | .input_len = 0, |
| 420 | 429 | .hash = "af1349b9f5f9a1a6a0404dea36dcc9499bcb25c9adc112b7cc9a93cae41f3262e00f03e7b69af26b7faaf09fcd333050338ddfe085b8cc869ca98b206c08243a26f5487789e8f660afe6c99ef9e0c52b92e7393024a80459cf91f476f9ffdbda7001c22e159b402631f277ca96f2defdf1078282314e763699a31c5363165421cce14d", |