예제 #1
0
def test_raw():
    vrs1 = b_ecdsa_raw_sign(msg32, priv)
    assert isinstance(vrs1, tuple)
    assert len(vrs1) == 3
    vrs3 = c_ecdsa_sign_raw(msg32, priv)
    p1 = b_ecdsa_raw_recover(msg32, vrs1)
    p3 = c_ecdsa_recover_raw(msg32, vrs1)
    p4 = c_ecdsa_recover_raw(msg32, vrs3)
    p5 = b_ecdsa_raw_recover(msg32, vrs3)

    # Ensure that recovered pub key is the same
    assert encode_pubkey(p1, 'bin') == pub
    assert p3 == pub
    assert p4 == pub
    assert encode_pubkey(p5, 'bin') == pub

    # check wrong pub
    wrong_vrs = c_ecdsa_sign_raw(msg32, 'x' * 32)
    p2 = c_ecdsa_recover_raw(msg32, wrong_vrs)
    assert encode_pubkey(p2, 'bin') != pub

    # verify
    p6 = encode_pubkey(p3, 'bin_electrum')
    assert c_ecdsa_verify_raw(msg32, vrs1, p6)
    p7 = encode_pubkey(p6, 'bin')
    assert c_ecdsa_verify_raw(msg32, vrs1, p7)
    assert c_ecdsa_verify_raw(msg32, vrs1, p3)

    # check wrong pub
    sig_vrs2 = c_ecdsa_sign_raw(msg32, 'x' * 32)
    p2 = c_ecdsa_recover_raw(msg32, sig_vrs2)
    assert p2 != pub

    # check wrong sig
    false_sig_vrs = sig_vrs2
    assert not c_ecdsa_verify_raw(msg32, false_sig_vrs, pub)
예제 #2
0
def test_raw():
    vrs1 = b_ecdsa_raw_sign(msg32, priv)
    assert isinstance(vrs1, tuple)
    assert len(vrs1) == 3
    vrs3 = c_ecdsa_sign_raw(msg32, priv)
    p1 = b_ecdsa_raw_recover(msg32, vrs1)
    p3 = c_ecdsa_recover_raw(msg32, vrs1)
    p4 = c_ecdsa_recover_raw(msg32, vrs3)
    p5 = b_ecdsa_raw_recover(msg32, vrs3)

    # Ensure that recovered pub key is the same
    assert encode_pubkey(p1, 'bin') == pub
    assert p3 == pub
    assert p4 == pub
    assert encode_pubkey(p5, 'bin') == pub

    # check wrong pub
    wrong_vrs = c_ecdsa_sign_raw(msg32, 'x' * 32)
    p2 = c_ecdsa_recover_raw(msg32, wrong_vrs)
    assert encode_pubkey(p2, 'bin') != pub

    # verify
    p6 = encode_pubkey(p3, 'bin_electrum')
    assert c_ecdsa_verify_raw(msg32, vrs1, p6)
    p7 = encode_pubkey(p6, 'bin')
    assert c_ecdsa_verify_raw(msg32, vrs1, p7)
    assert c_ecdsa_verify_raw(msg32, vrs1, p3)

    # check wrong pub
    sig_vrs2 = c_ecdsa_sign_raw(msg32, 'x' * 32)
    p2 = c_ecdsa_recover_raw(msg32, sig_vrs2)
    assert p2 != pub

    # check wrong sig
    false_sig_vrs = sig_vrs2
    assert not c_ecdsa_verify_raw(msg32, false_sig_vrs, pub)
예제 #3
0
def test_raw():
    vrs1 = b_ecdsa_raw_sign(msg32, priv)
    assert isinstance(vrs1, tuple)
    assert len(vrs1) == 3
    vrs3 = c_ecdsa_sign_raw(msg32, priv)
    p1 = b_ecdsa_raw_recover(msg32, vrs1)
    p3 = c_ecdsa_recover_raw(msg32, vrs1)
    p4 = c_ecdsa_recover_raw(msg32, vrs3)
    p5 = b_ecdsa_raw_recover(msg32, vrs3)
    vrs2 = lr.ecdsa_sign_raw(msg32, priv)
    p9 = b_ecdsa_raw_recover(msg32, vrs2)
    p10 = c_ecdsa_recover_raw(msg32, vrs2)
    p7 = lr.ecdsa_recover_raw(msg32, vrs2)
    vrs4 = lc.ecdsa_sign_compact(msg32, priv)
    p8 = lr.ecdsa_recover_raw(msg32, vrs1)

    # Ensure that recovered pub key is the same
    assert encode_pubkey(p1, 'bin') == pub
    assert p4 == pub
    assert p7 == pub
    assert p8 == pub
    assert encode_pubkey(p8, 'bin') == pub
    assert p10 == pub
    assert encode_pubkey(p5, 'bin') == pub

    # check wrong pub
    wrong_vrs = c_ecdsa_sign_raw(msg32, 'x' * 32)
    wrong_vrs2 = lr.ecdsa_sign_raw(msg32, 'x' * 32)
    p2 = c_ecdsa_recover_raw(msg32, wrong_vrs)
    p3 = lr.ecdsa_recover_raw(msg32, wrong_vrs2)
    assert encode_pubkey(p2, 'bin') != pub
    assert encode_pubkey(p3, 'bin') != pub

    # verify
    assert lr.ecdsa_verify_raw(msg32, vrs2, p7)
    assert lc.ecdsa_verify_compact(msg32, vrs4, p7)

    # check wrong pub
    sig_vrs2 = c_ecdsa_sign_raw(msg32, 'x' * 32)
    p2 = c_ecdsa_recover_raw(msg32, sig_vrs2)
    assert p2 != pub

    # check wrong sig
    false_sig_vrs = sig_vrs2
    assert not c_ecdsa_verify_raw(msg32, false_sig_vrs, pub)
    assert not lr.ecdsa_verify_raw(msg32, false_sig_vrs, pub)