-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpycryptodomex.py
executable file
·80 lines (68 loc) · 2.94 KB
/
pycryptodomex.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from Cryptodome.Hash import SHA256
from Cryptodome.PublicKey import ECC
from Cryptodome.Signature import DSS
from Cryptodome.PublicKey import RSA
from Cryptodome.Signature import pkcs1_15
import time
import numpy
def pycryptodome_ecdsa(count,loop):
ecc_key = ECC.generate(curve='P-256')
message = b'I give my permission to order #4355'
h = SHA256.new(message)
signer = DSS.new(ecc_key, 'fips-186-3')
time_list_sign = []
for l in range(loop):
start = time.time()
for c in range (count):
signature = signer.sign(h)
end = time.time() - start
# print("["+str(l)+"th pycryptodomex_ecdsa:sign second is "+ str(end) + "/"+str(count)+" signature")
time_list_sign.append(end)
ave_sign = numpy.mean(numpy.array(time_list_sign))
verifier = DSS.new(ecc_key, 'fips-186-3')
time_list_vrfy = []
for l in range(loop):
start = time.time()
for c in range (count):
try:
verifier.verify(h, signature)
except ValueError:
print ("The message is not authentiend")
end = time.time() - start
# print("["+str(l)+"th pycryptodomex_ecdsa:vrfy second is "+ str(end) + "/"+str(count)+" signature")
time_list_vrfy.append(end)
ave_vrfy = numpy.mean(numpy.array(time_list_vrfy))
print("pycryptodomex_ecdsa:sign average second is "+ str(ave_sign) + "/"+str(count)+" signature")
print("pycryptodomex_ecdsa:vrfy average second is "+ str(ave_vrfy) + "/"+str(count)+" signature")
return time_list_sign, time_list_vrfy
def pycryptodome_rsa(count, loop, keysize):
key = RSA.generate(keysize)
message = b'I give my permission to order #4355'
time_list_sign = []
for l in range(loop):
start = time.time()
for c in range (count):
h = SHA256.new(message)
signature = pkcs1_15.new(key).sign(h)
end = time.time() - start
# print("["+str(l)+"th pycryptodomex_ecdsa:sign second is "+ str(end) + "/"+str(count)+" signature")
time_list_sign.append(end)
ave_sign = numpy.mean(numpy.array(time_list_sign))
time_list_vrfy = []
for l in range(loop):
start = time.time()
for c in range(count):
try:
h = SHA256.new(message)
pkcs1_15.new(key).verify(h, signature)
except (ValueError, TypeError):
print ("The signature is not valid.")
end = time.time() - start
# print("["+str(l)+"th pycryptodomex_ecdsa:vrfy second is "+ str(end) + "/"+str(count)+" signature")
time_list_vrfy.append(end)
ave_vrfy = numpy.mean(numpy.array(time_list_vrfy))
print("pycryptodomex_rsa:sign average second is "+ str(ave_sign) + "/"+str(count)+" signature")
print("pycryptodomex_rsa:vrfy average second is "+ str(ave_vrfy) + "/"+str(count)+" signature")
return time_list_sign, time_list_vrfy
if __name__ == '__main__':
pycryptodome_ecdsa(1000,10)