Number Theory and RSA Attacks: A Brief Overview of Attack On RSA
Number Theory and RSA Attacks: A Brief Overview of Attack On RSA
RSA attacks
A brief overview of attack on RSA
Modular Arithmetic
• Modular arithmetic or Clock arithmetic is a circular system that
increases until a specific point called modulus then rest to zero again.
• Definition
• Let be a set of all non-negative integers that are smaller than :
• Congruence modulo:
To explain it in a simple way lets see
the representation for all integers
, all integers in slice
gives a remainder ,
we can say that those integers are
in the same equivalence class,
which can be represented as
.
Congruence modulo and
Equivalence relations
• If we looked at the previous chart, we could notice that the difference
between any two integers in the same slice can be represented as
multiple of 5.
• We can write the congruence mod as any of the following:
• for integer
Congruence modulo and
Equivalence relations
• The figure have the following
properties:
• Every pair in the same slice
are related
• We can never find the same
integer in 2 slides
• If we collected all the slices,
we will get all the numbers.
• Which means that the congruence
modulo is equivalence relation.
Congruence modulo and
Equivalence relations
• Why do we even care whether it’s an equivalence relation or not?
It’s simple, so we can apply the equivalence relation properties:
• (reflexive)
• (symmetric)
• then (transitive)
Operations on Modular Arithmetic
• Addition:
• Subtraction:
• Multiplication:
• Exponentiation:
Modular Inverses
• In basic arithmetic we know that the inverse of a number since
• But in Modular arithmetic we don’t have a division operation, so the
inverse would be :
• which is means
• is coprime to
Modular Inverses
• Calculating mod inverse:
the native method is brute forcing all the number from 0 to until we
find a number that makes
3 56 1 168
1 40 3 120
6 35 3 630
• Now our final is the sum of the last column
Fermat’s Little Theorem
• Fermat’s Little Theorem states that if is a prime number and doesn’t
divide then .
Choosing and
• There is some constrains on to which are:
• Encryption:
• Decryption:
Attacks on RSA
• Now let’s start to interduce how can attacker know our secrets, note
that we are not showing that the RSA is breakable, we will show that
bad choosing of numbers can lead to recover the private key.
• Factorizing :
• Choosing needs to be very careful, there is a lot of services online that works
on factorize a huge collection of numbers like factordb, as shown in the
previous example we could find just by getting the prime factorization of
• So,
RSA Security
• We still have many other factorizations methods like Quadratic sieve,
ECM but does that mean that the RSA is not secure?
• The answer is until now no, the strength point in RSA that it’s depends
on ignorance than knowledge, we don’t have an efficient way to
calculate how hard is to factor a huge number, we just know it’s hard,
and a small mitigation for the previous factorization methods is
adding more digits to our which will make it harder to factorize.
• But there are some attacks on RSA based on bad key generation for
our variables or even our encryption methodology.
Bad Key generation Attacks
• Some of the attacks can be applied on RSA are:
• Common Modulus
• Blinding
• Small Private Exponent: wiener
• Small Public Exponent: Coppersmith, Hastad
• Time Attack
• We will try to explain some of them by examples in order to make it
clearer.
Example1
• Question from PICOCTF 2018:
• N:
374159235470172130988938196520880526947952521620932362050308663243595788308583
992120881359365258949723819911758198013202644666489247987314025169670926273213
367237020188587742716017314320191350666762541039238241984934473188656610615918
474673963331992408750047451253205158436452814354564283003696666945950908549197
175404580533132142111356931324330631843602412540295482841975783884766801266552
337129105407869020730226041538750535628619717708838029286366761470986056335230
171148734027536820544543251801093230809186222940806718221638845816521738601843
083746103374974120575519418797642878012234163709518203946599836959811
• e: 3, c:
220531641393113403104644076762054198480109121635122278918058256455732876245542
272136802953136007672997221141223607292157731726471542495082309138220343548946
052209468914959595101034266236834798786287833885103889208279938902390041535116
4773
Example1
• As you can see the is huge number, factorizing it won’t be an easy
thing at all, but we notice that is so small, small such that , so
• So, to get we can just take the cubic root for , computer can do this
easily.
• So,
• Decoding the long to string using the ASCII table will result this
message:
• picoCTF{e_w4y_t00_sm411_81b6559f} , which is our solution.
Example2
• PICO CTF 2018:
• We are given the following inputs:
• c:
17786730185110751403506982528916395579064070902505390572218063407687767057631138153732717135982067349433
04136885307657644746166557801527614555955063613958550715606102502660768573300084767410478866161295739179
626743292839204862654148472896949835346074323716667404949929701903737872090588147698250826373180618
• n:
77531969503748326589677418948315140870584015245386763633241518845356850979564402923266696704186567270006
36120886208625452757601041213523027955368494063595665664972813489387456761994867530405248272043036774861
2708917105846534082863042823913166120865362252479206576942147071396319459112580853771742537940112457
• e:
56172436577459725698934391359139104915041430213184221292301658571726414059411889155782982024019814564512
29142193248973156351929637287341508054637942461930885915236021420974016913515976123489492314497137297403
8021945201954600238994209605035703317119192844975463915465725406543097929017637859019950590916533609
• As you can see everything is huge, and after tries to factorize it didn’t work, in this case we can consider checking another attack
called wiener attack
Wiener’s Attack
• Michael J. Wiener was able to state a theorem based on continuous
fractions that says if then we can recover without factoring .
• Explaining:
• we already mentioned before that , and since , and since are so large we can
take a good approximation that .
• Now substituting this into our first equation:
Wiener’s Attack
• So, let’s set our steps:
• We need to find a set of convergent that approximate (using continued
fractions and we will demonstrate it), under some conditions:
• Since and is product of 2 primes so it will be even number, will be odd, so we can skip
the convergent if our is not odd.
• Since must be a whole number, also must be a whole number, and if it’s not so we will
move to the next convergent.
• Now let be a quadratic equation then:
• If we got the right value for then the roots of the equation will be our factors
for .
Wiener’s Attack
• Short Example:
• Solution:
• now using the Euclidean algorithm to find the convergent in the continued
fraction
• (ignore)
• (ignore)
• (d is even, ignore)
• (passed first check)
Wiener’s Attack
• Now since
• We can set our quadratic equation as:
• Solving it will give us which are whole numbers, so we got the right
value of which is 3.
Example2
• Now applying this to the example will be hard to do manually so with
a use of simple script and run it on a computer we get the following
message: picoCTF{w@tch_y0ur_Xp0n3nt$_c@r3fu11y_5495627}
Example3
• Qiwi CTF 2016:
• We are given the following data:
• e=3
• n1 =
951183579890375398832721687460046528729588905624458143018898666630723524217032649859978006600753116455557997454268683433653215027347360062480079
024096285405786359255597422174807974871302027470202114526207430210975651130593925044727852271548241172310778444446723932218381929413903093124840
66647007469668558141
• n2 =
983641659192512462438466673235423180228042348336779241611757332536895813936073466678952982537181842735322689820609056293996281549819187120702414
514944911614708277371461763160118437389434271216023242087736531807827329994228694395881983184224516979206405638807773855770649139832020337442817
27004289781821019463
• n3 =
688279409393531896130903922268981550217427728978224384835450219442158121468093186865103757240648887052963738533989550930766633230013800478578097
748663900834342727813624471474414222079675773237698128960388165867572421302245248289350431873155795234124393091388163355698454700217208474058573
61000537204746060031
• c1 =
648304467081690127664145873275688124211304348175260891461901367964612985920712389303847075433183902924511189803028055121517902489896222693629587
182282984272126302725251864786272999998474890184006244006718766977089524476389908023455873819054072369354942714369607648990064309415076081523225
88169896193268212007
• c2 =
969074907173443465884324916037223126942086603342829642344876876545939847141448256561981807778723272792506679614651697992674057344316751110353620
897292499950273268630992625224212064594004052303776311411328829973368292188101717289250875356749074555845579568018314471254867535158680793421488
15961792481779375529
• c3 =
436838749130117465300561031454452502813077326340454374865246051046397854690504991716405214770364707509033415233365996022881766111606375225688683
912376892414463926993219107232350611808269454646497803733010281390492888815782348407395450003382029176780082697941791007323412694483629209247193
38148857398181962112
Example3
• As you can see yes, our public exponent is small, but taking the 3rd
root for won’t give us the solution, this means that
• Now there is an attack in this case we can apply called Hastad’s attack.
• Let’s discuss it in the next slide
Hastad’s Attack
• Simply when we send the same message to different receivers, an
attacker can retrieve the private key using Chinese remainder
theorem that we discussed before.
• ……
• So
• And from this
Common Modulus Attack
• To validate our result, we know from Bézout's identity that: which is
true
• Now to get our new
• Now we need to e EEA again for for short using computers it will give
us 16
• So
• And since so our
Example4
• Applying the same steps on the example we will get message:
CBCTF{6ac2afd2fc108894db8ab21d1e30d3f3}
Last Words
• Number theory is very interesting and fun, applying it to cryptography will
give you more fun, there is still a lot of topics we can discuss and other
attacks like: LLL and time attacks, also there is a lot of interesting topics in
cryptography like fast powering, elliptic curves, lattices, successive
powers, quadratic residue and much more, I really want to stay with you
and talk more but we can do it in another time, so always keep learning
and excited and never give up to math, it might seems hard and most of
simple thing seems weird to you but when you get it you will be so proud.
• In the next slide I will share a great resources that I use to practice and
learn.
Don’t learn to hack… hack to learn.
Resources
• Cryptohack one of the best websites that teaches you by challenges
• Math 3107 by prof. Jeff Suzuki Boston University
• MIT 6.875 MIT Cryptography Spring 2018
• An Introduction to Mathematical Cryptography by J.H. Silverman, Jill
Pipher, Jeffrey Hoffstein
References
• https://crypto.stanford.edu/~dabo/pubs/papers/RSA-survey.pdf
• https://cryptohack.org/challenges/maths/
• https://www.youtube.com/playlist?list=PLKXdxQAT3tCssgaWOy5vKXA
R4WTPpRVYK
• https://link.springer.com/book/10.1007/978-0-387-77993-5
• https://www.amazon.com/Friendly-Introduction-Number-Theory-4th/
dp/0321816196/ref=sr_1_2?ie=UTF8&qid=1326998078&sr=8-2
• https://www.khanacademy.org/computing/computer-science/cryptog
raphy/