diff options
Diffstat (limited to 'src/include/gnunet_crypto_lib.h')
-rw-r--r-- | src/include/gnunet_crypto_lib.h | 67 |
1 files changed, 40 insertions, 27 deletions
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 | /** |