anchor.diff:              %%ct:log("~p:~p return Other ~p ~ts", [?MODULE,?LINE,Other,DirPath]),
               Other
       end.
  +
  +%%%----------------------------------------------------------------
  +%%% New
  +
  +setup_all_user_host_keys(Config) ->
  +    DataDir = proplists:get_value(data_dir, Config),
  +    PrivDir = proplists:get_value(priv_dir, Config),
  +    setup_all_user_host_keys(DataDir, PrivDir).
  +
  +setup_all_user_host_keys(DataDir, PrivDir) ->
  +    setup_all_user_host_keys(DataDir, PrivDir, filename:join(PrivDir,"system")).
  +
  +setup_all_user_host_keys(DataDir, UserDir, SysDir) ->
  +    lists:foldl(fun(Alg, OkAlgs) ->
  +                        try
  +                            ok = ssh_test_lib:setup_user_key(Alg, DataDir, UserDir),
  +                            ok = ssh_test_lib:setup_host_key(Alg, DataDir, SysDir)
  +                        of
  +                            ok -> [Alg|OkAlgs]
  +                        catch
  +                            error:{badmatch, {error,enoent}} ->
  +                                OkAlgs;
  +                            C:E:S ->
  +                                ct:log("Exception in ~p:~p for alg ~p:  ~p:~p~n~p",
  +                                       [?MODULE,?FUNCTION_NAME,Alg,C,E,S]),
  +                                OkAlgs
  +                        end
  +                end, [], ssh_transport:supported_algorithms(public_key)).
  +
  +
  +setup_all_host_keys(Config) ->
  +    DataDir = proplists:get_value(data_dir, Config),
  +    PrivDir = proplists:get_value(priv_dir, Config),
  +    setup_all_host_keys(DataDir, filename:join(PrivDir,"system")).
  +
  +setup_all_host_keys(DataDir, SysDir) ->
  +    lists:foldl(fun(Alg, OkAlgs) ->
  +                        try
  +                            ok = ssh_test_lib:setup_host_key(Alg, DataDir, SysDir)
  +                        of
  +                            ok -> [Alg|OkAlgs]
  +                        catch
  +                            error:{badmatch, {error,enoent}} ->
  +                                OkAlgs;
  +                            C:E:S ->
  +                                ct:log("Exception in ~p:~p for alg ~p:  ~p:~p~n~p",
  +                                       [?MODULE,?FUNCTION_NAME,Alg,C,E,S]),
  +                                OkAlgs
  +                        end
  +                end, [], ssh_transport:supported_algorithms(public_key)).
  +
  +setup_user_key(SshAlg, DataDir, UserDir) ->
  +    file:make_dir(UserDir),
  +    %% Copy private user key to user's dir
  +    {ok,_} = file:copy(filename:join(DataDir, file_base_name(user_src,SshAlg)),
  +                       filename:join(UserDir, file_base_name(user,SshAlg))),
  +    %% Setup authorized_keys in user's dir
  +    {ok,Pub} = file:read_file(filename:join(DataDir, file_base_name(user_src,SshAlg)++".pub")),
  +    ok = file:write_file(filename:join(UserDir, "authorized_keys"),
  +                         io_lib:format("~n~s~n",[Pub]),
  +                         [append]).
  +
  +setup_host_key_create_dir(SshAlg, DataDir, BaseDir) ->
  +    SysDir = filename:join(BaseDir,"system"),
  +    ct:log("~p:~p  SshAlg=~p~nDataDir = ~p~nBaseDir = ~p~nSysDir = ~p",[?MODULE,?LINE,SshAlg, DataDir, BaseDir,SysDir]),
  +    file:make_dir(SysDir),
  +    setup_host_key(SshAlg, DataDir, SysDir),
  +    SysDir.
  +
  +setup_host_key(SshAlg, DataDir, SysDir) ->
  +    mk_dir_path(SysDir),
  +    %% Copy private host key to system's dir
  +    {ok,_} = file:copy(filename:join(DataDir, file_base_name(system_src,SshAlg)),
  +                       filename:join(SysDir,  file_base_name(system,SshAlg))),
  +    ok.
  +
  +setup_known_host(SshAlg, DataDir, UserDir) ->
  +    {ok,Pub} = file:read_file(filename:join(DataDir, file_base_name(system_src,SshAlg)++".pub")),
  +    S = lists:join(" ", lists:reverse(tl(lists:reverse(string:tokens(binary_to_list(Pub), " "))))),
  +    file:write_file(filename:join(UserDir, "known_hosts"),
  +                    io_lib:format("~p~n",[S])).
  +
  +get_addr_str() ->
  +    {ok, Hostname} = inet:gethostname(),
  +    {ok, {A, B, C, D}} = inet:getaddr(Hostname, inet),
  +    IP = lists:concat([A, ".", B, ".", C, ".", D]),
  +    lists:concat([Hostname,",",IP]).
  +
  +
  +file_base_name(user,   'ecdsa-sha2-nistp256') -> "id_ecdsa";
  +file_base_name(user,   'ecdsa-sha2-nistp384') -> "id_ecdsa";
  +file_base_name(user,   'ecdsa-sha2-nistp521') -> "id_ecdsa";
  +file_base_name(user,   'rsa-sha2-256'       ) -> "id_rsa";
  +file_base_name(user,   'rsa-sha2-384'       ) -> "id_rsa";
  +file_base_name(user,   'rsa-sha2-512'       ) -> "id_rsa";
  +file_base_name(user,   'ssh-dss'            ) -> "id_dsa";
  +file_base_name(user,   'ssh-ed25519'        ) -> "id_ed25519";
  +file_base_name(user,   'ssh-ed448'          ) -> "id_ed448";
  +file_base_name(user,   'ssh-rsa'            ) -> "id_rsa";
  +
  +file_base_name(user_src, 'ecdsa-sha2-nistp256') -> "id_ecdsa256";
  +file_base_name(user_src, 'ecdsa-sha2-nistp384') -> "id_ecdsa384";
  +file_base_name(user_src, 'ecdsa-sha2-nistp521') -> "id_ecdsa521";
  +file_base_name(user_src, Alg) -> file_base_name(user, Alg);
  +
  +file_base_name(system, 'ecdsa-sha2-nistp256') -> "ssh_host_ecdsa_key";
  +file_base_name(system, 'ecdsa-sha2-nistp384') -> "ssh_host_ecdsa_key";
  +file_base_name(system, 'ecdsa-sha2-nistp521') -> "ssh_host_ecdsa_key";
  +file_base_name(system, 'rsa-sha2-256'       ) -> "ssh_host_rsa_key";
  +file_base_name(system, 'rsa-sha2-384'       ) -> "ssh_host_rsa_key";
  +file_base_name(system, 'rsa-sha2-512'       ) -> "ssh_host_rsa_key";
  +file_base_name(system, 'ssh-dss'            ) -> "ssh_host_dsa_key";
  +file_base_name(system, 'ssh-ed25519'        ) -> "ssh_host_ed25519_key";
  +file_base_name(system, 'ssh-ed448'          ) -> "ssh_host_ed448_key";
  +file_base_name(system, 'ssh-rsa'            ) -> "ssh_host_rsa_key";
  +
  +file_base_name(system_src, 'ecdsa-sha2-nistp256') -> "ssh_host_ecdsa_key256";
  +file_base_name(system_src, 'ecdsa-sha2-nistp384') -> "ssh_host_ecdsa_key384";
  +file_base_name(system_src, 'ecdsa-sha2-nistp521') -> "ssh_host_ecdsa_key521";
  +file_base_name(system_src, Alg) -> file_base_name(system, Alg).
  +
  +%%%----------------------------------------------------------------
  
