1
1
import Blake3
2
2
3
3
abbrev input : ByteArray := ⟨#[0 ]⟩
4
- abbrev expected_output_regular_hashing : ByteArray := ⟨#[
4
+ abbrev expectedOutputRegularHashing : ByteArray := ⟨#[
5
5
45 , 58 , 222 , 223 , 241 , 27 , 97 , 241 ,
6
6
76 , 136 , 110 , 53 , 175 , 160 , 54 , 115 ,
7
7
109 , 205 , 135 , 167 , 77 , 39 , 181 , 193 ,
@@ -15,7 +15,7 @@ abbrev key : Blake3.Blake3Key := .ofBytes ⟨#[
15
15
213 , 14 , 159 , 189 , 82 , 166 , 91 , 107 ,
16
16
33 , 78 , 26 , 226 , 89 , 65 , 188 , 92
17
17
]⟩
18
- abbrev expected_output_keyed_hashing : ByteArray := ⟨#[
18
+ abbrev expectedOutputKeyedHashing : ByteArray := ⟨#[
19
19
145 , 187 , 220 , 234 , 206 , 139 , 205 , 138 ,
20
20
220 , 103 , 35 , 65 , 199 , 96 , 210 , 18 ,
21
21
145 , 201 , 131 , 254 , 79 , 208 , 229 , 157 ,
@@ -24,16 +24,37 @@ abbrev expected_output_keyed_hashing: ByteArray := ⟨#[
24
24
25
25
-- Context (with "bad" randomness)
26
26
abbrev context : ByteArray := ⟨#[0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 ]⟩
27
- abbrev expected_output_derive_key_hashing : ByteArray := ⟨#[
27
+ abbrev expectedOutputDeriveKeyHashing : ByteArray := ⟨#[
28
28
34 , 57 , 22 , 43 , 164 , 211 , 65 , 131 ,
29
29
90 , 55 , 55 , 92 , 68 , 90 , 63 , 136 ,
30
30
3 , 235 , 52 , 117 , 143 , 246 , 158 , 224 ,
31
- 178 , 170 , 234 , 211 , 148 , 21 , 97 , 183 ]⟩
31
+ 178 , 170 , 234 , 211 , 148 , 21 , 97 , 183
32
+ ]⟩
33
+
34
+ abbrev expectedOutputSponge : ByteArray := ⟨#[
35
+ 21 , 150 , 121 , 38 , 177 , 21 , 33 , 148 , 213 , 127 ,
36
+ 208 , 231 , 200 , 18 , 46 , 115 , 244 , 188 , 245 , 188 ,
37
+ 176 , 29 , 43 , 123 , 135 , 148 , 132 , 218 , 45 , 244 ,
38
+ 127 , 103 , 178 , 82 , 145 , 67 , 43 , 106 , 204 , 137 ,
39
+ 154 , 99 , 175 , 9 , 196 , 102 , 126 , 72 , 27 , 86
40
+ ]⟩
41
+
42
+ def hashingFails :=
43
+ (Blake3.hash input).val.data != expectedOutputRegularHashing.data ||
44
+ (Blake3.hashKeyed input key).val.data != expectedOutputKeyedHashing.data ||
45
+ (Blake3.hashDeriveKey input context).val.data != expectedOutputDeriveKeyHashing.data
46
+
47
+ def spongeFails :=
48
+ let sponge := Blake3.Sponge.init "ix 2025-01-01 16:18:03 content-addressing v1"
49
+ let sponge := sponge.absorb ⟨#[1 ]⟩
50
+ let sponge := sponge.absorb ⟨#[2 ]⟩
51
+ let sponge := sponge.absorb ⟨#[3 ]⟩
52
+ let sponge := sponge.absorb ⟨#[4 , 5 ]⟩
53
+ let output := sponge.squeeze 50
54
+ output.val.data != expectedOutputSponge.data
32
55
33
56
def main : IO UInt32 := do
34
57
println! s! "BLAKE3 version: { Blake3.version} "
35
- if (Blake3.hash input).val.data != expected_output_regular_hashing.data ||
36
- (Blake3.hashKeyed input key).val.data != expected_output_keyed_hashing.data ||
37
- (Blake3.hashDeriveKey input context).val.data != expected_output_derive_key_hashing.data
58
+ if hashingFails || spongeFails
38
59
then IO.eprintln "BLAKE3 test failed" ; return 1
39
60
else IO.println "BLAKE3 test succeeded" ; return 0
0 commit comments