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 with the following RSA 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.
Write your solution using Sage (in Python). 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.
For this homework, please do not use Sage's small_roots function, which uses Coppersmith's method internally. The point of this homework is for you to implement Coppersmith's method yourself.
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.
The autograder...
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.