@@ -13,7 +13,7 @@ SYNOPSIS
1313 $ciphertext = $rsa->encrypt($plaintext);
1414
1515 $rsa_priv = Crypt::OpenSSL::RSA->new_private_key($key_string);
16- $plaintext = $rsa->encrypt ($ciphertext);
16+ $plaintext = $rsa->decrypt ($ciphertext);
1717
1818 $rsa = Crypt::OpenSSL::RSA->generate_key(1024); # or
1919 $rsa = Crypt::OpenSSL::RSA->generate_key(1024, $prime);
@@ -28,6 +28,15 @@ SYNOPSIS
2828 $signature = $rsa_priv->sign($plaintext);
2929 print "Signed correctly\n" if ($rsa->verify($plaintext, $signature));
3030
31+ SECURITY
32+ Version 0.35 makes the use of PKCS#1 v1.5 padding a fatal error. It is
33+ very difficult to implement PKCS#1 v1.5 padding securely. If you are
34+ still using RSA in in general, you should be looking at alternative
35+ encryption algorithms. Version 0.36 implements RSA-PSS padding (PKCS#1
36+ v2.1) and makes setting an invalid padding a fatal error. Note,
37+ PKCS1_OAEP can only be used for encryption and PKCS1_PSS can only be
38+ used for signing.
39+
3140DESCRIPTION
3241 "Crypt::OpenSSL::RSA" provides the ability to RSA encrypt strings which
3342 are somewhat shorter than the block size of a key. It also allows for
@@ -48,6 +57,10 @@ Class Methods
4857 The padding is set to PKCS1_OAEP, but can be changed with the
4958 "use_xxx_padding" methods.
5059
60+ Note, PKCS1_OAEP can only be used for encryption. You must
61+ specifically call use_pkcs1_pss_padding (or use_pkcs1_pss_padding)
62+ prior to signing operations.
63+
5164 new_private_key
5265 Create a new "Crypt::OpenSSL::RSA" object by loading a private key
5366 in from an string containing the Base64/DER encoding of the PKCS1
@@ -140,27 +153,53 @@ Instance Methods
140153 verify
141154 Check the signature on a text.
142155
156+ Padding Methods
157+ Versions prior to 0.35 allowed using pkcs1 padding for both encryption
158+ and signature operations but has been disabled for security reasons.
159+
160+ While use_no_padding can be used for encryption or signature operations
161+ use_pkcs1_pss_padding is used for signature operations and
162+ use_pkcs1_oaep_padding is used for encryption operations.
163+
164+ Version 0.38 sets the appropriate padding for each operation unless
165+ use_no_padding is called before either operation.
166+
143167 use_no_padding
144168 Use raw RSA encryption. This mode should only be used to implement
145169 cryptographically sound padding modes in the application code.
146170 Encrypting user data directly with RSA is insecure.
147171
148172 use_pkcs1_padding
149- Use PKCS #1 v1.5 padding. This currently is the most widely used
150- mode of padding.
173+ PKCS #1 v1.5 padding has been disabled as it is nearly impossible to
174+ use this padding method in a secure manner. It is known to be
175+ vulnerable to timing based side channel attacks. use_pkcs1_padding()
176+ results in a fatal error.
177+
178+ Marvin Attack
179+ <https://github.com/tomato42/marvin-toolkit/blob/master/README.md>
151180
152181 use_pkcs1_oaep_padding
153182 Use "EME-OAEP" padding as defined in PKCS #1 v2.0 with SHA-1, MGF1
154183 and an empty encoding parameter. This mode of padding is recommended
155184 for all new applications. It is the default mode used by
156- "Crypt::OpenSSL::RSA".
185+ "Crypt::OpenSSL::RSA" but is only valid for encryption/decryption.
186+
187+ use_pkcs1_pss_padding
188+ Use RSA-PSS padding as defined in PKCS#1 v2.1. In general, RSA-PSS
189+ should be used as a replacement for RSA-PKCS#1 v1.5. The module
190+ specifies the message digest being requested and the appropriate mgf1
191+ setting and salt length for the digest.
192+
193+ Note: RSA-PSS cannot be used for encryption/decryption and results in
194+ a fatal error. Call use_pkcs1_oaep_padding for encryption operations.
157195
158196 use_sslv23_padding
159197 Use "PKCS #1 v1.5" padding with an SSL-specific modification that
160198 denotes that the server is SSL3 capable.
161199
162200 Not available since OpenSSL 3.
163201
202+ Hash/Digest Methods
164203 use_md5_hash
165204 Use the RFC 1321 MD5 hashing algorithm by Ron Rivest when signing
166205 and verifying messages.
0 commit comments