From 0f79e3f3d95fd8f04e3893e50c9f27b9e04c2c7e Mon Sep 17 00:00:00 2001
From: Raimo Niskanen
Date: Thu, 13 Sep 2018 15:26:24 +0200
Subject: Use long period counter for crypto_aes
Conflicts:
lib/crypto/doc/src/crypto.xml
lib/crypto/src/crypto.erl
---
lib/crypto/doc/src/crypto.xml | 110 +++++++++++++++++++++++++++++++++++++++---
1 file changed, 102 insertions(+), 8 deletions(-)
(limited to 'lib/crypto/doc')
diff --git a/lib/crypto/doc/src/crypto.xml b/lib/crypto/doc/src/crypto.xml
index 3fd99be5b6..c21aec50fe 100644
--- a/lib/crypto/doc/src/crypto.xml
+++ b/lib/crypto/doc/src/crypto.xml
@@ -1,4 +1,3 @@
-
@@ -905,7 +904,8 @@ _FloatValue = rand:uniform(). % [0.0; 1.0[
Creates state object for
random number generation,
- in order to generate cryptographically strong random numbers.
+ in order to generate cryptographically strong random numbers,
+ and saves it in the process dictionary before returning it as well.
See also
rand:seed/1 and
rand_seed_alg_s/1.
@@ -916,12 +916,6 @@ _FloatValue = rand:uniform(). % [0.0; 1.0[
may raise exception error:low_entropy in case the random generator
failed due to lack of secure "randomness".
-
- The cache size can be changed from its default value using the
-
- crypto app's
- configuration parameter rand_cache_size.
-
Example
_ = crypto:rand_seed_alg(crypto_cache),
@@ -930,6 +924,34 @@ _FloatValue = rand:uniform(). % [0.0; 1.0[
+
+ rand_seed_alg(Alg, Seed) -> rand:state()
+ Strong random number generation plugin state
+
+ Alg = crypto_aes
+
+
+
+
+ Creates a state object for
+ random number generation,
+ in order to generate cryptographically unpredictable random numbers,
+ and saves it in the process dictionary before returning it as well.
+ See also
+ rand_seed_alg_s/2.
+
+ Example
+
+_ = crypto:rand_seed_alg(crypto_aes, "my seed"),
+IntegerValue = rand:uniform(42), % [1; 42]
+FloatValue = rand:uniform(), % [0.0; 1.0[
+_ = crypto:rand_seed_alg(crypto_aes, "my seed"),
+IntegerValue = rand:uniform(42), % Same values
+FloatValue = rand:uniform(). % again
+
+
+
+
rand_seed_alg_s(Alg) -> rand:state()
Strong random number generation plugin state
@@ -967,6 +989,12 @@ _FloatValue = rand:uniform(). % [0.0; 1.0[
crypto app's
configuration parameter rand_cache_size.
+
+ When using the state object from this function the
+ rand functions using it
+ may throw exception low_entropy in case the random generator
+ failed due to lack of secure "randomness".
+
The state returned from this function cannot be used
@@ -988,6 +1016,72 @@ _FloatValue = rand:uniform(). % [0.0; 1.0[
+
+ rand_seed_alg_s(Alg, Seed) -> rand:state()
+ Strong random number generation plugin state
+
+ Alg = crypto_aes
+
+
+
+
+ Creates a state object for
+ random number generation,
+ in order to generate cryptographically unpredictable random numbers.
+ See also
+ rand_seed_alg/1.
+
+
+ To get a long period the Xoroshiro928 generator from the
+ rand
+ module is used as a counter (with period 2^928 - 1)
+ and the generator states are scrambled through AES
+ to create 58-bit pseudo random values.
+
+
+ The result should be statistically completely unpredictable
+ random values, since the scrambling is cryptographically strong
+ and the period is ridiculously long. But the generated numbers
+ are not to be regarded as cryptographically strong since
+ there is no re-keying schedule.
+
+
+ -
+
+ If you need cryptographically strong random numbers use
+ rand_seed_alg_s/1
+ with Alg =:= crypto or Alg =:= crypto_cache.
+
+
+ -
+
+ If you need to be able to repeat the sequence use this function.
+
+
+ -
+
+ If you do not need the statistical quality of this function,
+ there are faster algorithms in the
+ rand
+ module.
+
+
+
+
+ Thanks to the used generator the state object supports the
+ rand:jump/0,1
+ function with distance 2^512.
+
+
+ Numbers are generated in batches and cached for speed reasons.
+ The cache size can be changed from its default value using the
+
+ crypto app's
+ configuration parameter rand_cache_size.
+
+
+
+
--
cgit v1.2.3