def test_en_decrypt_shared_mac_data():
    alice, bob = crypto.ECCx(), crypto.ECCx()
    ciphertext = alice.encrypt('test',
                               bob.raw_pubkey,
                               shared_mac_data='shared mac data')
    assert bob.decrypt(ciphertext,
                       shared_mac_data=b'shared mac data') == b'test'
Beispiel #2
0
def test_signature():
    bob = get_ecc(b'secret2')

    # sign
    message = crypto.sha3(b"Hello Alice")
    signature = bob.sign(message)

    # verify signature
    assert crypto.verify(bob.raw_pubkey, signature, message) is True
    assert crypto.ECCx(raw_pubkey=bob.raw_pubkey).verify(signature, message) is True

    # wrong signature
    message = crypto.sha3(b"Hello Alicf")
    assert crypto.ECCx(raw_pubkey=bob.raw_pubkey).verify(signature, message) is False
    assert crypto.verify(bob.raw_pubkey, signature, message) is False
Beispiel #3
0
def test_decrypt2():
    kenc, penc = test_privtopub()
    cipher2 = fromHex(
        "0x0443c24d6ccef3ad095140760bb143078b3880557a06392f17c5e368502d79532bc18903d59ced4bbe858e870610ab0d5f8b7963dd5c9c4cf81128d10efd7c7aa80091563c273e996578403694673581829e25a865191bdc9954db14285b56eb0043b6288172e0d003c10f42fe413222e273d1d4340c38a2d8344d7aadcbc846ee")
    expectedPlain2 = "aaaaaaaaaaaaaaaa"
    plainTest2 = crypto.ECCx(raw_privkey=kenc).ecies_decrypt(cipher2)
    assert(expectedPlain2 == plainTest2)
Beispiel #4
0
def test_decrypt():
    kmK = fromHex("0x57baf2c62005ddec64c357d96183ebc90bf9100583280e848aa31d683cad73cb")
    kmCipher = fromHex(
        "0x04ff2c874d0a47917c84eea0b2a4141ca95233720b5c70f81a8415bae1dc7b746b61df7558811c1d6054333907333ef9bb0cc2fbf8b34abb9730d14e0140f4553f4b15d705120af46cf653a1dc5b95b312cf8444714f95a4f7a0425b67fc064d18f4d0a528761565ca02d97faffdac23de10")
    kmExpected = "a"
    kmPlain = crypto.ECCx(raw_privkey=kmK).ecies_decrypt(kmCipher)
    assert(kmExpected == kmPlain)
Beispiel #5
0
def test_decrypt3():
    kenc, penc = test_privtopub()
    cipher3 = fromHex(
        "0x04c4e40c86bb5324e017e598c6d48c19362ae527af8ab21b077284a4656c8735e62d73fb3d740acefbec30ca4c024739a1fcdff69ecaf03301eebf156eb5f17cca6f9d7a7e214a1f3f6e34d1ee0ec00ce0ef7d2b242fbfec0f276e17941f9f1bfbe26de10a15a6fac3cda039904ddd1d7e06e7b96b4878f61860e47f0b84c8ceb64f6a900ff23844f4359ae49b44154980a626d3c73226c19e")
    expectedPlain3 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
    plainTest3 = crypto.ECCx(raw_privkey=kenc).ecies_decrypt(cipher3)
    assert(expectedPlain3 == plainTest3)
Beispiel #6
0
def test_decrypt1():
    kenc, penc = test_privtopub()
    cipher1 = fromHex(
        "0x046f647e1bd8a5cd1446d31513bac233e18bdc28ec0e59d46de453137a72599533f1e97c98154343420d5f16e171e5107999a7c7f1a6e26f57bcb0d2280655d08fb148d36f1d4b28642d3bb4a136f0e33e3dd2e3cffe4b45a03fb7c5b5ea5e65617250fdc89e1a315563c20504b9d3a72555")

    expectedPlain1 = "a"
    plainTest1 = crypto.ECCx(raw_privkey=kenc).ecies_decrypt(cipher1)
    assert(expectedPlain1 == plainTest1)
Beispiel #7
0
def test_agree():
    secret = fromHex("0x332143e9629eedff7d142d741f896258f5a1bfab54dab2121d3ec5000093d74b")
    public = fromHex(
        "0xf0d2b97981bd0d415a843b5dfe8ab77a30300daab3658c578f2340308a2da1a07f0821367332598b6aa4e180a41e92f4ebbae3518da847f0b1c0bbfe20bcf4e1")
    agreeExpected = fromHex("0xee1418607c2fcfb57fda40380e885a707f49000a5dda056d828b7d9bd1f29a08")
    e = crypto.ECCx(raw_privkey=secret)
    agreeTest = e.raw_get_ecdh_key(pubkey_x=public[:32], pubkey_y=public[32:])
    assert(agreeExpected == agreeTest)
Beispiel #8
0
def test_get_ecdh_key():
    privkey = decode_hex("332143e9629eedff7d142d741f896258f5a1bfab54dab2121d3ec5000093d74b")
    remote_pubkey = decode_hex("f0d2b97981bd0d415a843b5dfe8ab77a30300daab3658c578f2340308a2da1a07f0821367332598b6aa4e180a41e92f4ebbae3518da847f0b1c0bbfe20bcf4e1")

    agree_expected = decode_hex("ee1418607c2fcfb57fda40380e885a707f49000a5dda056d828b7d9bd1f29a08")

    e = crypto.ECCx(raw_privkey=privkey)
    agree = e.get_ecdh_key(remote_pubkey)
    assert agree == agree_expected
def test_en_decrypt_shared_mac_data_fail():
    alice, bob = crypto.ECCx(), crypto.ECCx()
    ciphertext = alice.encrypt('test',
                               bob.raw_pubkey,
                               shared_mac_data='shared mac data')
    bob.decrypt(ciphertext, shared_mac_data=b'wrong')
def test_en_decrypt():
    alice = crypto.ECCx()
    bob = crypto.ECCx()
    msg = b'test'
    ciphertext = alice.encrypt(msg, bob.raw_pubkey)
    assert bob.decrypt(ciphertext) == msg
def get_ecc(secret=b''):
    return crypto.ECCx(raw_privkey=crypto.mk_privkey(secret))
def test_privtopub():
    priv = crypto.mk_privkey(b'test')
    pub = crypto.privtopub(priv)
    pub2 = crypto.ECCx(raw_privkey=priv).raw_pubkey
    assert pub == pub2
Beispiel #13
0
def test_ecies_enc():
    bob = crypto.ECCx()
    msg = b'test yeah'
    ciphertext = crypto.ECCx.ecies_encrypt(msg, bob.raw_pubkey)
    _dec = bob.ecies_decrypt(ciphertext)
    assert _dec == msg