Derives the correct (final) master key from the password and/or keyfile and
    sepcified transform seed & num rounds.

def derive_key(seed_key, seed_rand, rounds, password=None, keyfile=None):
    """
    Derives the correct (final) master key from the password and/or keyfile and
    sepcified transform seed & num rounds.
    """
    if password == '': password = None
    if keyfile == '': keyfile = None
    if password is None and keyfile is None:
        raise ValueError("Password and/or keyfile is required.")
        
    if password is None:
        masterkey = key_from_keyfile(keyfile)
    elif password and keyfile:
        passwordkey = key_from_password(password)
        filekey = key_from_keyfile(keyfile)
        sha = SHA256.new()
        sha.update(passwordkey + filekey)
        masterkey = sha.digest()
    else:
        masterkey = key_from_password(password)

    # Create the key that is needed to...
    final_key = transform_key(masterkey, seed_key=seed_key, seed_rand=seed_rand, rounds=rounds)
    
    return final_key