aboutsummaryrefslogtreecommitdiff
path: root/src/util/test_crypto_random.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/test_crypto_random.c')
-rw-r--r--src/util/test_crypto_random.c37
1 files changed, 18 insertions, 19 deletions
diff --git a/src/util/test_crypto_random.c b/src/util/test_crypto_random.c
index 6386c79db..11f87a25e 100644
--- a/src/util/test_crypto_random.c
+++ b/src/util/test_crypto_random.c
@@ -11,13 +11,13 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 19
20*/ 20 */
21 21
22/** 22/**
23 * @file util/test_crypto_random.c 23 * @file util/test_crypto_random.c
@@ -27,43 +27,42 @@
27#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
28 28
29static int 29static int
30test (enum GNUNET_CRYPTO_Quality mode) 30test(enum GNUNET_CRYPTO_Quality mode)
31{ 31{
32
33 int buf[1024]; 32 int buf[1024];
34 unsigned int *b2; 33 unsigned int *b2;
35 int i; 34 int i;
36 unsigned long long n; 35 unsigned long long n;
37 36
38 for (i = 0; i < 1024; i++) 37 for (i = 0; i < 1024; i++)
39 GNUNET_break (1024 > (buf[i] = GNUNET_CRYPTO_random_u32 (mode, 1024))); 38 GNUNET_break(1024 > (buf[i] = GNUNET_CRYPTO_random_u32(mode, 1024)));
40 for (i = 0; i < 10; i++) 39 for (i = 0; i < 10; i++)
41 {
42 b2 = GNUNET_CRYPTO_random_permute (mode, 1024);
43 if (0 == memcmp (b2, buf, sizeof (buf)))
44 { 40 {
45 fprintf (stderr, "%s", "!"); 41 b2 = GNUNET_CRYPTO_random_permute(mode, 1024);
46 GNUNET_free (b2); 42 if (0 == memcmp(b2, buf, sizeof(buf)))
47 continue; 43 {
44 fprintf(stderr, "%s", "!");
45 GNUNET_free(b2);
46 continue;
47 }
48 GNUNET_free(b2);
49 break;
48 } 50 }
49 GNUNET_free (b2);
50 break;
51 }
52 if (i == 10) 51 if (i == 10)
53 return 1; /* virtually impossible... */ 52 return 1; /* virtually impossible... */
54 53
55 for (n = 10; n < 1024LL * 1024LL * 1024LL; n *= 10) 54 for (n = 10; n < 1024LL * 1024LL * 1024LL; n *= 10)
56 GNUNET_break (n > GNUNET_CRYPTO_random_u64 (mode, n)); 55 GNUNET_break(n > GNUNET_CRYPTO_random_u64(mode, n));
57 return 0; 56 return 0;
58} 57}
59 58
60int 59int
61main (int argc, char *argv[]) 60main(int argc, char *argv[])
62{ 61{
63 GNUNET_log_setup ("test-crypto-random", "WARNING", NULL); 62 GNUNET_log_setup("test-crypto-random", "WARNING", NULL);
64 if (0 != test (GNUNET_CRYPTO_QUALITY_WEAK)) 63 if (0 != test(GNUNET_CRYPTO_QUALITY_WEAK))
65 return 1; 64 return 1;
66 if (0 != test (GNUNET_CRYPTO_QUALITY_STRONG)) 65 if (0 != test(GNUNET_CRYPTO_QUALITY_STRONG))
67 return 1; 66 return 1;
68 67
69 return 0; 68 return 0;