aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-04-16 19:57:15 +0200
committerChristian Grothoff <christian@grothoff.org>2019-04-16 19:57:15 +0200
commit3266ea560ea1b243810dce4d46ee2889da7b4f6c (patch)
tree555ce759adf099350f89fd520f11d04161e8df1c /src/util
parentcb169441f0ed127dd07e2c6f98436dcd0ece8f61 (diff)
downloadgnunet-3266ea560ea1b243810dce4d46ee2889da7b4f6c.tar.gz
gnunet-3266ea560ea1b243810dce4d46ee2889da7b4f6c.zip
implement backchannel encryption/decryption
Diffstat (limited to 'src/util')
-rw-r--r--src/util/crypto_random.c39
1 files changed, 35 insertions, 4 deletions
diff --git a/src/util/crypto_random.c b/src/util/crypto_random.c
index 54bea58e1..8bb5f0587 100644
--- a/src/util/crypto_random.c
+++ b/src/util/crypto_random.c
@@ -98,6 +98,34 @@ GNUNET_CRYPTO_seed_weak_random (int32_t seed)
98 98
99/** 99/**
100 * @ingroup crypto 100 * @ingroup crypto
101 * Zero out @a buffer, securely against compiler optimizations.
102 * Used to delete key material.
103 *
104 * @param buffer the buffer to zap
105 * @param length buffer length
106 */
107void
108GNUNET_CRYPTO_zero_keys (void *buffer,
109 size_t length)
110{
111#if HAVE_MEMSET_S
112 memset_s (buffer,
113 length,
114 0,
115 length);
116#elif HAVE_EXPLICIT_BZERO
117 explicit_bzero (buffer,
118 length);
119#else
120 volatile unsigned char *p = buffer;
121 while (length--)
122 *p++ = 0;
123#endif
124}
125
126
127/**
128 * @ingroup crypto
101 * Fill block with a random values. 129 * Fill block with a random values.
102 * 130 *
103 * @param mode desired quality of the random number 131 * @param mode desired quality of the random number
@@ -105,7 +133,9 @@ GNUNET_CRYPTO_seed_weak_random (int32_t seed)
105 * @param length buffer length 133 * @param length buffer length
106 */ 134 */
107void 135void
108GNUNET_CRYPTO_random_block (enum GNUNET_CRYPTO_Quality mode, void *buffer, size_t length) 136GNUNET_CRYPTO_random_block (enum GNUNET_CRYPTO_Quality mode,
137 void *buffer,
138 size_t length)
109{ 139{
110#ifdef gcry_fast_random_poll 140#ifdef gcry_fast_random_poll
111 static unsigned int invokeCount; 141 static unsigned int invokeCount;
@@ -146,7 +176,7 @@ GNUNET_CRYPTO_random_block (enum GNUNET_CRYPTO_Quality mode, void *buffer, size_
146 */ 176 */
147uint32_t 177uint32_t
148GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode, 178GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode,
149 uint32_t i) 179 uint32_t i)
150{ 180{
151#ifdef gcry_fast_random_poll 181#ifdef gcry_fast_random_poll
152 static unsigned int invokeCount; 182 static unsigned int invokeCount;
@@ -202,7 +232,7 @@ GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode,
202 */ 232 */
203unsigned int * 233unsigned int *
204GNUNET_CRYPTO_random_permute (enum GNUNET_CRYPTO_Quality mode, 234GNUNET_CRYPTO_random_permute (enum GNUNET_CRYPTO_Quality mode,
205 unsigned int n) 235 unsigned int n)
206{ 236{
207 unsigned int *ret; 237 unsigned int *ret;
208 unsigned int i; 238 unsigned int i;
@@ -232,7 +262,8 @@ GNUNET_CRYPTO_random_permute (enum GNUNET_CRYPTO_Quality mode,
232 * @return random 64-bit number 262 * @return random 64-bit number
233 */ 263 */
234uint64_t 264uint64_t
235GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode, uint64_t max) 265GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode,
266 uint64_t max)
236{ 267{
237 uint64_t ret; 268 uint64_t ret;
238 uint64_t ul; 269 uint64_t ul;