aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-08-19 19:18:17 +0000
committerChristian Grothoff <christian@grothoff.org>2013-08-19 19:18:17 +0000
commit165d153298d75b64a6a426b534a435945690b436 (patch)
tree3c95f417ebda73a68b347ec5c8aa3e18d2262593
parent6afb005da9165db3cd814864956f08e23828de63 (diff)
downloadgnunet-165d153298d75b64a6a426b534a435945690b436.tar.gz
gnunet-165d153298d75b64a6a426b534a435945690b436.zip
-remove ShortHashCode from API, deprecate SList
-rw-r--r--src/include/gnunet_container_lib.h41
-rw-r--r--src/include/gnunet_crypto_lib.h100
-rw-r--r--src/util/common_logging.c37
-rw-r--r--src/util/crypto_hash.c139
4 files changed, 33 insertions, 284 deletions
diff --git a/src/include/gnunet_container_lib.h b/src/include/gnunet_container_lib.h
index 87249faca..c0aa176c5 100644
--- a/src/include/gnunet_container_lib.h
+++ b/src/include/gnunet_container_lib.h
@@ -1394,22 +1394,26 @@ GNUNET_CONTAINER_heap_update_cost (struct GNUNET_CONTAINER_Heap *heap,
1394/** 1394/**
1395 * Possible ways for how data stored in the linked list 1395 * Possible ways for how data stored in the linked list
1396 * might be allocated. 1396 * might be allocated.
1397 * @deprecated use DLL macros
1397 */ 1398 */
1398enum GNUNET_CONTAINER_SListDisposition 1399enum GNUNET_CONTAINER_SListDisposition
1399{ 1400{
1400 /** 1401 /**
1401 * Single-linked list must copy the buffer. 1402 * Single-linked list must copy the buffer.
1402 */ 1403 * @deprecated use DLL macros
1404 */
1403 GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT = 0, 1405 GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT = 0,
1404 1406
1405 /** 1407 /**
1406 * Data is static, no need to copy or free. 1408 * Data is static, no need to copy or free.
1407 */ 1409 * @deprecated use DLL macros
1410 */
1408 GNUNET_CONTAINER_SLIST_DISPOSITION_STATIC = 2, 1411 GNUNET_CONTAINER_SLIST_DISPOSITION_STATIC = 2,
1409 1412
1410 /** 1413 /**
1411 * Data is dynamic, do not copy but free when done. 1414 * Data is dynamic, do not copy but free when done.
1412 */ 1415 * @deprecated use DLL macros
1416 */
1413 GNUNET_CONTAINER_SLIST_DISPOSITION_DYNAMIC = 4 1417 GNUNET_CONTAINER_SLIST_DISPOSITION_DYNAMIC = 4
1414}; 1418};
1415 1419
@@ -1417,11 +1421,13 @@ enum GNUNET_CONTAINER_SListDisposition
1417 1421
1418/** 1422/**
1419 * Handle to a singly linked list 1423 * Handle to a singly linked list
1424 * @deprecated use DLL macros
1420 */ 1425 */
1421struct GNUNET_CONTAINER_SList; 1426struct GNUNET_CONTAINER_SList;
1422 1427
1423/** 1428/**
1424 * Handle to a singly linked list iterator 1429 * Handle to a singly linked list iterator
1430 * @deprecated use DLL macros
1425 */ 1431 */
1426struct GNUNET_CONTAINER_SList_Iterator 1432struct GNUNET_CONTAINER_SList_Iterator
1427{ 1433{
@@ -1449,6 +1455,7 @@ struct GNUNET_CONTAINER_SList_Iterator
1449 * @param disp memory disposition 1455 * @param disp memory disposition
1450 * @param buf payload buffer 1456 * @param buf payload buffer
1451 * @param len length of the buffer 1457 * @param len length of the buffer
1458 * @deprecated use DLL macros
1452 */ 1459 */
1453void 1460void
1454GNUNET_CONTAINER_slist_add (struct GNUNET_CONTAINER_SList *l, 1461GNUNET_CONTAINER_slist_add (struct GNUNET_CONTAINER_SList *l,
@@ -1462,6 +1469,7 @@ GNUNET_CONTAINER_slist_add (struct GNUNET_CONTAINER_SList *l,
1462 * @param disp memory disposition 1469 * @param disp memory disposition
1463 * @param buf payload buffer 1470 * @param buf payload buffer
1464 * @param len length of the buffer 1471 * @param len length of the buffer
1472 * @deprecated use DLL macros
1465 */ 1473 */
1466void 1474void
1467GNUNET_CONTAINER_slist_add_end (struct GNUNET_CONTAINER_SList *l, 1475GNUNET_CONTAINER_slist_add_end (struct GNUNET_CONTAINER_SList *l,
@@ -1473,6 +1481,7 @@ GNUNET_CONTAINER_slist_add_end (struct GNUNET_CONTAINER_SList *l,
1473 * Append a singly linked list to another 1481 * Append a singly linked list to another
1474 * @param dst list to append to 1482 * @param dst list to append to
1475 * @param src source 1483 * @param src source
1484 * @deprecated use DLL macros
1476 */ 1485 */
1477void 1486void
1478GNUNET_CONTAINER_slist_append (struct GNUNET_CONTAINER_SList *dst, 1487GNUNET_CONTAINER_slist_append (struct GNUNET_CONTAINER_SList *dst,
@@ -1482,6 +1491,7 @@ GNUNET_CONTAINER_slist_append (struct GNUNET_CONTAINER_SList *dst,
1482/** 1491/**
1483 * Create a new singly linked list 1492 * Create a new singly linked list
1484 * @return the new list 1493 * @return the new list
1494 * @deprecated use DLL macros
1485 */ 1495 */
1486struct GNUNET_CONTAINER_SList * 1496struct GNUNET_CONTAINER_SList *
1487GNUNET_CONTAINER_slist_create (void); 1497GNUNET_CONTAINER_slist_create (void);
@@ -1490,6 +1500,7 @@ GNUNET_CONTAINER_slist_create (void);
1490/** 1500/**
1491 * Destroy a singly linked list 1501 * Destroy a singly linked list
1492 * @param l the list to be destroyed 1502 * @param l the list to be destroyed
1503 * @deprecated use DLL macros
1493 */ 1504 */
1494void 1505void
1495GNUNET_CONTAINER_slist_destroy (struct GNUNET_CONTAINER_SList *l); 1506GNUNET_CONTAINER_slist_destroy (struct GNUNET_CONTAINER_SList *l);
@@ -1502,6 +1513,7 @@ GNUNET_CONTAINER_slist_destroy (struct GNUNET_CONTAINER_SList *l);
1502 * @return iterator pointing to the beginning (by value! Either allocate the 1513 * @return iterator pointing to the beginning (by value! Either allocate the
1503 * structure on the stack, or use GNUNET_malloc() yourself! All other 1514 * structure on the stack, or use GNUNET_malloc() yourself! All other
1504 * functions do take pointer to this struct though) 1515 * functions do take pointer to this struct though)
1516 * @deprecated use DLL macros
1505 */ 1517 */
1506struct GNUNET_CONTAINER_SList_Iterator 1518struct GNUNET_CONTAINER_SList_Iterator
1507GNUNET_CONTAINER_slist_begin (struct GNUNET_CONTAINER_SList *l); 1519GNUNET_CONTAINER_slist_begin (struct GNUNET_CONTAINER_SList *l);
@@ -1511,6 +1523,7 @@ GNUNET_CONTAINER_slist_begin (struct GNUNET_CONTAINER_SList *l);
1511 * Clear a list 1523 * Clear a list
1512 * 1524 *
1513 * @param l list 1525 * @param l list
1526 * @deprecated use DLL macros
1514 */ 1527 */
1515void 1528void
1516GNUNET_CONTAINER_slist_clear (struct GNUNET_CONTAINER_SList *l); 1529GNUNET_CONTAINER_slist_clear (struct GNUNET_CONTAINER_SList *l);
@@ -1521,8 +1534,8 @@ GNUNET_CONTAINER_slist_clear (struct GNUNET_CONTAINER_SList *l);
1521 * @param l list 1534 * @param l list
1522 * @param buf payload buffer to find 1535 * @param buf payload buffer to find
1523 * @param len length of the payload (number of bytes in buf) 1536 * @param len length of the payload (number of bytes in buf)
1524 *
1525 * @return GNUNET_YES if found, GNUNET_NO otherwise 1537 * @return GNUNET_YES if found, GNUNET_NO otherwise
1538 * @deprecated use DLL macros
1526 */ 1539 */
1527int 1540int
1528GNUNET_CONTAINER_slist_contains (const struct GNUNET_CONTAINER_SList *l, 1541GNUNET_CONTAINER_slist_contains (const struct GNUNET_CONTAINER_SList *l,
@@ -1538,6 +1551,7 @@ GNUNET_CONTAINER_slist_contains (const struct GNUNET_CONTAINER_SList *l,
1538 * 1551 *
1539 * @return NULL if the 'buf' could not be found, pointer to the 1552 * @return NULL if the 'buf' could not be found, pointer to the
1540 * list element, if found 1553 * list element, if found
1554 * @deprecated use DLL macros
1541 */ 1555 */
1542void * 1556void *
1543GNUNET_CONTAINER_slist_contains2 (const struct GNUNET_CONTAINER_SList *l, 1557GNUNET_CONTAINER_slist_contains2 (const struct GNUNET_CONTAINER_SList *l,
@@ -1547,6 +1561,7 @@ GNUNET_CONTAINER_slist_contains2 (const struct GNUNET_CONTAINER_SList *l,
1547 * Count the elements of a list 1561 * Count the elements of a list
1548 * @param l list 1562 * @param l list
1549 * @return number of elements in the list 1563 * @return number of elements in the list
1564 * @deprecated use DLL macros
1550 */ 1565 */
1551int 1566int
1552GNUNET_CONTAINER_slist_count (const struct GNUNET_CONTAINER_SList *l); 1567GNUNET_CONTAINER_slist_count (const struct GNUNET_CONTAINER_SList *l);
@@ -1555,6 +1570,7 @@ GNUNET_CONTAINER_slist_count (const struct GNUNET_CONTAINER_SList *l);
1555/** 1570/**
1556 * Remove an element from the list 1571 * Remove an element from the list
1557 * @param i iterator that points to the element to be removed 1572 * @param i iterator that points to the element to be removed
1573 * @deprecated use DLL macros
1558 */ 1574 */
1559void 1575void
1560GNUNET_CONTAINER_slist_erase (struct GNUNET_CONTAINER_SList_Iterator *i); 1576GNUNET_CONTAINER_slist_erase (struct GNUNET_CONTAINER_SList_Iterator *i);
@@ -1566,6 +1582,7 @@ GNUNET_CONTAINER_slist_erase (struct GNUNET_CONTAINER_SList_Iterator *i);
1566 * @param disp memory disposition 1582 * @param disp memory disposition
1567 * @param buf payload buffer 1583 * @param buf payload buffer
1568 * @param len length of the payload 1584 * @param len length of the payload
1585 * @deprecated use DLL macros
1569 */ 1586 */
1570void 1587void
1571GNUNET_CONTAINER_slist_insert (struct GNUNET_CONTAINER_SList_Iterator *before, 1588GNUNET_CONTAINER_slist_insert (struct GNUNET_CONTAINER_SList_Iterator *before,
@@ -1577,6 +1594,7 @@ GNUNET_CONTAINER_slist_insert (struct GNUNET_CONTAINER_SList_Iterator *before,
1577 * Advance an iterator to the next element 1594 * Advance an iterator to the next element
1578 * @param i iterator 1595 * @param i iterator
1579 * @return GNUNET_YES on success, GNUNET_NO if the end has been reached 1596 * @return GNUNET_YES on success, GNUNET_NO if the end has been reached
1597 * @deprecated use DLL macros
1580 */ 1598 */
1581int 1599int
1582GNUNET_CONTAINER_slist_next (struct GNUNET_CONTAINER_SList_Iterator *i); 1600GNUNET_CONTAINER_slist_next (struct GNUNET_CONTAINER_SList_Iterator *i);
@@ -1587,6 +1605,7 @@ GNUNET_CONTAINER_slist_next (struct GNUNET_CONTAINER_SList_Iterator *i);
1587 * @param i iterator 1605 * @param i iterator
1588 * @return GNUNET_YES if the end has been reached, GNUNET_NO if the iterator 1606 * @return GNUNET_YES if the end has been reached, GNUNET_NO if the iterator
1589 * points to a valid element 1607 * points to a valid element
1608 * @deprecated use DLL macros
1590 */ 1609 */
1591int 1610int
1592GNUNET_CONTAINER_slist_end (struct GNUNET_CONTAINER_SList_Iterator *i); 1611GNUNET_CONTAINER_slist_end (struct GNUNET_CONTAINER_SList_Iterator *i);
@@ -1598,6 +1617,7 @@ GNUNET_CONTAINER_slist_end (struct GNUNET_CONTAINER_SList_Iterator *i);
1598 * @param i iterator 1617 * @param i iterator
1599 * @param len set to the payload length 1618 * @param len set to the payload length
1600 * @return payload 1619 * @return payload
1620 * @deprecated use DLL macros
1601 */ 1621 */
1602void * 1622void *
1603GNUNET_CONTAINER_slist_get (const struct GNUNET_CONTAINER_SList_Iterator *i, 1623GNUNET_CONTAINER_slist_get (const struct GNUNET_CONTAINER_SList_Iterator *i,
@@ -1607,6 +1627,7 @@ GNUNET_CONTAINER_slist_get (const struct GNUNET_CONTAINER_SList_Iterator *i,
1607/** 1627/**
1608 * Release an iterator 1628 * Release an iterator
1609 * @param i iterator 1629 * @param i iterator
1630 * @deprecated use DLL macros
1610 */ 1631 */
1611void 1632void
1612GNUNET_CONTAINER_slist_iter_destroy (struct GNUNET_CONTAINER_SList_Iterator *i); 1633GNUNET_CONTAINER_slist_iter_destroy (struct GNUNET_CONTAINER_SList_Iterator *i);
diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h
index 73a3db382..7fb3d2ac9 100644
--- a/src/include/gnunet_crypto_lib.h
+++ b/src/include/gnunet_crypto_lib.h
@@ -96,15 +96,6 @@ struct GNUNET_CRYPTO_HashAsciiEncoded
96}; 96};
97 97
98 98
99/**
100 * @brief 0-terminated ASCII encoding of a struct GNUNET_CRYPTO_ShortHashCode.
101 */
102struct GNUNET_CRYPTO_ShortHashAsciiEncoded
103{
104 unsigned char short_encoding[53];
105};
106
107
108GNUNET_NETWORK_STRUCT_BEGIN 99GNUNET_NETWORK_STRUCT_BEGIN
109 100
110 101
@@ -406,19 +397,6 @@ GNUNET_CRYPTO_hash_to_enc (const struct GNUNET_HashCode * block,
406 397
407/** 398/**
408 * @ingroup hash 399 * @ingroup hash
409 * Convert short hash to ASCII encoding.
410 *
411 * @param block the hash code
412 * @param result where to store the encoding (struct GNUNET_CRYPTO_ShortHashAsciiEncoded can be
413 * safely cast to char*, a '\\0' termination is set).
414 */
415void
416GNUNET_CRYPTO_short_hash_to_enc (const struct GNUNET_CRYPTO_ShortHashCode * block,
417 struct GNUNET_CRYPTO_ShortHashAsciiEncoded *result);
418
419
420/**
421 * @ingroup hash
422 * Convert ASCII encoding back to a 'struct GNUNET_HashCode' 400 * Convert ASCII encoding back to a 'struct GNUNET_HashCode'
423 * 401 *
424 * @param enc the encoding 402 * @param enc the encoding
@@ -433,20 +411,6 @@ GNUNET_CRYPTO_hash_from_string2 (const char *enc, size_t enclen,
433 411
434/** 412/**
435 * @ingroup hash 413 * @ingroup hash
436 * Convert ASCII encoding back to a 'struct GNUNET_CRYPTO_ShortHash'
437 *
438 * @param enc the encoding
439 * @param enclen number of characters in @a enc (without 0-terminator, which can be missing)
440 * @param result where to store the hash code
441 * @return #GNUNET_OK on success, #GNUNET_SYSERR if result has the wrong encoding
442 */
443int
444GNUNET_CRYPTO_short_hash_from_string2 (const char *enc, size_t enclen,
445 struct GNUNET_CRYPTO_ShortHashCode * result);
446
447
448/**
449 * @ingroup hash
450 * Convert ASCII encoding back to struct GNUNET_HashCode 414 * Convert ASCII encoding back to struct GNUNET_HashCode
451 * 415 *
452 * @param enc the encoding 416 * @param enc the encoding
@@ -459,31 +423,6 @@ GNUNET_CRYPTO_short_hash_from_string2 (const char *enc, size_t enclen,
459 423
460/** 424/**
461 * @ingroup hash 425 * @ingroup hash
462 * Convert ASCII encoding back to a 'struct GNUNET_CRYPTO_ShortHash'
463 *
464 * @param enc the encoding
465 * @param result where to store the GNUNET_CRYPTO_ShortHash
466 * @return #GNUNET_OK on success, #GNUNET_SYSERR if result has the wrong encoding
467 */
468#define GNUNET_CRYPTO_short_hash_from_string(enc, result) \
469 GNUNET_CRYPTO_short_hash_from_string2 (enc, strlen(enc), result)
470
471
472/**
473 * @ingroup hash
474 * Compare function for ShortHashCodes, producing a total ordering
475 * of all hashcodes.
476 *
477 * @param h1 some hash code
478 * @param h2 some hash code
479 * @return 1 if h1 > h2, -1 if h1 < h2 and 0 if h1 == h2.
480 */
481int
482GNUNET_CRYPTO_short_hash_cmp (const struct GNUNET_CRYPTO_ShortHashCode * h1,
483 const struct GNUNET_CRYPTO_ShortHashCode * h2);
484
485/**
486 * @ingroup hash
487 * Compute the distance between 2 hashcodes. 426 * Compute the distance between 2 hashcodes.
488 * The computation must be fast, not involve 427 * The computation must be fast, not involve
489 * a.a or a.e (they're used elsewhere), and 428 * a.a or a.e (they're used elsewhere), and
@@ -513,45 +452,6 @@ GNUNET_CRYPTO_hash (const void *block, size_t size, struct GNUNET_HashCode * ret
513 452
514/** 453/**
515 * @ingroup hash 454 * @ingroup hash
516 * Compute short (256-bit) hash of a given block.
517 *
518 * @param block the data to hash
519 * @param size size of the @a block
520 * @param ret pointer to where to write the hashcode
521 */
522void
523GNUNET_CRYPTO_short_hash (const void *block, size_t size,
524 struct GNUNET_CRYPTO_ShortHashCode * ret);
525
526
527/**
528 * @ingroup hash
529 * Double short (256-bit) hash to create a long hash.
530 *
531 * @param sh short hash to double
532 * @param dh where to store the (doubled) long hash (not really a hash)
533 */
534void
535GNUNET_CRYPTO_short_hash_double (const struct GNUNET_CRYPTO_ShortHashCode *sh,
536 struct GNUNET_HashCode *dh);
537
538
539/**
540 * @ingroup hash
541 * Truncate doubled short hash back to a short hash.
542 *
543 * @param dh doubled short hash to reduce again
544 * @param sh where to store the short hash
545 * @return GNUNET_OK on success, GNUNET_SYSERR if this was not a
546 * doubled short hash
547 */
548int
549GNUNET_CRYPTO_short_hash_from_truncation (const struct GNUNET_HashCode *dh,
550 struct GNUNET_CRYPTO_ShortHashCode *sh);
551
552
553/**
554 * @ingroup hash
555 * Calculate HMAC of a message (RFC 2104) 455 * Calculate HMAC of a message (RFC 2104)
556 * 456 *
557 * @param key secret key 457 * @param key secret key
diff --git a/src/util/common_logging.c b/src/util/common_logging.c
index 8f1c8e876..5929fc94a 100644
--- a/src/util/common_logging.c
+++ b/src/util/common_logging.c
@@ -1038,43 +1038,6 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind)
1038 1038
1039 1039
1040/** 1040/**
1041 * Convert a short hash to a string (for printing debug messages).
1042 * This is one of the very few calls in the entire API that is
1043 * NOT reentrant!
1044 *
1045 * @param hc the short hash code
1046 * @return string form; will be overwritten by next call to GNUNET_h2s.
1047 */
1048const char *
1049GNUNET_short_h2s (const struct GNUNET_CRYPTO_ShortHashCode * hc)
1050{
1051 static struct GNUNET_CRYPTO_ShortHashAsciiEncoded ret;
1052
1053 GNUNET_CRYPTO_short_hash_to_enc (hc, &ret);
1054 ret.short_encoding[8] = '\0';
1055 return (const char *) ret.short_encoding;
1056}
1057
1058
1059/**
1060 * Convert a short hash to a string (for printing debug messages).
1061 * This is one of the very few calls in the entire API that is
1062 * NOT reentrant!
1063 *
1064 * @param hc the short hash code
1065 * @return string form; will be overwritten by next call to GNUNET_h2s_full.
1066 */
1067const char *
1068GNUNET_short_h2s_full (const struct GNUNET_CRYPTO_ShortHashCode * hc)
1069{
1070 static struct GNUNET_CRYPTO_ShortHashAsciiEncoded ret;
1071
1072 GNUNET_CRYPTO_short_hash_to_enc (hc, &ret);
1073 ret.short_encoding[sizeof (ret) - 1] = '\0';
1074 return (const char *) ret.short_encoding;
1075}
1076
1077/**
1078 * Convert a hash to a string (for printing debug messages). 1041 * Convert a hash to a string (for printing debug messages).
1079 * This is one of the very few calls in the entire API that is 1042 * This is one of the very few calls in the entire API that is
1080 * NOT reentrant! 1043 * NOT reentrant!
diff --git a/src/util/crypto_hash.c b/src/util/crypto_hash.c
index 2e436c454..c1d82abae 100644
--- a/src/util/crypto_hash.c
+++ b/src/util/crypto_hash.c
@@ -1,10 +1,10 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2001, 2002, 2003, 2004, 2005, 2006, 2009, 2012 Christian Grothoff (and other contributing authors) 3 (C) 2001-2013 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
7 by the Free Software Foundation; either version 2, or (at your 7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version. 8 option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
@@ -17,11 +17,6 @@
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19 19
20 SHA-512 code by Jean-Luc Cooke <jlcooke@certainkey.com>
21
22 Copyright (c) Jean-Luc Cooke <jlcooke@certainkey.com>
23 Copyright (c) Andrew McDonald <andrew@mcdonald.org.uk>
24 Copyright (c) 2003 Kyle McMartin <kyle@debian.org>
25*/ 20*/
26 21
27/** 22/**
@@ -56,21 +51,6 @@ GNUNET_CRYPTO_hash (const void *block, size_t size, struct GNUNET_HashCode * ret
56 51
57 52
58/** 53/**
59 * Compute short (256-bit) hash of a given block.
60 *
61 * @param block the data to GNUNET_CRYPTO_hash, length is given as a second argument
62 * @param size the length of the data to GNUNET_CRYPTO_hash
63 * @param ret pointer to where to write the hashcode
64 */
65void
66GNUNET_CRYPTO_short_hash (const void *block, size_t size,
67 struct GNUNET_CRYPTO_ShortHashCode * ret)
68{
69 gcry_md_hash_buffer (GCRY_MD_SHA256, ret, block, size);
70}
71
72
73/**
74 * Context used when hashing a file. 54 * Context used when hashing a file.
75 */ 55 */
76struct GNUNET_CRYPTO_FileHashContext 56struct GNUNET_CRYPTO_FileHashContext
@@ -590,119 +570,4 @@ GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key,
590} 570}
591 571
592 572
593
594/**
595 * Double short (256-bit) hash to create a long hash.
596 *
597 * @param sh short hash to double
598 * @param dh where to store the (doubled) long hash (not really a hash)
599 */
600void
601GNUNET_CRYPTO_short_hash_double (const struct GNUNET_CRYPTO_ShortHashCode *sh,
602 struct GNUNET_HashCode *dh)
603{
604 char *ptr;
605
606 ptr = (char*) dh;
607 memcpy (ptr, sh, sizeof (struct GNUNET_CRYPTO_ShortHashCode));
608 memcpy (&ptr[sizeof (struct GNUNET_CRYPTO_ShortHashCode)], sh, sizeof (struct GNUNET_CRYPTO_ShortHashCode));
609}
610
611
612/**
613 * Truncate doubled short hash back to a short hash.
614 *
615 * @param dh doubled short hash to reduce again
616 * @param sh where to store the short hash
617 * @return GNUNET_OK on success, GNUNET_SYSERR if this was not a
618 * doubled short hash
619 */
620int
621GNUNET_CRYPTO_short_hash_from_truncation (const struct GNUNET_HashCode *dh,
622 struct GNUNET_CRYPTO_ShortHashCode *sh)
623{
624 const struct GNUNET_CRYPTO_ShortHashCode *s;
625
626 s = (const struct GNUNET_CRYPTO_ShortHashCode *) dh;
627 if (0 != memcmp (&s[0],
628 &s[1],
629 sizeof (struct GNUNET_CRYPTO_ShortHashCode)))
630 return GNUNET_SYSERR;
631 *sh = *s;
632 return GNUNET_OK;
633}
634
635
636/**
637 * Convert ASCII encoding back to a 'struct GNUNET_CRYPTO_ShortHash'
638 *
639 * @param enc the encoding
640 * @param enclen number of characters in 'enc' (without 0-terminator, which can be missing)
641 * @param result where to store the GNUNET_CRYPTO_hash code
642 * @return GNUNET_OK on success, GNUNET_SYSERR if result has the wrong encoding
643 */
644int
645GNUNET_CRYPTO_short_hash_from_string2 (const char *enc, size_t enclen,
646 struct GNUNET_CRYPTO_ShortHashCode * result)
647{
648
649 char upper_enc[enclen];
650 char* up_ptr = upper_enc;
651
652 GNUNET_STRINGS_utf8_toupper(enc, &up_ptr);
653 return GNUNET_STRINGS_string_to_data (upper_enc, enclen,
654 (unsigned char*) result,
655 sizeof (struct GNUNET_CRYPTO_ShortHashCode));
656}
657
658
659/**
660 * Convert short hash to ASCII encoding.
661 *
662 * @param block the hash code
663 * @param result where to store the encoding (struct GNUNET_CRYPTO_ShortHashAsciiEncoded can be
664 * safely cast to char*, a '\\0' termination is set).
665 */
666void
667GNUNET_CRYPTO_short_hash_to_enc (const struct GNUNET_CRYPTO_ShortHashCode * block,
668 struct GNUNET_CRYPTO_ShortHashAsciiEncoded *result)
669{
670 char *np;
671
672 np = GNUNET_STRINGS_data_to_string ((const unsigned char *) block,
673 sizeof (struct GNUNET_CRYPTO_ShortHashCode),
674 (char*) result,
675 sizeof (struct GNUNET_CRYPTO_ShortHashAsciiEncoded) - 1);
676 GNUNET_assert (NULL != np);
677 *np = '\0';
678}
679
680/**
681 * Compare function for ShortHashCodes, producing a total ordering
682 * of all hashcodes.
683 *
684 * @param h1 some hash code
685 * @param h2 some hash code
686 * @return 1 if h1 > h2, -1 if h1 < h2 and 0 if h1 == h2.
687 */
688int
689GNUNET_CRYPTO_short_hash_cmp (const struct GNUNET_CRYPTO_ShortHashCode * h1,
690 const struct GNUNET_CRYPTO_ShortHashCode * h2)
691{
692 unsigned int *i1;
693 unsigned int *i2;
694 int i;
695
696 i1 = (unsigned int *) h1;
697 i2 = (unsigned int *) h2;
698 for (i = (sizeof (struct GNUNET_CRYPTO_ShortHashCode) / sizeof (unsigned int)) - 1; i >= 0; i--)
699 {
700 if (i1[i] > i2[i])
701 return 1;
702 if (i1[i] < i2[i])
703 return -1;
704 }
705 return 0;
706}
707
708/* end of crypto_hash.c */ 573/* end of crypto_hash.c */