forked from vstoykovbg/doubleslow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
doubleslow-external.py
65 lines (47 loc) · 1.99 KB
/
doubleslow-external.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
#!/usr/bin/python3
from Cryptodome.Util.RFC1751 import english_to_key
from Cryptodome.Util.RFC1751 import key_to_english
from hashlib import blake2b
from doubleslow_module import SlowKDF_stage_2
from doubleslow_module import print_security_warning
print_security_warning()
while True:
try:
words = input("RFC1751 words: ")
input_data_192_bits = english_to_key(words)
except ValueError as detail:
print(detail)
continue
the_length_of_the_input = len(input_data_192_bits)
if the_length_of_the_input != 24:
print("We expected 24 bytes, got", the_length_of_the_input, "instead. Can't continue.")
quit()
print ("\nThe word sequence looks valid. The hash is:\n\n", key_to_english(blake2b(input_data_192_bits,digest_size=8).digest()))
answer=input("\n\nPlease verify that the hash is correct and type \"yes\" to continue: ").lower()
if answer == "yes":
break
elif answer == "quit":
quit()
else:
continue
mymemory_stage_2 = int.from_bytes(input_data_192_bits[0:2], 'big')
iterations_stage_2 = int.from_bytes(input_data_192_bits[2:4], 'big')
input_digest = input_data_192_bits[4:]
print("\nThe settings encoded in the RFC1751 words are:")
print("Iterations: ", iterations_stage_2)
print("Memory usage: ", mymemory_stage_2, "MiB")
print("Please consider the memory usage. The computer should have enough free RAM.\n")
while True:
answer=input("Please type \"yes\" if you want to continue. ").lower()
if answer == "yes":
break
elif answer == "quit":
quit()
else:
print("Invalid response.")
continue
mymemory_stage_2 = mymemory_stage_2 * 1024 # MiB * 1024
digest_for_export_256_bits = SlowKDF_stage_2(input_digest, mymemory_stage_2, iterations_stage_2)
print ("\n\nRFC1751 words:\n\n", key_to_english(digest_for_export_256_bits))
print ("\n\nHash for detecting errors:\t", key_to_english(blake2b(digest_for_export_256_bits,digest_size=8).digest()))
print_security_warning()