예제 #1
0
def test_ed25519_kat(secret_key, public_key, message, signed, signature):
    sk = binascii.unhexlify(secret_key)
    m = binascii.unhexlify(message)

    pk = ed25519.publickey_unsafe(sk)
    sig = ed25519.signature_unsafe(m, sk, pk)

    # Assert that the signature and public key are what we expected
    assert binascii.hexlify(pk) == public_key
    assert binascii.hexlify(sig) == signature

    # Validate the signature using the checkvalid routine
    ed25519.checkvalid(sig, m, pk)

    # Assert that we cannot forge a message
    try:
        if len(m) == 0:
            forgedm = b"x"
        else:
            forgedm = ed25519.intlist2bytes([
                ed25519.indexbytes(m, i) + (i == len(m) - 1)
                for i in range(len(m))
            ])
    except ValueError:
        # TODO: Yes this means that we "pass" a test if we can't generate a
        # forged message. This matches the original test suite, it's
        # unclear if it was intentional there or not.
        pass
    else:
        with pytest.raises(ed25519.SignatureMismatch):
            ed25519.checkvalid(sig, forgedm, pk)
예제 #2
0
def test_ed25519_kat(secret_key, public_key, message, signed, signature):
    sk = binascii.unhexlify(secret_key)
    m = binascii.unhexlify(message)

    pk = ed25519.publickey_unsafe(sk)
    sig = ed25519.signature_unsafe(m, sk, pk)

    # Assert that the signature and public key are what we expected
    assert binascii.hexlify(pk) == public_key
    assert binascii.hexlify(sig) == signature

    # Validate the signature using the checkvalid routine
    ed25519.checkvalid(sig, m, pk)

    # Assert that we cannot forge a message
    try:
        if len(m) == 0:
            forgedm = b"x"
        else:
            forgedm = ed25519.intlist2bytes([
                ed25519.indexbytes(m, i) + (i == len(m) - 1)
                for i in range(len(m))
            ])
    except ValueError:
        # TODO: Yes this means that we "pass" a test if we can't generate a
        # forged message. This matches the original test suite, it's
        # unclear if it was intentional there or not.
        pass
    else:
        with pytest.raises(ed25519.SignatureMismatch):
            ed25519.checkvalid(sig, forgedm, pk)
예제 #3
0
 def _signature(message, private_key):
     """
     Calculate signature for given message and private key
     :param message: proto that has payload message inside
     :param private_key: hex string with private key
     :return: a proto Signature message
     """
     public_key = IrohaCrypto.derive_public_key(private_key)
     sk = binascii.unhexlify(private_key)
     pk = binascii.unhexlify(public_key)
     message_hash = IrohaCrypto.hash(message)
     signature_bytes = ed25519.signature_unsafe(message_hash, sk, pk)
     signature = primitive_pb2.Signature()
     signature.public_key = public_key
     signature.signature = binascii.hexlify(signature_bytes)
     return signature
예제 #4
0
#            2013 by Donald Stufft <*****@*****.**>
#            2013 by Alex Gaynor <*****@*****.**>
#            2013 by Greg Price <*****@*****.**>
#
# To the extent possible under law, the author(s) have dedicated all copyright
# and related and neighboring rights to this software to the public domain
# worldwide. This software is distributed without any warranty.
#
# You should have received a copy of the CC0 Public Domain Dedication along
# with this software. If not, see
# <http://creativecommons.org/publicdomain/zero/1.0/>.
import os
import timeit

import ed25519

seed = os.urandom(32)

data = b"The quick brown fox jumps over the lazy dog"
private_key = seed
public_key = ed25519.publickey_unsafe(seed)
signature = ed25519.signature_unsafe(data, private_key, public_key)

print('\nTime verify signature')
print(
    timeit.timeit(
        "ed25519.checkvalid(signature, data, public_key)",
        setup="from __main__ import ed25519, signature, data, public_key",
        number=100,
    ))
예제 #5
0
#            2013 by Greg Price <*****@*****.**>
#
# To the extent possible under law, the author(s) have dedicated all copyright
# and related and neighboring rights to this software to the public domain
# worldwide. This software is distributed without any warranty.
#
# You should have received a copy of the CC0 Public Domain Dedication along
# with this software. If not, see
# <http://creativecommons.org/publicdomain/zero/1.0/>.
import os
import timeit

import ed25519


seed = os.urandom(32)

data = b"The quick brown fox jumps over the lazy dog"
private_key = seed
public_key = ed25519.publickey_unsafe(seed)
signature = ed25519.signature_unsafe(data, private_key, public_key)

print("\nTime verify signature")
print(
    timeit.timeit(
        "ed25519.checkvalid(signature, data, public_key)",
        setup="from __main__ import ed25519, signature, data, public_key",
        number=100,
    )
)