Debian Codegraph @

ML-DSA/benchmark/src/sample.patch

raw
1 diff --git a/src/crypto/internal/fips140/mldsa/mldsa.go b/src/crypto/internal/fips140/mldsa/mldsa.go
2 index 5013512df7..bd16b5437d 100644
3 --- a/src/crypto/internal/fips140/mldsa/mldsa.go
4 +++ b/src/crypto/internal/fips140/mldsa/mldsa.go
5 @@ -503,6 +503,15 @@
6 // Reject if ||z||∞ ≥ γ1 − β
7 if coefficientsExceedBound(z[i], γ1β) {
8 if testingOnlyRejectionReason != nil {
9 + for i := range w {
10 + r0 := polySub(w[i], cs2[i])
11 +
12 + // Reject if ||LowBits(r0)||∞ ≥ γ2 − β
13 + if lowBitsExceedBound(r0, γ2β, p) {
14 + testingOnlyRejectionReason("z/r0")
15 + continue sign
16 + }
17 + }
18 testingOnlyRejectionReason("z")
19 }
20 continue sign
21 diff --git a/src/crypto/internal/fips140/mldsa/stat_test.go b/src/crypto/internal/fips140/mldsa/stat_test.go
22 new file mode 100644
23 index 0000000000..85b595f751
24 --- /dev/null
25 +++ b/src/crypto/internal/fips140/mldsa/stat_test.go
26 @@ -0,0 +1,36 @@
27 +package mldsa
28 +
29 +import (
30 + "crypto/rand"
31 + "fmt"
32 + "testing"
33 +)
34 +
35 +func TestSample(t *testing.T) {
36 + t.Run("ML-DSA-44", func(t *testing.T) {
37 + testSample(t, NewPrivateKey44)
38 + })
39 + t.Run("ML-DSA-65", func(t *testing.T) {
40 + testSample(t, NewPrivateKey65)
41 + })
42 + t.Run("ML-DSA-87", func(t *testing.T) {
43 + testSample(t, NewPrivateKey87)
44 + })
45 +}
46 +
47 +func testSample(t *testing.T, keyGen func([]byte) (*PrivateKey, error)) {
48 + testingOnlyRejectionReason = func(reason string) {
49 + fmt.Printf("rejection: %s\n", reason)
50 + }
51 + t.Cleanup(func() {
52 + testingOnlyRejectionReason = nil
53 + })
54 + seed := make([]byte, 32)
55 + priv, err := keyGen(seed)
56 + if err != nil {
57 + t.Fatalf("keyGen: %v", err)
58 + }
59 + message := rand.Text()
60 + fmt.Printf("seed: %s\n", message)
61 + SignDeterministic(priv, []byte(message), "")
62 +}