DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Securing Verifiable Credentials With DPoP: A Spring Boot Implementation
  • Python Async/Sync: Advanced Blocking Detection and Best Practices (Part 2)
  • Pydantic: Simplifying Data Validation in Python
  • Bridging Graphviz and Cytoscape.js for Interactive Graphs

Trending

  • LLM-Powered Deep Parsing for Industrial Inventory Search
  • A 5-Step SOC Guide That Meets RBI Expectations and Strengthens Security Operations
  • Self-Hosted Inference Doesn’t Have to Be a Nightmare: How to Use GPUStack
  • Stop Writing Dialect-Specific SQL: A Unified Query Builder for Node.js
  1. DZone
  2. Data Engineering
  3. Data
  4. An Attack on RSA With Exponent 3

An Attack on RSA With Exponent 3

Learn more about an attack possible on RSA encryption using a very specific exponent — click here for the details!

By 
John Cook user avatar
John Cook
·
Mar. 08, 19 · Presentation
Likes (2)
Comment
Save
Tweet
Share
9.7K Views

Join the DZone community and get the full member experience.

Join For Free

As I noted in this post, RSA encryption is often carried out reusing exponents. Sometimes, the exponent is exponent 3, which is subject to an attack we’ll describe below [1]. (The most common exponent is 65537.)

Suppose the same message m is sent to three recipients and all three use exponent e= 3. Each recipient has a different modulus Ni, and each will receive a different encrypted message

ci = m³ mod Ni.

Someone with access to c1, c2, and c3 can recover the message m as follows. We can assume each modulus Ni is relatively prime to the others; otherwise, we can recover the private keys using the method described here. Since the moduli are relatively prime, we can solve the three equations for m³ using the Chinese Remainder Theorem. There is a unique x < N1 N2 N3, such that:

x = c1 mod N1
x = c2 mod N2
x = c3 mod N3

And m is simply the cube root of x. What makes this possible is knowing m is a positive integer less than each of the Ns and that x < N1 N2 N3. It follows that we can simply take the cube root in the integers and not the cube root in modular arithmetic.

This is an attack on “textbook” RSA because the weakness in this post could be avoiding by real-world precautions such as adding random padding to each message so that no two recipients are sent the exact same message.

Python Example

Here, we’ll work out a specific example using realistic RSA moduli.

    from secrets import randbits, randbelow
    from sympy import nextprime
    from sympy.ntheory.modular import crt

    def modulus():
        p = nextprime(randbits(2048))
        q = nextprime(randbits(2048))
        return p*q

    N = [modulus() for _ in range(3)]
    m = randbelow(min(N))
    c = [pow(m, 3, N[i]) for i in range(3)]
    x = crt(N, c)[0]

    assert(cbrt(x) == m) # integer cube root


Note that crt is the Chinese Remainder Theorem. It returns a pair of numbers, the first being the solution we’re after, hence the [0] after the call.

The script takes a few seconds to run. Nearly all the time goes to finding the 2048-bit (617-digit) primes that go into the moduli. Encrypting and decrypting m takes less than a second.

Related Posts

  • Common RSA implementation flaws
  • Regression, modular arithmetic, and PQC

[1] I don’t know who first discovered this line of attack, but you can find it written up here. At least in the first edition, the link is to the 2nd edition, which I don’t have.

MOD (file format) PRIME (PLC) POST (HTTP) Theorem Modulus (algebraic number theory) Python (language) Implementation Data Types Links

Published at DZone with permission of John Cook. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Securing Verifiable Credentials With DPoP: A Spring Boot Implementation
  • Python Async/Sync: Advanced Blocking Detection and Best Practices (Part 2)
  • Pydantic: Simplifying Data Validation in Python
  • Bridging Graphviz and Cytoscape.js for Interactive Graphs

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook