diff options
author | Christian Grothoff <christian@grothoff.org> | 2009-09-08 08:10:18 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2009-09-08 08:10:18 +0000 |
commit | c2017c2ba13736ee1fe4dc9d811d49bee1641ca3 (patch) | |
tree | 93ae178521584311eeecdf1e5448a27925bfc681 | |
parent | 3da5c316b7b992fcc33328043151cf8cb25bf640 (diff) | |
download | gnunet-c2017c2ba13736ee1fe4dc9d811d49bee1641ca3.tar.gz gnunet-c2017c2ba13736ee1fe4dc9d811d49bee1641ca3.zip |
fixes
-rw-r--r-- | src/datastore/perf_datastore_api.c | 1 | ||||
-rw-r--r-- | src/fs/Makefile.am | 4 | ||||
-rw-r--r-- | src/fs/test_fs_collection.c | 11 | ||||
-rw-r--r-- | src/fs/test_fs_directory.c | 24 | ||||
-rw-r--r-- | src/hostlist/test_gnunet_daemon_hostlist.c | 4 | ||||
-rw-r--r-- | src/include/gnunet_crypto_lib.h | 67 | ||||
-rw-r--r-- | src/testing/test_testing.c | 2 | ||||
-rw-r--r-- | src/util/crypto_aes.c | 13 | ||||
-rw-r--r-- | src/util/crypto_crc.c | 6 | ||||
-rw-r--r-- | src/util/crypto_hash.c | 51 | ||||
-rw-r--r-- | src/util/crypto_random.c | 26 | ||||
-rw-r--r-- | src/util/crypto_rsa.c | 7 | ||||
-rw-r--r-- | src/util/test_container_bloomfilter.c | 2 | ||||
-rw-r--r-- | src/util/test_crypto_hash.c | 4 | ||||
-rw-r--r-- | src/util/test_crypto_ksk.c | 2 | ||||
-rw-r--r-- | src/util/test_pseudonym.c | 4 |
16 files changed, 124 insertions, 104 deletions
diff --git a/src/datastore/perf_datastore_api.c b/src/datastore/perf_datastore_api.c index 0df55f878..626fbcf73 100644 --- a/src/datastore/perf_datastore_api.c +++ b/src/datastore/perf_datastore_api.c | |||
@@ -389,6 +389,7 @@ main (int argc, char *argv[]) | |||
389 | #if REPORT_ID | 389 | #if REPORT_ID |
390 | fprintf (stderr, "\n"); | 390 | fprintf (stderr, "\n"); |
391 | #endif | 391 | #endif |
392 | GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-datastore"); | ||
392 | return ret; | 393 | return ret; |
393 | } | 394 | } |
394 | 395 | ||
diff --git a/src/fs/Makefile.am b/src/fs/Makefile.am index f2bcab615..abc3d989b 100644 --- a/src/fs/Makefile.am +++ b/src/fs/Makefile.am | |||
@@ -107,7 +107,9 @@ check_PROGRAMS = \ | |||
107 | test_fs_getopt \ | 107 | test_fs_getopt \ |
108 | test_fs_uri | 108 | test_fs_uri |
109 | 109 | ||
110 | TESTS = $(check_PROGRAMS) | 110 | TESTS = test_fs_uri |
111 | |||
112 | # $(check_PROGRAMS) | ||
111 | 113 | ||
112 | test_fs_collection_SOURCES = \ | 114 | test_fs_collection_SOURCES = \ |
113 | test_fs_collection.c | 115 | test_fs_collection.c |
diff --git a/src/fs/test_fs_collection.c b/src/fs/test_fs_collection.c index 6857dfc25..dc93bbfb5 100644 --- a/src/fs/test_fs_collection.c +++ b/src/fs/test_fs_collection.c | |||
@@ -52,7 +52,9 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
52 | cfg, | 52 | cfg, |
53 | "test-fs-collection", | 53 | "test-fs-collection", |
54 | &progress_cb, | 54 | &progress_cb, |
55 | NULL); | 55 | NULL, |
56 | GNUNET_FS_FLAGS_NONE, | ||
57 | GNUNET_FS_OPTIONS_END); | ||
56 | GNUNET_assert (NULL != fsh); | 58 | GNUNET_assert (NULL != fsh); |
57 | GNUNET_FS_collection_stop (fsh); | 59 | GNUNET_FS_collection_stop (fsh); |
58 | GNUNET_assert (NULL == GNUNET_FS_collection_get (fsh)); | 60 | GNUNET_assert (NULL == GNUNET_FS_collection_get (fsh)); |
@@ -76,7 +78,9 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
76 | cfg, | 78 | cfg, |
77 | "test-fs-collection", | 79 | "test-fs-collection", |
78 | &progress_cb, | 80 | &progress_cb, |
79 | NULL); | 81 | NULL, |
82 | GNUNET_FS_FLAGS_NONE, | ||
83 | GNUNET_FS_OPTIONS_END); | ||
80 | have = GNUNET_FS_collection_get (fsh); | 84 | have = GNUNET_FS_collection_get (fsh); |
81 | GNUNET_assert (NULL != have); | 85 | GNUNET_assert (NULL != have); |
82 | GNUNET_FS_namespace_delete (have, GNUNET_NO); | 86 | GNUNET_FS_namespace_delete (have, GNUNET_NO); |
@@ -101,7 +105,8 @@ main (int argc, char *argv[]) | |||
101 | NULL); | 105 | NULL); |
102 | GNUNET_CRYPTO_random_disable_entropy_gathering (); | 106 | GNUNET_CRYPTO_random_disable_entropy_gathering (); |
103 | cfg = GNUNET_CONFIGURATION_create (); | 107 | cfg = GNUNET_CONFIGURATION_create (); |
104 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_parse (cfg, "test_fs_collection_data.conf")) | 108 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_parse (cfg, |
109 | "test_fs_collection_data.conf")) | ||
105 | { | 110 | { |
106 | GNUNET_CONFIGURATION_destroy (cfg); | 111 | GNUNET_CONFIGURATION_destroy (cfg); |
107 | return -1; | 112 | return -1; |
diff --git a/src/fs/test_fs_directory.c b/src/fs/test_fs_directory.c index 22dfa22cf..9d0101078 100644 --- a/src/fs/test_fs_directory.c +++ b/src/fs/test_fs_directory.c | |||
@@ -67,8 +67,9 @@ processor (void *cls, | |||
67 | static int | 67 | static int |
68 | testDirectory (unsigned int i) | 68 | testDirectory (unsigned int i) |
69 | { | 69 | { |
70 | struct GNUNET_FS_DirectoryBuilder *db; | ||
70 | char *data; | 71 | char *data; |
71 | unsigned long long dlen; | 72 | size_t dlen; |
72 | struct GNUNET_FS_Uri **uris; | 73 | struct GNUNET_FS_Uri **uris; |
73 | struct GNUNET_CONTAINER_MetaData **mds; | 74 | struct GNUNET_CONTAINER_MetaData **mds; |
74 | struct GNUNET_CONTAINER_MetaData *meta; | 75 | struct GNUNET_CONTAINER_MetaData *meta; |
@@ -96,7 +97,7 @@ testDirectory (unsigned int i) | |||
96 | } | 97 | } |
97 | GNUNET_snprintf (uri, | 98 | GNUNET_snprintf (uri, |
98 | sizeof(uri), | 99 | sizeof(uri), |
99 | "gnunet://ecrs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.%u", | 100 | "gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.%u", |
100 | p); | 101 | p); |
101 | uris[p] = GNUNET_FS_uri_parse (uri, &emsg); | 102 | uris[p] = GNUNET_FS_uri_parse (uri, &emsg); |
102 | if (uris[p] == NULL) | 103 | if (uris[p] == NULL) |
@@ -115,19 +116,12 @@ testDirectory (unsigned int i) | |||
115 | meta = GNUNET_CONTAINER_meta_data_create (); | 116 | meta = GNUNET_CONTAINER_meta_data_create (); |
116 | GNUNET_CONTAINER_meta_data_insert (meta, EXTRACTOR_TITLE, "A title"); | 117 | GNUNET_CONTAINER_meta_data_insert (meta, EXTRACTOR_TITLE, "A title"); |
117 | GNUNET_CONTAINER_meta_data_insert (meta, EXTRACTOR_AUTHOR, "An author"); | 118 | GNUNET_CONTAINER_meta_data_insert (meta, EXTRACTOR_AUTHOR, "An author"); |
118 | if (GNUNET_OK != | 119 | db = GNUNET_FS_directory_builder_create (meta); |
119 | GNUNET_FS_directory_create (&dlen, &data, i, uris, mds, meta)) | 120 | for (p=0;p<i;p++) |
120 | { | 121 | GNUNET_FS_directory_builder_add (db, uris[i], mds[i], NULL); |
121 | GNUNET_CONTAINER_meta_data_destroy (meta); | 122 | GNUNET_FS_directory_builder_finish (db, |
122 | for (p = 0; p < i; p++) | 123 | &dlen, |
123 | { | 124 | (void**) &data); |
124 | GNUNET_CONTAINER_meta_data_destroy (mds[p]); | ||
125 | GNUNET_FS_uri_destroy (uris[p]); | ||
126 | } | ||
127 | GNUNET_free (uris); | ||
128 | GNUNET_free (mds); | ||
129 | ABORT (); | ||
130 | } | ||
131 | cls.pos = 0; | 125 | cls.pos = 0; |
132 | cls.uri = uris; | 126 | cls.uri = uris; |
133 | cls.md = mds; | 127 | cls.md = mds; |
diff --git a/src/hostlist/test_gnunet_daemon_hostlist.c b/src/hostlist/test_gnunet_daemon_hostlist.c index e99b486cc..006c6b1d8 100644 --- a/src/hostlist/test_gnunet_daemon_hostlist.c +++ b/src/hostlist/test_gnunet_daemon_hostlist.c | |||
@@ -174,5 +174,7 @@ main (int argc, char *argv[]) | |||
174 | #endif | 174 | #endif |
175 | NULL); | 175 | NULL); |
176 | ret = check (); | 176 | ret = check (); |
177 | return 0; | 177 | return ret; |
178 | } | 178 | } |
179 | |||
180 | /* end of test_gnunet_daemon_hostlist.c */ | ||
diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h index 396f47355..9303aa98c 100644 --- a/src/include/gnunet_crypto_lib.h +++ b/src/include/gnunet_crypto_lib.h | |||
@@ -202,25 +202,31 @@ struct GNUNET_CRYPTO_AesInitializationVector | |||
202 | * @param len the length of the buffer in bytes | 202 | * @param len the length of the buffer in bytes |
203 | * @return the resulting CRC32 checksum | 203 | * @return the resulting CRC32 checksum |
204 | */ | 204 | */ |
205 | int GNUNET_CRYPTO_crc32_n (const void *buf, unsigned int len); | 205 | int32_t GNUNET_CRYPTO_crc32_n (const void *buf, |
206 | size_t len); | ||
206 | 207 | ||
207 | 208 | ||
208 | /** | 209 | /** |
209 | * Produce a random value. | 210 | * Produce a random value. |
210 | * | 211 | * |
212 | * @param mode desired quality of the random number | ||
211 | * @param i the upper limit (exclusive) for the random number | 213 | * @param i the upper limit (exclusive) for the random number |
212 | * @return a random value in the interval [0,i[. | 214 | * @return a random value in the interval [0,i) (exclusive). |
213 | */ | 215 | */ |
214 | unsigned int GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality, | 216 | uint32_t GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode, |
215 | unsigned int i); | 217 | uint32_t i); |
216 | 218 | ||
217 | 219 | ||
218 | /** | 220 | /** |
219 | * Random on unsigned 64-bit values. We break them down into signed | 221 | * Random on unsigned 64-bit values. We break them down into signed |
220 | * 32-bit values and reassemble the 64-bit random value bit-wise. | 222 | * 32-bit values and reassemble the 64-bit random value bit-wise. |
223 | * | ||
224 | * @param mode desired quality of the random number | ||
225 | * @param max value returned will be in range [0,max) (exclusive) | ||
226 | * @return random 64-bit number | ||
221 | */ | 227 | */ |
222 | unsigned long long GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode, | 228 | uint64_t GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode, |
223 | unsigned long long u); | 229 | uint64_t max); |
224 | 230 | ||
225 | 231 | ||
226 | /** | 232 | /** |
@@ -261,13 +267,13 @@ int GNUNET_CRYPTO_aes_check_session_key (const struct | |||
261 | * for streams. | 267 | * for streams. |
262 | * @returns the size of the encrypted block, -1 for errors | 268 | * @returns the size of the encrypted block, -1 for errors |
263 | */ | 269 | */ |
264 | int GNUNET_CRYPTO_aes_encrypt (const void *block, | 270 | ssize_t GNUNET_CRYPTO_aes_encrypt (const void *block, |
265 | uint16_t len, | 271 | size_t len, |
266 | const struct GNUNET_CRYPTO_AesSessionKey | 272 | const struct GNUNET_CRYPTO_AesSessionKey |
267 | *sessionkey, | 273 | *sessionkey, |
268 | const struct | 274 | const struct |
269 | GNUNET_CRYPTO_AesInitializationVector *iv, | 275 | GNUNET_CRYPTO_AesInitializationVector *iv, |
270 | void *result); | 276 | void *result); |
271 | 277 | ||
272 | 278 | ||
273 | /** | 279 | /** |
@@ -280,10 +286,11 @@ int GNUNET_CRYPTO_aes_encrypt (const void *block, | |||
280 | * @param result address to store the result at | 286 | * @param result address to store the result at |
281 | * @return -1 on failure, size of decrypted block on success | 287 | * @return -1 on failure, size of decrypted block on success |
282 | */ | 288 | */ |
283 | int GNUNET_CRYPTO_aes_decrypt (const void *block, uint16_t size, | 289 | ssize_t GNUNET_CRYPTO_aes_decrypt (const void *block, |
284 | const struct GNUNET_CRYPTO_AesSessionKey *sessionkey, | 290 | size_t size, |
285 | const struct GNUNET_CRYPTO_AesInitializationVector *iv, | 291 | const struct GNUNET_CRYPTO_AesSessionKey *sessionkey, |
286 | void *result); | 292 | const struct GNUNET_CRYPTO_AesInitializationVector *iv, |
293 | void *result); | ||
287 | 294 | ||
288 | 295 | ||
289 | /** | 296 | /** |
@@ -315,16 +322,19 @@ int GNUNET_CRYPTO_hash_from_string (const char *enc, | |||
315 | * result should be a positive number. | 322 | * result should be a positive number. |
316 | * @return number between 0 and 65536 | 323 | * @return number between 0 and 65536 |
317 | */ | 324 | */ |
318 | unsigned int GNUNET_CRYPTO_hash_distance_u32 (const GNUNET_HashCode * a, | 325 | uint32_t GNUNET_CRYPTO_hash_distance_u32 (const GNUNET_HashCode * a, |
319 | const GNUNET_HashCode * b); | 326 | const GNUNET_HashCode * b); |
320 | 327 | ||
321 | 328 | ||
322 | /** | 329 | /** |
323 | * Hash block of given size. | 330 | * Compute hash of a given block. |
324 | * @param block the data to GNUNET_CRYPTO_hash, length is given as a second argument | 331 | * |
332 | * @param block the data to hash | ||
333 | * @param size size of the block | ||
325 | * @param ret pointer to where to write the hashcode | 334 | * @param ret pointer to where to write the hashcode |
326 | */ | 335 | */ |
327 | void GNUNET_CRYPTO_hash (const void *block, unsigned int size, | 336 | void GNUNET_CRYPTO_hash (const void *block, |
337 | size_t size, | ||
328 | GNUNET_HashCode * ret); | 338 | GNUNET_HashCode * ret); |
329 | 339 | ||
330 | 340 | ||
@@ -363,7 +373,8 @@ void GNUNET_CRYPTO_hash_file (struct GNUNET_SCHEDULER_Handle *sched, | |||
363 | /** | 373 | /** |
364 | * Create a random hash code. | 374 | * Create a random hash code. |
365 | */ | 375 | */ |
366 | void GNUNET_CRYPTO_hash_create_random (GNUNET_HashCode * result); | 376 | void GNUNET_CRYPTO_hash_create_random (enum GNUNET_CRYPTO_Quality mode, |
377 | GNUNET_HashCode * result); | ||
367 | 378 | ||
368 | 379 | ||
369 | /** | 380 | /** |
@@ -491,7 +502,7 @@ void GNUNET_CRYPTO_rsa_key_get_public (const struct | |||
491 | * @returns GNUNET_SYSERR on error, GNUNET_OK if ok | 502 | * @returns GNUNET_SYSERR on error, GNUNET_OK if ok |
492 | */ | 503 | */ |
493 | int GNUNET_CRYPTO_rsa_encrypt (const void *block, | 504 | int GNUNET_CRYPTO_rsa_encrypt (const void *block, |
494 | uint16_t size, | 505 | size_t size, |
495 | const struct | 506 | const struct |
496 | GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded | 507 | GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded |
497 | *publicKey, | 508 | *publicKey, |
@@ -507,9 +518,11 @@ int GNUNET_CRYPTO_rsa_encrypt (const void *block, | |||
507 | * @param size how many bytes of a result are expected? Must be exact. | 518 | * @param size how many bytes of a result are expected? Must be exact. |
508 | * @returns the size of the decrypted block (that is, size) or -1 on error | 519 | * @returns the size of the decrypted block (that is, size) or -1 on error |
509 | */ | 520 | */ |
510 | int GNUNET_CRYPTO_rsa_decrypt (const struct GNUNET_CRYPTO_RsaPrivateKey *key, | 521 | ssize_t GNUNET_CRYPTO_rsa_decrypt (const struct GNUNET_CRYPTO_RsaPrivateKey *key, |
511 | const struct GNUNET_CRYPTO_RsaEncryptedData | 522 | const struct GNUNET_CRYPTO_RsaEncryptedData |
512 | *block, void *result, uint16_t size); | 523 | *block, |
524 | void *result, | ||
525 | size_t size); | ||
513 | 526 | ||
514 | 527 | ||
515 | /** | 528 | /** |
diff --git a/src/testing/test_testing.c b/src/testing/test_testing.c index cbedf60fb..b273eeef5 100644 --- a/src/testing/test_testing.c +++ b/src/testing/test_testing.c | |||
@@ -109,7 +109,7 @@ main (int argc, char *argv[]) | |||
109 | #endif | 109 | #endif |
110 | NULL); | 110 | NULL); |
111 | ret = check (); | 111 | ret = check (); |
112 | 112 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-testing"); | |
113 | return ret; | 113 | return ret; |
114 | } | 114 | } |
115 | 115 | ||
diff --git a/src/util/crypto_aes.c b/src/util/crypto_aes.c index 8fa935d9f..6db932b5b 100644 --- a/src/util/crypto_aes.c +++ b/src/util/crypto_aes.c | |||
@@ -72,9 +72,9 @@ GNUNET_CRYPTO_aes_check_session_key (const struct GNUNET_CRYPTO_AesSessionKey | |||
72 | * @param result the output parameter in which to store the encrypted result | 72 | * @param result the output parameter in which to store the encrypted result |
73 | * @returns the size of the encrypted block, -1 for errors | 73 | * @returns the size of the encrypted block, -1 for errors |
74 | */ | 74 | */ |
75 | int | 75 | ssize_t |
76 | GNUNET_CRYPTO_aes_encrypt (const void *block, | 76 | GNUNET_CRYPTO_aes_encrypt (const void *block, |
77 | uint16_t len, | 77 | size_t len, |
78 | const struct GNUNET_CRYPTO_AesSessionKey | 78 | const struct GNUNET_CRYPTO_AesSessionKey |
79 | *sessionkey, | 79 | *sessionkey, |
80 | const struct GNUNET_CRYPTO_AesInitializationVector | 80 | const struct GNUNET_CRYPTO_AesInitializationVector |
@@ -88,7 +88,7 @@ GNUNET_CRYPTO_aes_encrypt (const void *block, | |||
88 | (sessionkey, GNUNET_CRYPTO_AES_KEY_LENGTH))) | 88 | (sessionkey, GNUNET_CRYPTO_AES_KEY_LENGTH))) |
89 | { | 89 | { |
90 | GNUNET_break (0); | 90 | GNUNET_break (0); |
91 | return GNUNET_SYSERR; | 91 | return -1; |
92 | } | 92 | } |
93 | GNUNET_assert (0 == gcry_cipher_open (&handle, | 93 | GNUNET_assert (0 == gcry_cipher_open (&handle, |
94 | GCRY_CIPHER_AES256, | 94 | GCRY_CIPHER_AES256, |
@@ -115,8 +115,9 @@ GNUNET_CRYPTO_aes_encrypt (const void *block, | |||
115 | * @param result address to store the result at | 115 | * @param result address to store the result at |
116 | * @return -1 on failure, size of decrypted block on success | 116 | * @return -1 on failure, size of decrypted block on success |
117 | */ | 117 | */ |
118 | int | 118 | ssize_t |
119 | GNUNET_CRYPTO_aes_decrypt (const void *block, uint16_t size, | 119 | GNUNET_CRYPTO_aes_decrypt (const void *block, |
120 | size_t size, | ||
120 | const struct GNUNET_CRYPTO_AesSessionKey | 121 | const struct GNUNET_CRYPTO_AesSessionKey |
121 | *sessionkey, | 122 | *sessionkey, |
122 | const struct GNUNET_CRYPTO_AesInitializationVector | 123 | const struct GNUNET_CRYPTO_AesInitializationVector |
@@ -130,7 +131,7 @@ GNUNET_CRYPTO_aes_decrypt (const void *block, uint16_t size, | |||
130 | (sessionkey, GNUNET_CRYPTO_AES_KEY_LENGTH))) | 131 | (sessionkey, GNUNET_CRYPTO_AES_KEY_LENGTH))) |
131 | { | 132 | { |
132 | GNUNET_break (0); | 133 | GNUNET_break (0); |
133 | return GNUNET_SYSERR; | 134 | return -1; |
134 | } | 135 | } |
135 | GNUNET_assert (0 == gcry_cipher_open (&handle, | 136 | GNUNET_assert (0 == gcry_cipher_open (&handle, |
136 | GCRY_CIPHER_AES256, | 137 | GCRY_CIPHER_AES256, |
diff --git a/src/util/crypto_crc.c b/src/util/crypto_crc.c index 35d1e2576..a89b059c5 100644 --- a/src/util/crypto_crc.c +++ b/src/util/crypto_crc.c | |||
@@ -94,8 +94,8 @@ crc32 (uLong crc, const char *buf, size_t len) | |||
94 | * @param len the length of the buffer | 94 | * @param len the length of the buffer |
95 | * @return the resulting CRC32 checksum | 95 | * @return the resulting CRC32 checksum |
96 | */ | 96 | */ |
97 | int | 97 | int32_t |
98 | GNUNET_CRYPTO_crc32_n (const void *buf, unsigned int len) | 98 | GNUNET_CRYPTO_crc32_n (const void *buf, size_t len) |
99 | { | 99 | { |
100 | uLong crc; | 100 | uLong crc; |
101 | crc = crc32 (0L, Z_NULL, 0); | 101 | crc = crc32 (0L, Z_NULL, 0); |
@@ -103,4 +103,4 @@ GNUNET_CRYPTO_crc32_n (const void *buf, unsigned int len) | |||
103 | return crc; | 103 | return crc; |
104 | } | 104 | } |
105 | 105 | ||
106 | /* end of crc32.c */ | 106 | /* end of crypto_crc.c */ |
diff --git a/src/util/crypto_hash.c b/src/util/crypto_hash.c index fce93ceaf..4f8482c4c 100644 --- a/src/util/crypto_hash.c +++ b/src/util/crypto_hash.c | |||
@@ -359,7 +359,8 @@ sha512_final (struct sha512_ctx *sctx, unsigned char *hash) | |||
359 | * @param ret pointer to where to write the hashcode | 359 | * @param ret pointer to where to write the hashcode |
360 | */ | 360 | */ |
361 | void | 361 | void |
362 | GNUNET_CRYPTO_hash (const void *block, unsigned int size, | 362 | GNUNET_CRYPTO_hash (const void *block, |
363 | size_t size, | ||
363 | GNUNET_HashCode * ret) | 364 | GNUNET_HashCode * ret) |
364 | { | 365 | { |
365 | struct sha512_ctx ctx; | 366 | struct sha512_ctx ctx; |
@@ -660,18 +661,18 @@ GNUNET_CRYPTO_hash_distance_u32 (const GNUNET_HashCode * a, | |||
660 | } | 661 | } |
661 | 662 | ||
662 | void | 663 | void |
663 | GNUNET_CRYPTO_hash_create_random (GNUNET_HashCode * result) | 664 | GNUNET_CRYPTO_hash_create_random (enum GNUNET_CRYPTO_Quality mode, GNUNET_HashCode * result) |
664 | { | 665 | { |
665 | int i; | 666 | int i; |
666 | for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; | 667 | for (i = (sizeof (GNUNET_HashCode) / sizeof (uint32_t)) - 1; i >= 0; |
667 | i--) | 668 | i--) |
668 | result->bits[i] = rand (); | 669 | result->bits[i] = GNUNET_CRYPTO_random_u32 (mode, (uint32_t)-1); |
669 | } | 670 | } |
670 | 671 | ||
671 | void | 672 | void |
672 | GNUNET_CRYPTO_hash_difference (const GNUNET_HashCode * a, | 673 | GNUNET_CRYPTO_hash_difference (const GNUNET_HashCode * a, |
673 | const GNUNET_HashCode * b, | 674 | const GNUNET_HashCode * b, |
674 | GNUNET_HashCode * result) | 675 | GNUNET_HashCode * result) |
675 | { | 676 | { |
676 | int i; | 677 | int i; |
677 | for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; | 678 | for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; |
@@ -681,8 +682,8 @@ GNUNET_CRYPTO_hash_difference (const GNUNET_HashCode * a, | |||
681 | 682 | ||
682 | void | 683 | void |
683 | GNUNET_CRYPTO_hash_sum (const GNUNET_HashCode * a, | 684 | GNUNET_CRYPTO_hash_sum (const GNUNET_HashCode * a, |
684 | const GNUNET_HashCode * delta, | 685 | const GNUNET_HashCode * delta, |
685 | GNUNET_HashCode * result) | 686 | GNUNET_HashCode * result) |
686 | { | 687 | { |
687 | int i; | 688 | int i; |
688 | for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; | 689 | for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; |
@@ -692,7 +693,7 @@ GNUNET_CRYPTO_hash_sum (const GNUNET_HashCode * a, | |||
692 | 693 | ||
693 | void | 694 | void |
694 | GNUNET_CRYPTO_hash_xor (const GNUNET_HashCode * a, | 695 | GNUNET_CRYPTO_hash_xor (const GNUNET_HashCode * a, |
695 | const GNUNET_HashCode * b, GNUNET_HashCode * result) | 696 | const GNUNET_HashCode * b, GNUNET_HashCode * result) |
696 | { | 697 | { |
697 | int i; | 698 | int i; |
698 | for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; | 699 | for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; |
@@ -705,18 +706,18 @@ GNUNET_CRYPTO_hash_xor (const GNUNET_HashCode * a, | |||
705 | */ | 706 | */ |
706 | void | 707 | void |
707 | GNUNET_CRYPTO_hash_to_aes_key (const GNUNET_HashCode * hc, | 708 | GNUNET_CRYPTO_hash_to_aes_key (const GNUNET_HashCode * hc, |
708 | struct GNUNET_CRYPTO_AesSessionKey *skey, | 709 | struct GNUNET_CRYPTO_AesSessionKey *skey, |
709 | struct GNUNET_CRYPTO_AesInitializationVector | 710 | struct GNUNET_CRYPTO_AesInitializationVector |
710 | *iv) | 711 | *iv) |
711 | { | 712 | { |
712 | GNUNET_assert (sizeof (GNUNET_HashCode) >= | 713 | GNUNET_assert (sizeof (GNUNET_HashCode) >= |
713 | GNUNET_CRYPTO_AES_KEY_LENGTH + | 714 | GNUNET_CRYPTO_AES_KEY_LENGTH + |
714 | sizeof (struct GNUNET_CRYPTO_AesInitializationVector)); | 715 | sizeof (struct GNUNET_CRYPTO_AesInitializationVector)); |
715 | memcpy (skey, hc, GNUNET_CRYPTO_AES_KEY_LENGTH); | 716 | memcpy (skey, hc, GNUNET_CRYPTO_AES_KEY_LENGTH); |
716 | skey->crc32 = | 717 | skey->crc32 = |
717 | htonl (GNUNET_CRYPTO_crc32_n (skey, GNUNET_CRYPTO_AES_KEY_LENGTH)); | 718 | htonl (GNUNET_CRYPTO_crc32_n (skey, GNUNET_CRYPTO_AES_KEY_LENGTH)); |
718 | memcpy (iv, &((char *) hc)[GNUNET_CRYPTO_AES_KEY_LENGTH], | 719 | memcpy (iv, &((char *) hc)[GNUNET_CRYPTO_AES_KEY_LENGTH], |
719 | sizeof (struct GNUNET_CRYPTO_AesInitializationVector)); | 720 | sizeof (struct GNUNET_CRYPTO_AesInitializationVector)); |
720 | } | 721 | } |
721 | 722 | ||
722 | /** | 723 | /** |
@@ -739,21 +740,21 @@ GNUNET_CRYPTO_hash_get_bit (const GNUNET_HashCode * code, unsigned int bit) | |||
739 | */ | 740 | */ |
740 | int | 741 | int |
741 | GNUNET_CRYPTO_hash_cmp (const GNUNET_HashCode * h1, | 742 | GNUNET_CRYPTO_hash_cmp (const GNUNET_HashCode * h1, |
742 | const GNUNET_HashCode * h2) | 743 | const GNUNET_HashCode * h2) |
743 | { | 744 | { |
744 | unsigned int *i1; | 745 | unsigned int *i1; |
745 | unsigned int *i2; | 746 | unsigned int *i2; |
746 | int i; | 747 | int i; |
747 | 748 | ||
748 | i1 = (unsigned int *) h1; | 749 | i1 = (unsigned int *) h1; |
749 | i2 = (unsigned int *) h2; | 750 | i2 = (unsigned int *) h2; |
750 | for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; | 751 | for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; |
751 | i--) | 752 | i--) |
752 | { | 753 | { |
753 | if (i1[i] > i2[i]) | 754 | if (i1[i] > i2[i]) |
754 | return 1; | 755 | return 1; |
755 | if (i1[i] < i2[i]) | 756 | if (i1[i] < i2[i]) |
756 | return -1; | 757 | return -1; |
757 | } | 758 | } |
758 | return 0; | 759 | return 0; |
759 | } | 760 | } |
@@ -765,23 +766,23 @@ GNUNET_CRYPTO_hash_cmp (const GNUNET_HashCode * h1, | |||
765 | */ | 766 | */ |
766 | int | 767 | int |
767 | GNUNET_CRYPTO_hash_xorcmp (const GNUNET_HashCode * h1, | 768 | GNUNET_CRYPTO_hash_xorcmp (const GNUNET_HashCode * h1, |
768 | const GNUNET_HashCode * h2, | 769 | const GNUNET_HashCode * h2, |
769 | const GNUNET_HashCode * target) | 770 | const GNUNET_HashCode * target) |
770 | { | 771 | { |
771 | int i; | 772 | int i; |
772 | unsigned int d1; | 773 | unsigned int d1; |
773 | unsigned int d2; | 774 | unsigned int d2; |
774 | 775 | ||
775 | for (i = sizeof (GNUNET_HashCode) / sizeof (unsigned int) - 1; i >= 0; i--) | 776 | for (i = sizeof (GNUNET_HashCode) / sizeof (unsigned int) - 1; i >= 0; i--) |
776 | { | 777 | { |
777 | d1 = ((unsigned int *) h1)[i] ^ ((unsigned int *) target)[i]; | 778 | d1 = ((unsigned int *) h1)[i] ^ ((unsigned int *) target)[i]; |
778 | d2 = ((unsigned int *) h2)[i] ^ ((unsigned int *) target)[i]; | 779 | d2 = ((unsigned int *) h2)[i] ^ ((unsigned int *) target)[i]; |
779 | if (d1 > d2) | 780 | if (d1 > d2) |
780 | return 1; | 781 | return 1; |
781 | else if (d1 < d2) | 782 | else if (d1 < d2) |
782 | return -1; | 783 | return -1; |
783 | } | 784 | } |
784 | return 0; | 785 | return 0; |
785 | } | 786 | } |
786 | 787 | ||
787 | /* end of hashing.c */ | 788 | /* end of crypto_hash.c */ |
diff --git a/src/util/crypto_random.c b/src/util/crypto_random.c index 3f7ac4dd3..0ad1364cb 100644 --- a/src/util/crypto_random.c +++ b/src/util/crypto_random.c | |||
@@ -32,13 +32,14 @@ | |||
32 | /** | 32 | /** |
33 | * @return a random value in the interval [0,i[. | 33 | * @return a random value in the interval [0,i[. |
34 | */ | 34 | */ |
35 | unsigned int | 35 | uint32_t |
36 | GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode, unsigned int i) | 36 | GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode, |
37 | uint32_t i) | ||
37 | { | 38 | { |
38 | #ifdef gcry_fast_random_poll | 39 | #ifdef gcry_fast_random_poll |
39 | static unsigned int invokeCount; | 40 | static unsigned int invokeCount; |
40 | #endif | 41 | #endif |
41 | unsigned int ret; | 42 | uint32_t ret; |
42 | 43 | ||
43 | GNUNET_assert (i > 0); | 44 | GNUNET_assert (i > 0); |
44 | 45 | ||
@@ -49,11 +50,9 @@ GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode, unsigned int i) | |||
49 | if ((invokeCount++ % 256) == 0) | 50 | if ((invokeCount++ % 256) == 0) |
50 | gcry_fast_random_poll (); | 51 | gcry_fast_random_poll (); |
51 | #endif | 52 | #endif |
52 | ret = rand (); /* in case gcry_randomize fails, | ||
53 | we at least get a pseudo- | ||
54 | random number this way */ | ||
55 | gcry_randomize ((unsigned char *) &ret, | 53 | gcry_randomize ((unsigned char *) &ret, |
56 | sizeof (unsigned int), GCRY_STRONG_RANDOM); | 54 | sizeof (uint32_t), |
55 | GCRY_STRONG_RANDOM); | ||
57 | return ret % i; | 56 | return ret % i; |
58 | } | 57 | } |
59 | else | 58 | else |
@@ -80,10 +79,10 @@ GNUNET_CRYPTO_random_permute (enum GNUNET_CRYPTO_Quality mode, unsigned int n) | |||
80 | unsigned int *ret; | 79 | unsigned int *ret; |
81 | unsigned int i; | 80 | unsigned int i; |
82 | unsigned int tmp; | 81 | unsigned int tmp; |
83 | unsigned int x; | 82 | uint32_t x; |
84 | 83 | ||
85 | GNUNET_assert (n > 0); | 84 | GNUNET_assert (n > 0); |
86 | ret = GNUNET_malloc (n * sizeof (int)); | 85 | ret = GNUNET_malloc (n * sizeof (unsigned int)); |
87 | for (i = 0; i < n; i++) | 86 | for (i = 0; i < n; i++) |
88 | ret[i] = i; | 87 | ret[i] = i; |
89 | for (i = 0; i < n; i++) | 88 | for (i = 0; i < n; i++) |
@@ -99,17 +98,18 @@ GNUNET_CRYPTO_random_permute (enum GNUNET_CRYPTO_Quality mode, unsigned int n) | |||
99 | /** | 98 | /** |
100 | * Random on unsigned 64-bit values. | 99 | * Random on unsigned 64-bit values. |
101 | */ | 100 | */ |
102 | unsigned long long | 101 | uint64_t |
103 | GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode, | 102 | GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode, |
104 | unsigned long long u) | 103 | uint64_t u) |
105 | { | 104 | { |
106 | unsigned long long ret; | 105 | uint64_t ret; |
107 | 106 | ||
108 | GNUNET_assert (u > 0); | 107 | GNUNET_assert (u > 0); |
109 | if (mode == GNUNET_CRYPTO_QUALITY_STRONG) | 108 | if (mode == GNUNET_CRYPTO_QUALITY_STRONG) |
110 | { | 109 | { |
111 | gcry_randomize ((unsigned char *) &ret, | 110 | gcry_randomize ((unsigned char *) &ret, |
112 | sizeof (unsigned long long), GCRY_STRONG_RANDOM); | 111 | sizeof (uint64_t), |
112 | GCRY_STRONG_RANDOM); | ||
113 | return ret % u; | 113 | return ret % u; |
114 | } | 114 | } |
115 | else | 115 | else |
diff --git a/src/util/crypto_rsa.c b/src/util/crypto_rsa.c index edf1b2bdf..bb14f36c9 100644 --- a/src/util/crypto_rsa.c +++ b/src/util/crypto_rsa.c | |||
@@ -751,7 +751,7 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename) | |||
751 | */ | 751 | */ |
752 | int | 752 | int |
753 | GNUNET_CRYPTO_rsa_encrypt (const void *block, | 753 | GNUNET_CRYPTO_rsa_encrypt (const void *block, |
754 | uint16_t size, | 754 | size_t size, |
755 | const struct | 755 | const struct |
756 | GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey, | 756 | GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey, |
757 | struct GNUNET_CRYPTO_RsaEncryptedData *target) | 757 | struct GNUNET_CRYPTO_RsaEncryptedData *target) |
@@ -799,10 +799,11 @@ GNUNET_CRYPTO_rsa_encrypt (const void *block, | |||
799 | * the decrypted block is bigger, an error is returned | 799 | * the decrypted block is bigger, an error is returned |
800 | * @returns the size of the decrypted block, -1 on error | 800 | * @returns the size of the decrypted block, -1 on error |
801 | */ | 801 | */ |
802 | int | 802 | ssize_t |
803 | GNUNET_CRYPTO_rsa_decrypt (const struct GNUNET_CRYPTO_RsaPrivateKey *hostkey, | 803 | GNUNET_CRYPTO_rsa_decrypt (const struct GNUNET_CRYPTO_RsaPrivateKey *hostkey, |
804 | const struct GNUNET_CRYPTO_RsaEncryptedData *block, | 804 | const struct GNUNET_CRYPTO_RsaEncryptedData *block, |
805 | void *result, uint16_t max) | 805 | void *result, |
806 | size_t max) | ||
806 | { | 807 | { |
807 | gcry_sexp_t resultsexp; | 808 | gcry_sexp_t resultsexp; |
808 | gcry_sexp_t data; | 809 | gcry_sexp_t data; |
diff --git a/src/util/test_container_bloomfilter.c b/src/util/test_container_bloomfilter.c index ccaea45ae..012d3f954 100644 --- a/src/util/test_container_bloomfilter.c +++ b/src/util/test_container_bloomfilter.c | |||
@@ -38,7 +38,7 @@ | |||
38 | static void | 38 | static void |
39 | nextHC (GNUNET_HashCode * hc) | 39 | nextHC (GNUNET_HashCode * hc) |
40 | { | 40 | { |
41 | GNUNET_CRYPTO_hash_create_random (hc); | 41 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, hc); |
42 | } | 42 | } |
43 | 43 | ||
44 | static int | 44 | static int |
diff --git a/src/util/test_crypto_hash.c b/src/util/test_crypto_hash.c index e10aee9b1..97ef4ec88 100644 --- a/src/util/test_crypto_hash.c +++ b/src/util/test_crypto_hash.c | |||
@@ -73,8 +73,8 @@ testArithmetic () | |||
73 | struct GNUNET_CRYPTO_AesSessionKey skey; | 73 | struct GNUNET_CRYPTO_AesSessionKey skey; |
74 | struct GNUNET_CRYPTO_AesInitializationVector iv; | 74 | struct GNUNET_CRYPTO_AesInitializationVector iv; |
75 | 75 | ||
76 | GNUNET_CRYPTO_hash_create_random (&h1); | 76 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &h1); |
77 | GNUNET_CRYPTO_hash_create_random (&h2); | 77 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &h2); |
78 | if (GNUNET_CRYPTO_hash_distance_u32 (&h1, &h2) != | 78 | if (GNUNET_CRYPTO_hash_distance_u32 (&h1, &h2) != |
79 | GNUNET_CRYPTO_hash_distance_u32 (&h2, &h1)) | 79 | GNUNET_CRYPTO_hash_distance_u32 (&h2, &h1)) |
80 | return 1; | 80 | return 1; |
diff --git a/src/util/test_crypto_ksk.c b/src/util/test_crypto_ksk.c index 8bcb105ea..943e9792b 100644 --- a/src/util/test_crypto_ksk.c +++ b/src/util/test_crypto_ksk.c | |||
@@ -193,7 +193,7 @@ main (int argc, char *argv[]) | |||
193 | struct GNUNET_CRYPTO_RsaPrivateKey *hostkey; | 193 | struct GNUNET_CRYPTO_RsaPrivateKey *hostkey; |
194 | 194 | ||
195 | GNUNET_log_setup ("test-crypto-ksk", "WARNING", NULL); | 195 | GNUNET_log_setup ("test-crypto-ksk", "WARNING", NULL); |
196 | GNUNET_CRYPTO_hash_create_random (&in); | 196 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &in); |
197 | hostkey = GNUNET_CRYPTO_rsa_key_create_from_hash (&in); | 197 | hostkey = GNUNET_CRYPTO_rsa_key_create_from_hash (&in); |
198 | if (hostkey == NULL) | 198 | if (hostkey == NULL) |
199 | { | 199 | { |
diff --git a/src/util/test_pseudonym.c b/src/util/test_pseudonym.c index d358c8210..daa4c3168 100644 --- a/src/util/test_pseudonym.c +++ b/src/util/test_pseudonym.c | |||
@@ -99,7 +99,7 @@ main (int argc, char *argv[]) | |||
99 | old = GNUNET_PSEUDONYM_list_all (cfg, NULL, NULL); | 99 | old = GNUNET_PSEUDONYM_list_all (cfg, NULL, NULL); |
100 | meta = GNUNET_CONTAINER_meta_data_create (); | 100 | meta = GNUNET_CONTAINER_meta_data_create (); |
101 | GNUNET_CONTAINER_meta_data_insert (meta, EXTRACTOR_TITLE, "test"); | 101 | GNUNET_CONTAINER_meta_data_insert (meta, EXTRACTOR_TITLE, "test"); |
102 | GNUNET_CRYPTO_hash_create_random (&id1); | 102 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &id1); |
103 | GNUNET_PSEUDONYM_add (cfg, &id1, meta); | 103 | GNUNET_PSEUDONYM_add (cfg, &id1, meta); |
104 | CHECK (notiCount == 1); | 104 | CHECK (notiCount == 1); |
105 | GNUNET_PSEUDONYM_add (cfg, &id1, meta); | 105 | GNUNET_PSEUDONYM_add (cfg, &id1, meta); |
@@ -107,7 +107,7 @@ main (int argc, char *argv[]) | |||
107 | newVal = GNUNET_PSEUDONYM_list_all (cfg, &iter, &ok); | 107 | newVal = GNUNET_PSEUDONYM_list_all (cfg, &iter, &ok); |
108 | CHECK (old < newVal); | 108 | CHECK (old < newVal); |
109 | old = newVal; | 109 | old = newVal; |
110 | GNUNET_CRYPTO_hash_create_random (&id2); | 110 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &id2); |
111 | GNUNET_PSEUDONYM_add (cfg, &id2, meta); | 111 | GNUNET_PSEUDONYM_add (cfg, &id2, meta); |
112 | CHECK (notiCount == 3); | 112 | CHECK (notiCount == 3); |
113 | newVal = GNUNET_PSEUDONYM_list_all (cfg, &iter, &ok); | 113 | newVal = GNUNET_PSEUDONYM_list_all (cfg, &iter, &ok); |