Revision as of 12:58, 19 September 2006 editFrap (talk | contribs)Autopatrolled, Extended confirmed users, File movers, Pending changes reviewers, Rollbackers33,239 edits →See also: added portal← Previous edit | Latest revision as of 17:22, 7 January 2025 edit undoNabijaczleweli (talk | contribs)245 editsm plural -> bits | ||
Line 1: | Line 1: | ||
{{short description|Algorithm for public-key cryptography}} | |||
{{Otheruses4|an algorithm for public-key encryption|other meanings, including the company that first marketed the algorithm|RSA (disambiguation)}} | |||
{{about|a cryptosystem|the company|RSA Security}} | |||
In ], '''RSA''' is an ] for ]. It was the first algorithm known to be suitable for ] as well as ], and one of the first great advances in public key cryptography. RSA is still widely used in ] protocols, and is believed to be secure given sufficiently long keys. | |||
{{Infobox block cipher | |||
| name = RSA | |||
| designers = ],<ref name="rsa"/> ], and ] | |||
| publish date = 1977 | |||
| type = Public-Key | |||
| derived from = | |||
| derived to = | |||
| related to = | |||
| certification = ], ] | |||
| key size = variable but typically 2,048 to 4,096 bits | |||
| block size = | |||
| structure = | |||
| rounds = 1 | |||
| cryptanalysis = ] for classical computers;<br />] for quantum computers.<br />An ] has been broken. | |||
}} | |||
'''RSA''' ('''Rivest–Shamir–Adleman''') is a ], one of the oldest widely used for secure data transmission. The ] "RSA" comes from the surnames of ], ] and ], who publicly described the algorithm in 1977. An equivalent system was developed secretly in 1973 at ] (GCHQ), the British ] agency, by the English mathematician ]. That system was ] in 1997.<ref>{{cite web |url=http://www.bristol.ac.uk/graduation/honorary-degrees/hondeg08/cocks.html |first=Nigel |last=Smart |title=Dr Clifford Cocks CB |access-date=August 14, 2011 |date=February 19, 2008 |publisher=]}}</ref> | |||
== History== | |||
The algorithm was publically described in ] by ], ] and ] at ]; the letters '''RSA''' are the initials of their surnames. Apocryphally, it was invented at a ] in ], ] {{fact}}. | |||
In a public-key ], the ] is public and distinct from the ], which is kept secret (private). | |||
], a British ] working for the UK intelligence agency ], described an equivalent system in an internal document in ], but given the relatively expensive computers needed to implement it at the time, it was mostly considered a curiosity and, as far as is publicly known, was never deployed. His discovery, however, was not revealed until ] due to its top-secret classification, and Rivest, Shamir, and Adleman appear to have devised RSA independently of Cocks' work. | |||
An RSA user creates and publishes a public key based on two large ]s, along with an auxiliary value. The prime numbers are kept secret. Messages can be encrypted by anyone, via the public key, but can only be decrypted by someone who knows the private key.<ref name="rsa">{{cite journal | |||
| last1 = Rivest | first1 = R. | |||
| last2 = Shamir | first2 = A. | |||
| last3 = Adleman | first3 = L. | |||
| s2cid = 2873616 | |||
| url = http://people.csail.mit.edu/rivest/Rsapaper.pdf | |||
| title = A Method for Obtaining Digital Signatures and Public-Key Cryptosystems | |||
| journal = ] | |||
| volume = 21 | issue = 2 | pages = 120–126 | date = February 1978 | |||
| doi = 10.1145/359340.359342| citeseerx = 10.1.1.607.2677 | |||
| archive-url = https://web.archive.org/web/20230127011251/http://people.csail.mit.edu/rivest/Rsapaper.pdf | |||
| archive-date = 2023-01-27 | |||
| url-status = dead | |||
}}</ref> | |||
The security of RSA relies on the practical difficulty of ] the product of two large ]s, the "]". Breaking RSA encryption is known as the ]. Whether it is as difficult as the factoring problem is an open question.<ref>{{Cite journal|last=Castelvecchi|first=Davide|date=2020-10-30|title=Quantum-computing pioneer warns of complacency over Internet security|url=https://www.nature.com/articles/d41586-020-03068-9|journal=Nature|language=en|volume=587|issue=7833|pages=189|doi=10.1038/d41586-020-03068-9|pmid=33139910 |bibcode=2020Natur.587..189C |s2cid=226243008 }} 2020 interview of ].</ref> There are no published methods to defeat the system if a large enough key is used. | |||
The algorithm was ]ed by ] in ] in the ] as {{US patent|4,405,829}}. The patent expired on ] ]. Since the algorithm had been published prior to ] the ], regulations in much of the rest of the world precluded patents elsewhere. Had Cocks' work been publicly known, a patent in the US would not have been possible either. | |||
RSA is a relatively slow algorithm. Because of this, it is not commonly used to directly encrypt user data. More often, RSA is used to transmit shared keys for ] cryptography, which are then used for bulk encryption–decryption. | |||
== Operation == | |||
=== Intuition === | |||
RSA involves two '''keys''': public key and private key (a key is a constant number later used in the encryption formula.) The '''public key''' can be known to everyone and is used to '''encrypt''' messages. These messages can only be '''decrypted''' by use of the '''private key'''. In other words, anybody can encrypt a message, but only the holder of a private key can actually decrypt the message and read it. | |||
Intuitive example: Bob wants to send Alice a secret message that only she can read. To do this, Alice sends Bob a box with an open lock, for which only Alice has the key. Bob receives the box, he writes the message in plain English, puts it in the box and locks it with Alice's lock (now Bob can no longer read the message.) Bob sends the box to Alice and she opens it with her key. In this example, the box with the lock is Alice's public key, and the key to the lock is her private key. | |||
==History== | |||
=== Key generation === | |||
], co-inventor of RSA (the others are ] and ])]] | |||
Suppose ] are communicating over an insecure (open) channel, and Alice wants Bob to send her a private (or ''secure'') message. Using RSA, Alice will take the following steps to generate a public key and a private key: | |||
The idea of an asymmetric public-private key cryptosystem is attributed to ] and ], who published this concept in 1976. They also introduced digital signatures and attempted to apply number theory. Their formulation used a shared-secret-key created from exponentiation of some number, modulo a prime number. However, they left open the problem of realizing a one-way function, possibly because the difficulty of factoring was not well-studied at the time.<ref>{{Cite journal |title = New directions in cryptography |journal = IEEE Transactions on Information Theory |date = November 1976 |issn = 0018-9448 |pages = 644–654 |volume = 22 |issue = 6 |doi = 10.1109/TIT.1976.1055638 |first1 = W. |last1 = Diffie |first2 = M. E. |last2 = Hellman |citeseerx = 10.1.1.37.9720}}</ref> Moreover, like ], RSA is based on ]. | |||
], ], and ] at the ] made several attempts over the course of a year to create a function that was hard to invert. Rivest and Shamir, as computer scientists, proposed many potential functions, while Adleman, as a mathematician, was responsible for finding their weaknesses. They tried many approaches, including "]-based" and "permutation polynomials". For a time, they thought what they wanted to achieve was impossible due to contradictory requirements.<ref>{{Cite web |url = https://people.csail.mit.edu/rivest/pubs/ARS03.rivest-slides.pdf |title = The Early Days of RSA – History and Lessons |last = Rivest |first = Ronald}}</ref> In April 1977, they spent ] at the house of a student and drank a good deal of wine before returning to their homes at around midnight.<ref>{{Cite web |url = http://www.math.uchicago.edu/~may/VIGRE/VIGRE2007/REUPapers/FINALAPP/Calderbank.pdf |title = The RSA Cryptosystem: History, Algorithm, Primes |date = 2007-08-20 |last = Calderbank |first = Michael}}</ref> Rivest, unable to sleep, lay on the couch with a math textbook and started thinking about their one-way function. He spent the rest of the night formalizing his idea, and he had much of the paper ready by daybreak. The algorithm is now known as RSA{{snd}} the initials of their surnames in same order as their paper.<ref name="SIAM">{{cite journal |url=http://www.msri.org/people/members/sara/articles/rsa.pdf |journal=SIAM News |volume=36 |issue=5 |date=June 2003 |title=Still Guarding Secrets after Years of Attacks, RSA Earns Accolades for its Founders |first=Sara |last=Robinson }}</ref> | |||
#Choose two large ]s <math>p \,</math> and <math>q \,</math> such that <math>p \ne q</math>, randomly and independently of each other. | |||
#Compute <math>n = p q \,</math>. | |||
#Compute the ] <math>\phi(n) = (p-1)(q-1) \,</math>. | |||
#Choose an integer <math>e>1</math> that is ] to <math>\phi(n) \,</math> . | |||
#Compute <math>d</math> such that <math>d e \equiv 1 \pmod{\phi(n)}</math>. | |||
* The prime numbers can be ]. | |||
* A popular choice for the public exponents is e=2<sup>16</sup>+1=65537. Some applications choose smaller values such as <math>e = 3, 5,</math> or <math>35</math> instead. This is done in order to make implementations on small devices (e.g. smart cards) easier, i.e. encryption and signature verification are faster. But choosing small public exponents may lead to greater security risks. | |||
*Steps 4 and 5 can be performed with the ]; see ]. | |||
*Step 3 changed in PKCS#1 v2.0 to <math>\lambda = LCM(p-1, q-1) \,</math> instead of <math>\phi = (p-1)(q-1) \,</math>. | |||
], an English ] working for the ] intelligence agency ] (GCHQ), described a similar system in an internal document in 1973.<ref>{{Cite web |url=https://www.gchq.gov.uk/sites/default/files/document_files/Cliff%20Cocks%20paper%2019731120.pdf |title=A Note on Non-Secret Encryption |last=Cocks |first=C. C. |author-link=Clifford Cocks |date=20 November 1973 |website=www.gchq.gov.uk |access-date=2017-05-30 |archive-url=https://web.archive.org/web/20180928121748/https://www.gchq.gov.uk/sites/default/files/document_files/Cliff%20Cocks%20paper%2019731120.pdf |archive-date=28 September 2018 |url-status=dead}}</ref> However, given the relatively expensive computers needed to implement it at the time, it was considered to be mostly a curiosity and, as far as is publicly known, was never deployed. His ideas and concepts were not revealed until 1997 due to its top-secret classification. | |||
The '''public key''' consists of | |||
* ''n'', the modulus, and | |||
* ''e'', the public exponent (sometimes ''encryption exponent''). | |||
Kid-RSA (KRSA) is a simplified, insecure public-key cipher published in 1997, designed for educational purposes. Some people feel that learning Kid-RSA gives insight into RSA and other public-key ciphers, analogous to ].<ref> | |||
The '''private key''' consists of | |||
Jim Sauerberg. | |||
* ''n'', the modulus, which is public and appears in the public key, and | |||
. | |||
* ''d'', the private exponent (sometimes ''decryption exponent''), which must be kept secret. | |||
</ref><ref> | |||
Margaret Cozzens and Steven J. Miller. | |||
. | |||
p. 180. | |||
</ref><ref> | |||
Alasdair McAndrew. | |||
. | |||
p. 12. | |||
</ref><ref> | |||
Surender R. Chiluka. | |||
. | |||
</ref><ref> | |||
Neal Koblitz. | |||
. | |||
Cryptologia, Vol. 21, No. 4 (1997). | |||
</ref> | |||
==Patent== | |||
For reasons of efficiency sometimes a different form of the '''private key''' (including '''CRT parameters''') is stored: | |||
* ''p'' and ''q'', the primes from the key generation, | |||
* ''d mod (p-1)'' and ''d mod (q-1)'' (often known as ''dmp1'' and ''dmq1'') | |||
* ''(1/q) mod p'' (often known as ''iqmp'') | |||
Though this form allows faster decryption and signing using the ] (CRT), | |||
it considerably lowers the security. | |||
In this form, all of the parts of the private key must be kept secret. | |||
Yet, it is a bad idea to use it, since it enables ]s in particular if implemented on ], | |||
which would most benefit from the efficiency win. | |||
(Start with <math>y = x^e mod n</math> and let the card decrypt that. | |||
So it computes <math>y^d \pmod{p}</math> or <math>y^d \pmod{q}</math> whose results give some value <math>z</math>. | |||
Now, induce an error in one of the computations. | |||
Then <math>\gcd(z-x,n)</math> will reveal <math>p</math> or <math>q</math>.) | |||
A ] describing the RSA algorithm was granted to ] on 20 September 1983: {{US patent|4405829}} "Cryptographic communications system and method". From ]'s abstract of the patent: | |||
Alice transmits the public key to Bob, and keeps the private key secret. ''p'' and ''q'' are sensitive since they are the factors of ''n'', and allow computation of ''d'' given ''e''. If ''p'' and ''q'' are not stored in the CRT form of the private key, they are securely deleted along with the other intermediate values from the key generation. | |||
{{Blockquote|The system includes a communications channel coupled to at least one terminal having an encoding device and to at least one terminal having a decoding device. A message-to-be-transferred is enciphered to ciphertext at the encoding terminal by encoding the message as a number M in a predetermined set. That number is then raised to a first predetermined power (associated with the intended receiver) and finally computed. The remainder or residue, C, is... computed when the exponentiated number is divided by the product of two predetermined prime numbers (associated with the intended receiver).}} | |||
A detailed description of the algorithm was published in August 1977, in ]'s ] column.<ref name="SIAM" /> This preceded the patent's filing date of December 1977. Consequently, the patent had no legal standing outside the ]. Had Cocks' work been publicly known, a patent in the United States would not have been legal either. | |||
=== Encrypting messages === | |||
When the patent was issued, ] were 17 years. The patent was about to expire on 21 September 2000, but ] released the algorithm to the public domain on 6 September 2000.<ref>{{cite web |url=http://www.rsa.com/press_release.aspx?id=261 |title=RSA Security Releases RSA Encryption Algorithm into Public Domain |access-date=2010-03-03 |url-status=dead |archive-url=https://web.archive.org/web/20070621021111/http://www.rsa.com/press_release.aspx?id=261 |archive-date=June 21, 2007 }}</ref> | |||
Suppose Bob wishes to send a message ''M'' to Alice. He turns ''M'' into a number ''m'' < ''n'', using some previously agreed-upon reversible protocol known as a ]. | |||
==Operation== | |||
Bob now has ''m'', and knows ''n'' and ''e'', which Alice has announced. He then computes the ciphertext ''c'' corresponding to ''m'': | |||
The RSA algorithm involves four steps: ] generation, key distribution, encryption, and decryption. | |||
A basic principle behind RSA is the observation that it is practical to find three very large positive integers {{mvar|e}}, {{mvar|d}}, and {{mvar|n}}, such that for all integers {{mvar|m}} ({{math|0 ≤ ''m'' < ''n''}}), both <math>(m^e)^d</math> and <math>m</math> have the same ] when divided by <math>n</math> (they are ] <math>n</math>):<math display="block">(m^e)^d \equiv m \pmod{n}.</math>However, when given only {{mvar|e}} and {{mvar|n}}, it is extremely difficult to find {{mvar|d}}. | |||
: <math> c = m^e \mod{n}</math> | |||
The integers {{mvar|n}} and {{mvar|e}} comprise the public key, {{mvar|d}} represents the private key, and {{mvar|m}} represents the message. The ] to {{mvar|e}} and {{mvar|d}} corresponds to encryption and decryption, respectively. | |||
This can be done quickly using the method of ]. Bob then transmits ''c'' to Alice. | |||
In addition, because the two exponents ], the private and public key can also be swapped, allowing for message ] using the same algorithm. | |||
=== Decrypting messages === | |||
===Key generation=== | |||
Alice receives ''c'' from Bob, and knows her private key ''d''. She can recover ''m'' from ''c'' by the following procedure: | |||
The keys for the RSA algorithm are generated in the following way: | |||
# Choose two large ]s {{mvar|p}} and {{mvar|q}}. | |||
#* To make factoring harder, {{mvar|p}} and {{mvar|q}} should be chosen at random, be both large and have a large difference.<ref name="rsa"/> For choosing them the standard method is to choose random integers and use a ] until two primes are found. | |||
#* {{mvar|p}} and {{mvar|q}} are kept secret. | |||
# Compute {{math|1=''n'' = ''pq''}}. | |||
#* {{mvar|n}} is used as the ] for both the public and private keys. Its length, usually expressed in bits, is the ]. | |||
#* {{mvar|n}} is released as part of the public key. | |||
# Compute {{math|''λ''(''n'')}}, where {{mvar|λ}} is ]. Since {{math|1=''n'' = ''pq'', ''λ''(''n'') = ](''λ''(''p''), ''λ''(''q''))}}, and since {{mvar|p}} and {{mvar|q}} are prime, {{math|1=''λ''(''p'') = '']''(''p'') = ''p'' − 1}}, and likewise {{math|1=''λ''(''q'') = ''q'' − 1}}. Hence {{math|1=''λ''(''n'') = lcm(''p'' − 1, ''q'' − 1)}}. | |||
#* The {{math|1=lcm}} may be calculated through the ], since {{math|1=lcm(''a'', ''b'') = {{sfrac|{{abs|''ab''}}|gcd(''a'', ''b'')}}}}. | |||
#* {{math|''λ''(''n'')}} is kept secret. | |||
# Choose an integer {{mvar|e}} such that {{math|1 < ''e'' < ''λ''(''n'')}} and {{math|1=](''e'', ''λ''(''n'')) = 1}}; that is, {{mvar|e}} and {{math|''λ''(''n'')}} are ]. | |||
#* {{mvar|e}} having a short ] and small ] results in more efficient encryption{{snd}} the most commonly chosen value for {{mvar|e}} is {{math|1=2<sup>16</sup> + 1 = {{val|65,537}}}}. The smallest (and fastest) possible value for {{mvar|e}} is 3, but such a small value for {{mvar|e}} has been shown to be less secure in some settings.<ref name="Boneh99"> | |||
{{cite journal | |||
| url = http://crypto.stanford.edu/~dabo/abstracts/RSAattack-survey.html | |||
| last = Boneh | first = Dan | |||
| title = Twenty Years of attacks on the RSA Cryptosystem | |||
| journal = ] | |||
| volume = 46 | issue = 2 | |||
| pages = 203–213 | year = 1999 | |||
}}</ref> | |||
#* {{mvar|e}} is released as part of the public key. | |||
# Determine {{mvar|d}} as {{math|1=''d'' ≡ ''e''<sup>−1</sup> (mod ''λ''(''n''))}}; that is, {{mvar|d}} is the ] of {{mvar|e}} modulo {{math|''λ''(''n'')}}. | |||
#* This means: solve for {{mvar|d}} the equation {{math|1=''de'' ≡ 1 (mod ''λ''(''n''))}}; {{mvar|d}} can be computed efficiently by using the ], since, thanks to {{mvar|e}} and {{math|''λ''(''n'')}} being coprime, said equation is a form of ], where {{mvar|d}} is one of the coefficients. | |||
#* {{mvar|d}} is kept secret as the ''private key exponent''. | |||
The ''public key'' consists of the modulus {{mvar|n}} and the public (or encryption) exponent {{mvar|e}}. The ''private key'' consists of the private (or decryption) exponent {{mvar|d}}, which must be kept secret. {{mvar|p}}, {{mvar|q}}, and {{math|''λ''(''n'')}} must also be kept secret because they can be used to calculate {{mvar|d}}. In fact, they can all be discarded after {{mvar|d}} has been computed.<ref>Applied Cryptography, John Wiley & Sons, New York, 1996. ], p. 467.</ref> | |||
{{anchor|OriginalWithPhiN}}In the original RSA paper,<ref name=rsa /> the ] {{math|1=''φ''(''n'') = (''p'' − 1)(''q'' − 1)}} is used instead of {{math|''λ''(''n'')}} for calculating the private exponent {{mvar|d}}. Since {{math|''φ''(''n'')}} is always divisible by {{math|''λ''(''n'')}}, the algorithm works as well. The possibility of using ] results also from ] applied to the ]. Thus any {{mvar|d}} satisfying {{math|1=''d''⋅''e'' ≡ 1 (mod ''φ''(''n''))}} also satisfies {{math|1=''d''⋅''e'' ≡ 1 (mod ''λ''(''n''))}}. However, computing {{mvar|d}} modulo {{math|''φ''(''n'')}} will sometimes yield a result that is larger than necessary (i.e. {{math|1=''d'' > ''λ''(''n'')}}). Most of the implementations of RSA will accept exponents generated using either method (if they use the private exponent {{mvar|d}} at all, rather than using the optimized decryption method ] described below), but some standards such as (Section B.3.1) may require that {{math|''d'' < ''λ''(''n'')}}. Any "oversized" private exponents not meeting this criterion may always be reduced modulo {{math|''λ''(''n'')}} to obtain a smaller equivalent exponent. | |||
: <math>m = c^d \mod{n}</math> | |||
{{anchor|CryptoStrengthOfPQ}}Since any common factors of {{math|(''p'' − 1)}} and {{math|(''q'' − 1)}} are present in the factorisation of {{math|''n'' − 1}} = {{math|''pq'' − 1}} = {{math|(''p'' − 1)(''q'' − 1) + (''p'' − 1) + (''q'' − 1)}},<ref>{{cite web|title=Further Attacks on Server-Aided RSA Cryptosystems |first1=James |last1=McKee |first2=Richard |last2=Pinch |citeseerx=10.1.1.33.1333 |year=1998|url=https://citeseerx.ist.psu.edu/document?repid=rep1&type=pdf&doi=64294c404088b69a519614510b8d12b4809a6b10}}</ref>{{self published inline|date=December 2023|reason=This paper is not from a journal and may not have been peer-reviewed}} it is recommended that {{math|(''p'' − 1)}} and {{math|(''q'' − 1)}} have only very small common factors, if any, besides the necessary 2.<ref name="rsa" /><ref>A Course in Number Theory and Cryptography, Graduate Texts in Math. No. 114, Springer-Verlag, New York, 1987. ], Second edition, 1994. p. 94.</ref><ref>{{cite mailing list |title=common factors in (''p'' − 1) and (''q'' − 1) |first=Viktor |last=Dukhovni |mailing-list=openssl-dev |url=https://mta.openssl.org/pipermail/openssl-dev/2015-July/002266.html |date=July 31, 2015}}</ref>{{Failed verification|date=April 2022}}<ref>{{cite mailing list |title=common factors in (''p'' − 1) and (''q'' − 1) |first=Viktor |last=Dukhovni |mailing-list=openssl-dev |url=https://mta.openssl.org/pipermail/openssl-dev/2015-August/002277.html |date=August 1, 2015}}</ref>{{Failed verification|date=April 2022}} | |||
Given ''m'', she can recover the original message ''M''. The decryption procedure works because | |||
Note: The authors of the original RSA paper carry out the key generation by choosing {{mvar|d}} and then computing {{mvar|e}} as the ] of {{mvar|d}} modulo {{math|''φ''(''n'')}}, whereas most current implementations of RSA, such as those following ], do the reverse (choose {{mvar|e}} and compute {{mvar|d}}). Since the chosen key can be small, whereas the computed key normally is not, the RSA paper's algorithm optimizes decryption compared to encryption, while the modern algorithm optimizes encryption instead.<ref name="rsa" /><ref>{{Cite IETF |rfc=3447 |title=Public-Key Cryptography Standards (PKCS) #1: RSA Cryptography Specifications Version 2.1 |last=Johnson |first=J. |last2=Kaliski |first2=B. |date=February 2003 |publisher=Network Working Group |access-date=9 March 2016}}</ref> | |||
: <math>c^d \equiv (m^e)^d \equiv m^{ed} \pmod{n}</math>. | |||
===Key distribution=== | |||
Now, since ''ed'' ≡ 1 (mod ''p''-1) and ''ed'' ≡ 1 (mod ''q''-1), ] yields | |||
Suppose that ] wants to send information to ]. If they decide to use RSA, Bob must know Alice's public key to encrypt the message, and Alice must use her private key to decrypt the message. | |||
To enable Bob to send his encrypted messages, Alice transmits her public key {{math|(''n'', ''e'')}} to Bob via a reliable, but not necessarily secret, route. Alice's private key {{math|(''d'')}} is never distributed. | |||
: <math>m^{ed} \equiv m \pmod{p}</math> | |||
===Encryption=== | |||
and | |||
After Bob obtains Alice's public key, he can send a message {{mvar|M}} to Alice. | |||
To do it, he first turns {{mvar|M}} (strictly speaking, the un-padded plaintext) into an integer {{mvar|m}} (strictly speaking, the ] plaintext), such that {{math|0 ≤ ''m'' < ''n''}} by using an agreed-upon reversible protocol known as a ]. He then computes the ciphertext {{mvar|c}}, using Alice's public key {{mvar|e}}, corresponding to | |||
: <math>m^{ed} \equiv m \pmod{q}</math> | |||
<math display="block">c \equiv m^e \pmod{n}.</math> | |||
Since ''p'' and ''q'' are distinct prime numbers, applying the ] to these two congruences yields | |||
This can be done reasonably quickly, even for very large numbers, using ]. Bob then transmits {{mvar|c}} to Alice. Note that at least nine values of {{mvar|m}} will yield a ciphertext {{mvar|c}} equal to | |||
: <math>m^{ed} \equiv m \pmod{pq}</math>. | |||
{{mvar|m}},{{efn|Namely, the values of {{mvar|m}} which are equal to −1, 0, or 1 modulo {{mvar|p}} while also equal to −1, 0, or 1 modulo {{mvar|q}}. There will be more values of {{mvar|m}} having {{math|1=''c'' = ''m''}} if {{math|''p'' − 1}} or {{math|''q'' − 1}} has other divisors in common with {{math|''e'' − 1}} besides 2 because this gives more values of {{mvar|m}} such that <math>m^{e-1} \bmod p = 1</math> or <math>m^{e-1} \bmod q = 1</math> respectively.}} but this is very unlikely to occur in practice. | |||
===Decryption=== | |||
Thus, | |||
Alice can recover {{mvar|m}} from {{mvar|c}} by using her private key exponent {{mvar|d}} by computing | |||
<math display="block">c^d \equiv (m^e)^d \equiv m \pmod{n}.</math> | |||
Given {{mvar|m}}, she can recover the original message {{mvar|M}} by reversing the padding scheme. | |||
===A working example=== | |||
===Example=== | |||
Here is an example of RSA encryption and decryption. The parameters used here are artificially small, but you can also ]. | |||
Here is an example of RSA encryption and decryption:{{efn|The parameters used here are artificially small, but one can also ].}} | |||
# Choose two distinct prime numbers, such as | |||
We let | |||
#: <math>p = 61</math> and <math>q = 53</math>. | |||
{| border="0" width="95%" style="margin-left: 2em;" | |||
# Compute {{math|1=''n'' = ''pq''}} giving | |||
|- | |||
#: <math>n = 61\times 53 = 3233.</math> | |||
|width="15%"|''p'' = 61 || — first prime number (to be kept secret or deleted securely) | |||
# Compute the ] of the product as {{math|1=''λ''(''n'') = ](''p'' − 1, ''q'' − 1)}} giving | |||
|- | |||
#: <math>\lambda(3233) = \operatorname{lcm}(60, 52) = 780.</math> | |||
|''q'' = 53 || — second prime number (to be kept secret or deleted securely) | |||
# Choose any number {{math|2 < ''e'' < 780}} that is ] to 780. Choosing a prime number for {{mvar|e}} leaves us only to check that {{mvar|e}} is not a divisor of 780. | |||
|- | |||
#: Let <math>e = 17</math>. | |||
|''n'' = ''pq'' = 3233 || — modulus (to be made public) | |||
# Compute {{mvar|d}}, the ] of {{math|''e'' (mod ''λ''(''n''))}}, yielding<br /><math display="block">d = 413,</math> as <math>1 = (17 \times 413) \bmod 780.</math> | |||
|- | |||
|''e'' = 17 || — public exponent (to be made public) | |||
|- | |||
|''d'' = 2753 || — private exponent (to be kept secret) | |||
|} | |||
The public key is (''e'', ''n''). The private key is ''d''. The encryption function is: | |||
The '''public key''' is {{math|1=(''n'' = 3233, ''e'' = 17)}}. For a padded ] message {{mvar|m}}, the encryption function is | |||
:encrypt(''m'') = ''m''<sup>''e''</sup> mod ''n'' = ''m''<sup>17</sup> mod 3233 | |||
<math display="block">\begin{align} | |||
c(m) &= m^{e} \bmod n \\ | |||
&= m^{17} \bmod 3233. | |||
\end{align}</math> | |||
The '''private key''' is {{math|1=(''n'' = 3233, ''d'' = 413)}}. For an encrypted ] {{mvar|c}}, the decryption function is | |||
<math display="block">\begin{align} | |||
m(c) &= c^{d} \bmod n \\ | |||
&= c^{413} \bmod 3233. | |||
\end{align}</math> | |||
For instance, in order to encrypt {{math|1=''m'' = 65}}, one calculates | |||
:decrypt(''c'') = ''c''<sup>''d''</sup> mod ''n'' = ''c''<sup>2753</sup> mod 3233 | |||
<math display="block">c = 65^{17} \bmod 3233 = 2790.</math> | |||
To decrypt {{math|1=''c'' = 2790}}, one calculates | |||
where ''c'' is the ]. | |||
<math display="block">m = 2790^{413} \bmod 3233 = 65.</math> | |||
Both of these calculations can be computed efficiently using the ] for ]. In real-life situations the primes selected would be much larger; in our example it would be trivial to factor {{math|1=''n'' = 3233}} (obtained from the freely available public key) back to the primes {{mvar|p}} and {{mvar|q}}. {{mvar|e}}, also from the public key, is then inverted to get {{mvar|d}}, thus acquiring the private key. | |||
To encrypt the plaintext value 123, we calculate | |||
Practical implementations use the ] to speed up the calculation using modulus of factors (mod ''pq'' using mod ''p'' and mod ''q''). | |||
:encrypt(123) = 123<sup>17</sup> mod 3233 = 855 | |||
The values {{mvar|d<sub>''p''</sub>}}, {{mvar|d<sub>''q''</sub>}} and {{mvar|q<sub>inv</sub>}}, which are part of the private key are computed as follows: | |||
To decrypt the ciphertext value 855, we calculate | |||
<math display="block">\begin{align} | |||
d_p &= d \bmod (p-1) = 413 \bmod (61 - 1) = 53, \\ | |||
d_q &= d \bmod (q-1) = 413 \bmod (53 - 1) = 49, \\ | |||
q_\text{inv} &= q^{-1} \bmod p = 53^{-1} \bmod 61 = 38 \\ | |||
&\Rightarrow (q_\text{inv} \times q) \bmod p = 38 \times 53 \bmod 61 = 1. | |||
\end{align}</math> | |||
Here is how {{mvar|d<sub>''p''</sub>}}, {{mvar|d<sub>''q''</sub>}} and {{mvar|q<sub>inv</sub>}} are used for efficient decryption (encryption is efficient by choice of a suitable {{mvar|d}} and {{mvar|e}} pair): | |||
:decrypt(855) = 855<sup>2753</sup> mod 3233 = 123 | |||
<math display="block">\begin{align} | |||
m_1 &= c^{d_p} \bmod p = 2790^{53} \bmod 61 = 4, \\ | |||
m_2 &= c^{d_q} \bmod q = 2790^{49} \bmod 53 = 12, \\ | |||
h &= (q_\text{inv} \times (m_1 - m_2)) \bmod p = (38 \times -8) \bmod 61 = 1, \\ | |||
m &= m_2 + h \times q = 12 + 1 \times 53 = 65. | |||
\end{align}</math> | |||
===Signing messages=== | |||
Both of these computations can be done efficiently using the ] for ]. | |||
Suppose ] uses ]'s public key to send him an encrypted message. In the message, she can claim to be Alice, but Bob has no way of verifying that the message was from Alice, since anyone can use Bob's public key to send him encrypted messages. In order to verify the origin of a message, RSA can also be used to ] a message. | |||
Suppose Alice wishes to send a signed message to Bob. She can use her own private key to do so. She produces a ] of the message, raises it to the power of {{mvar|d}} (modulo {{mvar|n}}) (as she does when decrypting a message), and attaches it as a "signature" to the message. When Bob receives the signed message, he uses the same hash algorithm in conjunction with Alice's public key. He raises the signature to the power of {{mvar|e}} (modulo {{mvar|n}}) (as he does when encrypting a message), and compares the resulting hash value with the message's hash value. If the two agree, he knows that the author of the message was in possession of Alice's private key and that the message has not been tampered with since being sent. | |||
This works because of ] rules: | |||
<math display="block">h = \operatorname{hash}(m),</math> | |||
<math display="block">(h^e)^d = h^{ed} = h^{de} = (h^d)^e \equiv h \pmod{n}.</math> | |||
Thus the keys may be swapped without loss of generality, that is, a private key of a key pair may be used either to: | |||
# Decrypt a message only intended for the recipient, which may be encrypted by anyone having the public key (asymmetric encrypted transport). | |||
# Encrypt a message which may be decrypted by anyone, but which can only be encrypted by one person; this provides a digital signature. | |||
==Proofs of correctness== | |||
===Proof using Fermat's little theorem=== | |||
The proof of the correctness of RSA is based on ], stating that {{math| ''a''<sup>''p'' − 1</sup> ≡ 1 (mod ''p'')}} for any integer {{mvar|a}} and prime {{mvar|p}}, not dividing {{mvar|a}}.{{refn|group=note|We cannot trivially break RSA by applying the theorem (mod ''pq'') because {{math|''pq''}} is not prime.}} | |||
We want to show that | |||
<math display="block">(m^e)^d \equiv m \pmod{pq}</math> | |||
for every integer {{mvar|m}} when {{mvar|p}} and {{mvar|q}} are distinct prime numbers and {{mvar|e}} and {{mvar|d}} are positive integers satisfying {{math|1=''ed'' ≡ 1 (mod ''λ''(''pq''))}}. | |||
Since {{math|1=''λ''(''pq'') = ](''p'' − 1, ''q'' − 1)}} is, by construction, divisible by both {{math|''p'' − 1}} and {{math|''q'' − 1}}, we can write | |||
<math display="block">ed - 1 = h(p - 1) = k(q - 1)</math> | |||
for some nonnegative integers {{mvar|h}} and {{mvar|k}}.{{refn|group=note|In particular, the statement above holds for any {{mvar|e}} and {{mvar|d}} that satisfy {{math|1=''ed'' ≡ 1 (mod (''p'' − 1)(''q'' − 1))}}, since {{math|1=(''p'' − 1)(''q'' − 1)}} is divisible by {{math|1=''λ''(''pq'')}}, and thus trivially also by {{math|''p'' − 1}} and {{math|''q'' − 1}}. However, in modern implementations of RSA, it is common to use a reduced private exponent {{mvar|d}} that only satisfies the weaker, but sufficient condition {{math|1=''ed'' ≡ 1 (mod ''λ''(''pq''))}}.}} | |||
To check whether two numbers, such as {{mvar|m''<sup>ed</sup>''}} and {{mvar|m}}, are congruent {{math|mod ''pq''}}, it suffices (and in fact is equivalent) to check that they are congruent {{math|mod ''p''}} and {{math|mod ''q''}} separately.{{refn|group=note|This is part of the ], although it is not the significant part of that theorem.}} | |||
To show {{math|''m<sup>ed</sup>'' ≡ ''m'' (mod ''p'')}}, we consider two cases: | |||
# If {{math|''m'' ≡ 0 (mod ''p'')}}, {{mvar|m}} is a multiple of {{mvar|p}}. Thus ''m<sup>ed</sup>'' is a multiple of {{mvar|p}}. So {{math|''m<sup>ed</sup>'' ≡ 0 ≡ ''m'' (mod ''p'')}}. | |||
# If {{math|''m'' <math>\not\equiv</math> 0 (mod ''p'')}}, | |||
#: <math>m^{ed} = m^{ed - 1} m = m^{h(p - 1)} m = (m^{p - 1})^h m \equiv 1^h m \equiv m \pmod{p},</math> | |||
#: where we used ] to replace {{math|''m''<sup>''p''−1</sup> mod ''p''}} with 1. | |||
The verification that {{math|''m<sup>ed</sup>'' ≡ ''m'' (mod ''q'')}} proceeds in a completely analogous way: | |||
# If {{math|''m'' ≡ 0 (mod ''q'')}}, ''m<sup>ed</sup>'' is a multiple of {{mvar|q}}. So {{math|''m<sup>ed</sup>'' ≡ 0 ≡ ''m'' (mod ''q'')}}. | |||
# If {{math|''m'' <math>\not\equiv</math> 0 (mod ''q'')}}, | |||
#: <math>m^{ed} = m^{ed - 1} m = m^{k(q - 1)} m = (m^{q - 1})^k m \equiv 1^k m \equiv m \pmod{q}.</math> | |||
This completes the proof that, for any integer {{mvar|m}}, and integers {{mvar|e}}, {{mvar|d}} such that {{math|1=''ed'' ≡ 1 (mod ''λ''(''pq''))}}, | |||
<math display="block">(m^e)^d \equiv m \pmod{pq}.</math> | |||
====Notes==== | |||
{{reflist|group=note}} | |||
===Proof using Euler's theorem=== | |||
Although the original paper of Rivest, Shamir, and Adleman used Fermat's little theorem to explain why RSA works, it is common to find proofs that rely instead on ]. | |||
We want to show that {{math|''m<sup>ed</sup>'' ≡ ''m'' (mod ''n'')}}, where {{math|1=''n'' = ''pq''}} is a product of two different prime numbers, and {{mvar|e}} and {{mvar|d}} are positive integers satisfying {{math|''ed'' ≡ 1 (mod ''φ''(''n''))}}. Since {{mvar|e}} and {{mvar|d}} are positive, we can write {{math|1=''ed'' = 1 + ''hφ''(''n'')}} for some non-negative integer {{mvar|h}}. ''Assuming'' that {{mvar|m}} is relatively prime to {{mvar|n}}, we have | |||
<math display="block">m^{ed} = m^{1 + h\varphi(n)} = m (m^{\varphi(n)})^h \equiv m (1)^h \equiv m \pmod{n},</math> | |||
where the second-last congruence follows from ]. | |||
More generally, for any {{mvar|e}} and {{mvar|d}} satisfying {{math|''ed'' ≡ 1 (mod ''λ''(''n''))}}, the same conclusion follows from ], which states that {{math|''m''<sup>''λ''(n)</sup> ≡ 1 (mod ''n'')}} for all {{mvar|m}} relatively prime to {{mvar|n}}. | |||
When {{mvar|m}} is not relatively prime to {{mvar|n}}, the argument just given is invalid. This is highly improbable (only a proportion of {{math|1/''p'' + 1/''q'' − 1/(''pq'')}} numbers have this property), but even in this case, the desired congruence is still true. Either {{math|''m'' ≡ 0 (mod ''p'')}} or {{math|''m'' ≡ 0 (mod ''q'')}}, and these cases can be treated using the previous proof. | |||
==Padding== | |||
===Attacks against plain RSA=== | |||
There are a number of attacks against plain RSA as described below. | |||
* When encrypting with low encryption exponents (e.g., {{math|1=''e'' = 3}}) and small values of the {{mvar|m}} (i.e., {{math|''m'' < ''n''<sup>1/''e''</sup>}}), the result of {{math|''m''<sup>''e''</sup>}} is strictly less than the modulus {{mvar|n}}. In this case, ciphertexts can be decrypted easily by taking the {{mvar|e}}th root of the ciphertext over the integers. | |||
* If the same clear-text message is sent to {{mvar|e}} or more recipients in an encrypted way, and the receivers share the same exponent {{mvar|e}}, but different {{mvar|p}}, {{mvar|q}}, and therefore {{mvar|n}}, then it is easy to decrypt the original clear-text message via the ]. ] noticed that this attack is possible even if the clear texts are not equal, but the attacker knows a linear relation between them.<ref>{{cite book |first=Johan |last=Håstad |chapter=On using RSA with Low Exponent in a Public Key Network |title=Advances in Cryptology – CRYPTO '85 Proceedings |series=Lecture Notes in Computer Science |volume=218 |year=1986 |pages=403–408 |doi=10.1007/3-540-39799-X_29 |isbn=978-3-540-16463-0 }}</ref> This attack was later improved by ] (see ]).<ref>{{cite journal |first=Don |last=Coppersmith |s2cid=15726802 |title=Small Solutions to Polynomial Equations, and Low Exponent RSA Vulnerabilities |journal=] |volume=10 |issue=4 |pages=233–260 |year=1997 |doi=10.1007/s001459900030 |url=https://www.di.ens.fr/~fouque/ens-rennes/coppersmith.pdf |citeseerx=10.1.1.298.4806 }}</ref> | |||
* Because RSA encryption is a ] (i.e., has no random component) an attacker can successfully launch a ] against the cryptosystem, by encrypting likely plaintexts under the public key and test whether they are equal to the ciphertext. A cryptosystem is called ] if an attacker cannot distinguish two encryptions from each other, even if the attacker knows (or has chosen) the corresponding plaintexts. RSA without padding is not semantically secure.<ref>{{Cite book|last1=Goldwasser|first1=Shafi|last2=Micali|first2=Silvio|title=Proceedings of the fourteenth annual ACM symposium on Theory of computing - STOC '82 |chapter=Probabilistic encryption & how to play mental poker keeping secret all partial information |date=1982-05-05|chapter-url=https://doi.org/10.1145/800070.802212|location=New York, NY, USA|publisher=Association for Computing Machinery|pages=365–377|doi=10.1145/800070.802212|isbn=978-0-89791-070-5|s2cid=10316867 |author-link1=Shafi Goldwasser |author-link2=Silvio Micali }}</ref> | |||
* RSA has the property that the product of two ciphertexts is equal to the encryption of the product of the respective plaintexts. That is, {{math|''m''<sub>1</sub><sup>''e''</sup>''m''<sub>2</sub><sup>''e''</sup> ≡ (''m''<sub>1</sub>''m''<sub>2</sub>)<sup>''e''</sup> (mod ''n'')}}. Because of this multiplicative property, a ] is possible. E.g., an attacker who wants to know the decryption of a ciphertext {{math|''c'' ≡ ''m''<sup>''e''</sup> (mod ''n'')}} may ask the holder of the private key {{mvar|d}} to decrypt an unsuspicious-looking ciphertext {{math|''c''′ ≡ ''cr''<sup>''e''</sup> (mod ''n'')}} for some value {{mvar|r}} chosen by the attacker. Because of the multiplicative property, {{mvar|c}}' is the encryption of {{math|''mr'' (mod ''n'')}}. Hence, if the attacker is successful with the attack, they will learn {{math|''mr'' (mod ''n''),}} from which they can derive the message {{mvar|m}} by multiplying {{math|''mr''}} with the modular inverse of {{mvar|r}} modulo {{mvar|n}}.{{citation needed|reason=Someone had to have noticed this and published first, they should be cited|date=February 2015}} | |||
* Given the private exponent {{mvar|d}}, one can efficiently factor the modulus {{math|1=''n'' = ''pq''}}. And given factorization of the modulus {{math|1=''n'' = ''pq''}}, one can obtain any private key ({{mvar|d}}', {{mvar|n}}) generated against a public key ({{mvar|e}}', {{mvar|n}}).<ref name="Boneh99"/> | |||
===Padding schemes=== | ===Padding schemes=== | ||
To avoid these problems, practical RSA implementations typically embed some form of structured, randomized ] into the value {{mvar|m}} before encrypting it. This padding ensures that {{mvar|m}} does not fall into the range of insecure plaintexts, and that a given message, once padded, will encrypt to one of a large number of different possible ciphertexts. | |||
Standards such as ] have been carefully designed to securely pad messages prior to RSA encryption. Because these schemes pad the plaintext {{mvar|m}} with some number of additional bits, the size of the un-padded message {{mvar|M}} must be somewhat smaller. RSA padding schemes must be carefully designed so as to prevent sophisticated attacks that may be facilitated by a predictable message structure. Early versions of the PKCS#1 standard (up to version 1.5) used a construction that appears to make RSA semantically secure. However, at ] 1998, Bleichenbacher showed that this version is vulnerable to a practical ]. Furthermore, at ] 2000, Coron et al.<ref>{{Cite book |last1=Coron |first1=Jean-Sébastien |last2=Joye |first2=Marc |last3=Naccache |first3=David |last4=Paillier |first4=Pascal |title=Advances in Cryptology — EUROCRYPT 2000 |chapter=New Attacks on PKCS#1 v1.5 Encryption |date=2000 |editor-last=Preneel |editor-first=Bart |series=Lecture Notes in Computer Science |volume=1807 |language=en |location=Berlin, Heidelberg |publisher=Springer| pages=369–381 |doi=10.1007/3-540-45539-6_25 |isbn=978-3-540-45539-4 |doi-access=free}}</ref> showed that for some types of messages, this padding does not provide a high enough level of security. Later versions of the standard include ] (OAEP), which prevents these attacks. As such, OAEP should be used in any new application, and PKCS#1 v1.5 padding should be replaced wherever possible. The PKCS#1 standard also incorporates processing schemes designed to provide additional security for RSA signatures, e.g. the Probabilistic Signature Scheme for RSA (]). | |||
When used in practice, RSA must be combined with some form of ], so that no values of ''M'' result in insecure ciphertexts. RSA used without padding may suffer from a number of potential problems: | |||
Secure padding schemes such as RSA-PSS are as essential for the security of message signing as they are for message encryption. Two USA patents on PSS were granted ({{US patent|6266771}} and {{US patent|7036014}}); however, these patents expired on 24 July 2009 and 25 April 2010 respectively. Use of PSS no longer seems to be encumbered by patents.{{Original research inline|date=August 2019}} Note that using different RSA key pairs for encryption and signing is potentially more secure.<ref>{{Cite web | url=https://www.di-mgt.com.au/rsa_alg.html#weaknesses | title=RSA Algorithm}}</ref> | |||
*The values ''m'' = 0 or ''m'' = 1 always produce ciphertexts equal to 0 or 1 respectively, due to the properties of exponentiation. | |||
*When encrypting with low encryption exponents (e.g., ''e'' = 3) and small values of the ''m'', the (non-modular) result of <math>m^e</math> may be strictly less than the modulus ''n''. In this case, ciphertexts may be easily decrypted by taking the ''e''th root of the ciphertext with no regard to the modulus. | |||
*Because RSA encryption is a ] algorithm – i.e., has no random component – an attacker can successfully launch a ] against the cryptosystem, building a ] by encrypting likely plaintexts under the public key, and storing the resulting ciphertexts. When matching ciphertexts are observed on a communication channel, the attacker can use this dictionary in order to learn the content of the message. | |||
==Security and practical considerations== | |||
In practice, the first two problems might arise when sending short ] messages, where ''m'' is the concatenation of one or more ASCII-encoded character(s). A message consisting of a single ASCII <code>NUL</code> character (whose numeric value is 0) would be encoded as ''m'' = 0, which produces a ciphertext of 0 regardless of what ''e'' and ''N'' are used. Likewise, a single ASCII <code>SOH</code> (whose numeric value is 1) would always produce a ciphertext of 1. For systems which conventionally use small values of ''e'', such as 3, all single character ASCII messages encoded using this scheme would be insecure, since the largest ''m'' would have a value of 255, and 255<sup>3</sup> is less than any reasonable modulus. Such plaintexts could be recovered by simply taking the cube root of the ciphertext. | |||
===Using the Chinese remainder algorithm=== | |||
To avoid these problems, practical RSA implementations typically embed some form of structured, randomized ] into the value ''m'' before encrypting it. This padding ensures that ''m'' does not fall into the range of insecure plaintexts, and that a given message, once padded, will encrypt to one of a large number of different possible ciphertexts. The latter property can increase the cost of a dictionary attack beyond the capabilities of a reasonable attacker. | |||
For efficiency, many popular crypto libraries (such as ], ] and ]) use for decryption and signing the following optimization based on the ].<ref>{{cite web |title=OpenSSL bn_s390x.c |url=https://github.com/openssl/openssl/blob/422a13fb5cd668cdc4c1eebce8accb4d25c3d8eb/crypto/bn/bn_s390x.c#L70 |website=Github |access-date=2 August 2024}}</ref>{{fact|date=December 2023}} The following values are precomputed and stored as part of the private key: | |||
* <math>p</math> and <math>q</math>{{snd}} the primes from the key generation, | |||
* <math>d_P = d \pmod{p - 1},</math> | |||
* <math>d_Q = d \pmod{q - 1},</math> | |||
* <math>q_\text{inv} = q^{-1} \pmod{p}.</math> | |||
These values allow the recipient to compute the exponentiation {{math|1=''m'' = ''c''<sup>''d''</sup> (mod ''pq'')}} more efficiently as follows: | |||
Standards such as ] have been carefully designed to securely pad messages prior to RSA encryption. Because these schemes pad the plaintext ''m'' with some number of additional bits, the size of the un-padded message ''M'' must be somewhat smaller. RSA padding schemes must be carefully designed so as to prevent sophisticated attacks which may be facilitated by a predictable message structure. Early versions of the PKCS standard used ad-hoc constructions, which were later found vulnerable to a practical ]. Modern constructions use secure techniques such as ] (OAEP) to protect messages while preventing these attacks. The ] standard also incorporates processing schemes designed to provide additional security for RSA signatures, e.g., the Probabilistic Signature Scheme for RSA (]). | |||
{{indent|5}}<math>m_1 = c^{d_P} \pmod{p}</math>, | |||
{{indent|5}}<math>m_2 = c^{d_Q} \pmod{q}</math>, | |||
{{indent|5}}<math>h = q_\text{inv}(m_1 - m_2) \pmod{p}</math>,{{efn|If <math>m_1 < m_2</math>, then some{{clarify|date=June 2020}} libraries compute {{mvar|h}} as <math>q_\text{inv}\left \pmod{p}</math>.}} | |||
{{indent|5}}<math>m = m_2 + hq</math>. | |||
This is more efficient than computing ], even though two modular exponentiations have to be computed. The reason is that these two modular exponentiations both use a smaller exponent and a smaller modulus. | |||
=== Signing messages === | |||
===Integer factorization and the RSA problem=== | |||
Suppose Alice uses Bob's public key to send him an encrypted message. In the message, she can claim to be Alice but Bob has no way of verifying that the message was actually from Alice since anyone can use Bob's public key to send him encrypted messages. So, in order to verify the origin of a message, RSA can also be used to ] a message. | |||
{{See also|RSA Factoring Challenge|Integer factorization records|Shor's algorithm|}} | |||
The security of the RSA cryptosystem is based on two mathematical problems: the problem of ] and the ]. Full decryption of an RSA ciphertext is thought to be infeasible on the assumption that both of these problems are ], i.e., no efficient algorithm exists for solving them. Providing security against ''partial'' decryption may require the addition of a secure ].<ref>{{cite book |first=Edmond K. |last=Machie |url=https://books.google.com/books?id=AK5MySZbbuMC&pg=PA167 |title=Network security traceback attack and react in the United States Department of Defense network |date=29 March 2013 |pages=167 |publisher=Trafford |isbn=978-1466985742}}</ref> | |||
The ] is defined as the task of taking {{mvar|e}}th roots modulo a composite {{mvar|n}}: recovering a value {{mvar|m}} such that {{math|''c'' ≡ ''m''<sup>''e''</sup> (mod ''n'')}}, where {{math|(''n'', ''e'')}} is an RSA public key, and {{mvar|c}} is an RSA ciphertext. Currently the most promising approach to solving the RSA problem is to factor the modulus {{mvar|n}}. With the ability to recover prime factors, an attacker can compute the secret exponent {{mvar|d}} from a public key {{math|(''n'', ''e'')}}, then decrypt {{mvar|c}} using the standard procedure. To accomplish this, an attacker factors {{mvar|n}} into {{mvar|p}} and {{mvar|q}}, and computes {{math|lcm(''p'' − 1, ''q'' − 1)}} that allows the determination of {{mvar|d}} from {{mvar|e}}. No polynomial-time method for factoring large integers on a classical computer has yet been found, but it has not been proven that none exists; see ] for a discussion of this problem. | |||
Suppose Alice wishes to send a signed message to Bob. She produces a ] of the message, raises it to the power of ''d'' mod ''n'' (as she does when decrypting a message), and attaches it as a "signature" to the message. When Bob receives the signed message, he raises the signature to the power of ''e'' mod ''n'' (as he does when encrypting a message), and compares the resulting hash value with the message's actual hash value. If the two agree, he knows that the author of the message was in possession of Alice's secret key, and that the message has not been tampered with since. | |||
Multiple polynomial quadratic sieve (MPQS) can be used to factor the public modulus {{mvar|n}}. | |||
Note that secure padding schemes such as ] are as essential for the security of message signing as they are for message encryption, and that the same key should never be used for both encryption and signing purposes. | |||
The first RSA-512 factorization in 1999 used hundreds of computers and required the equivalent of 8,400 MIPS years, over an elapsed time of about seven months.<ref>{{Cite web |url=https://www.iacr.org/archive/eurocrypt2000/1807/18070001-new.pdf |title=Factorization of a 512-bit RSA Modulus |date=2000 |first=Arjen |last=Lenstra |collaboration=Group |publisher=Eurocrypt }}</ref> By 2009, Benjamin Moody could factor an 512-bit RSA key in 73 days using only public software (GGNFS) and his desktop computer (a dual-core ] with a 1,900 MHz CPU). Just less than 5 gigabytes of disk storage was required and about 2.5 gigabytes of RAM for the sieving process. | |||
== Security == | |||
Rivest, Shamir, and Adleman noted<ref name="rsa" /> that Miller has shown that – assuming the truth of the ] – finding {{mvar|d}} from {{mvar|n}} and {{mvar|e}} is as hard as factoring {{mvar|n}} into {{mvar|p}} and {{mvar|q}} (up to a polynomial time difference).<ref>{{cite conference |url=https://www.cs.cmu.edu/~glmiller/Publications/Papers/Mi75.pdf |first=Gary L. |last=Miller |title=Riemann's Hypothesis and Tests for Primality |book-title=Proceedings of Seventh Annual ACM Symposium on Theory of Computing |year=1975 |pages=234–239}}</ref> However, Rivest, Shamir, and Adleman noted, in section IX/D of their paper, that they had not found a proof that inverting RSA is as hard as factoring. | |||
The security of the RSA cryptosystem is based on two mathematical problems: the problem of ] and the ]. Full decryption of an RSA ciphertext is thought to be infeasible on the assumption that both of these problems are hard, i.e., no efficient algorithm exists for solving them. Providing security against ''partial'' decryption may require the addition of a secure ]. | |||
{{As of|2020}}, the largest publicly known factored ] had 829 bits (250 decimal digits, ]).<ref>{{cite web |title=Factorization of RSA-250 |date=2020-02-28 |first=Paul |last=Zimmermann |publisher=Cado-nfs-discuss |url=https://lists.gforge.inria.fr/pipermail/cado-nfs-discuss/2020-February/001166.html |access-date=2020-07-12 |archive-date=2020-02-28 |archive-url=https://web.archive.org/web/20200228234716/https://lists.gforge.inria.fr/pipermail/cado-nfs-discuss/2020-February/001166.html |url-status=dead }}</ref> Its factorization, by a state-of-the-art distributed implementation, took about 2,700 CPU-years. In practice, RSA keys are typically 1024 to 4096 bits long. In 2003, ] estimated that 1024-bit keys were likely to become crackable by 2010.<ref name="twirl">{{cite web |url=http://emc.com/emc-plus/rsa-labs/historical/twirl-and-rsa-key-size.htm|title=TWIRL and RSA Key Size |publisher=] |archive-url=https://web.archive.org/web/20170417095741/https://www.emc.com/emc-plus/rsa-labs/historical/twirl-and-rsa-key-size.htm |archive-date=2017-04-17 |url-status=dead |access-date=2017-11-24 |first=Burt |last=Kaliski |date=May 6, 2003 |df=ymd-all}}</ref> As of 2020, it is not known whether such keys can be cracked, but minimum recommendations have moved to at least 2048 bits.<ref name="keymanagement">{{cite web |url=http://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-57Pt3r1.pdf |title=NIST Special Publication 800-57 Part 3 Revision 1: Recommendation for Key Management: Application-Specific Key Management Guidance |date=2015-01-22 |page=12 |access-date=2017-11-24 |publisher=] |doi=10.6028/NIST.SP.800-57pt3r1 |first1=Elaine |last1=Barker |first2=Quynh |last2=Dang}}</ref> It is generally presumed that RSA is secure if {{mvar|n}} is sufficiently large, outside of quantum computing. | |||
The ] is defined as the task of taking ''e''th roots modulo a composite ''n'': recovering a value ''m'' such that ''m<sup>e</sup>=c'' mod n, where (''e'', ''n'') is an RSA public key and ''c'' is an RSA ciphertext. Currently the most promising approach to solving the RSA problem is to factor the modulus ''n''. With the ability to recover prime factors, an attacker can compute the secret exponent ''d'' from a public key (''e'', ''n''), then decrypt ''c'' using the standard procedure. To accomplish this, an attacker factors ''n'' into ''p'' and ''q'', and computes (''p''-1)(''q''-1) which allows the determination of ''d'' from ''e''. No polynomial-time method for factoring large integers on a classical computer has yet been found, but it has not been proven that none exists. See ] for a discussion of this problem. | |||
If {{mvar|n}} is 300 ]s or shorter, it can be factored in a few hours on a ], using software already freely available. Keys of 512 bits have been shown to be practically breakable in 1999, when ] was factored by using several hundred computers, and these are now factored in a few weeks using common hardware. Exploits using 512-bit code-signing certificates that may have been factored were reported in 2011.<ref>{{cite web |url=https://blog.fox-it.com/2011/11/21/rsa-512-certificates-abused-in-the-wild/ |title=RSA-512 certificates abused in-the-wild |website=Fox-IT International blog |date=November 21, 2011 |first=Michael |last=Sandee}}</ref> A theoretical hardware device named ], described by Shamir and Tromer in 2003, called into question the security of 1024-bit keys.<ref name="twirl" /> | |||
In |
In 1994, ] showed that a ] – if one could ever be practically created for the purpose – would be able to factor in ], breaking RSA; see ]. | ||
===Faulty key generation=== | |||
:''See also'': ] | |||
{{more citations needed|section|date=October 2017}} | |||
{{See also|Coppersmith's attack|Wiener's attack}} | |||
Finding the large primes {{mvar|p}} and {{mvar|q}} is usually done by testing random numbers of the correct size with probabilistic ]s that quickly eliminate virtually all of the nonprimes. | |||
== Practical considerations == | |||
=== Key generation === | |||
The numbers {{mvar|p}} and {{mvar|q}} should not be "too close", lest the ] for {{mvar|n}} be successful. If {{math|''p'' − ''q''}} is less than {{math|2''n''<sup>1/4</sup>}} ({{math|1=''n'' = ''p''⋅''q''}}, which even for "small" 1024-bit values of {{mvar|n}} is {{val|3|e=77}}), solving for {{mvar|p}} and {{mvar|q}} is trivial. Furthermore, if either {{math|''p'' − 1}} or {{math|''q'' − 1}} has only small prime factors, {{mvar|n}} can be factored quickly by ], and hence such values of {{mvar|p}} or {{mvar|q}} should be discarded. | |||
Finding the large primes ''p'' and ''q'' is usually done by testing random numbers of the right size with probabilistic ]s which quickly eliminate virtually all non-primes. | |||
It is important that the private exponent {{mvar|d}} be large enough. Michael J. Wiener showed that if {{mvar|p}} is between {{mvar|q}} and {{math|2''q''}} (which is quite typical) and {{math|''d'' < ''n''<sup>1/4</sup>/3}}, then {{mvar|d}} can be computed efficiently from {{mvar|n}} and {{mvar|e}}.<ref name="wiener">{{Cite journal | title=Cryptanalysis of short RSA secret exponents | first1=Michael J. | last1=Wiener | journal=IEEE Transactions on Information Theory | volume=36 | issue=3 | pages=553–558 | date=May 1990 | doi=10.1109/18.54902 | s2cid=7120331 |url=http://www.cits.rub.de/imperia/md/content/may/krypto2ss08/shortsecretexponents.pdf }}</ref> | |||
''p'' and ''q'' should not be 'too close', lest the ] for ''n'' be successful. Furthermore, if either ''p''-1 or ''q''-1 has only small prime factors, ''n'' can be factored quickly and these values of ''p'' or ''q'' should therefore be discarded as well. | |||
There is no known attack against small public exponents such as {{math|1=''e'' = 3}}, provided that the proper padding is used. ] has many applications in attacking RSA specifically if the public exponent {{mvar|e}} is small and if the encrypted message is short and not padded. ] is a commonly used value for {{mvar|e}}; this value can be regarded as a compromise between avoiding potential small-exponent attacks and still allowing efficient encryptions (or signature verification). The NIST Special Publication on Computer Security (SP 800-78 Rev. 1 of August 2007) does not allow public exponents {{mvar|e}} smaller than 65537, but does not state a reason for this restriction. | |||
One should not employ a prime search method which gives any information whatsoever about the primes to the attacker. In particular, a good ] for the start value needs to be employed. Note that the requirement here is both 'random' '''''and''''' 'unpredictable'. These are not the same criteria; a number may have been chosen by a random process (ie, no pattern in the results), but if it is predictable in any manner (or even partially predictable), the method used will result in loss of security. For example, the random number table published by the ] in the 1950s might very well be truly random, but it has been published and thus can serve an attacker as well. If the attacker can guess half of the digits of ''p'' or ''q'', they can quickly compute the other half (shown by ] in 1997). | |||
In October 2017, a team of researchers from ] announced the ], which affects RSA keys generated by an algorithm embodied in a library from ] known as RSALib. A large number of ]s and ]s (TPM) were shown to be affected. Vulnerable RSA keys are easily identified using a test program the team released.<ref name=nemecsys>{{cite conference |url=https://crocs.fi.muni.cz/_media/public/papers/nemec_roca_ccs17_preprint.pdf |title=The Return of Coppersmith's Attack: Practical Factorization of Widely Used RSA Moduli |first1=Matus |last1=Nemec |first2=Marek |last2=Sys |first3=Petr |last3=Svenda |first4=Dusan |last4=Klinec |first5=Vashek |last5=Matyas |date=November 2017 |doi=10.1145/3133956.3133969 |book-title=Proceedings of the 2017 ACM SIGSAC Conference on Computer and Communications Security |series=CCS '17}}</ref> | |||
It is important that the secret key ''d'' be large enough. Wiener showed in ] that if ''p'' is between ''q'' and 2''q'' (which is quite typical) and ''d'' < ''n''<sup>1/4</sup>/3, then ''d'' can be computed efficiently from ''n'' and ''e''. | |||
There is no known attack against small public exponents such as ''e''=3, provided that | |||
proper padding is used. However, when no padding is used or when the padding is improperly | |||
implemented then small public exponents have a greater risk of leading to an attack, | |||
such as for example the unpadded plaintext vulnerability listed above. | |||
65537 is a commonly used value for ''e''. This value can be regarded as a compromise | |||
between avoiding potential small exponent attacks and still allowing efficient | |||
encryptions (or signature verification). The NIST draft FIPS PUB 186-3 (March 2006) does | |||
not allow public exponents e smaller than 65537, but does not state a reason for this | |||
restriction. | |||
===Importance of strong random number generation=== | |||
=== Speed === | |||
A cryptographically strong ], which has been properly seeded with adequate entropy, must be used to generate the primes {{mvar|p}} and {{mvar|q}}. An analysis comparing millions of public keys gathered from the Internet was carried out in early 2012 by ], James P. Hughes, Maxime Augier, Joppe W. Bos, Thorsten Kleinjung and Christophe Wachter. They were able to factor 0.2% of the keys using only Euclid's algorithm.<ref>{{cite web|title=Flaw Found in an Online Encryption Method |url=https://www.nytimes.com/2012/02/15/technology/researchers-find-flaw-in-an-online-encryption-method.html |newspaper=] |date=February 14, 2012 |first=John |last=Markoff }}</ref><ref>{{cite web |title=Ron was wrong, Whit is right |url=http://eprint.iacr.org/2012/064.pdf |year=2012 |last1=Lenstra |first1=Arjen K. |last2=Hughes |first2=James P. |last3=Augier |first3=Maxime |last4=Bos |first4=Joppe W. |last5=Kleinjung |first5=Thorsten |last6=Wachter |first6=Christophe }}</ref>{{self published inline|date=December 2023|reason=This paper is not from a journal and may not have been peer-reviewed}} | |||
They exploited a weakness unique to cryptosystems based on integer factorization. If {{math|1=''n'' = ''pq''}} is one public key, and {{math|1=''n''′ = ''p''′''q''′}} is another, then if by chance {{math|1=''p'' = ''p''′}} (but {{mvar|q}} is not equal to {{mvar|q}}'), then a simple computation of {{math|1=gcd(''n'', ''n''′) = ''p''}} factors both {{mvar|n}} and {{mvar|n}}', totally compromising both keys. Lenstra et al. note that this problem can be minimized by using a strong random seed of bit length twice the intended security level, or by employing a deterministic function to choose {{mvar|q}} given {{mvar|p}}, instead of choosing {{mvar|p}} and {{mvar|q}} independently. | |||
RSA is much slower than ] and other ]. In practice, Bob typically encrypts a secret message with a symmetric algorithm, encrypts the (comparatively short) symmetric key with RSA, and transmits both the RSA-encrypted symmetric key and the symmetrically-encrypted message to Alice. | |||
] was part of a group that did a similar experiment. They used an idea of ] to compute the GCD of each RSA key {{mvar|n}} against the product of all the other keys {{mvar|n}}' they had found (a 729-million-digit number), instead of computing each {{math|gcd(''n'', ''n''′)}} separately, thereby achieving a very significant speedup, since after one large division, the GCD problem is of normal size. | |||
This procedure raises additional security issues. For instance, it is of utmost importance to use a strong ] for the symmetric key, because otherwise Eve (an eavesdropper wanting to see what was sent) could bypass RSA by guessing the symmetric key. | |||
Heninger says in her blog that the bad keys occurred almost entirely in embedded applications, including "firewalls, routers, VPN devices, remote server administration devices, printers, projectors, and VOIP phones" from more than 30 manufacturers. Heninger explains that the one-shared-prime problem uncovered by the two groups results from situations where the pseudorandom number generator is poorly seeded initially, and then is reseeded between the generation of the first and second primes. Using seeds of sufficiently high entropy obtained from key stroke timings or electronic diode noise or ] from a radio receiver tuned between stations should solve the problem.<ref>{{Cite web | url=https://freedom-to-tinker.com/blog/nadiah/new-research-theres-no-need-panic-over-factorable-keys-just-mind-your-ps-and-qs | title=New research: There's no need to panic over factorable keys–just mind your Ps and Qs | date=February 15, 2012 | website=Freedom to Tinker | first=Nadia | last=Heninger}}</ref> | |||
=== Key distribution === | |||
Strong random number generation is important throughout every phase of public-key cryptography. For instance, if a weak generator is used for the symmetric keys that are being distributed by RSA, then an eavesdropper could bypass RSA and guess the symmetric keys directly. | |||
As with all ciphers, how RSA public keys are distributed is important to security. Key distribution must be secured against a ]. Suppose Eve has some way to give Bob arbitrary keys and make him believe they belong to Alice. Suppose further that Eve can ''intercept'' transmissions between Alice and Bob. Eve sends Bob her own public key, which Bob believes to be Alice's. Eve can then intercept any ciphertext sent by Bob, decrypt it with her own secret key, keep a copy of the message, encrypt the message with Alice's public key, and send the new ciphertext to Alice. In principle, neither Alice nor Bob would be able to detect Eve's presence. Defenses against such attacks are often based on ]s or other components of a ]. | |||
=== |
===Timing attacks=== | ||
] described a new attack on RSA in 1995: if the attacker Eve knows Alice's hardware in sufficient detail and is able to measure the decryption times for several known ciphertexts, Eve can deduce the decryption key {{mvar|d}} quickly. This attack can also be applied against the RSA signature scheme. In 2003, ] and ] demonstrated a more practical attack capable of recovering RSA factorizations over a network connection (e.g., from a ] (SSL)-enabled webserver).<ref name="Boneh03">{{cite conference |url=http://crypto.stanford.edu/~dabo/papers/ssl-timing.pdf |title=Remote timing attacks are practical |first1=David |last1=Brumley |first2=Dan |last2=Boneh |year=2003 |series=SSYM'03 |book-title=Proceedings of the 12th Conference on USENIX Security Symposium}}</ref> This attack takes advantage of information leaked by the ] optimization used by many RSA implementations. | |||
One way to thwart these attacks is to ensure that the decryption operation takes a constant amount of time for every ciphertext. However, this approach can significantly reduce performance. Instead, most RSA implementations use an alternate technique known as ]. RSA blinding makes use of the multiplicative property of RSA. Instead of computing {{math|''c''<sup>''d''</sup> (mod ''n'')}}, Alice first chooses a secret random value {{mvar|r}} and computes {{math|(''r''<sup>''e''</sup>''c'')<sup>''d''</sup> (mod ''n'')}}. The result of this computation, after applying ], is {{math|''rc''<sup>''d''</sup> (mod ''n'')}}, and so the effect of {{mvar|r}} can be removed by multiplying by its inverse. A new value of {{mvar|r}} is chosen for each ciphertext. With blinding applied, the decryption time is no longer correlated to the value of the input ciphertext, and so the timing attack fails. | |||
] described a new attack on RSA in ]: if the attacker Eve knows Alice's hardware in sufficient detail and is able to measure the decryption times for several known ciphertexts, she can deduce the decryption key ''d'' quickly. This attack can also be applied against the RSA signature scheme. In ], ] and ] demonstrated a more practical attack capable of recovering RSA factorizations over a network connection (e.g., from a ] (SSL)-enabled webserver). This attack takes advantage of information leaked by the ] optimization used by many RSA implementations. | |||
===Adaptive chosen-ciphertext attacks=== | |||
One way to thwart these attacks is to ensure that the decryption operation takes a constant amount of time for every ciphertext. However, this approach can significantly reduce performance. Instead, most RSA implementations use an alternate technique known as cryptographic ]. RSA blinding makes use of the multiplicative property of RSA. Instead of computing ''c<sup>d</sup> mod n'', Alice first chooses a secret random value ''r'' and computes ''(r<sup>e</sup>c)<sup>d</sup> mod n''. The result of this computation is ''r m mod n'' and so the effect of ''r'' can be removed by multiplying by its inverse. A new value of ''r'' is chosen for each ciphertext. With blinding applied, the decryption time is no longer correlated to the value of the input ciphertext and so the timing attack fails. | |||
In 1998, ] described the first practical ] against RSA-encrypted messages using the PKCS #1 v1 ] (a padding scheme randomizes and adds structure to an RSA-encrypted message, so it is possible to determine whether a decrypted message is valid). Due to flaws with the PKCS #1 scheme, Bleichenbacher was able to mount a practical attack against RSA implementations of the ] protocol and to recover session keys. As a result of this work, cryptographers now recommend the use of provably secure padding schemes such as ], and RSA Laboratories has released new versions of PKCS #1 that are not vulnerable to these attacks. | |||
A variant of this attack, dubbed "BERserk", came back in 2014.<ref>{{cite web |title='BERserk' Bug Uncovered In Mozilla NSS Crypto Library Impacts Firefox, Chrome |date=25 September 2014 |url=https://www.darkreading.com/attacks-breaches/-berserk-bug-uncovered-in-mozilla-nss-crypto-library-impacts-firefox-chrome |access-date=4 January 2022}}</ref><ref>{{Cite web|url=https://www.mozilla.org/en-US/security/advisories/mfsa2014-73/|title=RSA Signature Forgery in NSS|website=Mozilla}}</ref> It impacted the Mozilla NSS Crypto Library, which was used notably by Firefox and Chrome. | |||
=== Adaptive chosen ciphertext attacks === | |||
In ], ] described the first practical ], against RSA-encrypted messages using the PKCS #1 v1 ] (a padding scheme randomizes and adds structure to an RSA-encrypted message, so it is possible to determine whether a decrypted message is valid.) Due to flaws with the PKCS #1 scheme, Bleichenbacher was able to mount a practical attack against RSA implementations of the ] protocol, and to recover session keys. As a result of this work, cryptographers now recommend the use of provably secure padding schemes such as ], and RSA Laboratories has released new versions of PKCS #1 that are not vulnerable to these attacks. | |||
===Side-channel analysis attacks=== | |||
== See also== | |||
A side-channel attack using branch-prediction analysis (BPA) has been described. Many processors use a ] to determine whether a conditional branch in the instruction flow of a program is likely to be taken or not. Often these processors also implement ] (SMT). Branch-prediction analysis attacks use a spy process to discover (statistically) the private key when processed with these processors. | |||
{{Portal|Cryptography|Key-crypto-sideways.png}} | |||
* ] | |||
Simple Branch Prediction Analysis (SBPA) claims to improve BPA in a non-statistical way. In their paper, "On the Power of Simple Branch Prediction Analysis",<ref>{{Cite conference |citeseerx = 10.1.1.80.1438 |title = On the power of simple branch prediction analysis |first1=Onur |last1=Acıiçmez |first2=Çetin Kaya |last2=Koç |first3=Jean-Pierre |last3=Seifert |pages = 312–320 |year = 2007 |book-title=Proceedings of the 2nd ACM Symposium on Information, Computer and Communications Security |series=ASIACCS '07 |doi=10.1145/1229285.1266999 }}</ref> the authors of SBPA (Onur Aciicmez and Cetin Kaya Koc) claim to have discovered 508 out of 512 bits of an RSA key in 10 iterations. | |||
* ] | |||
* ] | |||
A power-fault attack on RSA implementations was described in 2010.<ref>{{cite book |last1=Pellegrini |first1=Andrea |last2=Bertacco |first2=Valeria |last3=Austin |first3=Todd |chapter=Fault-based attack of RSA authentication |title=2010 Design, Automation & Test in Europe Conference & Exhibition (DATE 2010) |date=March 2010 |pages=855–860 |doi=10.1109/DATE.2010.5456933 |isbn=978-3-9810801-6-2 |access-date=21 November 2024 |chapter-url=https://ieeexplore.ieee.org/document/5456933}}</ref> The author recovered the key by varying the CPU power voltage outside limits; this caused multiple power faults on the server. | |||
===Tricky implementation=== | |||
There are many details to keep in mind in order to implement RSA securely (strong ], acceptable public exponent, etc.). This makes the implementation challenging, to the point the book Practical Cryptography With Go suggests avoiding RSA if possible.<ref>{{cite web |last1=Isom |first1=Kyle |title=Practical Cryptography With Go |url=https://leanpub.com/gocrypto/read#leanpub-auto-rsa |access-date=4 January 2022}}</ref> | |||
== Implementations == | |||
Some cryptography libraries that provide support for RSA include: | |||
* ] | |||
* ] | |||
* ] | |||
* ] | |||
* ] | |||
* ] | |||
* ] | |||
* ] | |||
* ] | |||
* ] | |||
* ] | |||
==See also== | |||
{{Portal|Mathematics}} | |||
* ] | |||
* ] | * ] | ||
* ] | |||
* ] | |||
* ] | |||
* ] | |||
* ] | |||
* ] | |||
* ] | |||
* ] | |||
* ] | |||
* ] | |||
==Notes== | |||
{{notelist}} | |||
== |
==References== | ||
{{Reflist|30em}} | |||
==Further reading== | |||
* R. Rivest, A. Shamir, L. Adleman. . Communications of the ACM, Vol. 21 (2), pp.120–126. 1978. Previously released as an MIT "Technical Memo" in April 1977. Initial publication of the ''RSA'' scheme. | |||
* {{cite book | last1 = Menezes | first1 = Alfred | last2 = van Oorschot | first2 = Paul C. | last3 = Vanstone | first3 = Scott A. | url = https://archive.org/details/handbookofapplie0000mene | title = Handbook of Applied Cryptography | publisher = CRC Press | date = October 1996 | isbn = 978-0-8493-8523-0 | url-access = registration }} | |||
* ], ], ], and ]. '']'', Second Edition. MIT Press and McGraw-Hill, 2001. ISBN 0-262-03293-7. Section 31.7: The RSA public-key cryptosystem, pp.881–887. | |||
* {{cite book | |||
|last1=Cormen |first1=Thomas H. |author-link1=Thomas H. Cormen | |||
|last2=Leiserson |first2=Charles E. |author-link2=Charles E. Leiserson | |||
|last3=Rivest |first3=Ronald L. |author-link3=Ronald L. Rivest | |||
|last4=Stein |first4=Clifford |author-link4=Clifford Stein | |||
| title = Introduction to Algorithms | |||
| edition = 2nd | |||
| publisher = MIT Press and McGraw-Hill | year = 2001 | |||
| isbn = 978-0-262-03293-3 | pages = –887|title-link=Introduction to Algorithms }} | |||
==External links== | ==External links== | ||
* The Original RSA Patent as filed with the U.S. Patent Office by Rivest; Ronald L. (Belmont, MA), Shamir; Adi (Cambridge, MA), Adleman; Leonard M. (Arlington, MA), December 14, 1977, '''{{US patent|4405829}}'''. | |||
* (] website) | |||
* | |||
** The ''] #1'' ] ''"provides recommendations for the implementation of ] based on the '''RSA''' algorithm, covering the following aspects: cryptographic ]; ] schemes; ] schemes with appendix; ] syntax for representing keys and for identifying the schemes"''. | |||
* {{YouTube|vgTtHV04xRI|Explanation of RSA using colored lamps}} | |||
* | |||
* | |||
{{Public-key cryptography}} | |||
* | |||
* | |||
{{Cryptography navbox | public-key}} | |||
] | |||
] | |||
{{DEFAULTSORT:Rsa}} | |||
] | |||
] | |||
] | |||
] | |||
] | |||
] | |||
] | |||
] | |||
] | |||
] | |||
] | |||
] | |||
] | |||
] | |||
] | |||
] | |||
] | |||
] | |||
] | |||
] | |||
] | |||
] | |||
] | |||
] | |||
] | |||
] | |||
] | |||
] | |||
] | |||
] | |||
] | |||
] |
Latest revision as of 17:22, 7 January 2025
Algorithm for public-key cryptography This article is about a cryptosystem. For the company, see RSA Security.General | |
---|---|
Designers | Ron Rivest, Adi Shamir, and Leonard Adleman |
First published | 1977 |
Certification | PKCS#1, ANSI X9.31 |
Cipher detail | |
Key sizes | variable but typically 2,048 to 4,096 bits |
Rounds | 1 |
Best public cryptanalysis | |
General number field sieve for classical computers; Shor's algorithm for quantum computers. An 829-bit key has been broken. |
RSA (Rivest–Shamir–Adleman) is a public-key cryptosystem, one of the oldest widely used for secure data transmission. The initialism "RSA" comes from the surnames of Ron Rivest, Adi Shamir and Leonard Adleman, who publicly described the algorithm in 1977. An equivalent system was developed secretly in 1973 at Government Communications Headquarters (GCHQ), the British signals intelligence agency, by the English mathematician Clifford Cocks. That system was declassified in 1997.
In a public-key cryptosystem, the encryption key is public and distinct from the decryption key, which is kept secret (private). An RSA user creates and publishes a public key based on two large prime numbers, along with an auxiliary value. The prime numbers are kept secret. Messages can be encrypted by anyone, via the public key, but can only be decrypted by someone who knows the private key.
The security of RSA relies on the practical difficulty of factoring the product of two large prime numbers, the "factoring problem". Breaking RSA encryption is known as the RSA problem. Whether it is as difficult as the factoring problem is an open question. There are no published methods to defeat the system if a large enough key is used.
RSA is a relatively slow algorithm. Because of this, it is not commonly used to directly encrypt user data. More often, RSA is used to transmit shared keys for symmetric-key cryptography, which are then used for bulk encryption–decryption.
History
The idea of an asymmetric public-private key cryptosystem is attributed to Whitfield Diffie and Martin Hellman, who published this concept in 1976. They also introduced digital signatures and attempted to apply number theory. Their formulation used a shared-secret-key created from exponentiation of some number, modulo a prime number. However, they left open the problem of realizing a one-way function, possibly because the difficulty of factoring was not well-studied at the time. Moreover, like Diffie-Hellman, RSA is based on modular exponentiation.
Ron Rivest, Adi Shamir, and Leonard Adleman at the Massachusetts Institute of Technology made several attempts over the course of a year to create a function that was hard to invert. Rivest and Shamir, as computer scientists, proposed many potential functions, while Adleman, as a mathematician, was responsible for finding their weaknesses. They tried many approaches, including "knapsack-based" and "permutation polynomials". For a time, they thought what they wanted to achieve was impossible due to contradictory requirements. In April 1977, they spent Passover at the house of a student and drank a good deal of wine before returning to their homes at around midnight. Rivest, unable to sleep, lay on the couch with a math textbook and started thinking about their one-way function. He spent the rest of the night formalizing his idea, and he had much of the paper ready by daybreak. The algorithm is now known as RSA – the initials of their surnames in same order as their paper.
Clifford Cocks, an English mathematician working for the British intelligence agency Government Communications Headquarters (GCHQ), described a similar system in an internal document in 1973. However, given the relatively expensive computers needed to implement it at the time, it was considered to be mostly a curiosity and, as far as is publicly known, was never deployed. His ideas and concepts were not revealed until 1997 due to its top-secret classification.
Kid-RSA (KRSA) is a simplified, insecure public-key cipher published in 1997, designed for educational purposes. Some people feel that learning Kid-RSA gives insight into RSA and other public-key ciphers, analogous to simplified DES.
Patent
A patent describing the RSA algorithm was granted to MIT on 20 September 1983: U.S. patent 4,405,829 "Cryptographic communications system and method". From DWPI's abstract of the patent:
The system includes a communications channel coupled to at least one terminal having an encoding device and to at least one terminal having a decoding device. A message-to-be-transferred is enciphered to ciphertext at the encoding terminal by encoding the message as a number M in a predetermined set. That number is then raised to a first predetermined power (associated with the intended receiver) and finally computed. The remainder or residue, C, is... computed when the exponentiated number is divided by the product of two predetermined prime numbers (associated with the intended receiver).
A detailed description of the algorithm was published in August 1977, in Scientific American's Mathematical Games column. This preceded the patent's filing date of December 1977. Consequently, the patent had no legal standing outside the United States. Had Cocks' work been publicly known, a patent in the United States would not have been legal either.
When the patent was issued, terms of patent were 17 years. The patent was about to expire on 21 September 2000, but RSA Security released the algorithm to the public domain on 6 September 2000.
Operation
The RSA algorithm involves four steps: key generation, key distribution, encryption, and decryption.
A basic principle behind RSA is the observation that it is practical to find three very large positive integers e, d, and n, such that for all integers m (0 ≤ m < n), both and have the same remainder when divided by (they are congruent modulo ):However, when given only e and n, it is extremely difficult to find d.
The integers n and e comprise the public key, d represents the private key, and m represents the message. The modular exponentiation to e and d corresponds to encryption and decryption, respectively.
In addition, because the two exponents can be swapped, the private and public key can also be swapped, allowing for message signing and verification using the same algorithm.
Key generation
The keys for the RSA algorithm are generated in the following way:
- Choose two large prime numbers p and q.
- To make factoring harder, p and q should be chosen at random, be both large and have a large difference. For choosing them the standard method is to choose random integers and use a primality test until two primes are found.
- p and q are kept secret.
- Compute n = pq.
- n is used as the modulus for both the public and private keys. Its length, usually expressed in bits, is the key length.
- n is released as part of the public key.
- Compute λ(n), where λ is Carmichael's totient function. Since n = pq, λ(n) = lcm(λ(p), λ(q)), and since p and q are prime, λ(p) = φ(p) = p − 1, and likewise λ(q) = q − 1. Hence λ(n) = lcm(p − 1, q − 1).
- The lcm may be calculated through the Euclidean algorithm, since lcm(a, b) = |ab|/gcd(a, b).
- λ(n) is kept secret.
- Choose an integer e such that 1 < e < λ(n) and gcd(e, λ(n)) = 1; that is, e and λ(n) are coprime.
- e having a short bit-length and small Hamming weight results in more efficient encryption – the most commonly chosen value for e is 2 + 1 = 65537. The smallest (and fastest) possible value for e is 3, but such a small value for e has been shown to be less secure in some settings.
- e is released as part of the public key.
- Determine d as d ≡ e (mod λ(n)); that is, d is the modular multiplicative inverse of e modulo λ(n).
- This means: solve for d the equation de ≡ 1 (mod λ(n)); d can be computed efficiently by using the extended Euclidean algorithm, since, thanks to e and λ(n) being coprime, said equation is a form of Bézout's identity, where d is one of the coefficients.
- d is kept secret as the private key exponent.
The public key consists of the modulus n and the public (or encryption) exponent e. The private key consists of the private (or decryption) exponent d, which must be kept secret. p, q, and λ(n) must also be kept secret because they can be used to calculate d. In fact, they can all be discarded after d has been computed.
In the original RSA paper, the Euler totient function φ(n) = (p − 1)(q − 1) is used instead of λ(n) for calculating the private exponent d. Since φ(n) is always divisible by λ(n), the algorithm works as well. The possibility of using Euler totient function results also from Lagrange's theorem applied to the multiplicative group of integers modulo pq. Thus any d satisfying d⋅e ≡ 1 (mod φ(n)) also satisfies d⋅e ≡ 1 (mod λ(n)). However, computing d modulo φ(n) will sometimes yield a result that is larger than necessary (i.e. d > λ(n)). Most of the implementations of RSA will accept exponents generated using either method (if they use the private exponent d at all, rather than using the optimized decryption method based on the Chinese remainder theorem described below), but some standards such as FIPS 186-4 (Section B.3.1) may require that d < λ(n). Any "oversized" private exponents not meeting this criterion may always be reduced modulo λ(n) to obtain a smaller equivalent exponent.
Since any common factors of (p − 1) and (q − 1) are present in the factorisation of n − 1 = pq − 1 = (p − 1)(q − 1) + (p − 1) + (q − 1), it is recommended that (p − 1) and (q − 1) have only very small common factors, if any, besides the necessary 2.
Note: The authors of the original RSA paper carry out the key generation by choosing d and then computing e as the modular multiplicative inverse of d modulo φ(n), whereas most current implementations of RSA, such as those following PKCS#1, do the reverse (choose e and compute d). Since the chosen key can be small, whereas the computed key normally is not, the RSA paper's algorithm optimizes decryption compared to encryption, while the modern algorithm optimizes encryption instead.
Key distribution
Suppose that Bob wants to send information to Alice. If they decide to use RSA, Bob must know Alice's public key to encrypt the message, and Alice must use her private key to decrypt the message.
To enable Bob to send his encrypted messages, Alice transmits her public key (n, e) to Bob via a reliable, but not necessarily secret, route. Alice's private key (d) is never distributed.
Encryption
After Bob obtains Alice's public key, he can send a message M to Alice.
To do it, he first turns M (strictly speaking, the un-padded plaintext) into an integer m (strictly speaking, the padded plaintext), such that 0 ≤ m < n by using an agreed-upon reversible protocol known as a padding scheme. He then computes the ciphertext c, using Alice's public key e, corresponding to
This can be done reasonably quickly, even for very large numbers, using modular exponentiation. Bob then transmits c to Alice. Note that at least nine values of m will yield a ciphertext c equal to m, but this is very unlikely to occur in practice.
Decryption
Alice can recover m from c by using her private key exponent d by computing
Given m, she can recover the original message M by reversing the padding scheme.
Example
Here is an example of RSA encryption and decryption:
- Choose two distinct prime numbers, such as
- and .
- Compute n = pq giving
- Compute the Carmichael's totient function of the product as λ(n) = lcm(p − 1, q − 1) giving
- Choose any number 2 < e < 780 that is coprime to 780. Choosing a prime number for e leaves us only to check that e is not a divisor of 780.
- Let .
- Compute d, the modular multiplicative inverse of e (mod λ(n)), yielding
as
The public key is (n = 3233, e = 17). For a padded plaintext message m, the encryption function is
The private key is (n = 3233, d = 413). For an encrypted ciphertext c, the decryption function is
For instance, in order to encrypt m = 65, one calculates
To decrypt c = 2790, one calculates
Both of these calculations can be computed efficiently using the square-and-multiply algorithm for modular exponentiation. In real-life situations the primes selected would be much larger; in our example it would be trivial to factor n = 3233 (obtained from the freely available public key) back to the primes p and q. e, also from the public key, is then inverted to get d, thus acquiring the private key.
Practical implementations use the Chinese remainder theorem to speed up the calculation using modulus of factors (mod pq using mod p and mod q).
The values dp, dq and qinv, which are part of the private key are computed as follows:
Here is how dp, dq and qinv are used for efficient decryption (encryption is efficient by choice of a suitable d and e pair):
Signing messages
Suppose Alice uses Bob's public key to send him an encrypted message. In the message, she can claim to be Alice, but Bob has no way of verifying that the message was from Alice, since anyone can use Bob's public key to send him encrypted messages. In order to verify the origin of a message, RSA can also be used to sign a message.
Suppose Alice wishes to send a signed message to Bob. She can use her own private key to do so. She produces a hash value of the message, raises it to the power of d (modulo n) (as she does when decrypting a message), and attaches it as a "signature" to the message. When Bob receives the signed message, he uses the same hash algorithm in conjunction with Alice's public key. He raises the signature to the power of e (modulo n) (as he does when encrypting a message), and compares the resulting hash value with the message's hash value. If the two agree, he knows that the author of the message was in possession of Alice's private key and that the message has not been tampered with since being sent.
This works because of exponentiation rules:
Thus the keys may be swapped without loss of generality, that is, a private key of a key pair may be used either to:
- Decrypt a message only intended for the recipient, which may be encrypted by anyone having the public key (asymmetric encrypted transport).
- Encrypt a message which may be decrypted by anyone, but which can only be encrypted by one person; this provides a digital signature.
Proofs of correctness
Proof using Fermat's little theorem
The proof of the correctness of RSA is based on Fermat's little theorem, stating that a ≡ 1 (mod p) for any integer a and prime p, not dividing a.
We want to show that for every integer m when p and q are distinct prime numbers and e and d are positive integers satisfying ed ≡ 1 (mod λ(pq)).
Since λ(pq) = lcm(p − 1, q − 1) is, by construction, divisible by both p − 1 and q − 1, we can write for some nonnegative integers h and k.
To check whether two numbers, such as m and m, are congruent mod pq, it suffices (and in fact is equivalent) to check that they are congruent mod p and mod q separately.
To show m ≡ m (mod p), we consider two cases:
- If m ≡ 0 (mod p), m is a multiple of p. Thus m is a multiple of p. So m ≡ 0 ≡ m (mod p).
- If m 0 (mod p),
- where we used Fermat's little theorem to replace m mod p with 1.
The verification that m ≡ m (mod q) proceeds in a completely analogous way:
- If m ≡ 0 (mod q), m is a multiple of q. So m ≡ 0 ≡ m (mod q).
- If m 0 (mod q),
This completes the proof that, for any integer m, and integers e, d such that ed ≡ 1 (mod λ(pq)),
Notes
- We cannot trivially break RSA by applying the theorem (mod pq) because pq is not prime.
- In particular, the statement above holds for any e and d that satisfy ed ≡ 1 (mod (p − 1)(q − 1)), since (p − 1)(q − 1) is divisible by λ(pq), and thus trivially also by p − 1 and q − 1. However, in modern implementations of RSA, it is common to use a reduced private exponent d that only satisfies the weaker, but sufficient condition ed ≡ 1 (mod λ(pq)).
- This is part of the Chinese remainder theorem, although it is not the significant part of that theorem.
Proof using Euler's theorem
Although the original paper of Rivest, Shamir, and Adleman used Fermat's little theorem to explain why RSA works, it is common to find proofs that rely instead on Euler's theorem.
We want to show that m ≡ m (mod n), where n = pq is a product of two different prime numbers, and e and d are positive integers satisfying ed ≡ 1 (mod φ(n)). Since e and d are positive, we can write ed = 1 + hφ(n) for some non-negative integer h. Assuming that m is relatively prime to n, we have
where the second-last congruence follows from Euler's theorem.
More generally, for any e and d satisfying ed ≡ 1 (mod λ(n)), the same conclusion follows from Carmichael's generalization of Euler's theorem, which states that m ≡ 1 (mod n) for all m relatively prime to n.
When m is not relatively prime to n, the argument just given is invalid. This is highly improbable (only a proportion of 1/p + 1/q − 1/(pq) numbers have this property), but even in this case, the desired congruence is still true. Either m ≡ 0 (mod p) or m ≡ 0 (mod q), and these cases can be treated using the previous proof.
Padding
Attacks against plain RSA
There are a number of attacks against plain RSA as described below.
- When encrypting with low encryption exponents (e.g., e = 3) and small values of the m (i.e., m < n), the result of m is strictly less than the modulus n. In this case, ciphertexts can be decrypted easily by taking the eth root of the ciphertext over the integers.
- If the same clear-text message is sent to e or more recipients in an encrypted way, and the receivers share the same exponent e, but different p, q, and therefore n, then it is easy to decrypt the original clear-text message via the Chinese remainder theorem. Johan Håstad noticed that this attack is possible even if the clear texts are not equal, but the attacker knows a linear relation between them. This attack was later improved by Don Coppersmith (see Coppersmith's attack).
- Because RSA encryption is a deterministic encryption algorithm (i.e., has no random component) an attacker can successfully launch a chosen plaintext attack against the cryptosystem, by encrypting likely plaintexts under the public key and test whether they are equal to the ciphertext. A cryptosystem is called semantically secure if an attacker cannot distinguish two encryptions from each other, even if the attacker knows (or has chosen) the corresponding plaintexts. RSA without padding is not semantically secure.
- RSA has the property that the product of two ciphertexts is equal to the encryption of the product of the respective plaintexts. That is, m1m2 ≡ (m1m2) (mod n). Because of this multiplicative property, a chosen-ciphertext attack is possible. E.g., an attacker who wants to know the decryption of a ciphertext c ≡ m (mod n) may ask the holder of the private key d to decrypt an unsuspicious-looking ciphertext c′ ≡ cr (mod n) for some value r chosen by the attacker. Because of the multiplicative property, c' is the encryption of mr (mod n). Hence, if the attacker is successful with the attack, they will learn mr (mod n), from which they can derive the message m by multiplying mr with the modular inverse of r modulo n.
- Given the private exponent d, one can efficiently factor the modulus n = pq. And given factorization of the modulus n = pq, one can obtain any private key (d', n) generated against a public key (e', n).
Padding schemes
To avoid these problems, practical RSA implementations typically embed some form of structured, randomized padding into the value m before encrypting it. This padding ensures that m does not fall into the range of insecure plaintexts, and that a given message, once padded, will encrypt to one of a large number of different possible ciphertexts.
Standards such as PKCS#1 have been carefully designed to securely pad messages prior to RSA encryption. Because these schemes pad the plaintext m with some number of additional bits, the size of the un-padded message M must be somewhat smaller. RSA padding schemes must be carefully designed so as to prevent sophisticated attacks that may be facilitated by a predictable message structure. Early versions of the PKCS#1 standard (up to version 1.5) used a construction that appears to make RSA semantically secure. However, at Crypto 1998, Bleichenbacher showed that this version is vulnerable to a practical adaptive chosen-ciphertext attack. Furthermore, at Eurocrypt 2000, Coron et al. showed that for some types of messages, this padding does not provide a high enough level of security. Later versions of the standard include Optimal Asymmetric Encryption Padding (OAEP), which prevents these attacks. As such, OAEP should be used in any new application, and PKCS#1 v1.5 padding should be replaced wherever possible. The PKCS#1 standard also incorporates processing schemes designed to provide additional security for RSA signatures, e.g. the Probabilistic Signature Scheme for RSA (RSA-PSS).
Secure padding schemes such as RSA-PSS are as essential for the security of message signing as they are for message encryption. Two USA patents on PSS were granted (U.S. patent 6,266,771 and U.S. patent 7,036,014); however, these patents expired on 24 July 2009 and 25 April 2010 respectively. Use of PSS no longer seems to be encumbered by patents. Note that using different RSA key pairs for encryption and signing is potentially more secure.
Security and practical considerations
Using the Chinese remainder algorithm
For efficiency, many popular crypto libraries (such as OpenSSL, Java and .NET) use for decryption and signing the following optimization based on the Chinese remainder theorem. The following values are precomputed and stored as part of the private key:
- and – the primes from the key generation,
These values allow the recipient to compute the exponentiation m = c (mod pq) more efficiently as follows:
,
,
,
.
This is more efficient than computing exponentiation by squaring, even though two modular exponentiations have to be computed. The reason is that these two modular exponentiations both use a smaller exponent and a smaller modulus.
Integer factorization and the RSA problem
See also: RSA Factoring Challenge, Integer factorization records, and Shor's algorithmThe security of the RSA cryptosystem is based on two mathematical problems: the problem of factoring large numbers and the RSA problem. Full decryption of an RSA ciphertext is thought to be infeasible on the assumption that both of these problems are hard, i.e., no efficient algorithm exists for solving them. Providing security against partial decryption may require the addition of a secure padding scheme.
The RSA problem is defined as the task of taking eth roots modulo a composite n: recovering a value m such that c ≡ m (mod n), where (n, e) is an RSA public key, and c is an RSA ciphertext. Currently the most promising approach to solving the RSA problem is to factor the modulus n. With the ability to recover prime factors, an attacker can compute the secret exponent d from a public key (n, e), then decrypt c using the standard procedure. To accomplish this, an attacker factors n into p and q, and computes lcm(p − 1, q − 1) that allows the determination of d from e. No polynomial-time method for factoring large integers on a classical computer has yet been found, but it has not been proven that none exists; see integer factorization for a discussion of this problem.
Multiple polynomial quadratic sieve (MPQS) can be used to factor the public modulus n.
The first RSA-512 factorization in 1999 used hundreds of computers and required the equivalent of 8,400 MIPS years, over an elapsed time of about seven months. By 2009, Benjamin Moody could factor an 512-bit RSA key in 73 days using only public software (GGNFS) and his desktop computer (a dual-core Athlon64 with a 1,900 MHz CPU). Just less than 5 gigabytes of disk storage was required and about 2.5 gigabytes of RAM for the sieving process.
Rivest, Shamir, and Adleman noted that Miller has shown that – assuming the truth of the extended Riemann hypothesis – finding d from n and e is as hard as factoring n into p and q (up to a polynomial time difference). However, Rivest, Shamir, and Adleman noted, in section IX/D of their paper, that they had not found a proof that inverting RSA is as hard as factoring.
As of 2020, the largest publicly known factored RSA number had 829 bits (250 decimal digits, RSA-250). Its factorization, by a state-of-the-art distributed implementation, took about 2,700 CPU-years. In practice, RSA keys are typically 1024 to 4096 bits long. In 2003, RSA Security estimated that 1024-bit keys were likely to become crackable by 2010. As of 2020, it is not known whether such keys can be cracked, but minimum recommendations have moved to at least 2048 bits. It is generally presumed that RSA is secure if n is sufficiently large, outside of quantum computing.
If n is 300 bits or shorter, it can be factored in a few hours on a personal computer, using software already freely available. Keys of 512 bits have been shown to be practically breakable in 1999, when RSA-155 was factored by using several hundred computers, and these are now factored in a few weeks using common hardware. Exploits using 512-bit code-signing certificates that may have been factored were reported in 2011. A theoretical hardware device named TWIRL, described by Shamir and Tromer in 2003, called into question the security of 1024-bit keys.
In 1994, Peter Shor showed that a quantum computer – if one could ever be practically created for the purpose – would be able to factor in polynomial time, breaking RSA; see Shor's algorithm.
Faulty key generation
This section needs additional citations for verification. Please help improve this article by adding citations to reliable sources in this section. Unsourced material may be challenged and removed. Find sources: "RSA" cryptosystem – news · newspapers · books · scholar · JSTOR (October 2017) (Learn how and when to remove this message) |
Finding the large primes p and q is usually done by testing random numbers of the correct size with probabilistic primality tests that quickly eliminate virtually all of the nonprimes.
The numbers p and q should not be "too close", lest the Fermat factorization for n be successful. If p − q is less than 2n (n = p⋅q, which even for "small" 1024-bit values of n is 3×10), solving for p and q is trivial. Furthermore, if either p − 1 or q − 1 has only small prime factors, n can be factored quickly by Pollard's p − 1 algorithm, and hence such values of p or q should be discarded.
It is important that the private exponent d be large enough. Michael J. Wiener showed that if p is between q and 2q (which is quite typical) and d < n/3, then d can be computed efficiently from n and e.
There is no known attack against small public exponents such as e = 3, provided that the proper padding is used. Coppersmith's attack has many applications in attacking RSA specifically if the public exponent e is small and if the encrypted message is short and not padded. 65537 is a commonly used value for e; this value can be regarded as a compromise between avoiding potential small-exponent attacks and still allowing efficient encryptions (or signature verification). The NIST Special Publication on Computer Security (SP 800-78 Rev. 1 of August 2007) does not allow public exponents e smaller than 65537, but does not state a reason for this restriction.
In October 2017, a team of researchers from Masaryk University announced the ROCA vulnerability, which affects RSA keys generated by an algorithm embodied in a library from Infineon known as RSALib. A large number of smart cards and trusted platform modules (TPM) were shown to be affected. Vulnerable RSA keys are easily identified using a test program the team released.
Importance of strong random number generation
A cryptographically strong random number generator, which has been properly seeded with adequate entropy, must be used to generate the primes p and q. An analysis comparing millions of public keys gathered from the Internet was carried out in early 2012 by Arjen K. Lenstra, James P. Hughes, Maxime Augier, Joppe W. Bos, Thorsten Kleinjung and Christophe Wachter. They were able to factor 0.2% of the keys using only Euclid's algorithm.
They exploited a weakness unique to cryptosystems based on integer factorization. If n = pq is one public key, and n′ = p′q′ is another, then if by chance p = p′ (but q is not equal to q'), then a simple computation of gcd(n, n′) = p factors both n and n', totally compromising both keys. Lenstra et al. note that this problem can be minimized by using a strong random seed of bit length twice the intended security level, or by employing a deterministic function to choose q given p, instead of choosing p and q independently.
Nadia Heninger was part of a group that did a similar experiment. They used an idea of Daniel J. Bernstein to compute the GCD of each RSA key n against the product of all the other keys n' they had found (a 729-million-digit number), instead of computing each gcd(n, n′) separately, thereby achieving a very significant speedup, since after one large division, the GCD problem is of normal size.
Heninger says in her blog that the bad keys occurred almost entirely in embedded applications, including "firewalls, routers, VPN devices, remote server administration devices, printers, projectors, and VOIP phones" from more than 30 manufacturers. Heninger explains that the one-shared-prime problem uncovered by the two groups results from situations where the pseudorandom number generator is poorly seeded initially, and then is reseeded between the generation of the first and second primes. Using seeds of sufficiently high entropy obtained from key stroke timings or electronic diode noise or atmospheric noise from a radio receiver tuned between stations should solve the problem.
Strong random number generation is important throughout every phase of public-key cryptography. For instance, if a weak generator is used for the symmetric keys that are being distributed by RSA, then an eavesdropper could bypass RSA and guess the symmetric keys directly.
Timing attacks
Kocher described a new attack on RSA in 1995: if the attacker Eve knows Alice's hardware in sufficient detail and is able to measure the decryption times for several known ciphertexts, Eve can deduce the decryption key d quickly. This attack can also be applied against the RSA signature scheme. In 2003, Boneh and Brumley demonstrated a more practical attack capable of recovering RSA factorizations over a network connection (e.g., from a Secure Sockets Layer (SSL)-enabled webserver). This attack takes advantage of information leaked by the Chinese remainder theorem optimization used by many RSA implementations.
One way to thwart these attacks is to ensure that the decryption operation takes a constant amount of time for every ciphertext. However, this approach can significantly reduce performance. Instead, most RSA implementations use an alternate technique known as cryptographic blinding. RSA blinding makes use of the multiplicative property of RSA. Instead of computing c (mod n), Alice first chooses a secret random value r and computes (rc) (mod n). The result of this computation, after applying Euler's theorem, is rc (mod n), and so the effect of r can be removed by multiplying by its inverse. A new value of r is chosen for each ciphertext. With blinding applied, the decryption time is no longer correlated to the value of the input ciphertext, and so the timing attack fails.
Adaptive chosen-ciphertext attacks
In 1998, Daniel Bleichenbacher described the first practical adaptive chosen-ciphertext attack against RSA-encrypted messages using the PKCS #1 v1 padding scheme (a padding scheme randomizes and adds structure to an RSA-encrypted message, so it is possible to determine whether a decrypted message is valid). Due to flaws with the PKCS #1 scheme, Bleichenbacher was able to mount a practical attack against RSA implementations of the Secure Sockets Layer protocol and to recover session keys. As a result of this work, cryptographers now recommend the use of provably secure padding schemes such as Optimal Asymmetric Encryption Padding, and RSA Laboratories has released new versions of PKCS #1 that are not vulnerable to these attacks.
A variant of this attack, dubbed "BERserk", came back in 2014. It impacted the Mozilla NSS Crypto Library, which was used notably by Firefox and Chrome.
Side-channel analysis attacks
A side-channel attack using branch-prediction analysis (BPA) has been described. Many processors use a branch predictor to determine whether a conditional branch in the instruction flow of a program is likely to be taken or not. Often these processors also implement simultaneous multithreading (SMT). Branch-prediction analysis attacks use a spy process to discover (statistically) the private key when processed with these processors.
Simple Branch Prediction Analysis (SBPA) claims to improve BPA in a non-statistical way. In their paper, "On the Power of Simple Branch Prediction Analysis", the authors of SBPA (Onur Aciicmez and Cetin Kaya Koc) claim to have discovered 508 out of 512 bits of an RSA key in 10 iterations.
A power-fault attack on RSA implementations was described in 2010. The author recovered the key by varying the CPU power voltage outside limits; this caused multiple power faults on the server.
Tricky implementation
There are many details to keep in mind in order to implement RSA securely (strong PRNG, acceptable public exponent, etc.). This makes the implementation challenging, to the point the book Practical Cryptography With Go suggests avoiding RSA if possible.
Implementations
Some cryptography libraries that provide support for RSA include:
See also
- Acoustic cryptanalysis
- Computational complexity theory
- Diffie–Hellman key exchange
- Digital Signature Algorithm
- Elliptic-curve cryptography
- Key exchange
- Key management
- Key size
- Public-key cryptography
- Rabin cryptosystem
- Trapdoor function
Notes
- Namely, the values of m which are equal to −1, 0, or 1 modulo p while also equal to −1, 0, or 1 modulo q. There will be more values of m having c = m if p − 1 or q − 1 has other divisors in common with e − 1 besides 2 because this gives more values of m such that or respectively.
- The parameters used here are artificially small, but one can also OpenSSL can also be used to generate and examine a real keypair.
- If , then some libraries compute h as .
References
- ^ Rivest, R.; Shamir, A.; Adleman, L. (February 1978). "A Method for Obtaining Digital Signatures and Public-Key Cryptosystems" (PDF). Communications of the ACM. 21 (2): 120–126. CiteSeerX 10.1.1.607.2677. doi:10.1145/359340.359342. S2CID 2873616. Archived from the original (PDF) on 2023-01-27.
- Smart, Nigel (February 19, 2008). "Dr Clifford Cocks CB". Bristol University. Retrieved August 14, 2011.
- Castelvecchi, Davide (2020-10-30). "Quantum-computing pioneer warns of complacency over Internet security". Nature. 587 (7833): 189. Bibcode:2020Natur.587..189C. doi:10.1038/d41586-020-03068-9. PMID 33139910. S2CID 226243008. 2020 interview of Peter Shor.
- Diffie, W.; Hellman, M. E. (November 1976). "New directions in cryptography". IEEE Transactions on Information Theory. 22 (6): 644–654. CiteSeerX 10.1.1.37.9720. doi:10.1109/TIT.1976.1055638. ISSN 0018-9448.
- Rivest, Ronald. "The Early Days of RSA – History and Lessons" (PDF).
- Calderbank, Michael (2007-08-20). "The RSA Cryptosystem: History, Algorithm, Primes" (PDF).
- ^ Robinson, Sara (June 2003). "Still Guarding Secrets after Years of Attacks, RSA Earns Accolades for its Founders" (PDF). SIAM News. 36 (5).
- Cocks, C. C. (20 November 1973). "A Note on Non-Secret Encryption" (PDF). www.gchq.gov.uk. Archived from the original (PDF) on 28 September 2018. Retrieved 2017-05-30.
- Jim Sauerberg. "From Private to Public Key Ciphers in Three Easy Steps".
- Margaret Cozzens and Steven J. Miller. "The Mathematics of Encryption: An Elementary Introduction". p. 180.
- Alasdair McAndrew. "Introduction to Cryptography with Open-Source Software". p. 12.
- Surender R. Chiluka. "Public key Cryptography".
- Neal Koblitz. "Cryptography As a Teaching Tool". Cryptologia, Vol. 21, No. 4 (1997).
- "RSA Security Releases RSA Encryption Algorithm into Public Domain". Archived from the original on June 21, 2007. Retrieved 2010-03-03.
- ^ Boneh, Dan (1999). "Twenty Years of attacks on the RSA Cryptosystem". Notices of the American Mathematical Society. 46 (2): 203–213.
- Applied Cryptography, John Wiley & Sons, New York, 1996. Bruce Schneier, p. 467.
- McKee, James; Pinch, Richard (1998). "Further Attacks on Server-Aided RSA Cryptosystems". CiteSeerX 10.1.1.33.1333.
- A Course in Number Theory and Cryptography, Graduate Texts in Math. No. 114, Springer-Verlag, New York, 1987. Neal Koblitz, Second edition, 1994. p. 94.
- Dukhovni, Viktor (July 31, 2015). "common factors in (p − 1) and (q − 1)". openssl-dev (Mailing list).
- Dukhovni, Viktor (August 1, 2015). "common factors in (p − 1) and (q − 1)". openssl-dev (Mailing list).
- Johnson, J.; Kaliski, B. (February 2003). Public-Key Cryptography Standards (PKCS) #1: RSA Cryptography Specifications Version 2.1. Network Working Group. doi:10.17487/RFC3447. RFC 3447. Retrieved 9 March 2016.
- Håstad, Johan (1986). "On using RSA with Low Exponent in a Public Key Network". Advances in Cryptology – CRYPTO '85 Proceedings. Lecture Notes in Computer Science. Vol. 218. pp. 403–408. doi:10.1007/3-540-39799-X_29. ISBN 978-3-540-16463-0.
- Coppersmith, Don (1997). "Small Solutions to Polynomial Equations, and Low Exponent RSA Vulnerabilities" (PDF). Journal of Cryptology. 10 (4): 233–260. CiteSeerX 10.1.1.298.4806. doi:10.1007/s001459900030. S2CID 15726802.
- Goldwasser, Shafi; Micali, Silvio (1982-05-05). "Probabilistic encryption & how to play mental poker keeping secret all partial information". Proceedings of the fourteenth annual ACM symposium on Theory of computing - STOC '82. New York, NY, USA: Association for Computing Machinery. pp. 365–377. doi:10.1145/800070.802212. ISBN 978-0-89791-070-5. S2CID 10316867.
- Coron, Jean-Sébastien; Joye, Marc; Naccache, David; Paillier, Pascal (2000). "New Attacks on PKCS#1 v1.5 Encryption". In Preneel, Bart (ed.). Advances in Cryptology — EUROCRYPT 2000. Lecture Notes in Computer Science. Vol. 1807. Berlin, Heidelberg: Springer. pp. 369–381. doi:10.1007/3-540-45539-6_25. ISBN 978-3-540-45539-4.
- "RSA Algorithm".
- "OpenSSL bn_s390x.c". Github. Retrieved 2 August 2024.
- Machie, Edmond K. (29 March 2013). Network security traceback attack and react in the United States Department of Defense network. Trafford. p. 167. ISBN 978-1466985742.
- Lenstra, Arjen; et al. (Group) (2000). "Factorization of a 512-bit RSA Modulus" (PDF). Eurocrypt.
- Miller, Gary L. (1975). "Riemann's Hypothesis and Tests for Primality" (PDF). Proceedings of Seventh Annual ACM Symposium on Theory of Computing. pp. 234–239.
- Zimmermann, Paul (2020-02-28). "Factorization of RSA-250". Cado-nfs-discuss. Archived from the original on 2020-02-28. Retrieved 2020-07-12.
- ^ Kaliski, Burt (2003-05-06). "TWIRL and RSA Key Size". RSA Laboratories. Archived from the original on 2017-04-17. Retrieved 2017-11-24.
- Barker, Elaine; Dang, Quynh (2015-01-22). "NIST Special Publication 800-57 Part 3 Revision 1: Recommendation for Key Management: Application-Specific Key Management Guidance" (PDF). National Institute of Standards and Technology. p. 12. doi:10.6028/NIST.SP.800-57pt3r1. Retrieved 2017-11-24.
- Sandee, Michael (November 21, 2011). "RSA-512 certificates abused in-the-wild". Fox-IT International blog.
- Wiener, Michael J. (May 1990). "Cryptanalysis of short RSA secret exponents" (PDF). IEEE Transactions on Information Theory. 36 (3): 553–558. doi:10.1109/18.54902. S2CID 7120331.
- Nemec, Matus; Sys, Marek; Svenda, Petr; Klinec, Dusan; Matyas, Vashek (November 2017). "The Return of Coppersmith's Attack: Practical Factorization of Widely Used RSA Moduli" (PDF). Proceedings of the 2017 ACM SIGSAC Conference on Computer and Communications Security. CCS '17. doi:10.1145/3133956.3133969.
- Markoff, John (February 14, 2012). "Flaw Found in an Online Encryption Method". The New York Times.
- Lenstra, Arjen K.; Hughes, James P.; Augier, Maxime; Bos, Joppe W.; Kleinjung, Thorsten; Wachter, Christophe (2012). "Ron was wrong, Whit is right" (PDF).
- Heninger, Nadia (February 15, 2012). "New research: There's no need to panic over factorable keys–just mind your Ps and Qs". Freedom to Tinker.
- Brumley, David; Boneh, Dan (2003). "Remote timing attacks are practical" (PDF). Proceedings of the 12th Conference on USENIX Security Symposium. SSYM'03.
- "'BERserk' Bug Uncovered In Mozilla NSS Crypto Library Impacts Firefox, Chrome". 25 September 2014. Retrieved 4 January 2022.
- "RSA Signature Forgery in NSS". Mozilla.
- Acıiçmez, Onur; Koç, Çetin Kaya; Seifert, Jean-Pierre (2007). "On the power of simple branch prediction analysis". Proceedings of the 2nd ACM Symposium on Information, Computer and Communications Security. ASIACCS '07. pp. 312–320. CiteSeerX 10.1.1.80.1438. doi:10.1145/1229285.1266999.
- Pellegrini, Andrea; Bertacco, Valeria; Austin, Todd (March 2010). "Fault-based attack of RSA authentication". 2010 Design, Automation & Test in Europe Conference & Exhibition (DATE 2010). pp. 855–860. doi:10.1109/DATE.2010.5456933. ISBN 978-3-9810801-6-2. Retrieved 21 November 2024.
- Isom, Kyle. "Practical Cryptography With Go". Retrieved 4 January 2022.
Further reading
- Menezes, Alfred; van Oorschot, Paul C.; Vanstone, Scott A. (October 1996). Handbook of Applied Cryptography. CRC Press. ISBN 978-0-8493-8523-0.
- Cormen, Thomas H.; Leiserson, Charles E.; Rivest, Ronald L.; Stein, Clifford (2001). Introduction to Algorithms (2nd ed.). MIT Press and McGraw-Hill. pp. 881–887. ISBN 978-0-262-03293-3.
External links
- The Original RSA Patent as filed with the U.S. Patent Office by Rivest; Ronald L. (Belmont, MA), Shamir; Adi (Cambridge, MA), Adleman; Leonard M. (Arlington, MA), December 14, 1977, U.S. patent 4,405,829.
- RFC 8017: PKCS #1: RSA Cryptography Specifications Version 2.2
- Explanation of RSA using colored lamps on YouTube
- Thorough walk through of RSA
- Prime Number Hide-And-Seek: How the RSA Cipher Works
- Onur Aciicmez, Cetin Kaya Koc, Jean-Pierre Seifert: On the Power of Simple Branch Prediction Analysis