Giter VIP home page Giter VIP logo

breakingecdsawithlll's Introduction

lint_python GitHub issues GitHub forks GitHub stars

BreakingECDSAwithLLL

Breaking ECDSA (not so broken) with LLL

The main idea behing this attack is the theorem of the great numbers, if you have a crypto funcion and lots of samples (signatures) generated with a private key having a bias in the nonce generation, then they will tend to converge to a single point which happens to be the private key, this is equal to solving the hidden number problem. And for solving it we employ Lenstra-Lenstra-Lovasz lattice reduction algorithm.

The main counter measure against this kind of attack is using deterministic signatures like Z=H(h||d), where Z is the digest, H is a crypto-secure hash funcion, h the nonce, and d our private key. This is needed in order to have a even distributed, random looking nonce.

Heavily based on previous work

https://blog.trailofbits.com/2020/06/11/ecdsa-handle-with-care/
https://www.youtube.com/watch?v=6ssTlSSIJQE

First install dependencies:

sudo apt-get install sagemath python3-ecdsa

Then run:

# (Victim) 
# This will generate 6 weak signatures with a known key, args:(privkey,bits,nonces)
python3 weak_signature_generator.py e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 176 6 > nonces.csv

# (Attacker) 
# Will find the private key if LLL converges, args:(bits,nonces)
python3 crack_weak_ECDSA_nonces_with_LLL.py nonces.csv 176 6 | grep -e e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855

breakingecdsawithlll's People

Contributors

daedalus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

breakingecdsawithlll's Issues

Error "sage.all_cmdline import *"

Hi, I first want to congratulate you for your work and contribution. For study purposes I implemented in Linux lll-VirtualBox 5.4.0-74-generic #83~18.04.1-Ubuntu SMP Tue May 11 16:01:00 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

It turns out that the first script normally generates the csv containing data.
But the second attack script returns the error below:

lll@lll-VirtualBox:~/BreakingECDSAwithLLL$ python3 crack_weak_ECDSA_nonces_with_LLL.py nonces.csv 176 6 | grep -e 9ec4bc49e828d924af1d1029cacf709431abbde46d59554b62bc270e3b29c4b1
Traceback (most recent call last):
File "crack_weak_ECDSA_nonces_with_LLL.py", line 11, in
from sage.all_cmdline import *
ModuleNotFoundError: No module named 'sage'

Do you have any idea what might be happening and how to solve it? Thanks

ethereum

hi . does it work in etereum network?

*.csv file parameters

Good afternoon.
Please tell me in what order the values in the nonce.csv file should go in order for the file crack_weak_ECDSA_nonces_with_LLL.py?
In order for these parameters to be read correctly. R,S,Z or Z,R,S?
And what is "pubs = []"?

Error

buntu@ip-172-31-65-90:~/BreakingECDSAwithLLL$ python3 weak_signature
_generator.py e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991
250 60 >>60.txt

--------------------------------------------

ubuntu@ip-172-31-65-90:~/BreakingECDSAwithLLL$ python3 crack_weak_ECD
SA_nonces_with_LLL.py 60.txt 250 60 | grep -e e3b0c44298fc1c149afbf4c
8996fb92427ae41e4649b934ca495991b7852b855
/usr/lib/python3/dist-packages/apport/report.py:13: DeprecationWarnin
g: the imp module is deprecated in favour of importlib; see the modul
e's documentation for alternative uses
import fnmatch, glob, traceback, errno, sys, atexit, locale, imp, s
tat
Traceback (most recent call last):
File "crack_weak_ECDSA_nonces_with_LLL.py", line 39, in
msgs,sigs,pubs = load_csv(filename)
File "crack_weak_ECDSA_nonces_with_LLL.py", line 32, in load_csv
tx,R,S,Z,pub = l
ValueError: too many values to unpack (expected 5)

How to fix this ?

Thanx

ethereum not suppported

i use web3 js for generate signature , with this code

for (var i=0;i<8;i++){
var a= await web3.eth.accounts.signTransaction({
to: addr[i],
value: valued[i],
gas: 21000,
nonce:686,
gasPrice:gaspriced[i],
chainId: 1,
data:0
}, '0x2EE0C4ED86CC5DAE5F593542783E9BE94E817FDD600903DD7499710175FDC2C6')
console.log(a.r+","+a.s+","+a.transactionHash)

writefile2(("1111,"+a.r+","+a.s+","+a.transactionHash+",0000"));
}

but when i test output with your code it cant find private key

What is a 1111 and 0000 ?

What is a 1111 and 0000 in generated data file ?

1111 mean nonce srart with 1111 or what ?

Thanx.

NameError: name 'Matrix' is not defined

Hello.
I have error below on python3.10, what i can do? Thanks.

