aboutsummaryrefslogtreecommitdiffstats
path: root/lib/public_key/priv/convert.escript
diff options
context:
space:
mode:
authorHans Nilsson <[email protected]>2015-10-21 17:25:42 +0200
committerHans Nilsson <[email protected]>2015-11-04 12:10:06 +0100
commitc50a9a6562a14f3a9fbd2071e3b19eed8c9c9b4b (patch)
treee521160deb7797e1b2180eb31219ede9df877708 /lib/public_key/priv/convert.escript
parent4f085471fc4e1886bd7549cf135e7038a87e6a8e (diff)
downloadotp-c50a9a6562a14f3a9fbd2071e3b19eed8c9c9b4b.tar.gz
otp-c50a9a6562a14f3a9fbd2071e3b19eed8c9c9b4b.tar.bz2
otp-c50a9a6562a14f3a9fbd2071e3b19eed8c9c9b4b.zip
ssh, public_key: random selection of diffie-hellman moduli
Also tool (public_key:gen_moduli_hrl) to convert an openssh moduli file to erlang format.
Diffstat (limited to 'lib/public_key/priv/convert.escript')
-rwxr-xr-xlib/public_key/priv/convert.escript50
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/public_key/priv/convert.escript b/lib/public_key/priv/convert.escript
new file mode 100755
index 0000000000..c7ea48c686
--- /dev/null
+++ b/lib/public_key/priv/convert.escript
@@ -0,0 +1,50 @@
+#!/usr/bin/env escript
+%% -*- erlang -*-
+
+main([InFile,OutFile]) ->
+ {ok,In} = file:open(InFile,read),
+ {ok,Out} = file:open(OutFile,write),
+ write_file(Out, read_file(In)),
+ file:close(In),
+ file:close(Out).
+
+write_file(D, {ok,Ms}) ->
+ io:format(D,'-define(dh_default_groups,~n ~p~n ).~n',[Ms]).
+
+one_line(Line, Acc) when is_binary(Line) ->
+ one_line(binary_to_list(Line), Acc);
+one_line("#"++_, Acc) ->
+ Acc;
+one_line(Line, Acc) when is_list(Line) ->
+ try
+ [_Time,_Type,_Tests,_Tries,Size,G,P] = string:tokens(Line," \r\n"),
+ [{list_to_integer(Size),
+ {list_to_integer(G), list_to_integer(P,16)}
+ } | Acc]
+ catch
+ _:_ -> io:format("*** skip line ~p",[Line]),
+ Acc
+ end.
+
+
+collect_per_size(L) ->
+ lists:foldr(
+ fun({Sz,GP}, [{Sz,GPs}|Acc]) -> [{Sz,[GP|GPs]}|Acc];
+ ({Sz,GP}, Acc) -> [{Sz,[GP]}|Acc]
+ end, [], lists:sort(L)).
+
+
+read_file(D) ->
+ read_file(D, []).
+
+read_file(D, Acc) ->
+ case io:get_line(D,"") of
+ {error,Error} ->
+ {error,Error};
+ eof ->
+ {ok, collect_per_size(Acc)};
+ Data ->
+ read_file(D, one_line(Data,Acc))
+ end.
+
+