def test1(self):
        data = [('EB33F77EE73D4053', 'TIDE ITCH SLOW REIN RULE MOT'),
                ('CCAC2AED591056BE4F90FD441C534766',
                 'RASH BUSH MILK LOOK BAD BRIM AVID GAFF BAIT ROT POD LOVE'),
                ('EFF81F9BFBC65350920CDD7416DE8009',
                 'TROD MUTE TAIL WARM CHAR KONG HAAG CITY BORE O TEAL AWL')]

        for key_hex, words in data:
            key_bin = binascii.a2b_hex(key_hex)

            w2 = key_to_english(key_bin)
            self.assertEqual(w2, words)

            k2 = english_to_key(words)
            self.assertEqual(k2, key_bin)
Exemplo n.º 2
0
    print("\n\nRFC1751 words:\n\n", key_to_english(data_for_export_192_bits))

    print(
        "\n\nHash for detecting errors:\t",
        key_to_english(
            blake2b(data_for_export_192_bits, digest_size=8).digest()))

    print(
        "\nPlease run the doubleslow-external.py script on the powerful computer and enter the above RFC1751 words there. Then, write below the output from the doubleslow-external.py script. \n\n"
    )

    while True:
        try:
            words = input("RFC1751 words: ")
            digest_external = english_to_key(words)
        except ValueError as detail:
            print("Error: ", detail, "\n")
            print("Please write the correct word sequence.\n")
            continue

        if data_for_export_192_bits == digest_external:
            print("You should not enter the above words here.")
            print(
                "You should enter the above words where the doubleslow-external.py script is asking for them."
            )
            print(
                "You should enter the output from the doubleslow-external.py script below.\n"
            )
            continue
Exemplo n.º 3
0
def read_salt():
    mysalt_input = input("Please enter the salt in your desired format: ")

    mysalt_input_all_spaces_removed="".join(mysalt_input.split())

    try:
        print("Trying to interpret it like integer...")
        salt_int = int(mysalt_input_all_spaces_removed)
        mysalt = int_to_bytes(salt_int)
    except ValueError as detail:
        print("  It does not look like an integer.", detail)
    else:
        print("  Success!")
        print("  The number was:", salt_int)
        return mysalt

    try:
        print("Trying to interpret it like BIP39 mnemonic...")
        mysalt = mnemonic.Mnemonic('english').to_entropy(mysalt_input)
        mysalt = bytes(mysalt)
    except Exception as detail:
        print("  It does not look like a BIP39 mnemonic.", detail)
    else:
        print("  Success!")
        return mysalt

    try:
        print("Trying to interpret it like BIP39 mnemonic not formatted correctly...")
        # strip() fixes UX issue: do not recognize BIP39 mnemonic if whitespace is present at the beginning
        mysalt_input_corrected = " ".join(mysalt_input.lower().split())
        mysalt = mnemonic.Mnemonic('english').to_entropy(mysalt_input_corrected)
        mysalt = bytes(mysalt)
    except Exception as detail:
        print("  It does not look like a BIP39 mnemonic.", detail)
    else:
        print("  Success!")
        print("  The BIP39 mnemonic was:", mysalt_input_corrected)
        return mysalt

    try:
        print("Trying to interpret it like RFC1751 mnemonic...")
        mysalt = english_to_key(mysalt_input)
    except ValueError as detail:
        print("  It does not look like a RFC1751 mnemonic.", detail)
    else:
        print("  Success!")
        return mysalt

    try:
        print("Trying to interpret it like Base58 with a checksum...")
        mysalt = b58decode_check(mysalt_input_all_spaces_removed)
    except ValueError as detail:
        print("  It does not look like a Base58 with a checksum.", detail)
    else:
        print("  Success!")
        return mysalt

    try:
        print("Trying to interpret it like hexidecimal...")
        mysalt = binascii.a2b_hex(mysalt_input_all_spaces_removed)
    except ValueError as detail:
        print("  It does not look like a hexadecimal.", detail)
    else:
        print("  Success!")
        return mysalt

    try:
        print("Trying to interpret it like Base64 string...")
        mysalt = binascii.a2b_base64(mysalt_input_all_spaces_removed)
    except ValueError as detail:
        print("  It does not look like a Base64 string.", detail)
    else:
        looks_like = binascii.b2a_base64(mysalt, newline=False).decode("utf-8")
        if mysalt_input_all_spaces_removed == looks_like:
            print("  Success!")
            return mysalt
        else:
            print("  It looks like a Base64 string, but not exactly.")
            print("  Looks like: [", looks_like, "]")

    print("Normalizing the input string with NFKC...")
    mysalt = normalize('NFKC', mysalt_input)

    if mysalt == mysalt_input:
        print("The salt has not been changed by the NFKC normalization.")
    else:
        print("The salt has been changed by the NFKC normalization.")

    if mysalt != mysalt.strip():
        print ("* * * Warning! Your salt contains leading or trailing whitespace.")

    if mysalt.count('  ') >= 1:
        print ("* * * Warning! Your salt contains consecutive whitespaces.")

    if mysalt.count('\t') >= 1:
        print ("* * * Warning! Your salt contains one or more tabs.")

    return mysalt.encode()
Exemplo n.º 4
0
#!/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: "