Exemplo n.º 1
0
def do_dsa_g0(message_hash):
    x = 8675309
    k = 24601
    y = mypow(prob45_g0, x, prob45_p)
    r = mypow(prob45_g0, k, prob45_p) % prob45_q
    s = (invmod(k, prob45_p) * (message_hash + x * r)) % prob45_q
    return (y, r, s)
def do_dsa_g0(message_hash):
    x = 8675309;
    k = 24601;
    y = mypow(prob45_g0, x, prob45_p);
    r = mypow(prob45_g0, k, prob45_p) % prob45_q;
    s = (invmod(k, prob45_p) * (message_hash + x*r)) % prob45_q;
    return (y,r,s)
Exemplo n.º 3
0
def validate_dsa_g1(y, r, s, message_hash):
    w = invmod(s, prob45_q)
    u1 = (message_hash * w) % prob45_q
    u2 = (r * w) % prob45_q
    v = (mypow(prob45_g1, u1, prob43_p) * mypow(y, u2, prob45_p) %
         prob45_p) % prob45_q
    return v == r
Exemplo n.º 4
0
def generate_rsa_key(bits, e=65537):
    result = {"e": e}
    p = (e + 1)
    q = (e + 1)
    while ((p % e) == 1):
        p = generatePrime(bits // 2)
    while ((q % e) == 1):
        q = generatePrime(bits // 2)
    result["p"] = p
    result["q"] = q
    result["N"] = p * q
    result["d"] = invmod(e, (p - 1) * (q - 1))
    return result
Exemplo n.º 5
0
def generate_rsa_key(bits, e=65537):
    result = { "e" : e }
    p = (e+1)
    q = (e+1)
    while ((p % e) == 1):
        p = generatePrime(bits//2);
    while ((q%e) == 1):
        q = generatePrime(bits//2);
    result["p"] = p;
    result["q"] = q;
    result["N"] = p*q;
    result["d"] = invmod(e, (p-1)*(q-1));
    return result;
def do_unpadded_rsa_attack():
    rsaparams = generate_rsa_key(2048);
    e = rsaparams['e']
    N = rsaparams['N']
    messageBytes = b'Oh captain my captain'
    messageInt = int.from_bytes(messageBytes, byteorder="big")
    capturedCipher = capture_ciphertext(messageInt, N, e);
    
    S = 8675309
    C_prime = (mypow(S, e, N) * capturedCipher) % N;
    P_prime = decrypt_cipher(C_prime, rsaparams);
    plain = (P_prime * invmod(S, N)) % N;
    assert(plain == messageInt);
Exemplo n.º 7
0
def do_unpadded_rsa_attack():
    rsaparams = generate_rsa_key(2048)
    e = rsaparams['e']
    N = rsaparams['N']
    messageBytes = b'Oh captain my captain'
    messageInt = int.from_bytes(messageBytes, byteorder="big")
    capturedCipher = capture_ciphertext(messageInt, N, e)

    S = 8675309
    C_prime = (mypow(S, e, N) * capturedCipher) % N
    P_prime = decrypt_cipher(C_prime, rsaparams)
    plain = (P_prime * invmod(S, N)) % N
    assert (plain == messageInt)
def validate_dsa_g1(y, r, s, message_hash):
    w = invmod(s, prob45_q);
    u1 = (message_hash * w) % prob45_q;
    u2 = (r*w) % prob45_q;
    v = (mypow(prob45_g1, u1, prob43_p) * mypow(y, u2, prob45_p) % prob45_p) % prob45_q
    return v == r;
Exemplo n.º 9
0
def get_dsa_key_from_known_k(r, s, k, msg_hash, q=prob43_q):
    top = ((s*k) - msg_hash) % q;
    x = top * invmod(r, q);
    return x;
def recover_dsa_k(hash1, hash2, r1, s1, r2, s2, q=prob43_q):
    top = (hash1 - hash2) % q;
    k = top * invmod((s1 - s2)%q, q);
    return k;
Exemplo n.º 11
0
def recover_dsa_k(hash1, hash2, r1, s1, r2, s2, q=prob43_q):
    top = (hash1 - hash2) % q
    k = top * invmod((s1 - s2) % q, q)
    return k
Exemplo n.º 12
0
def get_dsa_key_from_known_k(r, s, k, msg_hash, q=prob43_q):
    top = ((s*k) - msg_hash) % q;
    x = top * invmod(r, q);
    return x;