]> granicus.if.org Git - ejabberd/commitdiff
Get rid of compile warnings for random/crypto modules on R19
authorEvgeniy Khramtsov <ekhramtsov@process-one.net>
Tue, 18 Oct 2016 05:17:21 +0000 (08:17 +0300)
committerEvgeniy Khramtsov <ekhramtsov@process-one.net>
Tue, 18 Oct 2016 05:17:21 +0000 (08:17 +0300)
rebar.config
src/cyrsasl_scram.erl
src/ejabberd.erl
src/ejabberd_auth_mnesia.erl
src/ejabberd_auth_riak.erl
src/ejabberd_auth_sql.erl
src/ejabberd_s2s_out.erl
src/ejabberd_service.erl
src/extauth.erl
src/mod_echo.erl
src/randoms.erl

index 434c16af3d3bc5dca8861d9bce9224b4703d1dc4..27439109bfb5724ee10cd87604ae2458651ea33b 100644 (file)
@@ -71,6 +71,7 @@
             {if_var_match, db_type, mssql, {d, 'mssql'}},
             {if_var_true, elixir, {d, 'ELIXIR_ENABLED'}},
             {if_var_true, erlang_deprecated_types, {d, 'ERL_DEPRECATED_TYPES'}},
+           {if_version_above, "18", {d, 'STRONG_RAND_BYTES'}},
             {if_var_true, hipe, native},
             {src_dirs, [asn1, src,
                         {if_var_true, tools, tools},
index 18f52b48fe6b06d272c889bf730f062385fbbf1a..1c464e12107f41a140a80a43b51eedecb05d0764 100644 (file)
@@ -87,7 +87,7 @@ mech_step(#state{step = 2} = State, ClientIn) ->
                                      if is_tuple(Ret) -> Ret;
                                         true ->
                                             TempSalt =
-                                                crypto:rand_bytes(?SALT_LENGTH),
+                                                randoms:bytes(?SALT_LENGTH),
                                             SaltedPassword =
                                                 scram:salted_password(Ret,
                                                                       TempSalt,
@@ -101,7 +101,7 @@ mech_step(#state{step = 2} = State, ClientIn) ->
                                      str:substr(ClientIn,
                                                  str:str(ClientIn, <<"n=">>)),
                                  ServerNonce =
-                                     jlib:encode_base64(crypto:rand_bytes(?NONCE_LENGTH)),
+                                     jlib:encode_base64(randoms:bytes(?NONCE_LENGTH)),
                                  ServerFirstMessage =
                                         iolist_to_binary(
                                           ["r=",
index 6bd2422aecf3000f004e50913fda34cf7c191a55..5a6fc64d7491bd082a84b642d8851e8d61caaa93 100644 (file)
@@ -105,8 +105,6 @@ start_app([], _Type, _StartFlag) ->
     ok.
 
 check_app_modules(App, StartFlag) ->
-    {A, B, C} = p1_time_compat:timestamp(),
-    random:seed(A, B, C),
     sleep(5000),
     case application:get_key(App, modules) of
         {ok, Mods} ->
@@ -140,7 +138,7 @@ exit_or_halt(Reason, StartFlag) ->
     end.
 
 sleep(N) ->
-    timer:sleep(random:uniform(N)).
+    timer:sleep(randoms:uniform(N)).
 
 get_module_file(App, Mod) ->
     BaseName = atom_to_list(Mod),
index 2a4554d1573c02c7b3913e44e9e17582cae8fd0f..f36c9fbc7b4b50d3003bb7cf24a9eaab8a7e8ef4 100644 (file)
@@ -450,7 +450,7 @@ password_to_scram(Password) ->
                      ?SCRAM_DEFAULT_ITERATION_COUNT).
 
 password_to_scram(Password, IterationCount) ->
-    Salt = crypto:rand_bytes(?SALT_LENGTH),
+    Salt = randoms:bytes(?SALT_LENGTH),
     SaltedPassword = scram:salted_password(Password, Salt,
                                           IterationCount),
     StoredKey =
index c74f1b28ebbf85aa0b49c284ea2310524a8778df..05add262e0ed5302ba31aa23517379bea245e2a9 100644 (file)
@@ -270,7 +270,7 @@ password_to_scram(Password) ->
                      ?SCRAM_DEFAULT_ITERATION_COUNT).
 
 password_to_scram(Password, IterationCount) ->
-    Salt = crypto:rand_bytes(?SALT_LENGTH),
+    Salt = randoms:bytes(?SALT_LENGTH),
     SaltedPassword = scram:salted_password(Password, Salt,
                                           IterationCount),
     StoredKey =
index d6d945e02164af86ca88b49d225eaec03cb61684..93dac4f4fe7a5edf5ac3b1bf11c72a791aea644a 100644 (file)
@@ -406,7 +406,7 @@ password_to_scram(Password) ->
                      ?SCRAM_DEFAULT_ITERATION_COUNT).
 
 password_to_scram(Password, IterationCount) ->
-    Salt = crypto:rand_bytes(?SALT_LENGTH),
+    Salt = randoms:bytes(?SALT_LENGTH),
     SaltedPassword = scram:salted_password(Password, Salt,
                                           IterationCount),
     StoredKey =
index a30f2f438d0f3c7ece331cbc342a2bf888c0038c..ae3433a6a4160be2a4a51cc2a2b2edbea1b2bb24 100644 (file)
@@ -1099,13 +1099,12 @@ get_addr_port(Server) ->
          ?DEBUG("srv lookup of '~s': ~p~n",
                 [Server, HEnt#hostent.h_addr_list]),
          AddrList = HEnt#hostent.h_addr_list,
-         random:seed(p1_time_compat:timestamp()),
          case catch lists:map(fun ({Priority, Weight, Port,
                                     Host}) ->
                                       N = case Weight of
                                             0 -> 0;
                                             _ ->
-                                                (Weight + 1) * random:uniform()
+                                                (Weight + 1) * randoms:uniform()
                                           end,
                                       {Priority * 65536 - N, Host, Port}
                               end,
index 9dd7c831e68e9350336ea0ff645d32a53d95e83e..26374c1f12abe592e21b4aa877b5b483727124a8 100644 (file)
@@ -135,13 +135,13 @@ init([{SockMod, Socket}, Opts]) ->
                         fun({H, Os}, D) ->
                                 P = proplists:get_value(
                                       password, Os,
-                                      p1_sha:sha(crypto:rand_bytes(20))),
+                                      p1_sha:sha(randoms:bytes(20))),
                                 dict:store(H, P, D)
                         end, dict:new(), HOpts);
                   false ->
                       Pass = proplists:get_value(
                                password, Opts,
-                               p1_sha:sha(crypto:rand_bytes(20))),
+                               p1_sha:sha(randoms:bytes(20))),
                       dict:from_list([{global, Pass}])
               end,
     %% privilege access to entities data
index 50330b47b33340368bcb5c38c9dfd24bf450d6e9..6063d3670c83f7a88b4b7546cf7d3da030e718a8 100644 (file)
@@ -102,8 +102,7 @@ call_port(Server, Msg) ->
     receive {eauth, Result} -> Result end.
 
 random_instance(MaxNum) ->
-    random:seed(p1_time_compat:timestamp()),
-    random:uniform(MaxNum) - 1.
+    randoms:uniform(MaxNum) - 1.
 
 get_instances(Server) ->
     ejabberd_config:get_option(
index 96651aebfe8d52ebf10619dea9b1120446e852c9..da3f5cf0f07cb5e14e94bd48d277b53c4e359b3a 100644 (file)
@@ -172,7 +172,7 @@ do_client_version(disabled, _From, _To) -> ok;
 do_client_version(enabled, From, To) ->
     ToS = jid:to_string(To),
     Random_resource =
-       iolist_to_binary(integer_to_list(random:uniform(100000))),
+       iolist_to_binary(integer_to_list(randoms:uniform(100000))),
     From2 = From#jid{resource = Random_resource,
                     lresource = Random_resource},
     Packet = #xmlel{name = <<"iq">>,
index 52fceef4e61471d38a01582b0ee4c3c5108447b3..75bc280a2805139c62fd995090a70bdf9b6eeaec 100644 (file)
 
 -author('alexey@process-one.net').
 
--export([get_string/0]).
+-export([get_string/0, uniform/0, uniform/1, bytes/1]).
 
 -export([start/0]).
 
+-define(THRESHOLD, 16#10000000000000000).
+
 start() ->
     ok.
 
 get_string() ->
-    R = crypto:rand_uniform(0, 16#10000000000000000),
+    R = crypto:rand_uniform(0, ?THRESHOLD),
     jlib:integer_to_binary(R).
 
+uniform() ->
+    crypto:rand_uniform(0, ?THRESHOLD)/?THRESHOLD.
+
+uniform(N) ->
+    crypto:rand_uniform(0, N).
+
+-ifdef(STRONG_RAND_BYTES).
+bytes(N) ->
+    crypto:strong_rand_bytes(N).
+-else.
+bytes(N) ->
+    crypto:rand_bytes(N).
+-endif.