diff options
author | Ingela Anderton Andin <[email protected]> | 2012-08-22 09:58:22 +0200 |
---|---|---|
committer | Ingela Anderton Andin <[email protected]> | 2012-08-22 14:00:47 +0200 |
commit | 8aa39bf90a213f086b8e4990e77570ddb6748496 (patch) | |
tree | b5f6e265a0b3711453fc04570f36551248862154 /lib/ssl/src/ssl.erl | |
parent | c9db6bc867ecf1bf581849dd3290b0c9a40e1961 (diff) | |
download | otp-8aa39bf90a213f086b8e4990e77570ddb6748496.tar.gz otp-8aa39bf90a213f086b8e4990e77570ddb6748496.tar.bz2 otp-8aa39bf90a213f086b8e4990e77570ddb6748496.zip |
ssl: Use crypto:strong_rand_bytes if possible
Diffstat (limited to 'lib/ssl/src/ssl.erl')
-rw-r--r-- | lib/ssl/src/ssl.erl | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/lib/ssl/src/ssl.erl b/lib/ssl/src/ssl.erl index 4372a147fa..40d933a256 100644 --- a/lib/ssl/src/ssl.erl +++ b/lib/ssl/src/ssl.erl @@ -31,7 +31,7 @@ controlling_process/2, listen/2, pid/1, peername/1, peercert/1, recv/2, recv/3, send/2, getopts/2, setopts/2, sockname/1, versions/0, session_info/1, format_error/1, - renegotiate/1, prf/5, clear_pem_cache/0]). + renegotiate/1, prf/5, clear_pem_cache/0, random_bytes/1]). -deprecated({pid, 1, next_major_release}). @@ -484,6 +484,23 @@ format_error(Error) -> Other end. +%%-------------------------------------------------------------------- +-spec random_bytes(integer()) -> binary(). + +%% +%% Description: Generates cryptographically secure random sequence if possible +%% fallbacks on pseudo random function +%%-------------------------------------------------------------------- +random_bytes(N) -> + try crypto:strong_rand_bytes(N) of + RandBytes -> + RandBytes + catch + error:low_entropy -> + crypto:rand_bytes(N) + end. + + %%%-------------------------------------------------------------- %%% Internal functions %%%-------------------------------------------------------------------- |