# Class 18: RSA Digital Signatures

Overview: We set up the basic RSA digital signature scheme. The goal is an unforgeable tag/signature that can be validated by anyone with access to the public key but only made by someone with the private key.

What's the goal? I want to have a verifiable "signature" on a document, so that only one person in the world could generate that signature but anyone that knows that person could look at it and confirm that it is valid.

This is done by the public-key version of a message authentication code. Think about what is unique to a particular person: their private key of course. We want to use their private key to generate a signature (like a tag) on a message. Now anyone with access to their public-key, the message, and their signature should be able to verify the signature. Also no adversary should be able to forge another message and signature that would verify with the same public key.

Just like in the MAC world, a digital signature scheme fails when someone can forge a signature without having the private key.

Our first (straw-man) stab at a signature on a message goes like this:

• Public key is $$(n,e)$$, private key is $$d$$.
• Take the message $$m \in \mathbb{Z}_n^{*}$$ and compute the signature: $$\sigma = m^{d} \mod{n}$$
• To verify: take $$(n,e)$$, $$m \in \mathbb{Z}_n^{*}$$, and $$sigma$$ and check if $$m = \sigma^{e} \mod{n}$$

So you'll note that this is the exact complement of encryption, we use the private key to make a noisy result which can only be undone using the public key.

The scheme is secure if no one can generate another $$(m', \sigma')$$ pair that people could verify.

Sign the following message: "I solemnly swear to learn applied cryptography. Even though there are not enough graded assignments to incentivize the needed hours I will: 1) work problems 2) ask questions 3) ponder start-ups 4) think in a paranoid fashion 5) get it done without excuse" You'll need a 2048-bit RSA public/private key pair (  ssh-keygen -t rsa -m PEM will do the job). Get the message into integer format, confirm that it is smaller than your modulus. Publish $$m^d \mod{n}$$ and $$(n,e)$$ into our slack channel. Pick someone else's signature and verify it.

Overview: Now let's look at some weaknesses that we can start to exploit to make forgeries.

Gibberish Signature: Now, take someone's public key, and generate a random "fake signature" (any random number $$\sigma' \in \mathbb{Z}_n^{*}$$) then reverse a message $$m' := \sigma'^{e} \mod{n}$$. Now if you publish $$m', \sigma'$$ we will verify that the person who published that public key signed your gibberish message too.

Trick them twice, they'll say anthing: The next weakness of the school-book DS scheme is that $$\sigma_1 \cdot \sigma_2$$ is a valid signature for $$m_1 \cdot m_2$$. So if you can trick them with what looks like noise, then you can create a signature on any message you want.

Find a "factorization" of a message: Take the message: "I, the undersigned, do solemnly swear to pick boogers, eat them, and wipe any excess on my shirt." Convert it to an integer, $$m$$. Now take your own public-key, $$n$$, and pick a random number $$m_1 \in \mathbb{Z}_n^{*}$$. Compute an $$m_2$$ such that $$m_1 \cdot m_2$$ is the malicious message. Now sign the two noise messages $$m_1, m_2$$ and confirm that their product is your own signature on the the booger message.

Overview: These are very important and subtle weaknesses in RSA that you have to be aware of if you deploy it.

I want to point out two weaknesses in the RSA scheme that impact our choices as implementers:

The take home is that padding must be carefully done so that we don't know the higher order bits when an exponent is too small.

### Extra Security

The primitive RSA signature has the above weaknesses and so it's not quite good enough. The world invented "probabilistic signature schemes" which add salts into the process (and use a Fiestel-like construction to recover the salt).

Let's look at the RSA-PSS signature as laid out: here.

This is the diagram: Pull it off?
{"ft_lang_label":"__label__en","ft_lang_prob":0.9065234,"math_prob":0.9754686,"size":3816,"snap":"2023-40-2023-50","text_gpt3_token_len":907,"char_repetition_ratio":0.13116474,"word_repetition_ratio":0.0,"special_character_ratio":0.24004193,"punctuation_ratio":0.096,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9914889,"pos_list":[0,1,2],"im_url_duplicate_count":[null,3,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-12-05T18:12:31Z\",\"WARC-Record-ID\":\"<urn:uuid:201fd6db-e8ed-4d76-932e-e1193219f705>\",\"Content-Length\":\"8102\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:05235d57-724a-45b4-8978-573242a567bb>\",\"WARC-Concurrent-To\":\"<urn:uuid:a8e246b2-c981-4494-8b93-b6c8b675b122>\",\"WARC-IP-Address\":\"207.244.121.250\",\"WARC-Target-URI\":\"https://crypto.prof.ninja/class18/\",\"WARC-Payload-Digest\":\"sha1:HFXNKZ4MOJPYAM77GBCMBEZSJVFSAIFW\",\"WARC-Block-Digest\":\"sha1:B6XW5Y67RXTPZKYM3J2L7TBAZBXYPD3A\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-50/CC-MAIN-2023-50_segments_1700679100555.27_warc_CC-MAIN-20231205172745-20231205202745-00897.warc.gz\"}"}