示例#1
0
 def test_randoms(self):
     ''' Test 100 random exchanges against each other.
     '''
     for __ in range(100):
         alice = PrivateKey()
         bob = PrivateKey()
         a_to_b = alice.do_exchange(bob.get_public())
         b_to_a = bob.do_exchange(alice.get_public())
         self.assertEqual(a_to_b, b_to_a, 'Random key exchange mismatch.')
示例#2
0
 def test_init_typecheck(self):
     ''' Test type checking on init.
     '''
     mv = memoryview(self.alice.private)
     with self.assertRaises(TypeError, msg='PrivateKey failed init type check.'):
         alice = PrivateKey(mv)
     ba = bytearray(self.alice.private)
     with self.assertRaises(TypeError, msg='PrivateKey failed init type check.'):
         alice = PrivateKey(ba)
     other = int.from_bytes(TVa, byteorder='big')
     with self.assertRaises(TypeError, msg='PrivateKey failed init type check.'):
         alice = PrivateKey(other)
示例#3
0
 def test_init_lencheck(self):
     ''' Test length checking on init.
     '''
     less = bytes(31)
     with self.assertRaises(ValueError, msg='PrivateKey failed init len check.'):
         test = PrivateKey(less)
         
     more = bytes(33)
     with self.assertRaises(ValueError, msg='PrivateKey failed init len check.'):
         test = PrivateKey(more)
         
     edge = bytes()
     with self.assertRaises(ValueError, msg='PrivateKey failed init len check.'):
         test = PrivateKey(edge)
示例#4
0
def exchange_test():
    private = PrivateKey().load(
        bytes.fromhex(
            "309368A4418E889426F4655235E3605DA3D9EF9F942727C76D32EBA3A5579E41")
    )
    public = PublicKey(
        bytes.fromhex(
            "436D986682B88E668F383B8D7155B8CB30FFC739EDA65E198D471087C596B17B")
    )
    shared = private.do_exchange(public)
    print(shared.hex())
示例#5
0
def curve25519GenerateKeyAgreement(privateKey, publicKey):
  exchangepartner = PrivateKey(privateKey)
  pubKey = PublicKey(publicKey) 
  return exchangepartner.do_exchange(pubKey)
示例#6
0
 def setUp(self):
     self.alice = PrivateKey(TVa)
     self.bob = PrivateKey(TVb)
示例#7
0
 def setUp(self):
     ''' Test __init__ and create Alice and Bob from TVa, TVb above.
     '''
     self.alice = PrivateKey(TVa)
     self.bob = PrivateKey(TVb)
示例#8
0
import socket
from donna25519 import PrivateKey
from donna25519 import PublicKey
import base64
import pickle

variable_1 = PrivateKey()
# se muestra la llave privada generada
print(variable_1)
variable_2 = PrivateKey().get_public().public

# se muestra la llave publica de 32 bytes correspondiente a la PrivateKey
print(variable_2)
pk = pickle.dumps(variable_2)

HOST = '127.0.0.1'  # Standard loopback interface address (localhost)
PORT = 65432  # Port to listen on (non-privileged ports are > 1023)

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    s.bind((HOST, PORT))
    s.listen()
    conn, addr = s.accept()
    with conn:
        print('Connected by', addr)
        while True:
            data = conn.recv(1024)
            if not data:
                break

            # se envía por medio del socket en bloque la llave publica de 32 bytes
            conn.sendall(pk)
p256_time = ecdh('secP256r1')
print("P256 time:", p256_time, "s")

p384_time = ecdh('secP384r1')
print("P384 time:", p384_time, "s")

p521_time = ecdh('secP521r1')
print("P521 time:", p521_time, "s")
print('=' * 30)
print()

# Curve 25519 ECDH
print('=' * 30)
print("Curve 25519 ECDH\n")
start = time.time()
sk_alice = PrivateKey(os.urandom(32))
pk_alice = sk_alice.get_public()
sk_bob = PrivateKey(os.urandom(32))
pk_bob = sk_bob.get_public()
alice_ss = sk_alice.do_exchange(pk_bob)
bob_ss = sk_bob.do_exchange(pk_alice)
elapsed_time = time.time() - start
print("Alice Shared Secret:", alice_ss)
print("Bob Shared Secret:", bob_ss)
print("Shared Secrets Equal:", bob_ss == alice_ss)
print("Time:", elapsed_time)
print('=' * 30)
print()

# ECDSA w/ NIST P512
print('=' * 30)
示例#10
0
def generation_exchange_test():
    private = PrivateKey()
    public = PublicKey(public=os.urandom(32))
    shared = private.do_exchange(public)
    print(shared.hex())
                                 10000,
                                 dklen=64)
        nuevosHashes.append(dk.hex())

    print(
        "\n\n Usando sha512 con 10000 rondas, se logro hashear las contraseñas en:\n ",
        time.clock() - t0)
    archivo = open("./NuevosHashes/sha3-512_" + str(resultado) + ".txt", "w")

    for hash in nuevosHashes:
        archivo.write(str(hash) + "\n")
    archivo.close()

HOST = '127.0.0.1'  # The server's hostname or IP address
PORT = 65432  # The port used by the server

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    s.connect((HOST, PORT))
    s.sendall(b'Hello, world')
    data = s.recv(1024)
    data = pickle.loads(data)

print('Datos recibidos: ', repr(data))

llavePublica = PublicKey(data)
llavePrivada = PrivateKey().do_exchange(llavePublica)
print("\n")
print(llavePublica)
print("\n")
print(llavePrivada)