Exemplo n.º 1
0
    def encrypt(cls, data, key):
        validate_key_size(key, cls.key_size, "XSalsa20")

        iv = rndfile.read(cls.iv_size)
        ciphertext = salsa20.XSalsa20_xor(data, iv, key)

        return iv + ciphertext
Exemplo n.º 2
0
    def decrypt(cls, data, key):
        if len(key) != cls.key_size:
            raise TripleSecFailedAssertion(u"Wrong XSalsa20 key size")

        iv = data[:cls.iv_size]

        return salsa20.XSalsa20_xor(data[cls.iv_size:], iv, key)
Exemplo n.º 3
0
    def encrypt(cls, data, key):
        if len(key) != cls.key_size:
            raise TripleSecFailedAssertion(u"Wrong XSalsa20 key size")

        iv = rndfile.read(cls.iv_size)

        ciphertext = salsa20.XSalsa20_xor(data, iv, key)
        return iv + ciphertext
Exemplo n.º 4
0
    def decrypt(cls, data, key, reverse_endianness=False):
        validate_key_size(key, cls.key_size, "XSalsa20")
        if reverse_endianness:
            key = word_byteswap(key)

        iv = data[:cls.iv_size]
        if reverse_endianness:
            iv = word_byteswap(iv)

        return salsa20.XSalsa20_xor(data[cls.iv_size:], iv, key)
Exemplo n.º 5
0
    def encrypt(cls, data, key, iv_data, reverse_endianness=False):
        validate_key_size(key, cls.key_size, "XSalsa20")
        if reverse_endianness:
            key = word_byteswap(key)

        iv = iv_data
        if reverse_endianness:
            iv = word_byteswap(iv)
        ciphertext = salsa20.XSalsa20_xor(data, iv, key)
        if reverse_endianness:
            iv = word_byteswap(iv)

        return iv + ciphertext
Exemplo n.º 6
0
def decrypt_key(encrypted_keyinput, password):
    """
    Uses the output of the decode_backup_code function as input, extracts the salt, derives the key_decryption_key using the salt and the user-provided password and finally decrypts the private key (incl. all other encoded information)
    """
    salt = encrypted_keyinput[:8]
    ciphertext = encrypted_keyinput[8:]

    key_decryption_key = derive_key_decryption_key(password, salt)
    logger.info("[decrypt_key] derived key_decryption_key: %s",
                repr(key_decryption_key))

    decrypted_keyinfo = salsa20.XSalsa20_xor(ciphertext, "\x00" * 24,
                                             key_decryption_key)

    return decrypted_keyinfo
Exemplo n.º 7
0
    def decrypt(cls, data, key):
        validate_key_size(key, cls.key_size, "XSalsa20")

        iv = data[:cls.iv_size]

        return salsa20.XSalsa20_xor(data[cls.iv_size:], iv, key)