-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
61 lines (32 loc) · 967 Bytes
/
main.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
from pycrypto import ecc_secp256k1 as ecc
from pycrypto.os import urandom_sw
from pycrypto import aes
import random
random.seed(0)
data = b"Hola un gusto saludarte"
"""
tag_len = 12
key = urandom_sw(32)
nonce = urandom_sw(12)
print(f"{key.hex()=} {nonce.hex()=}")
out = aes.ccm_encrypt(data, key, nonce, tag_len)
print(f"{out.hex()=}")
print(aes.ccm_decrypt(out, key, nonce, tag_len))
print()
out = aes.gcm_encrypt(data, key, nonce, tag_len)
print(f"{out.hex()=}")
print(aes.gcm_decrypt(out, key, nonce, tag_len))
"""
"""
key = urandom_sw(32)
iv = urandom_sw(16)
print(f"{key.hex()=} {iv.hex()=}")
out = aes.cbc_encrypt(data, key, iv)
print(f"{out.hex()=}")
print(aes.cbc_decrypt(out, key, iv))
"""
priv1, pub1 = ecc.ecdh_generate_keys(urandom_sw)
priv2, pub2 = ecc.ecdh_generate_keys(urandom_sw)
sig = ecc.ecdsa_sign_sha256(priv1, data)
print(f"{priv1.hex()=} {pub1.hex()=} {sig.hex()=}")
print(ecc.ecdsa_verify_sha256(pub1, sig, data))