@@ -263,8 +263,11 @@ func (priv *PrivateKey) Validate() error {
263
263
return nil
264
264
}
265
265
266
- // GenerateKey generates an RSA keypair of the given bit size using the
267
- // random source random (for example, crypto/rand.Reader).
266
+ // GenerateKey generates a random RSA private key of the given bit size.
267
+ //
268
+ // Most applications should use [crypto/rand.Reader] as rand. Note that the
269
+ // returned key does not depend deterministically on the bytes read from rand,
270
+ // and may change between calls and/or between versions.
268
271
func GenerateKey (random io.Reader , bits int ) (* PrivateKey , error ) {
269
272
return GenerateMultiPrimeKey (random , 2 , bits )
270
273
}
@@ -500,6 +503,7 @@ func encrypt(pub *PublicKey, plaintext []byte) ([]byte, error) {
500
503
//
501
504
// The random parameter is used as a source of entropy to ensure that
502
505
// encrypting the same message twice doesn't result in the same ciphertext.
506
+ // Most applications should use [crypto/rand.Reader] as random.
503
507
//
504
508
// The label parameter may contain arbitrary data that will not be encrypted,
505
509
// but which gives important context to the message. For example, if a given
@@ -510,6 +514,12 @@ func encrypt(pub *PublicKey, plaintext []byte) ([]byte, error) {
510
514
// The message must be no longer than the length of the public modulus minus
511
515
// twice the hash length, minus a further 2.
512
516
func EncryptOAEP (hash hash.Hash , random io.Reader , pub * PublicKey , msg []byte , label []byte ) ([]byte , error ) {
517
+ // Note that while we don't commit to deterministic execution with respect
518
+ // to the random stream, we also don't apply MaybeReadByte, so per Hyrum's
519
+ // Law it's probably relied upon by some. It's a tolerable promise because a
520
+ // well-specified number of random bytes is included in the ciphertext, in a
521
+ // well-specified way.
522
+
513
523
if err := checkPub (pub ); err != nil {
514
524
return nil , err
515
525
}
@@ -691,7 +701,7 @@ func decrypt(priv *PrivateKey, ciphertext []byte, check bool) ([]byte, error) {
691
701
// Encryption and decryption of a given message must use the same hash function
692
702
// and sha256.New() is a reasonable choice.
693
703
//
694
- // The random parameter is legacy and ignored, and it can be as nil.
704
+ // The random parameter is legacy and ignored, and it can be nil.
695
705
//
696
706
// The label parameter must match the value given when encrypting. See
697
707
// EncryptOAEP for details.
0 commit comments