Esempio n. 1
0
def test_ecc_make_shared_secret():
    a = EccPrivate.make_key(32)
    a_pub = EccPublic()
    a_pub.import_x963(a.export_x963())

    b = EccPrivate.make_key(32)
    b_pub = EccPublic()
    b_pub.import_x963(b.export_x963())

    assert a.shared_secret(b) \
        == b.shared_secret(a) \
        == a.shared_secret(b_pub) \
        == b.shared_secret(a_pub)
Esempio n. 2
0
    def test_ecc_make_shared_secret():
        a = EccPrivate.make_key(32)
        a_pub = EccPublic()
        a_pub.import_x963(a.export_x963())

        b = EccPrivate.make_key(32)
        b_pub = EccPublic()
        b_pub.import_x963(b.export_x963())

        assert a.shared_secret(b) \
            == b.shared_secret(a) \
            == a.shared_secret(b_pub) \
            == b.shared_secret(a_pub)
Esempio n. 3
0
def test_ecc_sign_verify(ecc_private, ecc_public):
    plaintext = "Everyone gets Friday off."

    # normal usage, sign with private, verify with public
    signature = ecc_private.sign(plaintext)

    assert len(signature) <= ecc_private.max_signature_size
    assert ecc_public.verify(signature, plaintext)

    # invalid signature
    with pytest.raises(WolfCryptError):
        ecc_public.verify(signature[:-1], plaintext)

    # private object holds both private and public info, so it can also verify
    # using the known public key.
    assert ecc_private.verify(signature, plaintext)

    ecc_x963 = EccPublic()
    ecc_x963.import_x963(ecc_public.export_x963())
    assert ecc_x963.verify(signature, plaintext)

    ecc_x963 = EccPublic()
    ecc_x963.import_x963(ecc_private.export_x963())
    assert ecc_x963.verify(signature, plaintext)

    ecc_x963 = EccPublic()
    with pytest.raises(WolfCryptError):
        ecc_x963.import_x963(ecc_public.export_x963()[:-1])
Esempio n. 4
0
    def test_ecc_sign_verify(ecc_private, ecc_public):
        plaintext = "Everyone gets Friday off."

        # normal usage, sign with private, verify with public
        signature = ecc_private.sign(plaintext)

        assert len(signature) <= ecc_private.max_signature_size
        assert ecc_public.verify(signature, plaintext)

        # invalid signature
        with pytest.raises(WolfCryptError):
            ecc_public.verify(signature[:-1], plaintext)

        # private object holds both private and public info, so it can also verify
        # using the known public key.
        assert ecc_private.verify(signature, plaintext)

        ecc_x963 = EccPublic()
        ecc_x963.import_x963(ecc_public.export_x963())
        assert ecc_x963.verify(signature, plaintext)

        ecc_x963 = EccPublic()
        ecc_x963.import_x963(ecc_private.export_x963())
        assert ecc_x963.verify(signature, plaintext)

        ecc_x963 = EccPublic()
        with pytest.raises(WolfCryptError):
            ecc_x963.import_x963(ecc_public.export_x963()[:-1])