-
Notifications
You must be signed in to change notification settings - Fork 0
/
boost_python.py
120 lines (89 loc) · 1.88 KB
/
boost_python.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# coding: utf-8
# In[1]:
from tls_crypt import *
def str2list(s) :
r = []
for c in s: r.append(ord(c))
return r
def add_padding(l):
padding = 15 - len(l) % 16
for i in range(padding + 1): l.append(padding)
return l
def remove_padding(l):
padding = l[-1] + 1
for i in range(padding): l.pop()
return l
def list2str(l) :
r = ''
for c in l: r += chr(c)
return r
def hex2list(s):
assert len(s) % 16 == 0
l = []
str = ''
for c in s:
str += c
if len(str) == 2:
l.append(int(str, 16))
str = ''
return l
aes = AES()
client_key = 0x231a650ecfc578bea4b0467adaab33c2
server_key = 0x45ec5fe99527a6f2c9c3889fcd2e65c1
msg = '1400000c48037b71499792961515c436f4c6330f8748593625435272724d39632cdf4c060b0b0b0b0b0b0b0b0b0b0b0b'
iv = 0x4c63014c671a8bae25b22def0f57ce79
aes.key(server_key)
aes.iv(iv)
enc = aes.encrypt(hex2list(msg))
print enc
dec = aes.decrypt(enc)
print dec
#'e4228485b936b34af05bcb0e3aabd962206ad5f954708a1c901106dd9dd05de44408a5b9d376a437c399d144cc80990c'
#print hexdump(s)
# <h2>AES</h2>
# In[2]:
s = 'hello world'
print s
s = str2list(s)
print s
add_padding(s)
print s
s = aes.encrypt(s)#should be multiple of 16
print s
s = aes.decrypt(s)
print s
remove_padding(s)
print s
s = list2str(s)
print s
# <h2>Base64</h2>
# In[3]:
s = 'message to encode'
print s
s = str2list(s)
print s
s = base64_encode(s)
print s
s = base64_decode(s)
print s
s = list2str(s)
print s
# <h2>SHA hash & pem file read</h2>
# In[4]:
sha = SHA1()
print sha.hash(str2list(s))
sha = SHA256()
print sha.hash(str2list(s))
sha = SHA512()
print sha.hash(str2list(s))
mac = HMAC()
mac.key(str2list(s))
print mac.hash(str2list(s))
jv = eval (pem2json('../dndd2/cert.pem'))
print jv
# In[10]:
prf = PRF()
prf.label('client finished')
prf.seed(str2list(s))
prf.secret(str2list(s))
print [i for i in prf.get_n_byte(40)]