Skip to content

Commit f96e193

Browse files
rolandshoemakergopherbot
authored andcommitted
crypto/rsa: make DecryptPKCS1v15SessionKey warning more dire
Updates the DecryptPKCS1v15SessionKey function comment to be less cut and dry about its protections against Bleichenbacher attacks. In particular note that the protocol using this method must be explicitly designed with these mitigations in mind, and call out usages which may cause the migiations to be useless. Change-Id: I06fd25157f12a3afb401bb08dff4faef7fb0a9b0 Reviewed-on: https://go-review.googlesource.com/c/go/+/469235 Reviewed-by: Filippo Valsorda <[email protected]> Reviewed-by: Roland Shoemaker <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Roland Shoemaker <[email protected]> Auto-Submit: Roland Shoemaker <[email protected]> Reviewed-by: David Chase <[email protected]>
1 parent d6473a1 commit f96e193

File tree

1 file changed

+31
-16
lines changed

1 file changed

+31
-16
lines changed

src/crypto/rsa/pkcs1v15.go

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -113,25 +113,40 @@ func DecryptPKCS1v15(random io.Reader, priv *PrivateKey, ciphertext []byte) ([]b
113113
return out[index:], nil
114114
}
115115

116-
// DecryptPKCS1v15SessionKey decrypts a session key using RSA and the padding scheme from PKCS #1 v1.5.
117-
// The random parameter is legacy and ignored, and it can be as nil.
118-
// It returns an error if the ciphertext is the wrong length or if the
119-
// ciphertext is greater than the public modulus. Otherwise, no error is
120-
// returned. If the padding is valid, the resulting plaintext message is copied
121-
// into key. Otherwise, key is unchanged. These alternatives occur in constant
122-
// time. It is intended that the user of this function generate a random
123-
// session key beforehand and continue the protocol with the resulting value.
124-
// This will remove any possibility that an attacker can learn any information
125-
// about the plaintext.
126-
// See “Chosen Ciphertext Attacks Against Protocols Based on the RSA
127-
// Encryption Standard PKCS #1”, Daniel Bleichenbacher, Advances in Cryptology
128-
// (Crypto '98).
116+
// DecryptPKCS1v15SessionKey decrypts a session key using RSA and the padding
117+
// scheme from PKCS #1 v1.5. The random parameter is legacy and ignored, and it
118+
// can be nil.
119+
//
120+
// DecryptPKCS1v15SessionKey returns an error if the ciphertext is the wrong
121+
// length or if the ciphertext is greater than the public modulus. Otherwise, no
122+
// error is returned. If the padding is valid, the resulting plaintext message
123+
// is copied into key. Otherwise, key is unchanged. These alternatives occur in
124+
// constant time. It is intended that the user of this function generate a
125+
// random session key beforehand and continue the protocol with the resulting
126+
// value.
129127
//
130128
// Note that if the session key is too small then it may be possible for an
131-
// attacker to brute-force it. If they can do that then they can learn whether
132-
// a random value was used (because it'll be different for the same ciphertext)
133-
// and thus whether the padding was correct. This defeats the point of this
129+
// attacker to brute-force it. If they can do that then they can learn whether a
130+
// random value was used (because it'll be different for the same ciphertext)
131+
// and thus whether the padding was correct. This also defeats the point of this
134132
// function. Using at least a 16-byte key will protect against this attack.
133+
//
134+
// This method implements protections against Bleichenbacher chosen ciphertext
135+
// attacks [0] described in RFC 3218 Section 2.3.2 [1]. While these protections
136+
// make a Bleichenbacher attack significantly more difficult, the protections
137+
// are only effective if the rest of the protocol which uses
138+
// DecryptPKCS1v15SessionKey is designed with these considerations in mind. In
139+
// particular, if any subsequent operations which use the decrypted session key
140+
// leak any information about the key (e.g. whether it is a static or random
141+
// key) then the mitigations are defeated. This method must be used extremely
142+
// carefully, and typically should only be used when absolutely necessary for
143+
// compatibility with an existing protocol (such as TLS) that is designed with
144+
// these properties in mind.
145+
//
146+
// - [0] “Chosen Ciphertext Attacks Against Protocols Based on the RSA Encryption
147+
// Standard PKCS #1”, Daniel Bleichenbacher, Advances in Cryptology (Crypto '98)
148+
// - [1] RFC 3218, Preventing the Million Message Attack on CMS,
149+
// https://www.rfc-editor.org/rfc/rfc3218.html
135150
func DecryptPKCS1v15SessionKey(random io.Reader, priv *PrivateKey, ciphertext []byte, key []byte) error {
136151
if err := checkPub(&priv.PublicKey); err != nil {
137152
return err

0 commit comments

Comments
 (0)