Sybren A. Stüvel | dbea213 | 2011-08-03 13:31:57 +0200 | [diff] [blame] | 1 | .. _usage: |
| 2 | |
Sybren A. Stüvel | aa28c04 | 2011-07-30 23:48:00 +0200 | [diff] [blame] | 3 | Usage |
Sybren A. Stüvel | 3934ab4 | 2016-02-05 16:01:20 +0100 | [diff] [blame] | 4 | ===== |
Sybren A. Stüvel | aa28c04 | 2011-07-30 23:48:00 +0200 | [diff] [blame] | 5 | |
Sybren A. Stüvel | a3fd61a | 2011-07-31 00:22:31 +0200 | [diff] [blame] | 6 | This section describes the usage of the Python-RSA module. |
Sybren A. Stüvel | aa28c04 | 2011-07-30 23:48:00 +0200 | [diff] [blame] | 7 | |
Sybren A. Stüvel | a3fd61a | 2011-07-31 00:22:31 +0200 | [diff] [blame] | 8 | Before you can use RSA you need keys. You will receive a private key |
| 9 | and a public key. |
| 10 | |
Sybren A. Stüvel | dbea213 | 2011-08-03 13:31:57 +0200 | [diff] [blame] | 11 | .. important:: |
Sybren A. Stüvel | a3fd61a | 2011-07-31 00:22:31 +0200 | [diff] [blame] | 12 | |
| 13 | The private key is called *private* for a reason. Never share this |
| 14 | key with anyone. |
| 15 | |
Sybren A. Stüvel | d92b667 | 2011-07-31 17:44:44 +0200 | [diff] [blame] | 16 | The public key is used for encypting a message such that it can only |
| 17 | be read by the owner of the private key. As such it's also referred to |
| 18 | as the *encryption key*. Decrypting a message can only be done using |
| 19 | the private key, hence it's also called the *decryption key*. |
| 20 | |
| 21 | The private key is used for signing a message. With this signature and |
| 22 | the public key, the receiver can verifying that a message was signed |
| 23 | by the owner of the private key, and that the message was not modified |
| 24 | after signing. |
| 25 | |
Sybren A. Stüvel | e7c6e74 | 2015-08-31 21:49:42 +0200 | [diff] [blame] | 26 | |
Sybren A. Stüvel | d92b667 | 2011-07-31 17:44:44 +0200 | [diff] [blame] | 27 | Generating keys |
Sybren A. Stüvel | 3934ab4 | 2016-02-05 16:01:20 +0100 | [diff] [blame] | 28 | --------------- |
Sybren A. Stüvel | d92b667 | 2011-07-31 17:44:44 +0200 | [diff] [blame] | 29 | |
Sybren A. Stüvel | 1f011e1 | 2011-07-31 19:20:46 +0200 | [diff] [blame] | 30 | You can use the :py:func:`rsa.newkeys` function to create a keypair: |
| 31 | |
Sybren A. Stüvel | e7c6e74 | 2015-08-31 21:49:42 +0200 | [diff] [blame] | 32 | >>> import rsa |
Sybren A. Stüvel | 1f011e1 | 2011-07-31 19:20:46 +0200 | [diff] [blame] | 33 | >>> (pubkey, privkey) = rsa.newkeys(512) |
| 34 | |
| 35 | Alternatively you can use :py:meth:`rsa.PrivateKey.load_pkcs1` and |
| 36 | :py:meth:`rsa.PublicKey.load_pkcs1` to load keys from a file: |
| 37 | |
Sybren A. Stüvel | e7c6e74 | 2015-08-31 21:49:42 +0200 | [diff] [blame] | 38 | >>> import rsa |
Sybren A. Stüvel | f68c52a | 2016-01-18 15:39:50 +0100 | [diff] [blame] | 39 | >>> with open('private.pem', mode='rb') as privatefile: |
Sybren A. Stüvel | 1f011e1 | 2011-07-31 19:20:46 +0200 | [diff] [blame] | 40 | ... keydata = privatefile.read() |
Sybren A. Stüvel | f68c52a | 2016-01-18 15:39:50 +0100 | [diff] [blame] | 41 | >>> privkey = rsa.PrivateKey.load_pkcs1(keydata) |
Sybren A. Stüvel | d92b667 | 2011-07-31 17:44:44 +0200 | [diff] [blame] | 42 | |
Sybren A. Stüvel | 360d042 | 2011-08-10 12:52:59 +0200 | [diff] [blame] | 43 | |
| 44 | Time to generate a key |
Sybren A. Stüvel | 3934ab4 | 2016-02-05 16:01:20 +0100 | [diff] [blame] | 45 | ++++++++++++++++++++++ |
Sybren A. Stüvel | 360d042 | 2011-08-10 12:52:59 +0200 | [diff] [blame] | 46 | |
Sybren A. Stüvel | d92b667 | 2011-07-31 17:44:44 +0200 | [diff] [blame] | 47 | Generating a keypair may take a long time, depending on the number of |
| 48 | bits required. The number of bits determines the cryptographic |
| 49 | strength of the key, as well as the size of the message you can |
| 50 | encrypt. If you don't mind having a slightly smaller key than you |
| 51 | requested, you can pass ``accurate=False`` to speed up the key |
| 52 | generation process. |
| 53 | |
Sybren A. Stüvel | 360d042 | 2011-08-10 12:52:59 +0200 | [diff] [blame] | 54 | Another way to speed up the key generation process is to use multiple |
| 55 | processes in parallel to speed up the key generation. Use no more than |
| 56 | the number of processes that your machine can run in parallel; a |
| 57 | dual-core machine should use ``poolsize=2``; a quad-core |
| 58 | hyperthreading machine can run two threads on each core, and thus can |
| 59 | use ``poolsize=8``. |
Sybren A. Stüvel | d92b667 | 2011-07-31 17:44:44 +0200 | [diff] [blame] | 60 | |
Sybren A. Stüvel | 360d042 | 2011-08-10 12:52:59 +0200 | [diff] [blame] | 61 | >>> (pubkey, privkey) = rsa.newkeys(512, poolsize=8) |
| 62 | |
| 63 | These are some average timings from my desktop machine (Linux 2.6, |
| 64 | 2.93 GHz quad-core Intel Core i7, 16 GB RAM) using 64-bit CPython 2.7. |
| 65 | Since key generation is a random process, times may differ even on |
| 66 | similar hardware. On all tests, we used the default ``accurate=True``. |
| 67 | |
| 68 | +----------------+------------------+------------------+ |
| 69 | | Keysize (bits) | single process | eight processes | |
| 70 | +================+==================+==================+ |
| 71 | | 128 | 0.01 sec. | 0.01 sec. | |
| 72 | +----------------+------------------+------------------+ |
| 73 | | 256 | 0.03 sec. | 0.02 sec. | |
| 74 | +----------------+------------------+------------------+ |
| 75 | | 384 | 0.09 sec. | 0.04 sec. | |
| 76 | +----------------+------------------+------------------+ |
| 77 | | 512 | 0.11 sec. | 0.07 sec. | |
| 78 | +----------------+------------------+------------------+ |
| 79 | | 1024 | 0.79 sec. | 0.30 sec. | |
| 80 | +----------------+------------------+------------------+ |
| 81 | | 2048 | 6.55 sec. | 1.60 sec. | |
| 82 | +----------------+------------------+------------------+ |
| 83 | | 3072 | 23.4 sec. | 7.14 sec. | |
| 84 | +----------------+------------------+------------------+ |
| 85 | | 4096 | 72.0 sec. | 24.4 sec. | |
| 86 | +----------------+------------------+------------------+ |
Sybren A. Stüvel | d92b667 | 2011-07-31 17:44:44 +0200 | [diff] [blame] | 87 | |
Sybren A. Stüvel | 58fe946 | 2011-08-03 13:56:32 +0200 | [diff] [blame] | 88 | If key generation is too slow for you, you could use OpenSSL to |
Sybren A. Stüvel | 360d042 | 2011-08-10 12:52:59 +0200 | [diff] [blame] | 89 | generate them for you, then load them in your Python code. OpenSSL |
| 90 | generates a 4096-bit key in 3.5 seconds on the same machine as used |
| 91 | above. See :ref:`openssl` for more information. |
Sybren A. Stüvel | 58fe946 | 2011-08-03 13:56:32 +0200 | [diff] [blame] | 92 | |
| 93 | Key size requirements |
Sybren A. Stüvel | 3934ab4 | 2016-02-05 16:01:20 +0100 | [diff] [blame] | 94 | --------------------- |
Sybren A. Stüvel | 58fe946 | 2011-08-03 13:56:32 +0200 | [diff] [blame] | 95 | |
| 96 | Python-RSA version 3.0 introduced PKCS#1-style random padding. This |
| 97 | means that 11 bytes (88 bits) of your key are no longer usable for |
| 98 | encryption, so keys smaller than this are unusable. The larger the |
| 99 | key, the higher the security. |
| 100 | |
| 101 | Creating signatures also requires a key of a certain size, depending |
| 102 | on the used hash method: |
| 103 | |
| 104 | +-------------+-----------------------------------+ |
| 105 | | Hash method | Suggested minimum key size (bits) | |
| 106 | +=============+===================================+ |
| 107 | | MD5 | 360 | |
| 108 | +-------------+-----------------------------------+ |
| 109 | | SHA-1 | 368 | |
| 110 | +-------------+-----------------------------------+ |
| 111 | | SHA-256 | 496 | |
| 112 | +-------------+-----------------------------------+ |
| 113 | | SHA-384 | 624 | |
| 114 | +-------------+-----------------------------------+ |
| 115 | | SHA-512 | 752 | |
| 116 | +-------------+-----------------------------------+ |
| 117 | |
| 118 | |
Sybren A. Stüvel | a3fd61a | 2011-07-31 00:22:31 +0200 | [diff] [blame] | 119 | |
| 120 | Encryption and decryption |
Sybren A. Stüvel | 3934ab4 | 2016-02-05 16:01:20 +0100 | [diff] [blame] | 121 | ------------------------- |
Sybren A. Stüvel | a3fd61a | 2011-07-31 00:22:31 +0200 | [diff] [blame] | 122 | |
Sybren A. Stüvel | d92b667 | 2011-07-31 17:44:44 +0200 | [diff] [blame] | 123 | To encrypt or decrypt a message, use :py:func:`rsa.encrypt` resp. |
| 124 | :py:func:`rsa.decrypt`. Let's say that Alice wants to send a message |
| 125 | that only Bob can read. |
| 126 | |
| 127 | #. Bob generates a keypair, and gives the public key to Alice. This is |
| 128 | done such that Alice knows for sure that the key is really Bob's |
| 129 | (for example by handing over a USB stick that contains the key). |
| 130 | |
Sybren A. Stüvel | e7c6e74 | 2015-08-31 21:49:42 +0200 | [diff] [blame] | 131 | >>> import rsa |
Sybren A. Stüvel | 1f011e1 | 2011-07-31 19:20:46 +0200 | [diff] [blame] | 132 | >>> (bob_pub, bob_priv) = rsa.newkeys(512) |
| 133 | |
Sybren A. Stüvel | e7c6e74 | 2015-08-31 21:49:42 +0200 | [diff] [blame] | 134 | #. Alice writes a message, and encodes it in UTF-8. The RSA module |
| 135 | only operates on bytes, and not on strings, so this step is |
| 136 | necessary. |
Sybren A. Stüvel | d92b667 | 2011-07-31 17:44:44 +0200 | [diff] [blame] | 137 | |
Sybren A. Stüvel | e7c6e74 | 2015-08-31 21:49:42 +0200 | [diff] [blame] | 138 | >>> message = 'hello Bob!'.encode('utf8') |
Sybren A. Stüvel | 1f011e1 | 2011-07-31 19:20:46 +0200 | [diff] [blame] | 139 | |
Sybren A. Stüvel | d92b667 | 2011-07-31 17:44:44 +0200 | [diff] [blame] | 140 | #. Alice encrypts the message using Bob's public key, and sends the |
| 141 | encrypted message. |
| 142 | |
Sybren A. Stüvel | e7c6e74 | 2015-08-31 21:49:42 +0200 | [diff] [blame] | 143 | >>> import rsa |
Sybren A. Stüvel | db34825 | 2011-07-31 19:22:47 +0200 | [diff] [blame] | 144 | >>> crypto = rsa.encrypt(message, bob_pub) |
Sybren A. Stüvel | 1f011e1 | 2011-07-31 19:20:46 +0200 | [diff] [blame] | 145 | |
Sybren A. Stüvel | d92b667 | 2011-07-31 17:44:44 +0200 | [diff] [blame] | 146 | #. Bob receives the message, and decrypts it with his private key. |
| 147 | |
Sybren A. Stüvel | 1f011e1 | 2011-07-31 19:20:46 +0200 | [diff] [blame] | 148 | >>> message = rsa.decrypt(crypto, bob_priv) |
Sybren A. Stüvel | e7c6e74 | 2015-08-31 21:49:42 +0200 | [diff] [blame] | 149 | >>> print(message.decode('utf8')) |
Sybren A. Stüvel | 1f011e1 | 2011-07-31 19:20:46 +0200 | [diff] [blame] | 150 | hello Bob! |
| 151 | |
Sybren A. Stüvel | d92b667 | 2011-07-31 17:44:44 +0200 | [diff] [blame] | 152 | Since Bob kept his private key *private*, Alice can be sure that he is |
Sybren A. Stüvel | dbea213 | 2011-08-03 13:31:57 +0200 | [diff] [blame] | 153 | the only one who can read the message. Bob does *not* know for sure |
| 154 | that it was Alice that sent the message, since she didn't sign it. |
Sybren A. Stüvel | d92b667 | 2011-07-31 17:44:44 +0200 | [diff] [blame] | 155 | |
| 156 | |
Sybren A. Stüvel | b6c04dd | 2011-08-01 21:37:02 +0200 | [diff] [blame] | 157 | RSA can only encrypt messages that are smaller than the key. A couple |
| 158 | of bytes are lost on random padding, and the rest is available for the |
| 159 | message itself. For example, a 512-bit key can encode a 53-byte |
| 160 | message (512 bit = 64 bytes, 11 bytes are used for random padding and |
Sybren A. Stüvel | dbea213 | 2011-08-03 13:31:57 +0200 | [diff] [blame] | 161 | other stuff). See :ref:`bigfiles` for information on how to work with |
Sybren A. Stüvel | b6c04dd | 2011-08-01 21:37:02 +0200 | [diff] [blame] | 162 | larger files. |
| 163 | |
Sybren A. Stüvel | dbea213 | 2011-08-03 13:31:57 +0200 | [diff] [blame] | 164 | Altering the encrypted information will *likely* cause a |
| 165 | :py:class:`rsa.pkcs1.DecryptionError`. If you want to be *sure*, use |
| 166 | :py:func:`rsa.sign`. |
| 167 | |
Sybren A. Stüvel | e7c6e74 | 2015-08-31 21:49:42 +0200 | [diff] [blame] | 168 | >>> crypto = rsa.encrypt(b'hello', bob_pub) |
| 169 | >>> crypto = crypto[:-1] + b'X' # change the last byte |
| 170 | >>> rsa.decrypt(crypto, bob_priv) |
Sybren A. Stüvel | dbea213 | 2011-08-03 13:31:57 +0200 | [diff] [blame] | 171 | Traceback (most recent call last): |
| 172 | ... |
| 173 | rsa.pkcs1.DecryptionError: Decryption failed |
| 174 | |
| 175 | |
| 176 | .. warning:: |
| 177 | |
| 178 | Never display the stack trace of a |
| 179 | :py:class:`rsa.pkcs1.DecryptionError` exception. It shows where |
| 180 | in the code the exception occurred, and thus leaks information |
| 181 | about the key. It’s only a tiny bit of information, but every bit |
| 182 | makes cracking the keys easier. |
| 183 | |
Sybren A. Stüvel | d92b667 | 2011-07-31 17:44:44 +0200 | [diff] [blame] | 184 | Low-level operations |
Sybren A. Stüvel | 3934ab4 | 2016-02-05 16:01:20 +0100 | [diff] [blame] | 185 | ++++++++++++++++++++ |
Sybren A. Stüvel | d92b667 | 2011-07-31 17:44:44 +0200 | [diff] [blame] | 186 | |
| 187 | The core RSA algorithm operates on large integers. These operations |
| 188 | are considered low-level and are supported by the |
| 189 | :py:func:`rsa.core.encrypt_int` and :py:func:`rsa.core.decrypt_int` |
| 190 | functions. |
Sybren A. Stüvel | a3fd61a | 2011-07-31 00:22:31 +0200 | [diff] [blame] | 191 | |
| 192 | Signing and verification |
Sybren A. Stüvel | 3934ab4 | 2016-02-05 16:01:20 +0100 | [diff] [blame] | 193 | ------------------------ |
Sybren A. Stüvel | a3fd61a | 2011-07-31 00:22:31 +0200 | [diff] [blame] | 194 | |
Sybren A. Stüvel | 1f011e1 | 2011-07-31 19:20:46 +0200 | [diff] [blame] | 195 | You can create a detached signature for a message using the |
| 196 | :py:func:`rsa.sign` function: |
| 197 | |
| 198 | >>> (pubkey, privkey) = rsa.newkeys(512) |
| 199 | >>> message = 'Go left at the blue tree' |
| 200 | >>> signature = rsa.sign(message, privkey, 'SHA-1') |
Sybren A. Stüvel | 1d14c4e | 2017-04-10 11:31:09 +0200 | [diff] [blame] | 201 | |
Sybren A. Stüvel | 1f011e1 | 2011-07-31 19:20:46 +0200 | [diff] [blame] | 202 | This hashes the message using SHA-1. Other hash methods are also |
| 203 | possible, check the :py:func:`rsa.sign` function documentation for |
| 204 | details. The hash is then signed with the private key. |
| 205 | |
| 206 | In order to verify the signature, use the :py:func:`rsa.verify` |
Tim Heckman | 7446f0a | 2012-10-17 21:09:43 -0400 | [diff] [blame] | 207 | function. This function returns True if the verification is successful: |
Sybren A. Stüvel | 1f011e1 | 2011-07-31 19:20:46 +0200 | [diff] [blame] | 208 | |
| 209 | >>> message = 'Go left at the blue tree' |
| 210 | >>> rsa.verify(message, signature, pubkey) |
Tim Heckman | 7446f0a | 2012-10-17 21:09:43 -0400 | [diff] [blame] | 211 | True |
Sybren A. Stüvel | 1f011e1 | 2011-07-31 19:20:46 +0200 | [diff] [blame] | 212 | |
| 213 | Modify the message, and the signature is no longer valid and a |
| 214 | :py:class:`rsa.pkcs1.VerificationError` is thrown: |
| 215 | |
| 216 | >>> message = 'Go right at the blue tree' |
| 217 | >>> rsa.verify(message, signature, pubkey) |
| 218 | Traceback (most recent call last): |
| 219 | File "<stdin>", line 1, in <module> |
| 220 | File "/home/sybren/workspace/python-rsa/rsa/pkcs1.py", line 289, in verify |
| 221 | raise VerificationError('Verification failed') |
| 222 | rsa.pkcs1.VerificationError: Verification failed |
| 223 | |
Sybren A. Stüvel | dbea213 | 2011-08-03 13:31:57 +0200 | [diff] [blame] | 224 | .. warning:: |
Sybren A. Stüvel | 1f011e1 | 2011-07-31 19:20:46 +0200 | [diff] [blame] | 225 | |
| 226 | Never display the stack trace of a |
| 227 | :py:class:`rsa.pkcs1.VerificationError` exception. It shows where |
| 228 | in the code the exception occurred, and thus leaks information |
| 229 | about the key. It's only a tiny bit of information, but every bit |
| 230 | makes cracking the keys easier. |
| 231 | |
Sybren A. Stüvel | b6c04dd | 2011-08-01 21:37:02 +0200 | [diff] [blame] | 232 | Instead of a message you can also call :py:func:`rsa.sign` and |
| 233 | :py:func:`rsa.verify` with a :py:class:`file`-like object. If the |
| 234 | message object has a ``read(int)`` method it is assumed to be a file. |
| 235 | In that case the file is hashed in 1024-byte blocks at the time. |
| 236 | |
| 237 | >>> with open('somefile', 'rb') as msgfile: |
| 238 | ... signature = rsa.sign(msgfile, privkey, 'SHA-1') |
| 239 | |
| 240 | >>> with open('somefile', 'rb') as msgfile: |
| 241 | ... rsa.verify(msgfile, signature, pubkey) |
| 242 | |
Sybren A. Stüvel | a3fd61a | 2011-07-31 00:22:31 +0200 | [diff] [blame] | 243 | |
Sybren A. Stüvel | dbea213 | 2011-08-03 13:31:57 +0200 | [diff] [blame] | 244 | .. _bigfiles: |
| 245 | |
Sybren A. Stüvel | a3fd61a | 2011-07-31 00:22:31 +0200 | [diff] [blame] | 246 | Working with big files |
Sybren A. Stüvel | 3934ab4 | 2016-02-05 16:01:20 +0100 | [diff] [blame] | 247 | ---------------------- |
Sybren A. Stüvel | a3fd61a | 2011-07-31 00:22:31 +0200 | [diff] [blame] | 248 | |
Sybren A. Stüvel | b6c04dd | 2011-08-01 21:37:02 +0200 | [diff] [blame] | 249 | RSA can only encrypt messages that are smaller than the key. A couple |
| 250 | of bytes are lost on random padding, and the rest is available for the |
| 251 | message itself. For example, a 512-bit key can encode a 53-byte |
| 252 | message (512 bit = 64 bytes, 11 bytes are used for random padding and |
| 253 | other stuff). |
Sybren A. Stüvel | a3fd61a | 2011-07-31 00:22:31 +0200 | [diff] [blame] | 254 | |
Sybren A. Stüvel | b6c04dd | 2011-08-01 21:37:02 +0200 | [diff] [blame] | 255 | How it usually works |
Sybren A. Stüvel | 3934ab4 | 2016-02-05 16:01:20 +0100 | [diff] [blame] | 256 | ++++++++++++++++++++ |
Sybren A. Stüvel | b6c04dd | 2011-08-01 21:37:02 +0200 | [diff] [blame] | 257 | |
| 258 | The most common way to use RSA with larger files uses a block cypher |
| 259 | like AES or DES3 to encrypt the file with a random key, then encrypt |
| 260 | the random key with RSA. You would send the encrypted file along with |
| 261 | the encrypted key to the recipient. The complete flow is: |
| 262 | |
| 263 | #. Generate a random key |
| 264 | |
| 265 | >>> import rsa.randnum |
| 266 | >>> aes_key = rsa.randnum.read_random_bits(128) |
| 267 | |
| 268 | #. Use that key to encrypt the file with AES. |
Sybren A. Stüvel | dbea213 | 2011-08-03 13:31:57 +0200 | [diff] [blame] | 269 | #. :py:func:`Encrypt <rsa.encrypt>` the AES key with RSA |
Sybren A. Stüvel | b6c04dd | 2011-08-01 21:37:02 +0200 | [diff] [blame] | 270 | |
Sybren A. Stüvel | dbea213 | 2011-08-03 13:31:57 +0200 | [diff] [blame] | 271 | >>> encrypted_aes_key = rsa.encrypt(aes_key, public_rsa_key) |
Sybren A. Stüvel | b6c04dd | 2011-08-01 21:37:02 +0200 | [diff] [blame] | 272 | |
| 273 | #. Send the encrypted file together with ``encrypted_aes_key`` |
| 274 | #. The recipient now reverses this process to obtain the encrypted |
| 275 | file. |
| 276 | |
Sybren A. Stüvel | dbea213 | 2011-08-03 13:31:57 +0200 | [diff] [blame] | 277 | .. note:: |
Sybren A. Stüvel | b6c04dd | 2011-08-01 21:37:02 +0200 | [diff] [blame] | 278 | |
Sybren A. Stüvel | dbea213 | 2011-08-03 13:31:57 +0200 | [diff] [blame] | 279 | The Python-RSA module does not contain functionality to do the AES |
| 280 | encryption for you. |
| 281 | |
| 282 | Only using Python-RSA: the VARBLOCK format |
Sybren A. Stüvel | 3934ab4 | 2016-02-05 16:01:20 +0100 | [diff] [blame] | 283 | ++++++++++++++++++++++++++++++++++++++++++ |
Sybren A. Stüvel | b6c04dd | 2011-08-01 21:37:02 +0200 | [diff] [blame] | 284 | |
Sybren A. Stüvel | 1681a0b | 2016-01-22 13:54:52 +0100 | [diff] [blame] | 285 | .. warning:: |
| 286 | |
| 287 | The VARBLOCK format is NOT recommended for general use, has been deprecated since |
Sybren A. Stüvel | 1d14c4e | 2017-04-10 11:31:09 +0200 | [diff] [blame] | 288 | Python-RSA 3.4, and has been removed in version 4.0. It's vulnerable to a |
Sybren A. Stüvel | 1681a0b | 2016-01-22 13:54:52 +0100 | [diff] [blame] | 289 | number of attacks: |
| 290 | |
| 291 | 1. decrypt/encrypt_bigfile() does not implement `Authenticated encryption`_ nor |
| 292 | uses MACs to verify messages before decrypting public key encrypted messages. |
| 293 | |
| 294 | 2. decrypt/encrypt_bigfile() does not use hybrid encryption (it uses plain RSA) |
| 295 | and has no method for chaining, so block reordering is possible. |
| 296 | |
| 297 | See `issue #19 on Github`_ for more information. |
| 298 | |
| 299 | .. _Authenticated encryption: https://en.wikipedia.org/wiki/Authenticated_encryption |
| 300 | .. _issue #19 on Github: https://github.com/sybrenstuvel/python-rsa/issues/13 |
| 301 | |
Sybren A. Stüvel | 1d14c4e | 2017-04-10 11:31:09 +0200 | [diff] [blame] | 302 | As of Python-RSA version 4.0, the VARBLOCK format has been removed from the |
| 303 | library. For now, this section is kept here to document the issues with that |
| 304 | format, and ensure we don't do something like that again. |