Skip to content

Commit c58d075

Browse files
FiloSottilegopherbot
authored andcommitted
crypto/rsa: deprecate PKCS#1 v1.5 encryption
Fixes #75302 Change-Id: I6a6a6964c2b3b33bfb34b9677a57610b933bbfab Reviewed-on: https://go-review.googlesource.com/c/go/+/701436 Reviewed-by: Daniel McCarney <[email protected]> Reviewed-by: Mark Freeman <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Filippo Valsorda <[email protected]> Reviewed-by: Michael Pratt <[email protected]>
1 parent d55ecea commit c58d075

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

api/next/75302.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pkg crypto/rsa, func DecryptPKCS1v15 //deprecated #75302
2+
pkg crypto/rsa, func DecryptPKCS1v15SessionKey //deprecated #75302
3+
pkg crypto/rsa, func EncryptPKCS1v15 //deprecated #75302
4+
pkg crypto/rsa, type PKCS1v15DecryptOptions //deprecated #75302
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Unsafe PKCS #1 v1.5 encryption padding (implemented by [EncryptPKCS1v15],
2+
[DecryptPKCS1v15], and [DecryptPKCS1v15SessionKey]) is now deprecated.

src/crypto/rsa/pkcs1v15.go

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ import (
1818

1919
// PKCS1v15DecryptOptions is for passing options to PKCS #1 v1.5 decryption using
2020
// the [crypto.Decrypter] interface.
21+
//
22+
// Deprecated: PKCS #1 v1.5 encryption is dangerous and should not be used.
23+
// See [draft-irtf-cfrg-rsa-guidance-05] for more information. Use
24+
// [EncryptOAEP] and [DecryptOAEP] instead.
25+
//
26+
// [draft-irtf-cfrg-rsa-guidance-05]: https://www.ietf.org/archive/id/draft-irtf-cfrg-rsa-guidance-05.html#name-rationale
2127
type PKCS1v15DecryptOptions struct {
2228
// SessionKeyLen is the length of the session key that is being
2329
// decrypted. If not zero, then a padding error during decryption will
@@ -37,8 +43,11 @@ type PKCS1v15DecryptOptions struct {
3743
// deterministically on the bytes read from random, and may change
3844
// between calls and/or between versions.
3945
//
40-
// WARNING: use of this function to encrypt plaintexts other than
41-
// session keys is dangerous. Use RSA OAEP in new protocols.
46+
// Deprecated: PKCS #1 v1.5 encryption is dangerous and should not be used.
47+
// See [draft-irtf-cfrg-rsa-guidance-05] for more information. Use
48+
// [EncryptOAEP] and [DecryptOAEP] instead.
49+
//
50+
// [draft-irtf-cfrg-rsa-guidance-05]: https://www.ietf.org/archive/id/draft-irtf-cfrg-rsa-guidance-05.html#name-rationale
4251
func EncryptPKCS1v15(random io.Reader, pub *PublicKey, msg []byte) ([]byte, error) {
4352
if fips140only.Enabled {
4453
return nil, errors.New("crypto/rsa: use of PKCS#1 v1.5 encryption is not allowed in FIPS 140-only mode")
@@ -91,14 +100,17 @@ func EncryptPKCS1v15(random io.Reader, pub *PublicKey, msg []byte) ([]byte, erro
91100
return rsa.Encrypt(fk, em)
92101
}
93102

94-
// DecryptPKCS1v15 decrypts a plaintext using RSA and the padding scheme from PKCS #1 v1.5.
95-
// The random parameter is legacy and ignored, and it can be nil.
103+
// DecryptPKCS1v15 decrypts a plaintext using RSA and the padding scheme from
104+
// PKCS #1 v1.5. The random parameter is legacy and ignored, and it can be nil.
96105
//
97-
// Note that whether this function returns an error or not discloses secret
98-
// information. If an attacker can cause this function to run repeatedly and
99-
// learn whether each instance returned an error then they can decrypt and
100-
// forge signatures as if they had the private key. See
101-
// DecryptPKCS1v15SessionKey for a way of solving this problem.
106+
// Deprecated: PKCS #1 v1.5 encryption is dangerous and should not be used.
107+
// Whether this function returns an error or not discloses secret information.
108+
// If an attacker can cause this function to run repeatedly and learn whether
109+
// each instance returned an error then they can decrypt and forge signatures as
110+
// if they had the private key. See [draft-irtf-cfrg-rsa-guidance-05] for more
111+
// information. Use [EncryptOAEP] and [DecryptOAEP] instead.
112+
//
113+
// [draft-irtf-cfrg-rsa-guidance-05]: https://www.ietf.org/archive/id/draft-irtf-cfrg-rsa-guidance-05.html#name-rationale
102114
func DecryptPKCS1v15(random io.Reader, priv *PrivateKey, ciphertext []byte) ([]byte, error) {
103115
if err := checkPublicKeySize(&priv.PublicKey); err != nil {
104116
return nil, err
@@ -160,6 +172,13 @@ func DecryptPKCS1v15(random io.Reader, priv *PrivateKey, ciphertext []byte) ([]b
160172
// Standard PKCS #1”, Daniel Bleichenbacher, Advances in Cryptology (Crypto '98)
161173
// - [1] RFC 3218, Preventing the Million Message Attack on CMS,
162174
// https://www.rfc-editor.org/rfc/rfc3218.html
175+
//
176+
// Deprecated: PKCS #1 v1.5 encryption is dangerous and should not be used. The
177+
// protections implemented by this function are limited and fragile, as
178+
// explained above. See [draft-irtf-cfrg-rsa-guidance-05] for more information.
179+
// Use [EncryptOAEP] and [DecryptOAEP] instead.
180+
//
181+
// [draft-irtf-cfrg-rsa-guidance-05]: https://www.ietf.org/archive/id/draft-irtf-cfrg-rsa-guidance-05.html#name-rationale
163182
func DecryptPKCS1v15SessionKey(random io.Reader, priv *PrivateKey, ciphertext []byte, key []byte) error {
164183
if err := checkPublicKeySize(&priv.PublicKey); err != nil {
165184
return err

0 commit comments

Comments
 (0)