mirror of
https://github.com/golang/go
synced 2024-11-22 22:00:02 -07:00
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 <filippo@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-by: Daniel McCarney <daniel@binaryparadox.net>
This commit is contained in:
parent
0568cda10a
commit
81fc3d2239
@ -112,19 +112,15 @@ type decryptionKey struct {
|
|||||||
func GenerateKey() (*DecapsulationKey, error) {
|
func GenerateKey() (*DecapsulationKey, error) {
|
||||||
// The actual logic is in a separate function to outline this allocation.
|
// The actual logic is in a separate function to outline this allocation.
|
||||||
dk := &DecapsulationKey{}
|
dk := &DecapsulationKey{}
|
||||||
return generateKey(dk)
|
return generateKey(dk), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateKey(dk *DecapsulationKey) (*DecapsulationKey, error) {
|
func generateKey(dk *DecapsulationKey) *DecapsulationKey {
|
||||||
var d [32]byte
|
var d [32]byte
|
||||||
if _, err := rand.Read(d[:]); err != nil {
|
rand.Read(d[:])
|
||||||
return nil, errors.New("mlkem768: crypto/rand Read failed: " + err.Error())
|
|
||||||
}
|
|
||||||
var z [32]byte
|
var z [32]byte
|
||||||
if _, err := rand.Read(z[:]); err != nil {
|
rand.Read(z[:])
|
||||||
return nil, errors.New("mlkem768: crypto/rand Read failed: " + err.Error())
|
return kemKeyGen(dk, &d, &z)
|
||||||
}
|
|
||||||
return kemKeyGen(dk, &d, &z), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewKeyFromSeed deterministically generates a decapsulation key from a 64-byte
|
// NewKeyFromSeed deterministically generates a decapsulation key from a 64-byte
|
||||||
@ -214,9 +210,7 @@ func encapsulate(cc *[CiphertextSize]byte, encapsulationKey []byte) (ciphertext,
|
|||||||
return nil, nil, errors.New("mlkem768: invalid encapsulation key length")
|
return nil, nil, errors.New("mlkem768: invalid encapsulation key length")
|
||||||
}
|
}
|
||||||
var m [messageSize]byte
|
var m [messageSize]byte
|
||||||
if _, err := rand.Read(m[:]); err != nil {
|
rand.Read(m[:])
|
||||||
return nil, nil, errors.New("mlkem768: crypto/rand Read failed: " + err.Error())
|
|
||||||
}
|
|
||||||
// Note that the modulus check (step 2 of the encapsulation key check from
|
// Note that the modulus check (step 2 of the encapsulation key check from
|
||||||
// FIPS 203, Section 7.2) is performed by polyByteDecode in parseEK.
|
// FIPS 203, Section 7.2) is performed by polyByteDecode in parseEK.
|
||||||
return kemEncaps(cc, encapsulationKey, &m)
|
return kemEncaps(cc, encapsulationKey, &m)
|
||||||
|
Loading…
Reference in New Issue
Block a user