@@ -263,8 +263,11 @@ func (priv *PrivateKey) Validate() error {
263263 return nil
264264}
265265
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.
268271func GenerateKey (random io.Reader , bits int ) (* PrivateKey , error ) {
269272 return GenerateMultiPrimeKey (random , 2 , bits )
270273}
@@ -500,6 +503,7 @@ func encrypt(pub *PublicKey, plaintext []byte) ([]byte, error) {
500503//
501504// The random parameter is used as a source of entropy to ensure that
502505// encrypting the same message twice doesn't result in the same ciphertext.
506+ // Most applications should use [crypto/rand.Reader] as random.
503507//
504508// The label parameter may contain arbitrary data that will not be encrypted,
505509// 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) {
510514// The message must be no longer than the length of the public modulus minus
511515// twice the hash length, minus a further 2.
512516func 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+
513523 if err := checkPub (pub ); err != nil {
514524 return nil , err
515525 }
@@ -691,7 +701,7 @@ func decrypt(priv *PrivateKey, ciphertext []byte, check bool) ([]byte, error) {
691701// Encryption and decryption of a given message must use the same hash function
692702// and sha256.New() is a reasonable choice.
693703//
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.
695705//
696706// The label parameter must match the value given when encrypting. See
697707// EncryptOAEP for details.
0 commit comments