diff options
Diffstat (limited to 'src/include/gnunet_crypto_lib.h')
-rw-r--r-- | src/include/gnunet_crypto_lib.h | 99 |
1 files changed, 96 insertions, 3 deletions
diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h index 6224546b9..8270c89dd 100644 --- a/src/include/gnunet_crypto_lib.h +++ b/src/include/gnunet_crypto_lib.h | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 Christian Grothoff (and other contributing authors) | 3 | (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2012 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -138,6 +138,26 @@ struct GNUNET_CRYPTO_HashAsciiEncoded | |||
138 | 138 | ||
139 | 139 | ||
140 | 140 | ||
141 | |||
142 | /** | ||
143 | * @brief 256-bit hashcode | ||
144 | */ | ||
145 | struct GNUNET_CRYPTO_ShortHashCode | ||
146 | { | ||
147 | uint32_t bits[256 / 8 / sizeof (uint32_t)]; /* = 8 */ | ||
148 | }; | ||
149 | |||
150 | |||
151 | /** | ||
152 | * @brief 0-terminated ASCII encoding of a 'struct GNUNET_ShortHashCode'. | ||
153 | */ | ||
154 | struct GNUNET_CRYPTO_ShortHashAsciiEncoded | ||
155 | { | ||
156 | unsigned char short_encoding[53]; | ||
157 | }; | ||
158 | |||
159 | |||
160 | |||
141 | /** | 161 | /** |
142 | * @brief an RSA signature | 162 | * @brief an RSA signature |
143 | */ | 163 | */ |
@@ -433,7 +453,19 @@ GNUNET_CRYPTO_hash_to_enc (const GNUNET_HashCode * block, | |||
433 | 453 | ||
434 | 454 | ||
435 | /** | 455 | /** |
436 | * Convert ASCII encoding back to GNUNET_CRYPTO_hash | 456 | * Convert short hash to ASCII encoding. |
457 | * | ||
458 | * @param block the hash code | ||
459 | * @param result where to store the encoding (struct GNUNET_CRYPTO_ShortHashAsciiEncoded can be | ||
460 | * safely cast to char*, a '\\0' termination is set). | ||
461 | */ | ||
462 | void | ||
463 | GNUNET_CRYPTO_short_hash_to_enc (const struct GNUNET_CRYPTO_ShortHashCode * block, | ||
464 | struct GNUNET_CRYPTO_ShortHashAsciiEncoded *result); | ||
465 | |||
466 | |||
467 | /** | ||
468 | * Convert ASCII encoding back to a 'GNUNET_HashCode' | ||
437 | * | 469 | * |
438 | * @param enc the encoding | 470 | * @param enc the encoding |
439 | * @param enclen number of characters in 'enc' (without 0-terminator, which can be missing) | 471 | * @param enclen number of characters in 'enc' (without 0-terminator, which can be missing) |
@@ -446,16 +478,41 @@ GNUNET_CRYPTO_hash_from_string2 (const char *enc, size_t enclen, | |||
446 | 478 | ||
447 | 479 | ||
448 | /** | 480 | /** |
449 | * Convert ASCII encoding back to GNUNET_CRYPTO_hash | 481 | * Convert ASCII encoding back to a 'struct GNUNET_CRYPTO_ShortHash' |
482 | * | ||
450 | * @param enc the encoding | 483 | * @param enc the encoding |
484 | * @param enclen number of characters in 'enc' (without 0-terminator, which can be missing) | ||
451 | * @param result where to store the GNUNET_CRYPTO_hash code | 485 | * @param result where to store the GNUNET_CRYPTO_hash code |
452 | * @return GNUNET_OK on success, GNUNET_SYSERR if result has the wrong encoding | 486 | * @return GNUNET_OK on success, GNUNET_SYSERR if result has the wrong encoding |
453 | */ | 487 | */ |
488 | int | ||
489 | GNUNET_CRYPTO_short_hash_from_string2 (const char *enc, size_t enclen, | ||
490 | struct GNUNET_CRYPTO_ShortHashCode * result); | ||
491 | |||
492 | |||
493 | /** | ||
494 | * Convert ASCII encoding back to GNUNET_HashCode | ||
495 | * | ||
496 | * @param enc the encoding | ||
497 | * @param result where to store the hash code | ||
498 | * @return GNUNET_OK on success, GNUNET_SYSERR if result has the wrong encoding | ||
499 | */ | ||
454 | #define GNUNET_CRYPTO_hash_from_string(enc, result) \ | 500 | #define GNUNET_CRYPTO_hash_from_string(enc, result) \ |
455 | GNUNET_CRYPTO_hash_from_string2 (enc, strlen(enc), result) | 501 | GNUNET_CRYPTO_hash_from_string2 (enc, strlen(enc), result) |
456 | 502 | ||
457 | 503 | ||
458 | /** | 504 | /** |
505 | * Convert ASCII encoding back to a 'struct GNUNET_CRYPTO_ShortHash' | ||
506 | * | ||
507 | * @param enc the encoding | ||
508 | * @param result where to store the GNUNET_CRYPTO_ShortHash | ||
509 | * @return GNUNET_OK on success, GNUNET_SYSERR if result has the wrong encoding | ||
510 | */ | ||
511 | #define GNUNET_CRYPTO_short_hash_from_string(enc, result) \ | ||
512 | GNUNET_CRYPTO_short_hash_from_string2 (enc, strlen(enc), result) | ||
513 | |||
514 | |||
515 | /** | ||
459 | * Compute the distance between 2 hashcodes. | 516 | * Compute the distance between 2 hashcodes. |
460 | * The computation must be fast, not involve | 517 | * The computation must be fast, not involve |
461 | * a.a or a.e (they're used elsewhere), and | 518 | * a.a or a.e (they're used elsewhere), and |
@@ -483,6 +540,42 @@ GNUNET_CRYPTO_hash (const void *block, size_t size, GNUNET_HashCode * ret); | |||
483 | 540 | ||
484 | 541 | ||
485 | /** | 542 | /** |
543 | * Compute short (256-bit) hash of a given block. | ||
544 | * | ||
545 | * @param block the data to hash | ||
546 | * @param size size of the block | ||
547 | * @param ret pointer to where to write the hashcode | ||
548 | */ | ||
549 | void | ||
550 | GNUNET_CRYPTO_short_hash (const void *block, size_t size, | ||
551 | struct GNUNET_CRYPTO_ShortHashCode * ret); | ||
552 | |||
553 | |||
554 | /** | ||
555 | * Double short (256-bit) hash to create a long hash. | ||
556 | * | ||
557 | * @param sh short hash to double | ||
558 | * @param dh where to store the (doubled) long hash (not really a hash) | ||
559 | */ | ||
560 | void | ||
561 | GNUNET_CRYPTO_short_hash_double (const struct GNUNET_CRYPTO_ShortHashCode *sh, | ||
562 | struct GNUNET_HashCode *dh); | ||
563 | |||
564 | |||
565 | /** | ||
566 | * Truncate doubled short hash back to a short hash. | ||
567 | * | ||
568 | * @param lh doubled short hash to reduce again | ||
569 | * @param sh where to store the short hash | ||
570 | * @return GNUNET_OK on success, GNUNET_SYSERR if this was not a | ||
571 | * doubled short hash | ||
572 | */ | ||
573 | int | ||
574 | GNUNET_CRYPTO_short_hash_from_truncation (const struct GNUNET_HashCode *dh, | ||
575 | struct GNUNET_CRYPTO_ShortHashCode *sh); | ||
576 | |||
577 | |||
578 | /** | ||
486 | * Calculate HMAC of a message (RFC 2104) | 579 | * Calculate HMAC of a message (RFC 2104) |
487 | * | 580 | * |
488 | * @param key secret key | 581 | * @param key secret key |