#if REPORT_ID
fprintf (stderr, "\n");
#endif
+ GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-datastore");
return ret;
}
test_fs_getopt \
test_fs_uri
-TESTS = $(check_PROGRAMS)
+TESTS = test_fs_uri
+
+# $(check_PROGRAMS)
test_fs_collection_SOURCES = \
test_fs_collection.c
cfg,
"test-fs-collection",
&progress_cb,
- NULL);
+ NULL,
+ GNUNET_FS_FLAGS_NONE,
+ GNUNET_FS_OPTIONS_END);
GNUNET_assert (NULL != fsh);
GNUNET_FS_collection_stop (fsh);
GNUNET_assert (NULL == GNUNET_FS_collection_get (fsh));
cfg,
"test-fs-collection",
&progress_cb,
- NULL);
+ NULL,
+ GNUNET_FS_FLAGS_NONE,
+ GNUNET_FS_OPTIONS_END);
have = GNUNET_FS_collection_get (fsh);
GNUNET_assert (NULL != have);
GNUNET_FS_namespace_delete (have, GNUNET_NO);
NULL);
GNUNET_CRYPTO_random_disable_entropy_gathering ();
cfg = GNUNET_CONFIGURATION_create ();
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_parse (cfg, "test_fs_collection_data.conf"))
+ if (GNUNET_SYSERR == GNUNET_CONFIGURATION_parse (cfg,
+ "test_fs_collection_data.conf"))
{
GNUNET_CONFIGURATION_destroy (cfg);
return -1;
static int
testDirectory (unsigned int i)
{
+ struct GNUNET_FS_DirectoryBuilder *db;
char *data;
- unsigned long long dlen;
+ size_t dlen;
struct GNUNET_FS_Uri **uris;
struct GNUNET_CONTAINER_MetaData **mds;
struct GNUNET_CONTAINER_MetaData *meta;
}
GNUNET_snprintf (uri,
sizeof(uri),
- "gnunet://ecrs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.%u",
+ "gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.%u",
p);
uris[p] = GNUNET_FS_uri_parse (uri, &emsg);
if (uris[p] == NULL)
meta = GNUNET_CONTAINER_meta_data_create ();
GNUNET_CONTAINER_meta_data_insert (meta, EXTRACTOR_TITLE, "A title");
GNUNET_CONTAINER_meta_data_insert (meta, EXTRACTOR_AUTHOR, "An author");
- if (GNUNET_OK !=
- GNUNET_FS_directory_create (&dlen, &data, i, uris, mds, meta))
- {
- GNUNET_CONTAINER_meta_data_destroy (meta);
- for (p = 0; p < i; p++)
- {
- GNUNET_CONTAINER_meta_data_destroy (mds[p]);
- GNUNET_FS_uri_destroy (uris[p]);
- }
- GNUNET_free (uris);
- GNUNET_free (mds);
- ABORT ();
- }
+ db = GNUNET_FS_directory_builder_create (meta);
+ for (p=0;p<i;p++)
+ GNUNET_FS_directory_builder_add (db, uris[i], mds[i], NULL);
+ GNUNET_FS_directory_builder_finish (db,
+ &dlen,
+ (void**) &data);
cls.pos = 0;
cls.uri = uris;
cls.md = mds;
#endif
NULL);
ret = check ();
- return 0;
+ return ret;
}
+
+/* end of test_gnunet_daemon_hostlist.c */
* @param len the length of the buffer in bytes
* @return the resulting CRC32 checksum
*/
-int GNUNET_CRYPTO_crc32_n (const void *buf, unsigned int len);
+int32_t GNUNET_CRYPTO_crc32_n (const void *buf,
+ size_t len);
/**
* Produce a random value.
*
+ * @param mode desired quality of the random number
* @param i the upper limit (exclusive) for the random number
- * @return a random value in the interval [0,i[.
+ * @return a random value in the interval [0,i) (exclusive).
*/
-unsigned int GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality,
- unsigned int i);
+uint32_t GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode,
+ uint32_t i);
/**
* Random on unsigned 64-bit values. We break them down into signed
* 32-bit values and reassemble the 64-bit random value bit-wise.
+ *
+ * @param mode desired quality of the random number
+ * @param max value returned will be in range [0,max) (exclusive)
+ * @return random 64-bit number
*/
-unsigned long long GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode,
- unsigned long long u);
+uint64_t GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode,
+ uint64_t max);
/**
* for streams.
* @returns the size of the encrypted block, -1 for errors
*/
-int GNUNET_CRYPTO_aes_encrypt (const void *block,
- uint16_t len,
- const struct GNUNET_CRYPTO_AesSessionKey
- *sessionkey,
- const struct
- GNUNET_CRYPTO_AesInitializationVector *iv,
- void *result);
+ssize_t GNUNET_CRYPTO_aes_encrypt (const void *block,
+ size_t len,
+ const struct GNUNET_CRYPTO_AesSessionKey
+ *sessionkey,
+ const struct
+ GNUNET_CRYPTO_AesInitializationVector *iv,
+ void *result);
/**
* @param result address to store the result at
* @return -1 on failure, size of decrypted block on success
*/
-int GNUNET_CRYPTO_aes_decrypt (const void *block, uint16_t size,
- const struct GNUNET_CRYPTO_AesSessionKey *sessionkey,
- const struct GNUNET_CRYPTO_AesInitializationVector *iv,
- void *result);
+ssize_t GNUNET_CRYPTO_aes_decrypt (const void *block,
+ size_t size,
+ const struct GNUNET_CRYPTO_AesSessionKey *sessionkey,
+ const struct GNUNET_CRYPTO_AesInitializationVector *iv,
+ void *result);
/**
* result should be a positive number.
* @return number between 0 and 65536
*/
-unsigned int GNUNET_CRYPTO_hash_distance_u32 (const GNUNET_HashCode * a,
- const GNUNET_HashCode * b);
+uint32_t GNUNET_CRYPTO_hash_distance_u32 (const GNUNET_HashCode * a,
+ const GNUNET_HashCode * b);
/**
- * Hash block of given size.
- * @param block the data to GNUNET_CRYPTO_hash, length is given as a second argument
+ * Compute hash of a given block.
+ *
+ * @param block the data to hash
+ * @param size size of the block
* @param ret pointer to where to write the hashcode
*/
-void GNUNET_CRYPTO_hash (const void *block, unsigned int size,
+void GNUNET_CRYPTO_hash (const void *block,
+ size_t size,
GNUNET_HashCode * ret);
/**
* Create a random hash code.
*/
-void GNUNET_CRYPTO_hash_create_random (GNUNET_HashCode * result);
+void GNUNET_CRYPTO_hash_create_random (enum GNUNET_CRYPTO_Quality mode,
+ GNUNET_HashCode * result);
/**
* @returns GNUNET_SYSERR on error, GNUNET_OK if ok
*/
int GNUNET_CRYPTO_rsa_encrypt (const void *block,
- uint16_t size,
+ size_t size,
const struct
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
*publicKey,
* @param size how many bytes of a result are expected? Must be exact.
* @returns the size of the decrypted block (that is, size) or -1 on error
*/
-int GNUNET_CRYPTO_rsa_decrypt (const struct GNUNET_CRYPTO_RsaPrivateKey *key,
- const struct GNUNET_CRYPTO_RsaEncryptedData
- *block, void *result, uint16_t size);
+ssize_t GNUNET_CRYPTO_rsa_decrypt (const struct GNUNET_CRYPTO_RsaPrivateKey *key,
+ const struct GNUNET_CRYPTO_RsaEncryptedData
+ *block,
+ void *result,
+ size_t size);
/**
#endif
NULL);
ret = check ();
-
+ GNUNET_DISK_directory_remove ("/tmp/test-gnunet-testing");
return ret;
}
* @param result the output parameter in which to store the encrypted result
* @returns the size of the encrypted block, -1 for errors
*/
-int
+ssize_t
GNUNET_CRYPTO_aes_encrypt (const void *block,
- uint16_t len,
+ size_t len,
const struct GNUNET_CRYPTO_AesSessionKey
*sessionkey,
const struct GNUNET_CRYPTO_AesInitializationVector
(sessionkey, GNUNET_CRYPTO_AES_KEY_LENGTH)))
{
GNUNET_break (0);
- return GNUNET_SYSERR;
+ return -1;
}
GNUNET_assert (0 == gcry_cipher_open (&handle,
GCRY_CIPHER_AES256,
* @param result address to store the result at
* @return -1 on failure, size of decrypted block on success
*/
-int
-GNUNET_CRYPTO_aes_decrypt (const void *block, uint16_t size,
+ssize_t
+GNUNET_CRYPTO_aes_decrypt (const void *block,
+ size_t size,
const struct GNUNET_CRYPTO_AesSessionKey
*sessionkey,
const struct GNUNET_CRYPTO_AesInitializationVector
(sessionkey, GNUNET_CRYPTO_AES_KEY_LENGTH)))
{
GNUNET_break (0);
- return GNUNET_SYSERR;
+ return -1;
}
GNUNET_assert (0 == gcry_cipher_open (&handle,
GCRY_CIPHER_AES256,
* @param len the length of the buffer
* @return the resulting CRC32 checksum
*/
-int
-GNUNET_CRYPTO_crc32_n (const void *buf, unsigned int len)
+int32_t
+GNUNET_CRYPTO_crc32_n (const void *buf, size_t len)
{
uLong crc;
crc = crc32 (0L, Z_NULL, 0);
return crc;
}
-/* end of crc32.c */
+/* end of crypto_crc.c */
* @param ret pointer to where to write the hashcode
*/
void
-GNUNET_CRYPTO_hash (const void *block, unsigned int size,
+GNUNET_CRYPTO_hash (const void *block,
+ size_t size,
GNUNET_HashCode * ret)
{
struct sha512_ctx ctx;
}
void
-GNUNET_CRYPTO_hash_create_random (GNUNET_HashCode * result)
+GNUNET_CRYPTO_hash_create_random (enum GNUNET_CRYPTO_Quality mode, GNUNET_HashCode * result)
{
int i;
- for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0;
+ for (i = (sizeof (GNUNET_HashCode) / sizeof (uint32_t)) - 1; i >= 0;
i--)
- result->bits[i] = rand ();
+ result->bits[i] = GNUNET_CRYPTO_random_u32 (mode, (uint32_t)-1);
}
void
GNUNET_CRYPTO_hash_difference (const GNUNET_HashCode * a,
- const GNUNET_HashCode * b,
- GNUNET_HashCode * result)
+ const GNUNET_HashCode * b,
+ GNUNET_HashCode * result)
{
int i;
for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0;
void
GNUNET_CRYPTO_hash_sum (const GNUNET_HashCode * a,
- const GNUNET_HashCode * delta,
- GNUNET_HashCode * result)
+ const GNUNET_HashCode * delta,
+ GNUNET_HashCode * result)
{
int i;
for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0;
void
GNUNET_CRYPTO_hash_xor (const GNUNET_HashCode * a,
- const GNUNET_HashCode * b, GNUNET_HashCode * result)
+ const GNUNET_HashCode * b, GNUNET_HashCode * result)
{
int i;
for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0;
*/
void
GNUNET_CRYPTO_hash_to_aes_key (const GNUNET_HashCode * hc,
- struct GNUNET_CRYPTO_AesSessionKey *skey,
- struct GNUNET_CRYPTO_AesInitializationVector
- *iv)
+ struct GNUNET_CRYPTO_AesSessionKey *skey,
+ struct GNUNET_CRYPTO_AesInitializationVector
+ *iv)
{
GNUNET_assert (sizeof (GNUNET_HashCode) >=
- GNUNET_CRYPTO_AES_KEY_LENGTH +
- sizeof (struct GNUNET_CRYPTO_AesInitializationVector));
+ GNUNET_CRYPTO_AES_KEY_LENGTH +
+ sizeof (struct GNUNET_CRYPTO_AesInitializationVector));
memcpy (skey, hc, GNUNET_CRYPTO_AES_KEY_LENGTH);
skey->crc32 =
htonl (GNUNET_CRYPTO_crc32_n (skey, GNUNET_CRYPTO_AES_KEY_LENGTH));
memcpy (iv, &((char *) hc)[GNUNET_CRYPTO_AES_KEY_LENGTH],
- sizeof (struct GNUNET_CRYPTO_AesInitializationVector));
+ sizeof (struct GNUNET_CRYPTO_AesInitializationVector));
}
/**
*/
int
GNUNET_CRYPTO_hash_cmp (const GNUNET_HashCode * h1,
- const GNUNET_HashCode * h2)
+ const GNUNET_HashCode * h2)
{
unsigned int *i1;
unsigned int *i2;
int i;
-
+
i1 = (unsigned int *) h1;
i2 = (unsigned int *) h2;
for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0;
i--)
{
if (i1[i] > i2[i])
- return 1;
+ return 1;
if (i1[i] < i2[i])
- return -1;
+ return -1;
}
return 0;
}
*/
int
GNUNET_CRYPTO_hash_xorcmp (const GNUNET_HashCode * h1,
- const GNUNET_HashCode * h2,
- const GNUNET_HashCode * target)
+ const GNUNET_HashCode * h2,
+ const GNUNET_HashCode * target)
{
int i;
unsigned int d1;
unsigned int d2;
-
+
for (i = sizeof (GNUNET_HashCode) / sizeof (unsigned int) - 1; i >= 0; i--)
{
d1 = ((unsigned int *) h1)[i] ^ ((unsigned int *) target)[i];
d2 = ((unsigned int *) h2)[i] ^ ((unsigned int *) target)[i];
if (d1 > d2)
- return 1;
+ return 1;
else if (d1 < d2)
- return -1;
+ return -1;
}
return 0;
}
-/* end of hashing.c */
+/* end of crypto_hash.c */
/**
* @return a random value in the interval [0,i[.
*/
-unsigned int
-GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode, unsigned int i)
+uint32_t
+GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode,
+ uint32_t i)
{
#ifdef gcry_fast_random_poll
static unsigned int invokeCount;
#endif
- unsigned int ret;
+ uint32_t ret;
GNUNET_assert (i > 0);
if ((invokeCount++ % 256) == 0)
gcry_fast_random_poll ();
#endif
- ret = rand (); /* in case gcry_randomize fails,
- we at least get a pseudo-
- random number this way */
gcry_randomize ((unsigned char *) &ret,
- sizeof (unsigned int), GCRY_STRONG_RANDOM);
+ sizeof (uint32_t),
+ GCRY_STRONG_RANDOM);
return ret % i;
}
else
unsigned int *ret;
unsigned int i;
unsigned int tmp;
- unsigned int x;
+ uint32_t x;
GNUNET_assert (n > 0);
- ret = GNUNET_malloc (n * sizeof (int));
+ ret = GNUNET_malloc (n * sizeof (unsigned int));
for (i = 0; i < n; i++)
ret[i] = i;
for (i = 0; i < n; i++)
/**
* Random on unsigned 64-bit values.
*/
-unsigned long long
+uint64_t
GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode,
- unsigned long long u)
+ uint64_t u)
{
- unsigned long long ret;
+ uint64_t ret;
GNUNET_assert (u > 0);
if (mode == GNUNET_CRYPTO_QUALITY_STRONG)
{
gcry_randomize ((unsigned char *) &ret,
- sizeof (unsigned long long), GCRY_STRONG_RANDOM);
+ sizeof (uint64_t),
+ GCRY_STRONG_RANDOM);
return ret % u;
}
else
*/
int
GNUNET_CRYPTO_rsa_encrypt (const void *block,
- uint16_t size,
+ size_t size,
const struct
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey,
struct GNUNET_CRYPTO_RsaEncryptedData *target)
* the decrypted block is bigger, an error is returned
* @returns the size of the decrypted block, -1 on error
*/
-int
+ssize_t
GNUNET_CRYPTO_rsa_decrypt (const struct GNUNET_CRYPTO_RsaPrivateKey *hostkey,
const struct GNUNET_CRYPTO_RsaEncryptedData *block,
- void *result, uint16_t max)
+ void *result,
+ size_t max)
{
gcry_sexp_t resultsexp;
gcry_sexp_t data;
static void
nextHC (GNUNET_HashCode * hc)
{
- GNUNET_CRYPTO_hash_create_random (hc);
+ GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, hc);
}
static int
struct GNUNET_CRYPTO_AesSessionKey skey;
struct GNUNET_CRYPTO_AesInitializationVector iv;
- GNUNET_CRYPTO_hash_create_random (&h1);
- GNUNET_CRYPTO_hash_create_random (&h2);
+ GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &h1);
+ GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &h2);
if (GNUNET_CRYPTO_hash_distance_u32 (&h1, &h2) !=
GNUNET_CRYPTO_hash_distance_u32 (&h2, &h1))
return 1;
struct GNUNET_CRYPTO_RsaPrivateKey *hostkey;
GNUNET_log_setup ("test-crypto-ksk", "WARNING", NULL);
- GNUNET_CRYPTO_hash_create_random (&in);
+ GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &in);
hostkey = GNUNET_CRYPTO_rsa_key_create_from_hash (&in);
if (hostkey == NULL)
{
old = GNUNET_PSEUDONYM_list_all (cfg, NULL, NULL);
meta = GNUNET_CONTAINER_meta_data_create ();
GNUNET_CONTAINER_meta_data_insert (meta, EXTRACTOR_TITLE, "test");
- GNUNET_CRYPTO_hash_create_random (&id1);
+ GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &id1);
GNUNET_PSEUDONYM_add (cfg, &id1, meta);
CHECK (notiCount == 1);
GNUNET_PSEUDONYM_add (cfg, &id1, meta);
newVal = GNUNET_PSEUDONYM_list_all (cfg, &iter, &ok);
CHECK (old < newVal);
old = newVal;
- GNUNET_CRYPTO_hash_create_random (&id2);
+ GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &id2);
GNUNET_PSEUDONYM_add (cfg, &id2, meta);
CHECK (notiCount == 3);
newVal = GNUNET_PSEUDONYM_list_all (cfg, &iter, &ok);