| 1 |
//+build !noasm,!appengine,gc |
| 2 |
|
| 3 |
// Copyright (c) 2020 MinIO Inc. All rights reserved. |
| 4 |
// Use of this source code is governed by a license that can be |
| 5 |
// found in the LICENSE file. |
| 6 |
|
| 7 |
package md5simd |
| 8 |
|
| 9 |
import ( |
| 10 |
"reflect" |
| 11 |
"testing" |
| 12 |
) |
| 13 |
|
| 14 |
type maskTest struct { |
| 15 |
in [8]int |
| 16 |
out []maskRounds |
| 17 |
} |
| 18 |
|
| 19 |
var goldenMask = []maskTest{ |
| 20 |
{[8]int{0, 0, 0, 0, 0, 0, 0, 0}, []maskRounds{}}, |
| 21 |
{[8]int{64, 0, 64, 0, 64, 0, 64, 0}, []maskRounds{{0x55, 1}}}, |
| 22 |
{[8]int{0, 64, 0, 64, 0, 64, 0, 64}, []maskRounds{{0xaa, 1}}}, |
| 23 |
{[8]int{64, 64, 64, 64, 64, 64, 64, 64}, []maskRounds{{0xff, 1}}}, |
| 24 |
{[8]int{128, 128, 128, 128, 128, 128, 128, 128}, []maskRounds{{0xff, 2}}}, |
| 25 |
{[8]int{64, 128, 64, 128, 64, 128, 64, 128}, []maskRounds{{0xff, 1}, {0xaa, 1}}}, |
| 26 |
{[8]int{128, 64, 128, 64, 128, 64, 128, 64}, []maskRounds{{0xff, 1}, {0x55, 1}}}, |
| 27 |
{[8]int{64, 192, 64, 192, 64, 192, 64, 192}, []maskRounds{{0xff, 1}, {0xaa, 2}}}, |
| 28 |
{[8]int{0, 64, 128, 0, 64, 128, 0, 64}, []maskRounds{{0xb6, 1}, {0x24, 1}}}, |
| 29 |
{[8]int{1 * 64, 2 * 64, 3 * 64, 4 * 64, 5 * 64, 6 * 64, 7 * 64, 8 * 64}, |
| 30 |
[]maskRounds{{0xff, 1}, {0xfe, 1}, {0xfc, 1}, {0xf8, 1}, {0xf0, 1}, {0xe0, 1}, {0xc0, 1}, {0x80, 1}}}, |
| 31 |
{[8]int{2 * 64, 1 * 64, 3 * 64, 4 * 64, 5 * 64, 6 * 64, 7 * 64, 8 * 64}, |
| 32 |
[]maskRounds{{0xff, 1}, {0xfd, 1}, {0xfc, 1}, {0xf8, 1}, {0xf0, 1}, {0xe0, 1}, {0xc0, 1}, {0x80, 1}}}, |
| 33 |
{[8]int{10 * 64, 20 * 64, 30 * 64, 40 * 64, 50 * 64, 60 * 64, 70 * 64, 80 * 64}, |
| 34 |
[]maskRounds{{0xff, 10}, {0xfe, 10}, {0xfc, 10}, {0xf8, 10}, {0xf0, 10}, {0xe0, 10}, {0xc0, 10}, {0x80, 10}}}, |
| 35 |
{[8]int{10 * 64, 19 * 64, 27 * 64, 34 * 64, 40 * 64, 45 * 64, 49 * 64, 52 * 64}, |
| 36 |
[]maskRounds{{0xff, 10}, {0xfe, 9}, {0xfc, 8}, {0xf8, 7}, {0xf0, 6}, {0xe0, 5}, {0xc0, 4}, {0x80, 3}}}, |
| 37 |
} |
| 38 |
|
| 39 |
func TestGenerateMaskAndRounds(t *testing.T) { |
| 40 |
input := [8][]byte{} |
| 41 |
maskRound := [8]maskRounds{} |
| 42 |
for gcase, g := range goldenMask { |
| 43 |
for i, l := range g.in { |
| 44 |
buf := make([]byte, l) |
| 45 |
input[i] = buf[:] |
| 46 |
} |
| 47 |
|
| 48 |
rounds := generateMaskAndRounds8(input, &maskRound) |
| 49 |
|
| 50 |
mr := make([]maskRounds, 0, 8) |
| 51 |
for r := 0; r < rounds; r++ { |
| 52 |
mr = append(mr, maskRound[r]) |
| 53 |
} |
| 54 |
|
| 55 |
if !reflect.DeepEqual(mr, g.out) { |
| 56 |
t.Fatalf("case %d: got %04x\n want %04x", gcase, mr, g.out) |
| 57 |
} |
| 58 |
} |
| 59 |
} |