File tree Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Original file line number Diff line number Diff line change 3
3
import hashlib
4
4
from binascii import hexlify , unhexlify
5
5
6
-
7
6
BLOCK_SIZE = AES .block_size # Bytes
8
7
9
8
salt = unhexlify ("3fb8877d37fdc04e4a4765EFb8ab7d36" )
@@ -19,25 +18,31 @@ class PaddingError(Exception):
19
18
def __init__ (self , message ):
20
19
self .message = message
21
20
21
+
22
22
pad = lambda s : s + ((BLOCK_SIZE - len (s ) % BLOCK_SIZE ) *
23
- chr (BLOCK_SIZE - len (s ) % BLOCK_SIZE )).encode ('utf-8' )
23
+ chr (BLOCK_SIZE - len (s ) % BLOCK_SIZE )).encode ('ascii' )
24
+
24
25
25
26
def unpad (s ):
26
27
in_len = len (s )
27
28
if in_len == 0 :
28
29
raise PaddingError ("empty input" )
29
30
pad_char = s [- 1 ]
30
- pad_len = ord (s [in_len - 1 :])
31
- if pad_len > BLOCK_SIZE :
31
+ if pad_char > BLOCK_SIZE :
32
32
raise PaddingError ("padding length > 16" )
33
- for i in s [in_len - pad_len :]:
33
+ for i in s [in_len - pad_char :]:
34
34
if i != pad_char :
35
35
raise PaddingError ("unexpected padding char" )
36
- return s [:- pad_len ]
36
+ return s [:- pad_char ]
37
37
38
38
39
39
# kdf does 2 times sha256 and takes the first 16 bytes
40
40
def kdf (raw_key ):
41
+ """
42
+ kdf does 2 times sha256 and takes the first 16 bytes
43
+ :param raw_key:
44
+ :return:
45
+ """
41
46
return hashlib .sha256 (hashlib .sha256 (raw_key + salt ).digest ()).digest ()[:16 ]
42
47
43
48
You can’t perform that action at this time.
0 commit comments