25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-20 17:27:00 +01:00

Get rid of compile warnings for random/crypto modules on R19

This commit is contained in:
Evgeniy Khramtsov 2016-10-18 08:17:21 +03:00
parent 90acec8a2b
commit 4c5460f0bd
11 changed files with 29 additions and 17 deletions

View 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},

View 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=",

View 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),

View 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 =

View 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 =

View 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 =

View 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,

View 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

View 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(

View 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">>,

View File

@ -27,14 +27,29 @@
-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.