コード例 #1
0
ファイル: RecvModule.py プロジェクト: 0-1CxH/Digital-Envelope
def veritfyANumber(numeric_to_verify, sign_r, sign_s, sender_ecc_pubkey):
    return ecdsa.verify(numeric_to_verify, (sign_r, sign_s), sender_ecc_pubkey)
コード例 #2
0
 def verify(self, data, sig, hashfunc='sha256'):
     '''Verify the signature of data using the specified hash function'''
     h = dec_long(hashlib.new(hashfunc, data).digest())
     s = dec_point(sig)
     return ecdsa.verify(h, s, self._pub)
コード例 #3
0
            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)
            md5a = md5()
            md5a.update(hstringa.encode())
            ha = md5a.hexdigest()[8:-8]
            ha = int(ha, 16)
            if verify(ha, sa, (256, (int(PKax), int(PKay)))) == True:
                Kb = mul(c_p, c_q, c_n, PKa, SKb)
                # 4.3) compute sb
                hstringb = 'helloB' + str(PKbx) + str(PKby)
                md5b = md5()
                md5b.update(hstringb.encode())
                hb = md5b.hexdigest()[8:-8]
                hb = int(hb, 16)
                sb = sign(hb, (256, int(SKb)))
                # 4.4) send M4
                M4 = str(sb[0]) + ',' + str(sb[1])
                connection.send(M4.encode())
                print('signature of client is valid')
                print('the shared secrety is', Kb)
            else:
                print('signature of client is invalid, protocol fails')
コード例 #4
0
ファイル: ecdsa_demo.py プロジェクト: 0-1CxH/Digital-Envelope
from ecc import ecdsa, Key

ECC_keylen = 192
ecc_key = Key.Key.generate(ECC_keylen)

ecc_pubkey = ecc_key._pub
print ecc_pubkey
print type(ecc_pubkey)
ecc_privkey = ecc_key._priv
print ecc_privkey

numeric_to_sign = 0x882da7b

sign_r, sign_s = ecdsa.sign(numeric_to_sign, ecc_privkey)
print sign_r, sign_s
res = ecdsa.verify(numeric_to_sign, (sign_r, sign_s), ecc_pubkey)
print res