Exemplo n.º 1
0
    def test_keypair(self):
        sk, vk = ed25519.create_keypair()
        self.assertTrue(isinstance(sk, ed25519.SigningKey), sk)
        self.assertTrue(isinstance(vk, ed25519.VerifyingKey), vk)
        sk2, vk2 = ed25519.create_keypair()
        self.assertNotEqual(hexlify(sk.to_bytes()), hexlify(sk2.to_bytes()))

        # you can control the entropy source
        def not_so_random(length):
            return b"4" * length

        sk1, vk1 = ed25519.create_keypair(entropy=not_so_random)
        self.assertEqual(
            sk1.to_ascii(encoding="base64"),
            b"NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ",
        )
        self.assertEqual(
            vk1.to_ascii(encoding="base64"),
            b"6yzxO/euOl9hQWih+wknLTl3HsS4UjcngV5GbK+O4WM",
        )
        sk2, vk2 = ed25519.create_keypair(entropy=not_so_random)
        self.assertEqual(sk1.to_ascii(encoding="base64"),
                         sk2.to_ascii(encoding="base64"))
        self.assertEqual(vk1.to_ascii(encoding="base64"),
                         vk2.to_ascii(encoding="base64"))
Exemplo n.º 2
0
    def test_keypair(self):
        sk, vk = ed25519.create_keypair()
        self.assertTrue(isinstance(sk, ed25519.SigningKey), sk)
        self.assertTrue(isinstance(vk, ed25519.VerifyingKey), vk)
        sk2, vk2 = ed25519.create_keypair()
        self.assertNotEqual(hexlify(sk.to_bytes()), hexlify(sk2.to_bytes()))

        # you can control the entropy source
        def not_so_random(length):
            return b"4"*length
        sk1, vk1 = ed25519.create_keypair(entropy=not_so_random)
        self.assertEqual(sk1.to_ascii(encoding="base64"),
                         b"NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ")
        self.assertEqual(vk1.to_ascii(encoding="base64"),
                         b"6yzxO/euOl9hQWih+wknLTl3HsS4UjcngV5GbK+O4WM")
        sk2, vk2 = ed25519.create_keypair(entropy=not_so_random)
        self.assertEqual(sk1.to_ascii(encoding="base64"),
                         sk2.to_ascii(encoding="base64"))
        self.assertEqual(vk1.to_ascii(encoding="base64"),
                         vk2.to_ascii(encoding="base64"))
Exemplo n.º 3
0
    def test_prefix(self):
        sk1, vk1 = ed25519.create_keypair()
        PREFIX = b"private0-"
        p = sk1.to_bytes(PREFIX)
        # that gives us a binary string with a prefix
        self.assertTrue(p[:len(PREFIX)] == PREFIX, repr(p))
        sk2 = ed25519.SigningKey(p, prefix=PREFIX)
        self.assertEqual(sk1, sk2)
        self.assertEqual(repr(sk1.to_bytes()), repr(sk2.to_bytes()))
        self.assertRaises(ed25519.BadPrefixError,
                          ed25519.SigningKey,
                          p,
                          prefix=b"WRONG-")
        # SigningKey.to_seed() can do a prefix too
        p = sk1.to_seed(PREFIX)
        self.assertTrue(p[:len(PREFIX)] == PREFIX, repr(p))
        sk3 = ed25519.SigningKey(p, prefix=PREFIX)
        self.assertEqual(sk1, sk3)
        self.assertEqual(repr(sk1.to_bytes()), repr(sk3.to_bytes()))
        self.assertRaises(ed25519.BadPrefixError,
                          ed25519.SigningKey,
                          p,
                          prefix=b"WRONG-")

        # verifying keys can do this too
        PREFIX = b"public0-"
        p = vk1.to_bytes(PREFIX)
        self.assertTrue(p.startswith(PREFIX), repr(p))
        vk2 = ed25519.VerifyingKey(p, prefix=PREFIX)
        self.assertEqual(vk1, vk2)
        self.assertEqual(repr(vk1.to_bytes()), repr(vk2.to_bytes()))
        self.assertRaises(ed25519.BadPrefixError,
                          ed25519.VerifyingKey,
                          p,
                          prefix=b"WRONG-")

        # and signatures
        PREFIX = b"sig0-"
        p = sk1.sign(b"msg", PREFIX)
        self.assertTrue(p.startswith(PREFIX), repr(p))
        vk1.verify(p, b"msg", PREFIX)
        self.assertRaises(ed25519.BadPrefixError,
                          vk1.verify,
                          p,
                          b"msg",
                          prefix=b"WRONG-")
