Codebase list golang-github-minio-sha256-simd / 2b112c4
Reformatted test code (battling assembly code) frankw 7 years ago
1 changed file(s) with 549 addition(s) and 36 deletion(s). Raw diff Collapse all Expand all
2929 import (
3030 "fmt"
3131 "testing"
32 "encoding/hex"
3233 )
3334
3435 type sha256Test struct {
35 out string
36 out [32]byte
3637 in string
3738 }
3839
3940 var golden = []sha256Test{
40 {"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", ""},
41 {"ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb", "a"},
42 {"fb8e20fc2e4c3f248c60c39bd652f3c1347298bb977b8b4d5903b85055620603", "ab"},
43 {"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", "abc"},
44 {"88d4266fd4e6338d13b845fcf289579d209c897823b9217da3e161936f031589", "abcd"},
45 {"36bbe50ed96841d10443bcb670d6554f0a34b761be67ec9c4a8ad2c0c44ca42c", "abcde"},
46 {"bef57ec7f53a6d40beb640a780a639c83bc29ac8a9816f1fc6c5c6dcd93c4721", "abcdef"},
47 {"7d1a54127b222502f5b79b5fb0803061152a44f92b37e23c6527baf665d4da9a", "abcdefg"},
48 {"9c56cc51b374c3ba189210d5b6d4bf57790d351c96c47c02190ecf1e430635ab", "abcdefgh"},
49 {"19cc02f26df43cc571bc9ed7b0c4d29224a3ec229529221725ef76d021c8326f", "abcdefghi"},
50 {"72399361da6a7754fec986dca5b7cbaf1c810a28ded4abaf56b2106d06cb78b0", "abcdefghij"},
51 {"a144061c271f152da4d151034508fed1c138b8c976339de229c3bb6d4bbb4fce", "Discard medicine more than two years old."},
52 {"6dae5caa713a10ad04b46028bf6dad68837c581616a1589a265a11288d4bb5c4", "He who has a shady past knows that nice guys finish last."},
53 {"ae7a702a9509039ddbf29f0765e70d0001177914b86459284dab8b348c2dce3f", "I wouldn't marry him with a ten foot pole."},
54 {"6748450b01c568586715291dfa3ee018da07d36bb7ea6f180c1af6270215c64f", "Free! Free!/A trip/to Mars/for 900/empty jars/Burma Shave"},
55 {"14b82014ad2b11f661b5ae6a99b75105c2ffac278cd071cd6c05832793635774", "The days of the digital watch are numbered. -Tom Stoppard"},
56 {"7102cfd76e2e324889eece5d6c41921b1e142a4ac5a2692be78803097f6a48d8", "Nepal premier won't resign."},
57 {"23b1018cd81db1d67983c5f7417c44da9deb582459e378d7a068552ea649dc9f", "For every action there is an equal and opposite government program."},
58 {"8001f190dfb527261c4cfcab70c98e8097a7a1922129bc4096950e57c7999a5a", "His money is twice tainted: 'taint yours and 'taint mine."},
59 {"8c87deb65505c3993eb24b7a150c4155e82eee6960cf0c3a8114ff736d69cad5", "There is no reason for any individual to have a computer in their home. -Ken Olsen, 1977"},
60 {"bfb0a67a19cdec3646498b2e0f751bddc41bba4b7f30081b0b932aad214d16d7", "It's a tiny change to the code and not completely disgusting. - Bob Manchek"},
61 {"7f9a0b9bf56332e19f5a0ec1ad9c1425a153da1c624868fda44561d6b74daf36", "size: a.out: bad magic"},
62 {"b13f81b8aad9e3666879af19886140904f7f429ef083286195982a7588858cfc", "The major problem is with sendmail. -Mark Horton"},
63 {"b26c38d61519e894480c70c8374ea35aa0ad05b2ae3d6674eec5f52a69305ed4", "Give me a rock, paper and scissors and I will move the world. CCFestoon"},
64 {"049d5e26d4f10222cd841a119e38bd8d2e0d1129728688449575d4ff42b842c1", "If the enemy is within range, then so are you."},
65 {"0e116838e3cc1c1a14cd045397e29b4d087aa11b0853fc69ec82e90330d60949", "It's well we cannot hear the screams/That we create in others' dreams."},
66 {"4f7d8eb5bcf11de2a56b971021a444aa4eafd6ecd0f307b5109e4e776cd0fe46", "You remind me of a TV show, but that's all right: I watch it anyway."},
67 {"61c0cc4c4bd8406d5120b3fb4ebc31ce87667c162f29468b3c779675a85aebce", "C is as portable as Stonehedge!!"},
68 {"1fb2eb3688093c4a3f80cd87a5547e2ce940a4f923243a79a2a1e242220693ac", "Even if I could be Shakespeare, I think I should still choose to be Faraday. - A. Huxley"},
69 {"395585ce30617b62c80b93e8208ce866d4edc811a177fdb4b82d3911d8696423", "The fugacity of a constituent in a mixture of gases at a given temperature is proportional to its mole fraction. Lewis-Randall Rule"},
70 {"4f9b189a13d030838269dce846b16a1ce9ce81fe63e65de2f636863336a98fe6", "How can you write a big system without C++? -Paul Glick"},
41 {[32]byte{227, 176,
42 196, 66,
43 152, 252,
44 28, 20,
45 154, 251,
46 244, 200,
47 153, 111,
48 185, 36,
49 39, 174,
50 65, 228,
51 100, 155,
52 147, 76,
53 164, 149,
54 153, 27,
55 120, 82,
56 184, 85},
57 ""},
58 {[32]byte{202, 151,
59 129, 18,
60 202, 27,
61 189, 202,
62 250, 194,
63 49, 179,
64 154, 35,
65 220, 77,
66 167, 134,
67 239, 248,
68 20, 124,
69 78, 114,
70 185, 128,
71 119, 133,
72 175, 238,
73 72, 187},
74 "a"},
75 {[32]byte{251, 142,
76 32, 252,
77 46, 76,
78 63, 36,
79 140, 96,
80 195, 155,
81 214, 82,
82 243, 193,
83 52, 114,
84 152, 187,
85 151, 123,
86 139, 77,
87 89, 3,
88 184, 80,
89 85, 98,
90 6, 3},
91 "ab"},
92 {[32]byte{186, 120,
93 22, 191,
94 143, 1,
95 207, 234,
96 65, 65,
97 64, 222,
98 93, 174,
99 34, 35,
100 176, 3,
101 97, 163,
102 150, 23,
103 122, 156,
104 180, 16,
105 255, 97,
106 242, 0,
107 21, 173},
108 "abc"},
109 {[32]byte{186, 120,
110 22, 191,
111 143, 1,
112 207, 234,
113 65, 65,
114 64, 222,
115 93, 174,
116 34, 35,
117 176, 3,
118 97, 163,
119 150, 23,
120 122, 156,
121 180, 16,
122 255, 97,
123 242, 0,
124 21, 173},
125 "abc"},
126 {[32]byte{136, 212,
127 38, 111,
128 212, 230,
129 51, 141,
130 19, 184,
131 69, 252,
132 242, 137,
133 87, 157,
134 32, 156,
135 137, 120,
136 35, 185,
137 33, 125,
138 163, 225,
139 97, 147,
140 111, 3,
141 21, 137},
142 "abcd"},
143 {[32]byte{54, 187,
144 229, 14,
145 217, 104,
146 65, 209,
147 4, 67,
148 188, 182,
149 112, 214,
150 85, 79,
151 10, 52,
152 183, 97,
153 190, 103,
154 236, 156,
155 74, 138,
156 210, 192,
157 196, 76,
158 164, 44},
159 "abcde"},
160 {[32]byte{190, 245,
161 126, 199,
162 245, 58,
163 109, 64,
164 190, 182,
165 64, 167,
166 128, 166,
167 57, 200,
168 59, 194,
169 154, 200,
170 169, 129,
171 111, 31,
172 198, 197,
173 198, 220,
174 217, 60,
175 71, 33},
176 "abcdef"},
177 {[32]byte{125, 26,
178 84, 18,
179 123, 34,
180 37, 2,
181 245, 183,
182 155, 95,
183 176, 128,
184 48, 97,
185 21, 42,
186 68, 249,
187 43, 55,
188 226, 60,
189 101, 39,
190 186, 246,
191 101, 212,
192 218, 154},
193 "abcdefg"},
194 {[32]byte{156, 86,
195 204, 81,
196 179, 116,
197 195, 186,
198 24, 146,
199 16, 213,
200 182, 212,
201 191, 87,
202 121, 13,
203 53, 28,
204 150, 196,
205 124, 2,
206 25, 14,
207 207, 30,
208 67, 6,
209 53, 171},
210 "abcdefgh"},
211 {[32]byte{25, 204,
212 2, 242,
213 109, 244,
214 60, 197,
215 113, 188,
216 158, 215,
217 176, 196,
218 210, 146,
219 36, 163,
220 236, 34,
221 149, 41,
222 34, 23,
223 37, 239,
224 118, 208,
225 33, 200,
226 50, 111},
227 "abcdefghi"},
228 {[32]byte{114, 57,
229 147, 97,
230 218, 106,
231 119, 84,
232 254, 201,
233 134, 220,
234 165, 183,
235 203, 175,
236 28, 129,
237 10, 40,
238 222, 212,
239 171, 175,
240 86, 178,
241 16, 109,
242 6, 203,
243 120, 176},
244 "abcdefghij"},
245 {[32]byte{161, 68,
246 6, 28,
247 39, 31,
248 21, 45,
249 164, 209,
250 81, 3,
251 69, 8,
252 254, 209,
253 193, 56,
254 184, 201,
255 118, 51,
256 157, 226,
257 41, 195,
258 187, 109,
259 75, 187,
260 79, 206},
261 "Discard medicine more than two years old."},
262 {[32]byte{109, 174,
263 92, 170,
264 113, 58,
265 16, 173,
266 4, 180,
267 96, 40,
268 191, 109,
269 173, 104,
270 131, 124,
271 88, 22,
272 22, 161,
273 88, 154,
274 38, 90,
275 17, 40,
276 141, 75,
277 181, 196},
278 "He who has a shady past knows that nice guys finish last."},
279 {[32]byte{174, 122,
280 112, 42,
281 149, 9,
282 3, 157,
283 219, 242,
284 159, 7,
285 101, 231,
286 13, 0,
287 1, 23,
288 121, 20,
289 184, 100,
290 89, 40,
291 77, 171,
292 139, 52,
293 140, 45,
294 206, 63},
295 "I wouldn't marry him with a ten foot pole."},
296 {[32]byte{103, 72,
297 69, 11,
298 1, 197,
299 104, 88,
300 103, 21,
301 41, 29,
302 250, 62,
303 224, 24,
304 218, 7,
305 211, 107,
306 183, 234,
307 111, 24,
308 12, 26,
309 246, 39,
310 2, 21,
311 198, 79},
312 "Free! Free!/A trip/to Mars/for 900/empty jars/Burma Shave"},
313 {[32]byte{20, 184,
314 32, 20,
315 173, 43,
316 17, 246,
317 97, 181,
318 174, 106,
319 153, 183,
320 81, 5,
321 194, 255,
322 172, 39,
323 140, 208,
324 113, 205,
325 108, 5,
326 131, 39,
327 147, 99,
328 87, 116},
329 "The days of the digital watch are numbered. -Tom Stoppard"},
330 {[32]byte{113, 2,
331 207, 215,
332 110, 46,
333 50, 72,
334 137, 238,
335 206, 93,
336 108, 65,
337 146, 27,
338 30, 20,
339 42, 74,
340 197, 162,
341 105, 43,
342 231, 136,
343 3, 9,
344 127, 106,
345 72, 216},
346 "Nepal premier won't resign."},
347 {[32]byte{35, 177,
348 1, 140,
349 216, 29,
350 177, 214,
351 121, 131,
352 197, 247,
353 65, 124,
354 68, 218,
355 157, 235,
356 88, 36,
357 89, 227,
358 120, 215,
359 160, 104,
360 85, 46,
361 166, 73,
362 220, 159},
363 "For every action there is an equal and opposite government program."},
364 {[32]byte{128, 1,
365 241, 144,
366 223, 181,
367 39, 38,
368 28, 76,
369 252, 171,
370 112, 201,
371 142, 128,
372 151, 167,
373 161, 146,
374 33, 41,
375 188, 64,
376 150, 149,
377 14, 87,
378 199, 153,
379 154, 90},
380 "His money is twice tainted: 'taint yours and 'taint mine."},
381 {[32]byte{140, 135,
382 222, 182,
383 85, 5,
384 195, 153,
385 62, 178,
386 75, 122,
387 21, 12,
388 65, 85,
389 232, 46,
390 238, 105,
391 96, 207,
392 12, 58,
393 129, 20,
394 255, 115,
395 109, 105,
396 202, 213},
397 "There is no reason for any individual to have a computer in their home. -Ken Olsen, 1977"},
398 {[32]byte{191, 176,
399 166, 122,
400 25, 205,
401 236, 54,
402 70, 73,
403 139, 46,
404 15, 117,
405 27, 221,
406 196, 27,
407 186, 75,
408 127, 48,
409 8, 27,
410 11, 147,
411 42, 173,
412 33, 77,
413 22, 215},
414 "It's a tiny change to the code and not completely disgusting. - Bob Manchek"},
415 {[32]byte{127, 154,
416 11, 155,
417 245, 99,
418 50, 225,
419 159, 90,
420 14, 193,
421 173, 156,
422 20, 37,
423 161, 83,
424 218, 28,
425 98, 72,
426 104, 253,
427 164, 69,
428 97, 214,
429 183, 77,
430 175, 54},
431 "size: a.out: bad magic"},
432 {[32]byte{177, 63,
433 129, 184,
434 170, 217,
435 227, 102,
436 104, 121,
437 175, 25,
438 136, 97,
439 64, 144,
440 79, 127,
441 66, 158,
442 240, 131,
443 40, 97,
444 149, 152,
445 42, 117,
446 136, 133,
447 140, 252},
448 "The major problem is with sendmail. -Mark Horton"},
449 {[32]byte{178, 108,
450 56, 214,
451 21, 25,
452 232, 148,
453 72, 12,
454 112, 200,
455 55, 78,
456 163, 90,
457 160, 173,
458 5, 178,
459 174, 61,
460 102, 116,
461 238, 197,
462 245, 42,
463 105, 48,
464 94, 212},
465 "Give me a rock, paper and scissors and I will move the world. CCFestoon"},
466 {[32]byte{4, 157,
467 94, 38,
468 212, 241,
469 2, 34,
470 205, 132,
471 26, 17,
472 158, 56,
473 189, 141,
474 46, 13,
475 17, 41,
476 114, 134,
477 136, 68,
478 149, 117,
479 212, 255,
480 66, 184,
481 66, 193},
482 "If the enemy is within range, then so are you."},
483 {[32]byte{14, 17,
484 104, 56,
485 227, 204,
486 28, 26,
487 20, 205,
488 4, 83,
489 151, 226,
490 155, 77,
491 8, 122,
492 161, 27,
493 8, 83,
494 252, 105,
495 236, 130,
496 233, 3,
497 48, 214,
498 9, 73},
499 "It's well we cannot hear the screams/That we create in others' dreams."},
500 {[32]byte{79, 125,
501 142, 181,
502 188, 241,
503 29, 226,
504 165, 107,
505 151, 16,
506 33, 164,
507 68, 170,
508 78, 175,
509 214, 236,
510 208, 243,
511 7, 181,
512 16, 158,
513 78, 119,
514 108, 208,
515 254, 70},
516 "You remind me of a TV show, but that's all right: I watch it anyway."},
517 {[32]byte{97, 192,
518 204, 76,
519 75, 216,
520 64, 109,
521 81, 32,
522 179, 251,
523 78, 188,
524 49, 206,
525 135, 102,
526 124, 22,
527 47, 41,
528 70, 139,
529 60, 119,
530 150, 117,
531 168, 90,
532 235, 206},
533 "C is as portable as Stonehedge!!"},
534 {[32]byte{31, 178,
535 235, 54,
536 136, 9,
537 60, 74,
538 63, 128,
539 205, 135,
540 165, 84,
541 126, 44,
542 233, 64,
543 164, 249,
544 35, 36,
545 58, 121,
546 162, 161,
547 226, 66,
548 34, 6,
549 147, 172},
550 "Even if I could be Shakespeare, I think I should still choose to be Faraday. - A. Huxley"},
551 {[32]byte{57, 85,
552 133, 206,
553 48, 97,
554 123, 98,
555 200, 11,
556 147, 232,
557 32, 140,
558 232, 102,
559 212, 237,
560 200, 17,
561 161, 119,
562 253, 180,
563 184, 45,
564 57, 17,
565 216, 105,
566 100, 35},
567 "The fugacity of a constituent in a mixture of gases at a given temperature is proportional to its mole fraction. Lewis-Randall Rule"},
568 {[32]byte{79, 155,
569 24, 154,
570 19, 208,
571 48, 131,
572 130, 105,
573 220, 232,
574 70, 177,
575 106, 28,
576 233, 206,
577 129, 254,
578 99, 230,
579 93, 226,
580 246, 54,
581 134, 51,
582 54, 169,
583 143, 230},
584 "How can you write a big system without C++? -Paul Glick"},
71585 }
72586
73587 func TestGolden(t *testing.T) {
74 for i := 0; i < len(golden); i++ {
75 g := golden[i]
588 for _, g := range golden {
76589 s := fmt.Sprintf("%x", Sum256([]byte(g.in)))
77 if s != g.out {
78 t.Fatalf("Sum256 function: sha256(%s) = %s want %s", g.in, s, g.out)
590 if Sum256([]byte(g.in)) != g.out {
591 t.Fatalf("Sum256 function: sha256(%s) = %s want %s", g.in, s, hex.EncodeToString(g.out[:]))
79592 }
80593 }
81594 }