zuc: add test case

This commit is contained in:
Sun Yimin 2022-07-15 17:18:14 +08:00 committed by GitHub
parent fdb89d3233
commit 08bb2e2b57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -230,15 +230,33 @@ func TestEIA256_Sum32(t *testing.T) {
} }
} }
func TestEIA256_Finish32(t *testing.T) { func TestEIA256_Finish(t *testing.T) {
expected := "f4f20d7c" expected := []struct {
h, err := NewHash256(zucEIA256Tests[2].key, zucEIA256Tests[2].iv, 4) expected string
if err != nil { macLen int
t.Fatal(err) }{
{
"9dd592c4",
4,
},
{
"1f6f71e386a2ce01",
8,
},
{
"bf5339cfd87bba97d70ef4f5973af8bb",
16,
},
} }
mac := h.Finish([]byte("emmansunshangmi1emmansun shangmiemmansun shangmi 1234"), 8*53) for _, exp := range expected {
if hex.EncodeToString(mac) != expected { h, err := NewHash256(zucEIA256Tests[2].key, zucEIA256Tests[2].iv, exp.macLen)
t.Errorf("expected=%s, result=%s\n", expected, hex.EncodeToString(mac)) if err != nil {
t.Fatal(err)
}
mac := h.Finish([]byte("emmansunshangmi1emmansun shangmiemmansun shangmi 12345"), 8*53+4)
if hex.EncodeToString(mac) != exp.expected {
t.Errorf("expected=%s, result=%s\n", exp.expected, hex.EncodeToString(mac))
}
} }
} }