C:\Users\K\Desktop\BreakingECDSAwithLLL-master>python crack_weak_ECDSA_nonces_with_LLL.py nonces.csv 176 6 grep -e e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
Using: 6 sigs...
Traceback (most recent call last):
File "C:\Users\K\Desktop\BreakingECDSAwithLLL-master\crack_weak_ECDSA_nonces_with_LLL.py", line 109, in
main()
File "C:\Users\K\Desktop\BreakingECDSAwithLLL-master\crack_weak_ECDSA_nonces_with_LLL.py", line 97, in main
matrix = make_matrix(msgs, sigs, pubs, B)
File "C:\Users\K\Desktop\BreakingECDSAwithLLL-master\crack_weak_ECDSA_nonces_with_LLL.py", line 43, in make_matrix
matrix = Matrix(QQ, m + 2, m + 2)
NameError: name 'Matrix' is not defined. Did you mean: 'matrix'?

Can you add check secret key to public key ?

Can you add check founbed secret key's to public key ?

Scrypt generate many private keys but only one can be valid for publick key.

Check all keys manualy is hard task, so this feather can be helpful.

Regards.

Adding LSB Function

Hi Daedalus,

Thanks for the nice python script.
I am trying to add LSB function to the code.

According to Nadia Heninger it is easy to use LSB by shifting the signatures by 2^-L bits.

I did the following in your code:

  1. Generate bit shifted nonces:
    nonces = [random.randrange(1, 2**bits) + yubikey_fixed_prefix for i in range(n)]
    nonces_shift = [nonces[i] << 80 & mask for i in range(n)]

  2. Shifting sigs in crack.py for a p192- curve and 192 bit length nonces:
    mask = 2 ** 192 - 1
    msgs.append(int(Z,16))
    sigs.append((int((bin(int(R,16) >> 80 & mask)),2),int((bin(int(S,16) >> 80 & mask)),2)))

So doing a left shift in the nonces to get 80-Bits 0s then right shift the sigs 80-bits to get the 0s MSB.

This does not work and the key is wrong.

Maybe you can help me out on this?

thx

not working

File "/home/BreakingECDSAwithLLL/crack_weak_ECDSA_nonces_with_LLL.py", line 28, in load_csv
if n < limit:
TypeError: '<' not supported between instances of 'int' and 'function'

created empty nonces.csv

Hi,
I've tried to run your scripts. But it created an empty nonce.csv
I just run the same as you described in the readme

Short Nonces in ECDSA

Hello @daedalus It happens that some devices generate short Nonces.
Approximately 2 ^ 243-2 ^ 244

Accordingly, if Nonces is short, then it must contain null at the beginning.
That is, the first 3 bits of Nonces contain a leading zero.

Given the known values of the signature [R, S, H (e)], can we determine whether the size of Nonces is short?

Is there a way to find out information about the first 3 bit of Nonces?

Please explain

@daedalus hello please explain to me, can this program calculate the private key when i have different value of r and k, i have a wallet for bitcoin but the value of r is different, please explain to me

Clarification on the input

(Attacker)

Will find the private key if LLL converges, args:(bits,nonces)

python3 crack_weak_ECDSA_nonces_with_LLL.py nonces.csv 176 6 | grep -e e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855

Sorry. what did you input here?

"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" is that the txiD?

Hello

Why this code not found privkey ?

thon3 weak_signature
_generator.py e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991
b7852b855 252 252 > nonces111.csv

/BreakingECDSAwithLLL$ python3 crack_weak_ECD
SA_nonces_with_LLL.py nonces111.csv 252 252 | grep -e e3b0c44298fc1c
149afbf4c8996fb92427ae41e4649b934ca495991b7852b855

????

Help me please ?

Regard

sageroot

hi
how can i find sage.allcmd_line ?
can yo help me?
thanks

rnsn_inv' is not defined

hi bro,

I ran a new version that is now up, and the following error occurs:

Please check.

python3 crack_weak_ECDSA_nonces_with_LLL.py nonces.csv 176 6
Using: 6 sigs...
/usr/lib/python3/dist-packages/apport/report.py:13: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
import fnmatch, glob, traceback, errno, sys, atexit, locale, imp, stat
Traceback (most recent call last):
File "crack_weak_ECDSA_nonces_with_LLL.py", line 116, in
main()
File "crack_weak_ECDSA_nonces_with_LLL.py", line 104, in main
matrix = make_matrix(msgs,sigs,pubs)
File "crack_weak_ECDSA_nonces_with_LLL.py", line 51, in make_matrix
x0=(sigs[i][0] * modular_inv(sigs[i][1], order)) - rnsn_inv
NameError: name 'rnsn_inv' is not defined

cf) The first version that was uploaded worked well without any problems. Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.