| 1 |
diff --git a/src/crypto/internal/fips140/mldsa/mldsa.go b/src/crypto/internal/fips140/mldsa/mldsa.go |
| 2 |
index 5013512df7..c9ee231e50 100644 |
| 3 |
--- a/src/crypto/internal/fips140/mldsa/mldsa.go |
| 4 |
+++ b/src/crypto/internal/fips140/mldsa/mldsa.go |
| 5 |
@@ -12,6 +12,7 @@ |
| 6 |
"crypto/internal/fips140/subtle" |
| 7 |
"crypto/internal/fips140deps/byteorder" |
| 8 |
"errors" |
| 9 |
+ "fmt" |
| 10 |
) |
| 11 |
|
| 12 |
type parameters struct { |
| 13 |
@@ -436,8 +437,9 @@ |
| 14 |
nonce := make([]byte, 64) |
| 15 |
H.Read(nonce) |
| 16 |
|
| 17 |
+ var bitmaps [16]int |
| 18 |
+ |
| 19 |
κ := 0 |
| 20 |
-sign: |
| 21 |
for { |
| 22 |
// Main rejection sampling loop. Note that leaking rejected signatures |
| 23 |
// leaks information about the private key. However, as explained in |
| 24 |
@@ -461,6 +463,11 @@ |
| 25 |
y[r] = bitUnpack(v, p) |
| 26 |
} |
| 27 |
|
| 28 |
+ if int(uint16(κ)) < κ { |
| 29 |
+ drbg.Read(nonce) |
| 30 |
+ κ = 0 |
| 31 |
+ } |
| 32 |
+ |
| 33 |
// w = NTT⁻¹(Â ∘ NTT(y)) |
| 34 |
yHat := make([]nttElement, l, maxL) |
| 35 |
for i := range y { |
| 36 |
@@ -496,6 +503,8 @@ |
| 37 |
cs2[i] = inverseNTT(nttMul(c, s2[i])) |
| 38 |
} |
| 39 |
|
| 40 |
+ var rejectionBitmap uint8 |
| 41 |
+ |
| 42 |
z := make([]ringElement, l, maxL) |
| 43 |
for i := range y { |
| 44 |
z[i] = polyAdd(y[i], cs1[i]) |
| 45 |
@@ -505,7 +514,7 @@ |
| 46 |
if testingOnlyRejectionReason != nil { |
| 47 |
testingOnlyRejectionReason("z") |
| 48 |
} |
| 49 |
- continue sign |
| 50 |
+ rejectionBitmap |= 1 |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
@@ -517,7 +526,7 @@ |
| 55 |
if testingOnlyRejectionReason != nil { |
| 56 |
testingOnlyRejectionReason("r0") |
| 57 |
} |
| 58 |
- continue sign |
| 59 |
+ rejectionBitmap |= 2 |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
@@ -530,7 +539,7 @@ |
| 64 |
if testingOnlyRejectionReason != nil { |
| 65 |
testingOnlyRejectionReason("ct0") |
| 66 |
} |
| 67 |
- continue sign |
| 68 |
+ rejectionBitmap |= 4 |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
@@ -546,10 +555,12 @@ |
| 73 |
if testingOnlyRejectionReason != nil { |
| 74 |
testingOnlyRejectionReason("h") |
| 75 |
} |
| 76 |
- continue sign |
| 77 |
+ rejectionBitmap |= 8 |
| 78 |
} |
| 79 |
|
| 80 |
- return sigEncode(ch, z, h, p) |
| 81 |
+ bitmaps[rejectionBitmap]++ |
| 82 |
+ |
| 83 |
+ fmt.Printf("\r%#v", bitmaps) |
| 84 |
} |
| 85 |
} |
| 86 |
|