@@ -112,19 +112,15 @@ type decryptionKey struct {
112
112
func GenerateKey () (* DecapsulationKey , error ) {
113
113
// The actual logic is in a separate function to outline this allocation.
114
114
dk := & DecapsulationKey {}
115
- return generateKey (dk )
115
+ return generateKey (dk ), nil
116
116
}
117
117
118
- func generateKey (dk * DecapsulationKey ) ( * DecapsulationKey , error ) {
118
+ func generateKey (dk * DecapsulationKey ) * DecapsulationKey {
119
119
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 [:])
123
121
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 )
128
124
}
129
125
130
126
// NewKeyFromSeed deterministically generates a decapsulation key from a 64-byte
@@ -214,9 +210,7 @@ func encapsulate(cc *[CiphertextSize]byte, encapsulationKey []byte) (ciphertext,
214
210
return nil , nil , errors .New ("mlkem768: invalid encapsulation key length" )
215
211
}
216
212
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 [:])
220
214
// Note that the modulus check (step 2 of the encapsulation key check from
221
215
// FIPS 203, Section 7.2) is performed by polyByteDecode in parseEK.
222
216
return kemEncaps (cc , encapsulationKey , & m )
0 commit comments