authorgravatar for jay@jayschwa.netJay Petacat <jay@jayschwa.net> 2020-02-02 18:44:50-05:00
committergravatar for jay@jayschwa.netJay Petacat <jay@jayschwa.net> 2020-02-02 18:44:50-05:00
logcb2c14e03fa86ad0214e92c821026931f38edd61
tree4c8f47931cd3dbe42098c7306cd26c8932f7cb4d
parent923e567c6d73c4dea4ffff937c5e4cc4a26264da

blake3: Workaround issue #4373 with named types


1 files changed, 16 insertions(+), 7 deletions(-)

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