(i < sizeof(struct GNUNET_HashCode) * 8) && (i < bucket + 1 + 32 - 9);
i++)
{
- if (GNUNET_CRYPTO_hash_get_bit (target, i) !=
- GNUNET_CRYPTO_hash_get_bit (have, i))
+ if (GNUNET_CRYPTO_hash_get_bit_rtl (target, i) !=
+ GNUNET_CRYPTO_hash_get_bit_rtl (have, i))
lsb |= (1 << (bucket + 32 - 9 - i)); /* first bit set will be 10,
* last bit set will be 31 -- if
* i does not reach 512 first... */
fprintf (stdout,
"EXPIRATION: %"PRIu64"\n", rd->expiration_time);
fprintf (stdout,
- "DATA_SIZE: %"PRIu64"\n", rd->data_size);
+ "DATA_SIZE: %zu\n", rd->data_size);
fprintf (stdout,
"TYPE: %d\n", rd->record_type);
fprintf (stdout,
* Obtain a bit from a hashcode.
*
* @param code the `struct GNUNET_HashCode` to index bit-wise
- * @param bit index into the hashcode, [0...159]
+ * @param bit index into the hashcode, [0...159] where 0 is the leftmost bit
+ * (bytes in code interpreted big endian)
* @return Bit \a bit from hashcode \a code, -1 for invalid index
*/
int
-GNUNET_CRYPTO_hash_get_bit (const struct GNUNET_HashCode *code,
- unsigned int bit);
+GNUNET_CRYPTO_hash_get_bit_ltr (const struct GNUNET_HashCode *code,
+ unsigned int bit);
+
+
+/**
+ * Obtain a bit from a hashcode.
+ * @param code the GNUNET_CRYPTO_hash to index bit-wise
+ * @param bit index into the hashcode, [0...511] where 0 is the rightmost bit
+ * (bytes in code interpreted little endian)
+ * @return Bit \a bit from hashcode \a code, -1 for invalid index
+ */
+int
+GNUNET_CRYPTO_hash_get_bit_rtl (const struct GNUNET_HashCode *code,
+ unsigned int bit);
/**
unsigned int hash_count;
hash_count = 0;
- while (0 == GNUNET_CRYPTO_hash_get_bit (hash, hash_count))
+ while (0 == GNUNET_CRYPTO_hash_get_bit_ltr (hash, hash_count))
hash_count++;
return hash_count;
}
{
unsigned int hash_count;
hash_count = 0;
- while ((0 == GNUNET_CRYPTO_hash_get_bit (hash, hash_count)))
+ while ((0 == GNUNET_CRYPTO_hash_get_bit_ltr (hash, hash_count)))
hash_count++;
return hash_count;
}
+ sizeof (struct GNUNET_TIME_AbsoluteNBO)
+ sizeof (uint64_t)] GNUNET_ALIGN;
struct GNUNET_REVOCATION_SignaturePurposePS spurp;
- struct GNUNET_CRYPTO_HashAsciiEncoded h_str;
struct GNUNET_HashCode result;
struct GNUNET_TIME_Absolute ts;
struct GNUNET_TIME_Absolute exp;
"Score %u with %" PRIu64 " (#%u)\n",
tmp_score, pow_val, i);
- GNUNET_CRYPTO_hash_to_enc (&result,
- &h_str);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Hash: %s\n", (char*)&h_str);
-
score += tmp_score;
}
unsigned int difficulty)
{
struct GNUNET_REVOCATION_PowCalculationHandle *pc;
+ struct GNUNET_TIME_Relative ttl;
+
pc = GNUNET_new (struct GNUNET_REVOCATION_PowCalculationHandle);
pc->pow = pow;
+ ttl = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_YEARS,
+ epochs);
+ pc->pow->ttl = GNUNET_TIME_relative_hton (ttl);
pc->current_pow = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
UINT64_MAX);
pc->difficulty = difficulty;
GNUNET_CRYPTO_eddsa_key_create (struct GNUNET_CRYPTO_EddsaPrivateKey *pk)
{
BENCHMARK_START (eddsa_key_create);
+ /*
+ * We do not clamp for EdDSA, since all functions that use the private key do
+ * their own clamping (just like in libsodium). What we call "private key"
+ * here, actually corresponds to the seed in libsodium.
+ *
+ * (Contrast this to ECDSA, where functions using the private key can't clamp
+ * due to properties needed for GNS. That is a worse/unsafer API, but
+ * required for the GNS constructions to work.)
+ */
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
pk,
sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey));
- // FIXME: should we not do the clamping here? Or is this done elsewhere?
BENCHMARK_END (eddsa_key_create);
}
/**
* Obtain a bit from a hashcode.
* @param code the GNUNET_CRYPTO_hash to index bit-wise
- * @param bit index into the hashcode, [0...511]
+ * @param bit index into the hashcode, [0...511] where 0 is the leftmost bit
+ * (bytes in code interpreted big endian)
* @return Bit \a bit from hashcode \a code, -1 for invalid index
*/
int
-GNUNET_CRYPTO_hash_get_bit (const struct GNUNET_HashCode *code, unsigned int
- bit)
+GNUNET_CRYPTO_hash_get_bit_ltr (const struct GNUNET_HashCode *code,
+ unsigned int bit)
+{
+ GNUNET_assert (bit < 8 * sizeof(struct GNUNET_HashCode));
+ return (((unsigned char *) code)[bit >> 3] & (128 >> (bit & 7))) > 0;
+}
+
+/**
+ * Obtain a bit from a hashcode.
+ * @param code the GNUNET_CRYPTO_hash to index bit-wise
+ * @param bit index into the hashcode, [0...511] where 0 is the rightmost bit
+ * (bytes in code interpreted little endian)
+ * @return Bit \a bit from hashcode \a code, -1 for invalid index
+ */
+int
+GNUNET_CRYPTO_hash_get_bit_rtl (const struct GNUNET_HashCode *code,
+ unsigned int bit)
{
GNUNET_assert (bit < 8 * sizeof(struct GNUNET_HashCode));
return (((unsigned char *) code)[bit >> 3] & (1 << (bit & 7))) > 0;
}
+
/**
* Determine how many low order bits match in two
* `struct GNUNET_HashCode`s. i.e. - 010011 and 011111 share
unsigned int i;
for (i = 0; i < sizeof(struct GNUNET_HashCode) * 8; i++)
- if (GNUNET_CRYPTO_hash_get_bit (first, i) !=
- GNUNET_CRYPTO_hash_get_bit (second, i))
+ if (GNUNET_CRYPTO_hash_get_bit_rtl (first, i) !=
+ GNUNET_CRYPTO_hash_get_bit_rtl (second, i))
return i;
return sizeof(struct GNUNET_HashCode) * 8;
}
size_t buf_len,
struct GNUNET_HashCode *result)
{
- GNUNET_break (ARGON2_OK == argon2d_hash_raw (3, /* iterations */
- 1024, /* memory (1 MiB) */
- 1, /* threads */
- buf,
- buf_len,
- salt,
- strlen (salt),
- result,
- sizeof (struct
- GNUNET_HashCode)));
-
+ GNUNET_break (ARGON2_OK ==
+ argon2id_hash_raw (3, /* iterations */
+ 1024, /* memory (1 MiB) */
+ 1, /* threads */
+ buf,
+ buf_len,
+ salt,
+ strlen (salt),
+ result,
+ sizeof (struct GNUNET_HashCode)));
}
unsigned int hash_count;
hash_count = 0;
- while (0 == GNUNET_CRYPTO_hash_get_bit (hash, hash_count))
+ while (0 == GNUNET_CRYPTO_hash_get_bit_ltr (hash, hash_count))
hash_count++;
return hash_count;
}
struct GNUNET_CRYPTO_EcdsaPrivateKey *dpriv;
struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
struct GNUNET_CRYPTO_EcdsaPublicKey dpub;
+ struct GNUNET_CRYPTO_EcdsaPublicKey dpub2;
dpriv = GNUNET_CRYPTO_ecdsa_private_key_derive (&key,
"test-derive",
"test-derive",
"test-CTX",
&dpub);
+ GNUNET_CRYPTO_ecdsa_key_get_public (dpriv, &dpub2);
purp.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose));
purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST);
+ if (0 != GNUNET_memcmp (&dpub.q_y, &dpub2.q_y))
+ {
+ fprintf (stderr, "%s", "key derivation failed\n");
+ GNUNET_free (dpriv);
+ return GNUNET_SYSERR;
+ }
+
if (GNUNET_SYSERR ==
GNUNET_CRYPTO_ecdsa_sign_ (dpriv,
&purp,
return 1;
if (1 != GNUNET_CRYPTO_hash_xorcmp (&h1, &h2, &h2))
return 1;
- memset (&d, 0xF0, sizeof(d));
- if (0 != GNUNET_CRYPTO_hash_get_bit (&d, 3))
+ memset (&d, 0x40, sizeof(d));
+ if (0 != GNUNET_CRYPTO_hash_get_bit_rtl (&d, 3))
return 1;
- if (1 != GNUNET_CRYPTO_hash_get_bit (&d, 6))
+ if (1 != GNUNET_CRYPTO_hash_get_bit_rtl (&d, 6))
+ return 1;
+ memset (&d, 0x02, sizeof(d));
+ if (0 != GNUNET_CRYPTO_hash_get_bit_ltr (&d, 3))
+ return 1;
+ if (1 != GNUNET_CRYPTO_hash_get_bit_ltr (&d, 6))
return 1;
memset (&d, 0, sizeof(d));
GNUNET_CRYPTO_hash_to_aes_key (&d, &skey, &iv);