Exemplo n.º 4
0
    def test_prefix(self):
        sk1,vk1 = ed25519.create_keypair()
        PREFIX = b"private0-"
        p = sk1.to_bytes(PREFIX)
        # that gives us a binary string with a prefix
        self.assertTrue(p[:len(PREFIX)] == PREFIX, repr(p))
        sk2 = ed25519.SigningKey(p, prefix=PREFIX)
        self.assertEqual(sk1, sk2)
        self.assertEqual(repr(sk1.to_bytes()), repr(sk2.to_bytes()))
        self.assertRaises(ed25519.BadPrefixError,
                          ed25519.SigningKey, p, prefix=b"WRONG-")
        # SigningKey.to_seed() can do a prefix too
        p = sk1.to_seed(PREFIX)
        self.assertTrue(p[:len(PREFIX)] == PREFIX, repr(p))
        sk3 = ed25519.SigningKey(p, prefix=PREFIX)
        self.assertEqual(sk1, sk3)
        self.assertEqual(repr(sk1.to_bytes()), repr(sk3.to_bytes()))
        self.assertRaises(ed25519.BadPrefixError,
                          ed25519.SigningKey, p, prefix=b"WRONG-")

        # verifying keys can do this too
        PREFIX = b"public0-"
        p = vk1.to_bytes(PREFIX)
        self.assertTrue(p.startswith(PREFIX), repr(p))
        vk2 = ed25519.VerifyingKey(p, prefix=PREFIX)
        self.assertEqual(vk1, vk2)
        self.assertEqual(repr(vk1.to_bytes()), repr(vk2.to_bytes()))
        self.assertRaises(ed25519.BadPrefixError,
                          ed25519.VerifyingKey, p, prefix=b"WRONG-")

        # and signatures
        PREFIX = b"sig0-"
        p = sk1.sign(b"msg", PREFIX)
        self.assertTrue(p.startswith(PREFIX), repr(p))
        vk1.verify(p, b"msg", PREFIX)
        self.assertRaises(ed25519.BadPrefixError,
                          vk1.verify, p, b"msg", prefix=b"WRONG-")
Exemplo n.º 5
0
 def _make_keys(self):
     # Makes a set of private and public keys
     privkey, pubkey = ed25519.create_keypair()
     pri = privkey.to_ascii(encoding=self.key_encoding)
     pub = pubkey.to_ascii(encoding=self.key_encoding)
     return pri, pub
Exemplo n.º 6
0
from pure25519 import ed25519_oop
privKey, pubKey = ed25519_oop.create_keypair()
print("Private key (32 bytes):", privKey.to_ascii(encoding='hex'))
print("Public key (32 bytes): ", pubKey.to_ascii(encoding='hex'))
msg = b'Message for signing'
signature = privKey.sign(msg, encoding='hex')
print("Signature (64 bytes):", signature)
try:
    pubKey.verify(signature, msg, encoding='hex')
    print("The signature is valid.")
except:
    print("Invalid signature!")
Exemplo n.º 7
0
 def _make_keys(self):
     # Makes a set of private and public keys
     privkey, pubkey = ed25519.create_keypair()
     pri = privkey.to_ascii(encoding=self.key_encoding)
     pub = pubkey.to_ascii(encoding=self.key_encoding)
     return pri, pub
Exemplo n.º 8
0
def gen_keypair():
	return create_keypair()