Skip to content

Commit 32046e4

Browse files
committed
Convert to a long test.
1 parent 092d7a3 commit 32046e4

File tree

2 files changed

+33
-24
lines changed

2 files changed

+33
-24
lines changed

sign/slhdsa/slhdsa_test.go

+30-23
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package slhdsa_test
22

33
import (
44
"crypto/rand"
5+
"flag"
56
"testing"
67

78
"github.com/cloudflare/circl/internal/sha3"
@@ -32,28 +33,34 @@ var supportedPrehashIDs = [5]slhdsa.PreHashID{
3233
slhdsa.PreHashSHAKE256,
3334
}
3435

35-
func TestSlhdsa(t *testing.T) {
36-
for i := range supportedParameters {
37-
id := supportedParameters[i]
36+
// Indicates whether long tests should be run
37+
var runLongTest = flag.Bool("long", false, "runs longer tests")
3838

39-
t.Run(id.Name(), func(t *testing.T) {
40-
t.Run("Keys", func(t *testing.T) { testKeys(t, id) })
39+
func TestSlhdsaLong(t *testing.T) {
40+
if !*runLongTest {
41+
t.Skip("Skipped one long test, add -long flag to run longer tests")
42+
}
4143

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")
44+
for _, paramID := range supportedParameters {
45+
t.Run(paramID.Name(), func(t *testing.T) {
46+
t.Run("Keys", func(t *testing.T) { testKeys(t, paramID) })
4847

49-
t.Run("Sign/"+ph.String(), func(t *testing.T) {
50-
testSign(t, &pub, &priv, msg, ctx, ph)
51-
})
48+
for _, ph := range supportedPrehashIDs {
49+
t.Run(ph.String(), func(t *testing.T) { testSign(t, paramID, ph) })
5250
}
5351
})
5452
}
5553
}
5654

55+
func TestSlhdsa(t *testing.T) {
56+
t.Run("Keys", func(t *testing.T) {
57+
testKeys(t, slhdsa.ParamIDSHA2Fast128)
58+
})
59+
t.Run("PreHashSHA256", func(t *testing.T) {
60+
testSign(t, slhdsa.ParamIDSHA2Fast128, slhdsa.PreHashSHA256)
61+
})
62+
}
63+
5764
func testKeys(t *testing.T, id slhdsa.ParamID) {
5865
reader := sha3.NewShake128()
5966

@@ -79,13 +86,13 @@ func testKeys(t *testing.T, id slhdsa.ParamID) {
7986
test.CheckOk(pub2.Equal(pub3), "public key not equal", t)
8087
}
8188

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

@@ -95,13 +102,13 @@ func testSign(
95102
sig, err := sk.SignRandomized(rand.Reader, &m, ctx)
96103
test.CheckNoErr(t, err, "SignRandomized failed")
97104

98-
valid := slhdsa.Verify(pk, &m, ctx, sig)
105+
valid := slhdsa.Verify(&pk, &m, ctx, sig)
99106
test.CheckOk(valid, "Verify failed", t)
100107

101108
sig, err = sk.SignDeterministic(&m, ctx)
102109
test.CheckNoErr(t, err, "SignDeterministic failed")
103110

104-
valid = slhdsa.Verify(pk, &m, ctx, sig)
111+
valid = slhdsa.Verify(&pk, &m, ctx, sig)
105112
test.CheckOk(valid, "Verify failed", t)
106113
}
107114

sign/slhdsa/wotsp.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ func (ws *wotsSignature) fromBytes(p *params, c *cursor) {
2222
}
2323

2424
// See FIPS 205 -- Section 5 -- Algorithm 5.
25-
func (s *state) chain(x []byte, index, steps uint32, addr address) (out []byte) {
25+
func (s *state) chain(
26+
x []byte, index, steps uint32, addr address,
27+
) (out []byte) {
2628
out = x
2729
s.F.address.Set(addr)
2830
for j := index; j < index+steps; j++ {

0 commit comments

Comments
 (0)