Skip to content

Commit 12020e3

Browse files
committed
Simplifying test for prehash.
1 parent 092d7a3 commit 12020e3

File tree

1 file changed

+34
-25
lines changed

1 file changed

+34
-25
lines changed

sign/slhdsa/slhdsa_test.go

+34-25
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,34 @@ var supportedPrehashIDs = [5]slhdsa.PreHashID{
3232
slhdsa.PreHashSHAKE256,
3333
}
3434

35-
func TestSlhdsa(t *testing.T) {
36-
for i := range supportedParameters {
37-
id := supportedParameters[i]
35+
func TestSlhdsaNoPreHash(t *testing.T) {
36+
for _, paramID := range supportedParameters {
37+
testKeys(t, paramID)
38+
t.Run(paramID.Name(), func(t *testing.T) { testSign(t, paramID, slhdsa.NoPreHash) })
39+
}
40+
}
3841

39-
t.Run(id.Name(), func(t *testing.T) {
40-
t.Run("Keys", func(t *testing.T) { testKeys(t, id) })
42+
func TestSlhdsaPreHashSHA256(t *testing.T) {
43+
for _, paramID := range supportedParameters {
44+
t.Run(paramID.Name(), func(t *testing.T) { testSign(t, paramID, slhdsa.PreHashSHA256) })
45+
}
46+
}
4147

42-
for j := range supportedPrehashIDs {
43-
ph := supportedPrehashIDs[j]
44-
msg := []byte("Alice and Bob")
45-
ctx := []byte("this is a context string")
46-
pub, priv, err := slhdsa.GenerateKey(rand.Reader, id)
47-
test.CheckNoErr(t, err, "keygen failed")
48+
func TestSlhdsaPreHashSHA512(t *testing.T) {
49+
for _, paramID := range supportedParameters {
50+
t.Run(paramID.Name(), func(t *testing.T) { testSign(t, paramID, slhdsa.PreHashSHA512) })
51+
}
52+
}
4853

49-
t.Run("Sign/"+ph.String(), func(t *testing.T) {
50-
testSign(t, &pub, &priv, msg, ctx, ph)
51-
})
52-
}
53-
})
54+
func TestSlhdsaPreHashSHAKE128(t *testing.T) {
55+
for _, paramID := range supportedParameters {
56+
t.Run(paramID.Name(), func(t *testing.T) { testSign(t, paramID, slhdsa.PreHashSHAKE128) })
57+
}
58+
}
59+
60+
func TestSlhdsaPreHashSHAKE256(t *testing.T) {
61+
for _, paramID := range supportedParameters {
62+
t.Run(paramID.Name(), func(t *testing.T) { testSign(t, paramID, slhdsa.PreHashSHAKE256) })
5463
}
5564
}
5665

@@ -79,13 +88,13 @@ func testKeys(t *testing.T, id slhdsa.ParamID) {
7988
test.CheckOk(pub2.Equal(pub3), "public key not equal", t)
8089
}
8190

82-
func testSign(
83-
t *testing.T,
84-
pk *slhdsa.PublicKey,
85-
sk *slhdsa.PrivateKey,
86-
msg, ctx []byte,
87-
ph slhdsa.PreHashID,
88-
) {
91+
func testSign(t *testing.T, id slhdsa.ParamID, ph slhdsa.PreHashID) {
92+
msg := []byte("Alice and Bob")
93+
ctx := []byte("this is a context string")
94+
95+
pk, sk, err := slhdsa.GenerateKey(rand.Reader, id)
96+
test.CheckNoErr(t, err, "keygen failed")
97+
8998
m, err := slhdsa.NewMessageWithPreHash(ph)
9099
test.CheckNoErr(t, err, "NewMessageWithPreHash failed")
91100

@@ -95,13 +104,13 @@ func testSign(
95104
sig, err := sk.SignRandomized(rand.Reader, &m, ctx)
96105
test.CheckNoErr(t, err, "SignRandomized failed")
97106

98-
valid := slhdsa.Verify(pk, &m, ctx, sig)
107+
valid := slhdsa.Verify(&pk, &m, ctx, sig)
99108
test.CheckOk(valid, "Verify failed", t)
100109

101110
sig, err = sk.SignDeterministic(&m, ctx)
102111
test.CheckNoErr(t, err, "SignDeterministic failed")
103112

104-
valid = slhdsa.Verify(pk, &m, ctx, sig)
113+
valid = slhdsa.Verify(&pk, &m, ctx, sig)
105114
test.CheckOk(valid, "Verify failed", t)
106115
}
107116

0 commit comments

Comments
 (0)