simple Sagemath script for LLL_nonce_leakage.py

3 replies 155 views
cobra2013Senior Member
Posts: 308 · Reputation: 1912
#1Dec 30, 2022, 01:32 AM
import olll import random import math import secp256k1 as ice G = ice.scalar_multiplication(1) N = ice.N # Secret key = x = (rns1 r1sn)-1 (snm1 s1mn s1sn(k1 kn)) # For 128 bit leaks, around 3 signatures are needed. fix_bits = 128 out_file_name = 'pseudo_sig_rsz.txt' kbits = 256 fix_bits #============================================================================== def write_rsz_file(rr, ss, zz, pb): with open(out_file_name, 'w') as f: sz = len(rr) for i in range(sz): f.write('r = ' + hex(rr)[2:].zfill(64) + '\n') f.write('s = ' + hex(ss)[2:].zfill(64) + '\n') f.write('z = ' + hex(zz)[2:].zfill(64) + '\n') f.write('pubkey = ' + pb.hex()) def modinv(v): return pow(v, N-2, N) def getx(Q): return int(Q[1:33].hex(), 16) def minimum_sigs_required(num_bits): return math.ceil(1.03 * 4 / 3 * 256 / num_bits) def identity_plus2(u, elem=1): m=[[0 for x in range(u+2)] for y in range(u)] for i in range(0,u): m = elem return m #============================================================================== n = 1 + minimum_sigs_required(fix_bits) print(f'\n Fixed Nonce bits = {fix_bits} Minimum Signature Required = {n}') # example secret = 0x7cf5d79d200207963474c64e64bde80ff4cb3e225b6ac5b6e958522fdab60578 secret = random.randint(1,N) pub = ice.scalar_multiplication(secret) print('###############################################################################') print(f'secret: {hex(secret)}') print(f'Pubkey: {pub.hex()}') print('#
2 Reply Quote Share
benseedFull Member
Posts: 60 · Reputation: 461
#2Dec 30, 2022, 01:59 AM
download or clone the file from here to the same directory you have the LLL program. you need to use ice_secp256k1.dll or .so for linux to use this program.. https://github.com/iceland2k14/secp256k1
2 Reply Quote Share
cobra2013Senior Member
Posts: 308 · Reputation: 1912
#3Dec 30, 2022, 07:18 AM
Yes, I know, but I am asking for simple math for easy understanding. Please explain how LLL_nonce_leakage works, write simple math, or explain
1 Reply Quote Share
Posts: 4 · Reputation: 90
#4Dec 30, 2022, 11:04 AM
Lenstra–Lenstra–Lovász lattice basis reduction algorithm is not a something that can be understood using simple mathematics. Try to read this for example.
4 Reply Quote Share

Related topics