示例#1
0
def test_generation_perf(n=100):
    results = OrderedDict()
    for bits in (192, 224, 256, 384, 521):
        t = time.time()
        for i in xrange(n):
            k = Key.generate(bits)
        t = time.time() - t
        results[bits] = t
    return results
示例#2
0
def test_signing_perf(n=100):
    results = OrderedDict()
    for bits in (192, 224, 256, 384, 521):
        k = Key.generate(bits)
        t = time.time()
        for i in xrange(n):
            k.sign('random string')
        t = time.time() - t
        results[bits] = t
    return results
    idB = '00000002'
    token = 0

    # TCP connection to responder B
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.setblocking(1)
    print('begin connection')
    sock.connect((server_ip, server_port))

    try:
        while (token == 0):
            print('connection up')
            print('connected')
            # 1. A send M1=(PKax,PKay) to B
            time1 = time.time()
            keypair = Key.generate(192)
            PKax = keypair._pub[1][0]
            PKay = keypair._pub[1][1]
            PKa = (PKax, PKay)
            SKa = keypair._priv[1]
            time2 = time.time()

            M1 = str(PKax) + ',' + str(PKay)
            sock.send(M1.encode())

            # 3. A receive M2, send Na
            M2 = sock.recv(1024).decode()
            PKbx = M2.split(',')[0]
            PKby = M2.split(',')[1]
            cb = M2.split(',')[2]
            PKb = (int(PKbx), int(PKby))
示例#4
0
    print('Listen to the connection from client...')
    sock.listen(5)
    try:
        while (token == 0):
            connection, address = sock.accept()
            print('Connected. Got connection from ', address)

            # 2. B side: 1)receive M1 from A, 2)generate my keypair 3) send M2
            # 2.1) receive M1=(helloA,PKax,PKay) from A
            M1 = connection.recv(1024).decode()
            helloA = M1.split(',')[0]
            PKax = M1.split(',')[1]
            PKay = M1.split(',')[2]
            PKa = (int(PKax), int(PKay))
            # 2.2) generate my keypair
            keypair = Key.generate(256)
            PKbx = keypair._pub[1][0]
            PKby = keypair._pub[1][1]
            SKb = keypair._priv[1]
            # 2.3) B->A: M2=(helloB,PKbx,PKby)
            M2 = 'helloB' + ',' + str(PKbx) + ',' + str(PKby)
            connection.send(M2.encode())

            # 4. B side: 1) receive M3 from A 2) verify ecdsa signature sa 3) compute ecdsa signature sb 4)send M4
            # 4.1) receive M3=sa from A
            M3 = connection.recv(1024).decode()
            sa_0 = M3.split(',')[0]
            sa_1 = M3.split(',')[1]
            sa = (int(sa_0), int(sa_1))
            # 4.2) verify sa
            hstringa = helloA + str(PKax) + str(PKay)
示例#5
0
    print('Listen to the connection from client...')
    sock.listen(5)
    try:
        while (token==0):
            connection, address = sock.accept()
            print('Connected. Got connection from ', address)

            # 2. B receive M1 from A,generate my keypair, generate Nb, compute Cb, send M2
            M1 = connection.recv(1024).decode()
            PKax= M1.split(',')[0]
            PKay = M1.split(',')[1]
            PKa = (int(PKax), int(PKay))

            time1 = time.time()
            keypair = Key.generate(521)
            PKbx = keypair._pub[1][0]
            PKby = keypair._pub[1][1]
            SKb = keypair._priv[1]

            # generate random number Rb1
            Rb1 = random.randint(10000000, 999999999)
            # calculate random number Rb2
            Rb2 = SKb - Rb1

            # calculate the same shared key
            Kb1 = mul(c_p, c_q, c_n, PKa, Rb1)
            Kb2 = mul(c_p, c_q, c_n, PKa, Rb2)
            Kb = add(c_p, c_q, c_n, Kb1, Kb2)

            Nb = random.randint(000000,999999)