aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/Makefile.am1
-rw-r--r--src/util/buffer.c2
-rw-r--r--src/util/crypto_pow.c86
-rw-r--r--src/util/gnunet-config.c2
-rw-r--r--src/util/gnunet-ecc.c2
-rw-r--r--src/util/gnunet-resolver.c12
-rw-r--r--src/util/gnunet-scrypt.c2
-rw-r--r--src/util/gnunet-uri.c2
-rw-r--r--src/util/os_priority.c2
-rw-r--r--src/util/scheduler.c10
-rw-r--r--src/util/test_common_allocation.c26
11 files changed, 55 insertions, 92 deletions
diff --git a/src/util/Makefile.am b/src/util/Makefile.am
index ae72abb44..fed0dad79 100644
--- a/src/util/Makefile.am
+++ b/src/util/Makefile.am
@@ -133,6 +133,7 @@ libgnunetutil_la_LIBADD = \
133 $(LIBIDN) $(LIBIDN2) \ 133 $(LIBIDN) $(LIBIDN2) \
134 $(Z_LIBS) \ 134 $(Z_LIBS) \
135 -lunistring \ 135 -lunistring \
136 -largon2 \
136 $(XLIB) \ 137 $(XLIB) \
137 $(PTHREAD) 138 $(PTHREAD)
138 139
diff --git a/src/util/buffer.c b/src/util/buffer.c
index 8efb3e284..dabf630c7 100644
--- a/src/util/buffer.c
+++ b/src/util/buffer.c
@@ -56,6 +56,8 @@ GNUNET_buffer_ensure_remaining (struct GNUNET_Buffer *buf,
56{ 56{
57 size_t new_capacity = buf->position + n; 57 size_t new_capacity = buf->position + n;
58 58
59 /* guard against overflow */
60 GNUNET_assert (new_capacity >= buf->position);
59 if (new_capacity <= buf->capacity) 61 if (new_capacity <= buf->capacity)
60 return; 62 return;
61 /* warn if calculation of expected size was wrong */ 63 /* warn if calculation of expected size was wrong */
diff --git a/src/util/crypto_pow.c b/src/util/crypto_pow.c
index 9b20ab345..35511a130 100644
--- a/src/util/crypto_pow.c
+++ b/src/util/crypto_pow.c
@@ -25,7 +25,7 @@
25 */ 25 */
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_crypto_lib.h" 27#include "gnunet_crypto_lib.h"
28#include <gcrypt.h> 28#include <argon2.h>
29 29
30/** 30/**
31 * Calculate the 'proof-of-work' hash (an expensive hash). 31 * Calculate the 'proof-of-work' hash (an expensive hash).
@@ -43,81 +43,17 @@ GNUNET_CRYPTO_pow_hash (const char *salt,
43 size_t buf_len, 43 size_t buf_len,
44 struct GNUNET_HashCode *result) 44 struct GNUNET_HashCode *result)
45{ 45{
46#ifdef LSD001 46 GNUNET_break (ARGON2_OK == argon2d_hash_raw (3, /* iterations */
47 char twofish_iv[128 / 8]; //128 bit IV 47 1024, /* memory (1 MiB) */
48 char twofish_key[256 / 8]; //256 bit Key 48 1, /* threads */
49 char rbuf[buf_len]; 49 buf,
50 int rc; 50 buf_len,
51 gcry_cipher_hd_t handle; 51 salt,
52 strlen (salt),
53 result,
54 sizeof (struct
55 GNUNET_HashCode)));
52 56
53 GNUNET_break (0 == gcry_kdf_derive (buf,
54 buf_len,
55 GCRY_KDF_SCRYPT,
56 1 /* subalgo */,
57 salt,
58 strlen (salt),
59 2 /* iterations; keep cost of individual op small */,
60 sizeof(twofish_key),
61 &twofish_key));
62
63 GNUNET_CRYPTO_kdf (twofish_iv,
64 sizeof (twofish_iv),
65 "gnunet-proof-of-work-iv",
66 strlen ("gnunet-proof-of-work-iv"),
67 twofish_key,
68 sizeof(twofish_key),
69 salt,
70 strlen (salt),
71 NULL, 0);
72 GNUNET_assert (0 ==
73 gcry_cipher_open (&handle, GCRY_CIPHER_TWOFISH,
74 GCRY_CIPHER_MODE_CFB, 0));
75 rc = gcry_cipher_setkey (handle,
76 twofish_key,
77 sizeof(twofish_key));
78 GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY));
79 rc = gcry_cipher_setiv (handle,
80 twofish_iv,
81 sizeof(twofish_iv));
82 GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY));
83 GNUNET_assert (0 == gcry_cipher_encrypt (handle, &rbuf, buf_len, buf, buf_len));
84 gcry_cipher_close (handle);
85#else
86 struct GNUNET_CRYPTO_SymmetricInitializationVector iv;
87 struct GNUNET_CRYPTO_SymmetricSessionKey skey;
88 char rbuf[buf_len];
89
90 GNUNET_break (0 == gcry_kdf_derive (buf,
91 buf_len,
92 GCRY_KDF_SCRYPT,
93 1 /* subalgo */,
94 salt,
95 strlen (salt),
96 2 /* iterations; keep cost of individual op small */,
97 sizeof(skey),
98 &skey));
99 GNUNET_CRYPTO_symmetric_derive_iv (&iv,
100 &skey,
101 "gnunet-proof-of-work-iv",
102 strlen ("gnunet-proof-of-work-iv"),
103 salt,
104 strlen (salt),
105 NULL, 0);
106 GNUNET_CRYPTO_symmetric_encrypt (buf,
107 buf_len,
108 &skey,
109 &iv,
110 &rbuf);
111#endif
112 GNUNET_break (0 == gcry_kdf_derive (rbuf,
113 buf_len,
114 GCRY_KDF_SCRYPT,
115 1 /* subalgo */,
116 salt,
117 strlen (salt),
118 2 /* iterations; keep cost of individual op small */,
119 sizeof(struct GNUNET_HashCode),
120 result));
121} 57}
122 58
123 59
diff --git a/src/util/gnunet-config.c b/src/util/gnunet-config.c
index f101e8b61..5883c1497 100644
--- a/src/util/gnunet-config.c
+++ b/src/util/gnunet-config.c
@@ -331,7 +331,7 @@ main (int argc, char *const *argv)
331 options, 331 options,
332 &run, 332 &run,
333 NULL); 333 NULL);
334 GNUNET_free ((void *) argv); 334 GNUNET_free_nz ((void *) argv);
335 if (GNUNET_OK == ret) 335 if (GNUNET_OK == ret)
336 return global_ret; 336 return global_ret;
337 return ret; 337 return ret;
diff --git a/src/util/gnunet-ecc.c b/src/util/gnunet-ecc.c
index 764a507b6..8e30ac416 100644
--- a/src/util/gnunet-ecc.c
+++ b/src/util/gnunet-ecc.c
@@ -501,7 +501,7 @@ main (int argc, char *const *argv)
501 NULL)) 501 NULL))
502 ? 0 502 ? 0
503 : 1; 503 : 1;
504 GNUNET_free ((void *) argv); 504 GNUNET_free_nz ((void *) argv);
505 return ret; 505 return ret;
506} 506}
507 507
diff --git a/src/util/gnunet-resolver.c b/src/util/gnunet-resolver.c
index 6a602c64e..8a6c7fbe9 100644
--- a/src/util/gnunet-resolver.c
+++ b/src/util/gnunet-resolver.c
@@ -171,14 +171,18 @@ main (int argc, char *const *argv)
171 }; 171 };
172 int ret; 172 int ret;
173 173
174 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 174 if (GNUNET_OK !=
175 GNUNET_STRINGS_get_utf8_args (argc, argv,
176 &argc, &argv))
175 return 2; 177 return 2;
176 178
177 ret = (GNUNET_OK == 179 ret = (GNUNET_OK ==
178 GNUNET_PROGRAM_run (argc, argv, "gnunet-resolver [hostname]", 180 GNUNET_PROGRAM_run (argc, argv,
181 "gnunet-resolver [hostname]",
179 gettext_noop ("Use build-in GNUnet stub resolver"), 182 gettext_noop ("Use build-in GNUnet stub resolver"),
180 options, &run, NULL)) ? 0 : 1; 183 options,
181 GNUNET_free ((void *) argv); 184 &run, NULL)) ? 0 : 1;
185 GNUNET_free_nz ((void *) argv);
182 return ret; 186 return ret;
183} 187}
184 188
diff --git a/src/util/gnunet-scrypt.c b/src/util/gnunet-scrypt.c
index 8c46136b9..70ba48d82 100644
--- a/src/util/gnunet-scrypt.c
+++ b/src/util/gnunet-scrypt.c
@@ -322,7 +322,7 @@ main (int argc, char *const *argv)
322 NULL)) 322 NULL))
323 ? 0 323 ? 0
324 : 1; 324 : 1;
325 GNUNET_free ((void *) argv); 325 GNUNET_free_nz ((void *) argv);
326 GNUNET_free_non_null (pwfn); 326 GNUNET_free_non_null (pwfn);
327 return ret; 327 return ret;
328} 328}
diff --git a/src/util/gnunet-uri.c b/src/util/gnunet-uri.c
index 84100ff56..48c46ee49 100644
--- a/src/util/gnunet-uri.c
+++ b/src/util/gnunet-uri.c
@@ -184,7 +184,7 @@ main (int argc, char *const *argv)
184 shc_chld = NULL; 184 shc_chld = NULL;
185 GNUNET_DISK_pipe_close (sigpipe); 185 GNUNET_DISK_pipe_close (sigpipe);
186 sigpipe = NULL; 186 sigpipe = NULL;
187 GNUNET_free ((void *) argv); 187 GNUNET_free_nz ((void *) argv);
188 return ((GNUNET_OK == ret) && (0 == exit_code)) ? 0 : 1; 188 return ((GNUNET_OK == ret) && (0 == exit_code)) ? 0 : 1;
189} 189}
190 190
diff --git a/src/util/os_priority.c b/src/util/os_priority.c
index 36f0d8e30..5799d893b 100644
--- a/src/util/os_priority.c
+++ b/src/util/os_priority.c
@@ -875,7 +875,7 @@ GNUNET_OS_start_process_s (int pipe_control,
875 binary_path, 875 binary_path,
876 argv); 876 argv);
877 while (argv_size > 0) 877 while (argv_size > 0)
878 GNUNET_free (argv[--argv_size]); 878 GNUNET_free_nz (argv[--argv_size]);
879 GNUNET_free (argv); 879 GNUNET_free (argv);
880 return proc; 880 return proc;
881} 881}
diff --git a/src/util/scheduler.c b/src/util/scheduler.c
index 45a6b61e5..93393bd7c 100644
--- a/src/util/scheduler.c
+++ b/src/util/scheduler.c
@@ -584,28 +584,26 @@ dump_backtrace (struct GNUNET_SCHEDULER_Task *t)
584static void 584static void
585destroy_task (struct GNUNET_SCHEDULER_Task *t) 585destroy_task (struct GNUNET_SCHEDULER_Task *t)
586{ 586{
587 unsigned int i;
588
589 LOG (GNUNET_ERROR_TYPE_DEBUG, 587 LOG (GNUNET_ERROR_TYPE_DEBUG,
590 "destroying task %p\n", 588 "destroying task %p\n",
591 t); 589 t);
592 590
593 if (GNUNET_YES == t->own_handles) 591 if (GNUNET_YES == t->own_handles)
594 { 592 {
595 for (i = 0; i != t->fds_len; ++i) 593 for (unsigned int i = 0; i != t->fds_len; ++i)
596 { 594 {
597 const struct GNUNET_NETWORK_Handle *fd = t->fds[i].fd; 595 const struct GNUNET_NETWORK_Handle *fd = t->fds[i].fd;
598 const struct GNUNET_DISK_FileHandle *fh = t->fds[i].fh; 596 const struct GNUNET_DISK_FileHandle *fh = t->fds[i].fh;
599 if (fd) 597 if (fd)
600 { 598 {
601 GNUNET_NETWORK_socket_free_memory_only_ ((struct 599 GNUNET_NETWORK_socket_free_memory_only_ (
602 GNUNET_NETWORK_Handle *) fd); 600 (struct GNUNET_NETWORK_Handle *) fd);
603 } 601 }
604 if (fh) 602 if (fh)
605 { 603 {
606 // FIXME: on WIN32 this is not enough! A function 604 // FIXME: on WIN32 this is not enough! A function
607 // GNUNET_DISK_file_free_memory_only would be nice 605 // GNUNET_DISK_file_free_memory_only would be nice
608 GNUNET_free ((void *) fh); 606 GNUNET_free_nz ((void *) fh);
609 } 607 }
610 } 608 }
611 } 609 }
diff --git a/src/util/test_common_allocation.c b/src/util/test_common_allocation.c
index e2fc29e82..a24af7124 100644
--- a/src/util/test_common_allocation.c
+++ b/src/util/test_common_allocation.c
@@ -27,7 +27,7 @@
27 27
28 28
29static int 29static int
30check () 30check (void)
31{ 31{
32#define MAX_TESTVAL 1024 32#define MAX_TESTVAL 1024
33 char *ptrs[MAX_TESTVAL]; 33 char *ptrs[MAX_TESTVAL];
@@ -134,6 +134,28 @@ check ()
134} 134}
135 135
136 136
137static int
138check2 (void)
139{
140 char *a1 = NULL;
141 unsigned int a1_len = 0;
142 const char *a2 = "test";
143
144 GNUNET_array_append (a1,
145 a1_len,
146 'x');
147 GNUNET_array_concatenate (a1,
148 a1_len,
149 a2,
150 4);
151 GNUNET_assert (0 == strncmp ("xtest",
152 a1,
153 5));
154 GNUNET_assert (5 == a1_len);
155 return 0;
156}
157
158
137int 159int
138main (int argc, char *argv[]) 160main (int argc, char *argv[])
139{ 161{
@@ -142,7 +164,7 @@ main (int argc, char *argv[])
142 GNUNET_log_setup ("test-common-allocation", 164 GNUNET_log_setup ("test-common-allocation",
143 "WARNING", 165 "WARNING",
144 NULL); 166 NULL);
145 ret = check (); 167 ret = check () | check2 ();
146 if (ret != 0) 168 if (ret != 0)
147 fprintf (stderr, 169 fprintf (stderr,
148 "ERROR %d.\n", 170 "ERROR %d.\n",