positive.code:     KnownHostsEnc = public_key:ssh_encode(KnownHosts, known_hosts),
      KHFile = filename:join(UserDir, "known_hosts"),
      file:write_file(KHFile, KnownHostsEnc).
  
  setup_dsa_auth_keys(Dir, UserDir) ->
      {ok, Pem} = file:read_file(filename:join(Dir, "id_dsa")),
      DSA = public_key:pem_entry_decode(hd(public_key:pem_decode(Pem))),
      PKey = DSA#'DSAPrivateKey'.y,
      P = DSA#'DSAPrivateKey'.p,
      Q = DSA#'DSAPrivateKey'.q,
      G = DSA#'DSAPrivateKey'.g,
      Dss = #'Dss-Parms'{p=P, q=Q, g=G},
      setup_auth_keys([{{PKey, Dss}, [{comment, "Test"}]}], UserDir).
  
  setup_rsa_auth_keys(Dir, UserDir) ->
      {ok, Pem} = file:read_file(filename:join(Dir, "id_rsa")),
      RSA = public_key:pem_entry_decode(hd(public_key:pem_decode(Pem))),
      #'RSAPrivateKey'{publicExponent = E, modulus = N} = RSA,
      PKey = #'RSAPublicKey'{publicExponent = E, modulus = N},
      setup_auth_keys([{ PKey, [{comment, "Test"}]}], UserDir).
  
  setup_ecdsa_auth_keys(Size, Dir, UserDir) ->
      {ok, Pem} =
          case file:read_file(F=filename:join(Dir, "id_ecdsa"++Size)) of
              {error,E} ->
                  ct:log("Failed (~p) to read ~p~nFiles: ~p", [E,F,file:list_dir(Dir)]),
                  file:read_file(filename:join(Dir, "id_ecdsa"));
              Other ->
                  Other
          end,
      ECDSA = public_key:pem_entry_decode(hd(public_key:pem_decode(Pem))),
      #'ECPrivateKey'{publicKey = Q,
  		    parameters = Param = {namedCurve,_Id0}} = ECDSA,
      PKey = #'ECPoint'{point = Q},
      setup_auth_keys([{ {PKey,Param}, [{comment, "Test"}]}], UserDir).
  
  setup_eddsa_auth_keys(Alg, Dir, UserDir) ->
      SshAlg = case Alg of
                   ed25519 -> 'ssh-ed25519';
                   ed448 -> 'ssh-ed448'
               end,
      {ok, {ed_pri,Alg,Pub,_}} = ssh_file:user_key(SshAlg, [{user_dir,Dir}]),
      setup_auth_keys([{{ed_pub,Alg,Pub}, [{comment, "Test"}]}], UserDir).
  
  setup_auth_keys(Keys, Dir) ->
      AuthKeys = public_key:ssh_encode(Keys, auth_keys),
  
negative.code: 	    file:rename(B, KnownHosts)
      end.
  
  setup_all_known_hosts(SystemDir, UserDir) ->
      PubKeys =
          lists:map(fun(Name) ->
                            {ok, SshBin} = file:read_file(filename:join(SystemDir, Name)), 
                            [{Key, _}] = public_key:ssh_decode(SshBin, public_key),
                            Key
                    end, filelib:wildcard("*.pub", SystemDir)),
      lists:foldl(
        fun(Key, Acc) ->
                case setup_known_hosts(Key,UserDir) of
                    ok -> Acc;
                    Other -> Other
                end
        end, ok, PubKeys).
  
  
  setup_known_hosts(Key, UserDir) ->
      {ok, Hostname} = inet:gethostname(),
  