Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

An article to explain how this attack works and how to protect from it.

NotificationsYou must be signed in to change notification settings

Kiooku/Small-Subgroup-Confinement-Attack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 

Repository files navigation

Prerequisite

In this article, I hope to explain clearly and as simply as possible what asmall subgroup confinement attack is and how this attack works.
And finally, at the end of this article, how to protect yourDiffie-Hellman key exchange from this attack.

What’s a Small subgroup confinement attack ?


The goal of asmall subgroup confinement attack is to force the key to be confined to an unexpectedly small subgroup of the desire group and to recover a secret private integer (a orb).

Perform a Small Subgroup Confinement Attack on a Diffie Hellman Key Exchange


Prior knowledge

To perform this attack and retrieve the secret integer chosen by our target, we must use aman in the middle attack (MITM) attack and give a tampered parameter to our target.

I’m not going to explain what’s a MITM attack and how to perform it in this article.

Situation

We’ve intercepted Alice’s parameters, but we can only interact with Bob. How do we get the shared secret to decrypt Alice's encrypted message?

We will tamper Bob’s parameters in order to get his secret private integerb.
For that, we’re going to use a small subgroup confinement attack.

Setup

Thefirst step is to find asmooth prime numberp upper than the p given by Alice, with many small factors(factors less than or equal to 216 are good because they don't require much computation time, which makes the attack faster).

You can find a very good function (get_smooth_prime) in thisCTF write up, to make smooth prime where you can easily choose his length and smoothness.

With this smooth prime numberp, we have a lot of small factors which dividep-1.

The attack can start !

Exploit the vulnerability of smooth prime number

You will do these4 steps on all factors ofp to get the secret integerb of Bob.
We’re going to call each factorf.

Step 1

To do that, we have to find a number A’ in order that:

A’(rand_int(p-1) / p) (mod p) != 1.
Example of a python function to find A’:

fromrandomimportrandintdefget_tampered_public_key(f,p):tampered_A=1whiletampered_A==1:tampered_A=pow(randint(1,p), (p-1)//f,p)returntampered_A

Step 2

SendA’ to Bob asAlice public key

Step 3

Bob useA’ to create hisshared secret. [Bob shared secret =A’b (mod p)]

Step 4

Intercept Bob’sMAC(shared_secret, message)
WithA’ used in Bob shared secret, we have reduced the possible value of theshared secret, because Bob raised our A’ to a power b and the order ofA’ isf.
We deliberately choose small factorsf so we can brute force all possible value from1 tof until we find anx such asA’x (mod p) is equal to BobMAC(shared_secret, message).
The result can be written like that:x ≡ b1 (mod f1)

After repeating this fourth step, we have a lot of equations like this:

  • x1 ≡ b1 (mod f1)
  • x2 ≡ b2 (mod f2)
  • xn ≡ bn (mod fn)

Find the secret integer b of Bob

With all these equations we can easily recover the secret integer of Bob using theChinese remainder theorem (CRT).

Example to calculate the CRT of our equations in python:

fromsympy.ntheory.modularimportcrt#Where f_n is the list of all the factors of our tampered p and x_n the list of all the x in our equationsb=crt(f_n,x_n)[0]

Countermeasure against the Small subgroup confinement attack


One solution to protect your Diffie-Hellman key exchange from this attack is to use asafe prime p wherep = 2q + 1 andq is prime.

Check that 2 <= y <= p-2 (otherwise there may be a 1 bit leak)

Withp a safe prime,p-1 has a large prime factor that makes the small subgroup confinement attack impossible due to computational time.

Obviously, don’t use a prime number p with a small bit-length for a communication. According to theFederal Office for Information Security:

“The length of p should be at least 2000 bits, and at least 3000 bits for a period of use beyond 2022” (7.2.1 Diffie Hellman – Key length)

References


About

An article to explain how this attack works and how to protect from it.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp