Skip to content

Commit 81fc3d2

Browse files
FiloSottilegopherbot
authored andcommitted
crypto/internal/mlkem768: remove crypto/rand.Read error checking
After #66821 crypto/rand.Read can't return an error. Change-Id: I185063a25ef70986448f2a300e5578de17f6e61e Reviewed-on: https://go-review.googlesource.com/c/go/+/621979 Auto-Submit: Filippo Valsorda <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Michael Knyszek <[email protected]> Reviewed-by: Russ Cox <[email protected]> Reviewed-by: Daniel McCarney <[email protected]>
1 parent 0568cda commit 81fc3d2

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

src/crypto/internal/mlkem768/mlkem768.go

+6-12
Original file line numberDiff line numberDiff line change
@@ -112,19 +112,15 @@ type decryptionKey struct {
112112
func GenerateKey() (*DecapsulationKey, error) {
113113
// The actual logic is in a separate function to outline this allocation.
114114
dk := &DecapsulationKey{}
115-
return generateKey(dk)
115+
return generateKey(dk), nil
116116
}
117117

118-
func generateKey(dk *DecapsulationKey) (*DecapsulationKey, error) {
118+
func generateKey(dk *DecapsulationKey) *DecapsulationKey {
119119
var d [32]byte
120-
if _, err := rand.Read(d[:]); err != nil {
121-
return nil, errors.New("mlkem768: crypto/rand Read failed: " + err.Error())
122-
}
120+
rand.Read(d[:])
123121
var z [32]byte
124-
if _, err := rand.Read(z[:]); err != nil {
125-
return nil, errors.New("mlkem768: crypto/rand Read failed: " + err.Error())
126-
}
127-
return kemKeyGen(dk, &d, &z), nil
122+
rand.Read(z[:])
123+
return kemKeyGen(dk, &d, &z)
128124
}
129125

130126
// NewKeyFromSeed deterministically generates a decapsulation key from a 64-byte
@@ -214,9 +210,7 @@ func encapsulate(cc *[CiphertextSize]byte, encapsulationKey []byte) (ciphertext,
214210
return nil, nil, errors.New("mlkem768: invalid encapsulation key length")
215211
}
216212
var m [messageSize]byte
217-
if _, err := rand.Read(m[:]); err != nil {
218-
return nil, nil, errors.New("mlkem768: crypto/rand Read failed: " + err.Error())
219-
}
213+
rand.Read(m[:])
220214
// Note that the modulus check (step 2 of the encapsulation key check from
221215
// FIPS 203, Section 7.2) is performed by polyByteDecode in parseEK.
222216
return kemEncaps(cc, encapsulationKey, &m)

0 commit comments

Comments
 (0)