aboutsummaryrefslogtreecommitdiff
path: root/src/util/crypto_random.c
diff options
context:
space:
mode:
authorNils Durner <durner@gnunet.org>2010-10-03 13:29:09 +0000
committerNils Durner <durner@gnunet.org>2010-10-03 13:29:09 +0000
commit9d9853441df5b565f6932fcf7fbb156b2d929392 (patch)
tree87d09554c804030a48fe33e46206c91dc312bf12 /src/util/crypto_random.c
parentb7c95147188502651e4cb2b60c7062137f73e878 (diff)
downloadgnunet-9d9853441df5b565f6932fcf7fbb156b2d929392.tar.gz
gnunet-9d9853441df5b565f6932fcf7fbb156b2d929392.zip
KDF code
Diffstat (limited to 'src/util/crypto_random.c')
-rw-r--r--src/util/crypto_random.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/util/crypto_random.c b/src/util/crypto_random.c
index 0a092cdcc..14d87b1cd 100644
--- a/src/util/crypto_random.c
+++ b/src/util/crypto_random.c
@@ -76,6 +76,17 @@ GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode, uint32_t i)
76 while (ret >= ul); 76 while (ret >= ul);
77 return ret % i; 77 return ret % i;
78 } 78 }
79 else if (mode == GNUNET_CRYPTO_QUALITY_NONCE)
80 {
81 ul = UINT32_MAX - (UINT32_MAX % i);
82 do
83 {
84 gcry_create_nonce(&ret, sizeof(ret));
85 }
86 while (ret >= ul);
87
88 return ret % i;
89 }
79 else 90 else
80 { 91 {
81 ret = i * weak_random (); 92 ret = i * weak_random ();
@@ -142,6 +153,17 @@ GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode, uint64_t max)
142 while (ret >= ul); 153 while (ret >= ul);
143 return ret % max; 154 return ret % max;
144 } 155 }
156 else if (mode == GNUNET_CRYPTO_QUALITY_NONCE)
157 {
158 ul = UINT64_MAX - (UINT64_MAX % max);
159 do
160 {
161 gcry_create_nonce(&ret, sizeof(ret));
162 }
163 while (ret >= ul);
164
165 return ret % max;
166 }
145 else 167 else
146 { 168 {
147 ret = max * weak_random (); 169 ret = max * weak_random ();