The Pretty Bad Privacy encryption tool can be used to insecurely encrypt files to a 2048-bit RSA public key using 256-bit AES.
The pdf file for your next homework assignment has been encrypted using PBP to the following RSA public key:
-----BEGIN PUBLIC KEY----- MIIBHzANBgkqhkiG9w0BAQEFAAOCAQwAMIIBBwKCAQAJHWeNUIw6obJL1lfrF/sy XaQZBV3e9Scs5KIQAg+MujXNLrI909lDA5V1ZcyiptneVNIV41wIVgPgL30TPHl1 h0exQHfSw4B/gyC/NjNqiQQlwO9vpcmy2P++71Nx96XaSLbvB0IYNBSYyvsUHw8j cUtNw4nEzvm0KBHFA4QNOD8y9RkDFbC51wYBSxzv/lngpMu6Fzb9m8uEgEiWreNn ypPko/kgrMrGtlS1dJC8z1Sf138plLN9e7l/WL0BVyR41eLfyB9mZeHiP/9Na8gj H/v/Rpp4uwNFiT18YrKzstu0RW8aFSQUVt3LnyxVwK+nBjRiTcGZEZ+hXhJI1Qg5 AgED -----END PUBLIC KEY-----
The encrypted file is available here. Your task is to break the RSA-encrypted AES session key and use it to decrypt the homework file. Fortunately for you, PBP uses PKCS#1v1.5 signature padding for encryption.
You will want to use Coppersmith's method to recover the key. You can find concrete examples in the lecture slides from class and a bit more detail in this survey.
You may use pure Python or any version of Sage to implement your solution, just document what version you used for the graders. The Sage 9.x code used to encrypt the homework is here. Sage's documentation for LLL lattice basis reduction is here and documentation on polynomial construction and root-finding is here.
Please submit your code as hw8-solution.py and a short description of how you solved the problem to Gradescope on December 10, 2020. You may discuss this assignment in small groups with classmates, but please code and write up your solutions yourself. Please credit any collaborators you discussed with and any references you used.
For reference, we give some excerpts from the OpenPBP RFC, inspired by the OpenPGP RFC and the relevant section of the PKCS#1 RFC.
5.1. Public-Key Encrypted Messages The body of the message consists of a string of octets that is the encrypted session key, followed by the symmetrically encrypted data. - multiprecision integer (MPI) of RSA encrypted value m**e mod n. - Encrypted data, the output of the AES symmetric-key cipher operating in CBC mode, with PKCS 7 padding. The session key is encoded as described in PKCS#1 block encoding EME-PKCS1-v1_5 in Section 8.1 to form the "m" value used in the formulas above. 8.1 Encryption-block formatting A block type BT, a padding string PS, and the data D shall be formatted into an octet string EB, the encryption block. EB = 00 || BT || PS || 00 || D . (1) The block type BT shall be a single octet indicating the structure of the encryption block. For this version of the document it shall have value 00, 01, or 02. For a private- key operation, the block type shall be 00 or 01. For a public-key operation, it shall be 02. The padding string PS shall consist of k-3-||D|| octets. For block type 00, the octets shall have value 00; for block type 01, they shall have value FF; and for block type 02, they shall be pseudorandomly generated and nonzero. This makes the length of the encryption block EB equal to k.