43{
45 gcry_md_hash_buffer (GCRY_MD_SHA512,
ret, block,
size);
47}
48
49
50
51
52
53void
56{
57 char *np;
58
62 sizeof(struct
64 - 1);
66 *np = '\0';
67}
68
69
72 size_t enclen,
74{
76 char *up_ptr;
77
79 if (NULL == up_ptr)
82 strlen (up_ptr),
87}
88
89
90unsigned int
93{
94 unsigned int x1 = (a->
bits[1] - b->
bits[1]) >> 16;
95 unsigned int x2 = (b->
bits[1] - a->
bits[1]) >> 16;
96
97 return(x1 * x2);
98}
99
100
101void
104{
106}
107
108
109void
113{
114 for (ssize_t i = (
sizeof(
struct GNUNET_HashCode) /
sizeof(
unsigned int)) - 1;
115 i >= 0;
116 i--)
118}
119
120
121void
125{
126 for (ssize_t i = (
sizeof(
struct GNUNET_HashCode) /
sizeof(
unsigned int)) - 1;
127 i >= 0;
128 i--)
130}
131
132
133void
137{
138 const unsigned long long *lla = (const unsigned long long *) a;
139 const unsigned long long *llb = (const unsigned long long *) b;
140 unsigned long long *llr = (
unsigned long long *)
result;
141
144
145 for (
int i =
sizeof (*
result) /
sizeof (*llr) - 1; i>=0; i--)
146 llr[i] = lla[i] ^ llb[i];
147}
148
149
150void
155{
158 skey,
159 sizeof(*skey),
160 "Hash key derivation",
161 strlen ("Hash key derivation"),
162 hc, sizeof(*hc),
163 NULL, 0));
166 iv,
167 sizeof(*iv),
168 "Initialization vector derivation",
169 strlen ("Initialization vector derivation"),
170 hc, sizeof(*hc),
171 NULL, 0));
172}
173
174
175unsigned int
177{
178 const unsigned long long *llp = (
const unsigned long long *)
h;
179 unsigned int ret = 0;
180 unsigned int i;
181
184 for (i = 0; i<sizeof (*h) / sizeof (*llp); i++)
185 {
186 if (0LLU != llp[i])
187 break;
188 ret +=
sizeof (*llp) * 8;
189 }
190 if (
ret == 8 *
sizeof (*
h))
194}
195
196
197unsigned int
199{
200 const unsigned long long *llp = (
const unsigned long long *)
h;
201 unsigned int ret = 0;
202 int i;
203
206 for (i =
sizeof (*
h) /
sizeof (*llp) - 1; i>=0; i--)
207 {
208 if (0LLU != llp[i])
209 break;
210 ret +=
sizeof (*llp) * 8;
211 }
212 if (
ret == 8 *
sizeof (*
h))
216}
217
218
219int
222{
223 unsigned int *i1;
224 unsigned int *i2;
225
226 i1 = (unsigned int *) h1;
227 i2 = (unsigned int *) h2;
228 for (ssize_t i = (
sizeof(
struct GNUNET_HashCode) /
sizeof(
unsigned int)) - 1;
229 i >= 0;
230 i--)
231 {
232 if (i1[i] > i2[i])
233 return 1;
234 if (i1[i] < i2[i])
235 return -1;
236 }
237 return 0;
238}
239
240
241int
245{
246 const unsigned long long *l1 = (const unsigned long long *) h1;
247 const unsigned long long *l2 = (const unsigned long long *) h2;
248 const unsigned long long *
t = (
const unsigned long long *) target;
249
251 for (size_t i = 0; i < sizeof(*h1) / sizeof(*l1); i++)
252 {
253 unsigned long long x1 = l1[i] ^
t[i];
254 unsigned long long x2 = l2[i] ^
t[i];
255
256 if (x1 > x2)
257 return 1;
258 if (x1 < x2)
259 return -1;
260 }
261 return 0;
262}
263
264
265void
269 const void *
salt,
size_t salt_len,
270 ...)
271{
272 va_list argp;
273
274 va_start (argp,
275 salt_len);
277 rkey,
279 argp);
280 va_end (argp);
281}
282
283
284void
288 const void *
salt,
size_t salt_len,
289 va_list argp)
290{
294 argp);
295}
296
297
298void
300 const void *plaintext, size_t plaintext_len,
302{
304 static gcry_md_hd_t md;
305 const unsigned char *
mc;
306
308 {
311 gcry_md_open (&md,
312 GCRY_MD_SHA512,
313 GCRY_MD_FLAG_HMAC));
314 }
315 else
316 {
317 gcry_md_reset (md);
318 }
320 gcry_md_setkey (md,
key, key_len));
321 gcry_md_write (md, plaintext, plaintext_len);
322 mc = gcry_md_read (md, GCRY_MD_SHA512);
325}
326
327
328void
330 const void *plaintext, size_t plaintext_len,
332{
334 plaintext, plaintext_len,
335 hmac);
336}
337
338
340{
345};
346
347
350{
352
356 gcry_md_open (&hc->
hd,
357 GCRY_MD_SHA512,
358 0));
360 return hc;
361}
362
363
364void
366 const void *buf,
368{
370 gcry_md_write (hc->
hd, buf,
size);
372}
373
374
377{
379
382 gcry_md_copy (&cp->
hd,
384 return cp;
385}
386
387
388void
391{
392 const void *
res = gcry_md_read (hc->
hd, 0);
393
395
397 if (NULL != r_hash)
403}
404
405
406void
408{
409 gcry_md_close (hc->
hd);
411}
412
413
414
#define BENCHMARK_START(opname)
#define BENCHMARK_END(opname)
static struct GNUNET_ARM_Handle * h
Connection with ARM.
static int ret
Final status code.
struct GNUNET_HashCode key
The key used in the DHT.
static OpusEncoder * enc
OPUS encoder.
static struct GNUNET_SCHEDULER_Task * t
Main task.
static char * res
Currently read line or NULL on EOF.
static int once
Option -i.
static struct GNUNET_TESTBED_Controller * mc
Handle to the master controller.
static int result
Global testing status.
static struct GNUNET_CRYPTO_PowSalt salt
Salt for PoW calculations.
static enum @49 mode
Should we do a PUT (mode = 0) or GET (mode = 1);.
void GNUNET_CRYPTO_random_block(enum GNUNET_CRYPTO_Quality mode, void *buffer, size_t length)
Fill block with a random values.
GNUNET_CRYPTO_Quality
Desired quality level for random numbers.
void GNUNET_CRYPTO_hash_difference(const struct GNUNET_HashCode *a, const struct GNUNET_HashCode *b, struct GNUNET_HashCode *result)
compute result = b - a
void GNUNET_CRYPTO_hash_to_enc(const struct GNUNET_HashCode *block, struct GNUNET_CRYPTO_HashAsciiEncoded *result)
Convert hash to ASCII encoding.
void GNUNET_CRYPTO_hash_create_random(enum GNUNET_CRYPTO_Quality mode, struct GNUNET_HashCode *result)
Create a random hash code.
void GNUNET_CRYPTO_hmac(const struct GNUNET_CRYPTO_AuthKey *key, const void *plaintext, size_t plaintext_len, struct GNUNET_HashCode *hmac)
Calculate HMAC of a message (RFC 2104)
void GNUNET_CRYPTO_hash_sum(const struct GNUNET_HashCode *a, const struct GNUNET_HashCode *delta, struct GNUNET_HashCode *result)
compute result = a + delta
void GNUNET_CRYPTO_hash_xor(const struct GNUNET_HashCode *a, const struct GNUNET_HashCode *b, struct GNUNET_HashCode *result)
compute result = a ^ b
int GNUNET_CRYPTO_hash_xorcmp(const struct GNUNET_HashCode *h1, const struct GNUNET_HashCode *h2, const struct GNUNET_HashCode *target)
Find out which of the two GNUNET_CRYPTO_hash codes is closer to target in the XOR metric (Kademlia).
void GNUNET_CRYPTO_hmac_derive_key_v(struct GNUNET_CRYPTO_AuthKey *key, const struct GNUNET_CRYPTO_SymmetricSessionKey *rkey, const void *salt, size_t salt_len, va_list argp)
Derive an authentication key.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hash_from_string2(const char *enc, size_t enclen, struct GNUNET_HashCode *result)
Convert ASCII encoding back to a 'struct GNUNET_HashCode'.
int GNUNET_CRYPTO_hash_cmp(const struct GNUNET_HashCode *h1, const struct GNUNET_HashCode *h2)
Compare function for HashCodes, producing a total ordering of all hashcodes.
unsigned int GNUNET_CRYPTO_hash_distance_u32(const struct GNUNET_HashCode *a, const struct GNUNET_HashCode *b)
Compute the distance between 2 hashcodes.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_kdf(void *result, size_t out_len, const void *xts, size_t xts_len, const void *skm, size_t skm_len,...)
Derive key.
void GNUNET_CRYPTO_hmac_derive_key(struct GNUNET_CRYPTO_AuthKey *key, const struct GNUNET_CRYPTO_SymmetricSessionKey *rkey, const void *salt, size_t salt_len,...)
Derive an authentication key.
void GNUNET_CRYPTO_hash_to_aes_key(const struct GNUNET_HashCode *hc, struct GNUNET_CRYPTO_SymmetricSessionKey *skey, struct GNUNET_CRYPTO_SymmetricInitializationVector *iv)
Convert a hashcode into a key.
unsigned int GNUNET_CRYPTO_hash_count_leading_zeros(const struct GNUNET_HashCode *h)
Count the number of leading 0 bits in h.
void GNUNET_CRYPTO_hash_context_read(struct GNUNET_HashContext *hc, const void *buf, size_t size)
Add data to be hashed.
struct GNUNET_HashContext * GNUNET_CRYPTO_hash_context_copy(const struct GNUNET_HashContext *hc)
Make a copy of the hash computation.
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_kdf_v(void *result, size_t out_len, const void *xts, size_t xts_len, const void *skm, size_t skm_len, va_list argp)
Derive key.
void GNUNET_CRYPTO_hash_context_abort(struct GNUNET_HashContext *hc)
Abort hashing, do not bother calculating final result.
void GNUNET_CRYPTO_hash_context_finish(struct GNUNET_HashContext *hc, struct GNUNET_HashCode *r_hash)
Finish the hash computation.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
unsigned int GNUNET_CRYPTO_hash_count_tailing_zeros(const struct GNUNET_HashCode *h)
Count the number of tailing 0 bits in h.
GNUNET_GenericReturnValue
Named constants for return values.
struct GNUNET_HashContext * GNUNET_CRYPTO_hash_context_start()
Start incremental hashing operation.
void GNUNET_CRYPTO_hmac_raw(const void *key, size_t key_len, const void *plaintext, size_t plaintext_len, struct GNUNET_HashCode *hmac)
Calculate HMAC of a message (RFC 2104) TODO: Shouldn't this be the standard hmac function and the abo...
#define GNUNET_static_assert(cond)
Assertion to be checked (if supported by C compiler) at compile time, otherwise checked at runtime an...
uint32_t bits[512/8/sizeof(uint32_t)]
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
char * GNUNET_STRINGS_data_to_string(const void *data, size_t size, char *out, size_t out_size)
Convert binary data to ASCII encoding using CrockfordBase32.
char * GNUNET_STRINGS_utf8_toupper(const char *input)
Convert the utf-8 input string to upper case.
enum GNUNET_GenericReturnValue GNUNET_STRINGS_string_to_data(const char *enc, size_t enclen, void *out, size_t out_size)
Convert CrockfordBase32 encoding back to data.
static unsigned int size
Size of the "table".
static struct GNUNET_TIME_Relative delta
type for (message) authentication keys
0-terminated ASCII encoding of a struct GNUNET_HashCode.
gcry_md_hd_t hd
Internal state of the hash function.