From: Martin Schanzenbach Date: Mon, 19 Mar 2012 18:51:32 +0000 (+0000) Subject: -new short hashes, new short hash cmp X-Git-Tag: initial-import-from-subversion-38251~14188 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=d2fb255905f0c93f50db2112594307bb1265742c;p=oweals%2Fgnunet.git -new short hashes, new short hash cmp --- diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c index 9332eba93..bc1a713b6 100644 --- a/src/gns/gnunet-service-gns.c +++ b/src/gns/gnunet-service-gns.c @@ -139,7 +139,7 @@ static struct GNUNET_SERVER_NotificationContext *nc; /** * Our zone hash */ -GNUNET_HashCode zone_hash; +struct GNUNET_CRYPTO_ShortHashCode zone_hash; /** * Useful for zone update for DHT put @@ -228,8 +228,10 @@ put_gns_record(void *cls, { struct GNSNameRecordBlock *nrb; - GNUNET_HashCode name_hash; + struct GNUNET_CRYPTO_ShortHashCode name_hash; GNUNET_HashCode xor_hash; + GNUNET_HashCode name_hash_double; + GNUNET_HashCode zone_hash_double; struct GNUNET_CRYPTO_HashAsciiEncoded xor_hash_string; uint32_t rd_payload_length; char* nrb_data = NULL; @@ -302,8 +304,10 @@ put_gns_record(void *cls, /* * calculate DHT key: H(name) xor H(pubkey) */ - GNUNET_CRYPTO_hash(name, strlen(name), &name_hash); - GNUNET_CRYPTO_hash_xor(&zone_hash, &name_hash, &xor_hash); + GNUNET_CRYPTO_short_hash(name, strlen(name), &name_hash); + GNUNET_CRYPTO_short_hash_double (&name_hash, &name_hash_double); + GNUNET_CRYPTO_short_hash_double (&zone_hash, &zone_hash_double); + GNUNET_CRYPTO_hash_xor(&zone_hash_double, &name_hash_double, &xor_hash); GNUNET_CRYPTO_hash_to_enc (&xor_hash, &xor_hash_string); GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, @@ -757,7 +761,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, zone_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); GNUNET_CRYPTO_rsa_key_get_public (zone_key, &pkey); - GNUNET_CRYPTO_hash(&pkey, sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), + GNUNET_CRYPTO_short_hash(&pkey, + sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &zone_hash); GNUNET_free(keyfile); diff --git a/src/gns/gnunet-service-gns_interceptor.c b/src/gns/gnunet-service-gns_interceptor.c index 7f34c93ce..e50e8e626 100644 --- a/src/gns/gnunet-service-gns_interceptor.c +++ b/src/gns/gnunet-service-gns_interceptor.c @@ -59,7 +59,7 @@ static struct GNUNET_DNS_Handle *dns_handle; /** * The root zone for this interceptor */ -static GNUNET_HashCode our_zone; +static struct GNUNET_CRYPTO_ShortHashCode our_zone; /** * Our priv key @@ -336,7 +336,7 @@ handle_dns_request(void *cls, * @return GNUNET_OK on success */ int -gns_interceptor_init(GNUNET_HashCode zone, +gns_interceptor_init(struct GNUNET_CRYPTO_ShortHashCode zone, struct GNUNET_CRYPTO_RsaPrivateKey *key, const struct GNUNET_CONFIGURATION_Handle *c) { diff --git a/src/gns/gnunet-service-gns_interceptor.h b/src/gns/gnunet-service-gns_interceptor.h index 855b034b1..be7250b52 100644 --- a/src/gns/gnunet-service-gns_interceptor.h +++ b/src/gns/gnunet-service-gns_interceptor.h @@ -9,7 +9,7 @@ * @return GNUNET_YES on success GNUNET_SYSERR on error */ int -gns_interceptor_init(GNUNET_HashCode zone, +gns_interceptor_init(struct GNUNET_CRYPTO_ShortHashCode zone, struct GNUNET_CRYPTO_RsaPrivateKey *key, const struct GNUNET_CONFIGURATION_Handle *c); diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c index 4ac6cea36..ca7a5ea85 100644 --- a/src/gns/gnunet-service-gns_resolver.c +++ b/src/gns/gnunet-service-gns_resolver.c @@ -106,7 +106,7 @@ process_pseu_lookup_ns(void* cls, "Name %s not taken in NS! Adding\n", gph->new_name); new_pkey.expiration = GNUNET_TIME_absolute_get_forever (); - new_pkey.data_size = sizeof(GNUNET_HashCode); + new_pkey.data_size = sizeof(struct GNUNET_CRYPTO_ShortHashCode); new_pkey.data = &gph->new_zone; new_pkey.record_type = GNUNET_GNS_RECORD_PKEY; GNUNET_NAMESTORE_record_create (namestore_handle, @@ -294,12 +294,16 @@ process_zone_to_name_discover(void *cls, * check dht */ uint32_t xquery; - GNUNET_HashCode name_hash; + struct GNUNET_CRYPTO_ShortHashCode name_hash; GNUNET_HashCode lookup_key; struct GNUNET_CRYPTO_HashAsciiEncoded lookup_key_string; + GNUNET_HashCode name_hash_double; + GNUNET_HashCode zone_hash_double; - GNUNET_CRYPTO_hash("+", strlen("+"), &name_hash); - GNUNET_CRYPTO_hash_xor(&name_hash, &gph->new_zone, &lookup_key); + GNUNET_CRYPTO_short_hash("+", strlen("+"), &name_hash); + GNUNET_CRYPTO_short_hash_double (&name_hash, &name_hash_double); + GNUNET_CRYPTO_short_hash_double (&gph->new_zone, &zone_hash_double); + GNUNET_CRYPTO_hash_xor(&name_hash_double, &zone_hash_double, &lookup_key); GNUNET_CRYPTO_hash_to_enc (&lookup_key, &lookup_key_string); GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, @@ -333,8 +337,8 @@ process_zone_to_name_discover(void *cls, * @param zone the authority * @param the private key of our authority */ -static void process_discovered_authority(char* name, GNUNET_HashCode zone, - GNUNET_HashCode our_zone, +static void process_discovered_authority(char* name, struct GNUNET_CRYPTO_ShortHashCode zone, + struct GNUNET_CRYPTO_ShortHashCode our_zone, struct GNUNET_CRYPTO_RsaPrivateKey *key) { struct GetPseuAuthorityHandle *gph; @@ -490,7 +494,6 @@ process_record_result_dht(void* cls, int i; int rd_size; - GNUNET_HashCode zone, name_hash; GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "got dht result (size=%d)\n", size); if (data == NULL) @@ -544,9 +547,6 @@ process_record_result_dht(void* cls, } - GNUNET_CRYPTO_hash(name, strlen(name), &name_hash); - GNUNET_CRYPTO_hash_xor(key, &name_hash, &zone); - /** * FIXME check pubkey against existing key in namestore? * https://gnunet.org/bugs/view.php?id=2179 @@ -582,13 +582,17 @@ static void resolve_record_dht(struct ResolverHandle *rh) { uint32_t xquery; - GNUNET_HashCode name_hash; + struct GNUNET_CRYPTO_ShortHashCode name_hash; GNUNET_HashCode lookup_key; + GNUNET_HashCode name_hash_double; + GNUNET_HashCode zone_hash_double; struct GNUNET_CRYPTO_HashAsciiEncoded lookup_key_string; struct RecordLookupHandle *rlh = (struct RecordLookupHandle *)rh->proc_cls; - GNUNET_CRYPTO_hash(rh->name, strlen(rh->name), &name_hash); - GNUNET_CRYPTO_hash_xor(&name_hash, &rh->authority, &lookup_key); + GNUNET_CRYPTO_short_hash(rh->name, strlen(rh->name), &name_hash); + GNUNET_CRYPTO_short_hash_double(&name_hash, &name_hash_double); + GNUNET_CRYPTO_short_hash_double(&rh->authority, &zone_hash_double); + GNUNET_CRYPTO_hash_xor(&name_hash_double, &zone_hash_double, &lookup_key); GNUNET_CRYPTO_hash_to_enc (&lookup_key, &lookup_key_string); GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, @@ -636,11 +640,11 @@ process_record_result_ns(void* cls, struct ResolverHandle *rh; struct RecordLookupHandle *rlh; struct GNUNET_TIME_Relative remaining_time; - GNUNET_HashCode zone; + struct GNUNET_CRYPTO_ShortHashCode zone; rh = (struct ResolverHandle *) cls; rlh = (struct RecordLookupHandle *)rh->proc_cls; - GNUNET_CRYPTO_hash(key, + GNUNET_CRYPTO_short_hash(key, sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &zone); remaining_time = GNUNET_TIME_absolute_get_remaining (expiration); @@ -809,7 +813,8 @@ process_delegation_result_dht(void* cls, char* rd_data = (char*) data; int i; int rd_size; - GNUNET_HashCode zone, name_hash; + struct GNUNET_CRYPTO_ShortHashCode zone, name_hash; + GNUNET_HashCode zone_hash_double, name_hash_double; GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Got DHT result\n"); @@ -863,7 +868,7 @@ process_delegation_result_dht(void* cls, { GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Authority found in DHT\n"); rh->answered = 1; - memcpy(&rh->authority, rd[i].data, sizeof(GNUNET_HashCode)); + memcpy(&rh->authority, rd[i].data, sizeof(struct GNUNET_CRYPTO_ShortHashCode)); struct AuthorityChain *auth = GNUNET_malloc(sizeof(struct AuthorityChain)); auth->zone = rh->authority; @@ -883,11 +888,14 @@ process_delegation_result_dht(void* cls, } - GNUNET_CRYPTO_hash(name, strlen(name), &name_hash); - GNUNET_CRYPTO_hash_xor(key, &name_hash, &zone); + GNUNET_CRYPTO_short_hash(name, strlen(name), &name_hash); + GNUNET_CRYPTO_short_hash_double(&name_hash, &name_hash_double); + GNUNET_CRYPTO_hash_xor(key, &name_hash_double, &zone_hash_double); + GNUNET_CRYPTO_short_hash_from_truncation (&zone_hash_double, &zone); /* Save to namestore */ - if (0 != GNUNET_CRYPTO_hash_cmp(&rh->authority_chain_tail->zone, &zone)) + if (0 != GNUNET_CRYPTO_short_hash_cmp(&rh->authority_chain_tail->zone, + &zone)) { GNUNET_NAMESTORE_record_put (namestore_handle, &nrb->public_key, @@ -1083,8 +1091,8 @@ handle_record_ns(void* cls, struct ResolverHandle *rh, { /* ns entry expired and not ours. try dht */ if (rh->status & (EXPIRED | !EXISTS) && - GNUNET_CRYPTO_hash_cmp(&rh->authority_chain_head->zone, - &rh->authority_chain_tail->zone)) + GNUNET_CRYPTO_short_hash_cmp(&rh->authority_chain_head->zone, + &rh->authority_chain_tail->zone)) { rh->proc = &handle_record_dht; resolve_record_dht(rh); @@ -1254,13 +1262,17 @@ static void resolve_delegation_dht(struct ResolverHandle *rh) { uint32_t xquery; - GNUNET_HashCode name_hash; + struct GNUNET_CRYPTO_ShortHashCode name_hash; + GNUNET_HashCode name_hash_double; + GNUNET_HashCode zone_hash_double; GNUNET_HashCode lookup_key; - GNUNET_CRYPTO_hash(rh->authority_name, + GNUNET_CRYPTO_short_hash(rh->authority_name, strlen(rh->authority_name), &name_hash); - GNUNET_CRYPTO_hash_xor(&name_hash, &rh->authority, &lookup_key); + GNUNET_CRYPTO_short_hash_double(&name_hash, &name_hash_double); + GNUNET_CRYPTO_short_hash_double(&rh->authority, &zone_hash_double); + GNUNET_CRYPTO_hash_xor(&name_hash_double, &zone_hash_double, &lookup_key); rh->dht_timeout_task = GNUNET_SCHEDULER_add_delayed (DHT_LOOKUP_TIMEOUT, &dht_authority_lookup_timeout, @@ -1324,7 +1336,7 @@ handle_delegation_ns(void* cls, struct ResolverHandle *rh, * or we are authority **/ if ((rh->status & (EXISTS | !EXPIRED)) || - !GNUNET_CRYPTO_hash_cmp(&rh->authority_chain_head->zone, + !GNUNET_CRYPTO_short_hash_cmp(&rh->authority_chain_head->zone, &rh->authority_chain_tail->zone)) { if (is_canonical(rh->name)) @@ -1381,14 +1393,14 @@ process_delegation_result_ns(void* cls, { struct ResolverHandle *rh; struct GNUNET_TIME_Relative remaining_time; - GNUNET_HashCode zone; + struct GNUNET_CRYPTO_ShortHashCode zone; char new_name[MAX_DNS_NAME_LENGTH]; GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Got %d records from authority lookup\n", rd_count); rh = (struct ResolverHandle *)cls; - GNUNET_CRYPTO_hash(key, + GNUNET_CRYPTO_short_hash(key, sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &zone); remaining_time = GNUNET_TIME_absolute_get_remaining (expiration); @@ -1474,7 +1486,7 @@ process_delegation_result_ns(void* cls, * Resolve rest of query with new authority */ GNUNET_assert(rd[i].record_type == GNUNET_GNS_RECORD_PKEY); - memcpy(&rh->authority, rd[i].data, sizeof(GNUNET_HashCode)); + memcpy(&rh->authority, rd[i].data, sizeof(struct GNUNET_CRYPTO_ShortHashCode)); struct AuthorityChain *auth = GNUNET_malloc(sizeof(struct AuthorityChain)); auth->zone = rh->authority; memset(auth->name, 0, strlen(rh->authority_name)+1); @@ -1535,7 +1547,7 @@ resolve_delegation_ns(struct ResolverHandle *rh) * @param cls the closure to pass to proc */ void -gns_resolver_lookup_record(GNUNET_HashCode zone, +gns_resolver_lookup_record(struct GNUNET_CRYPTO_ShortHashCode zone, uint32_t record_type, const char* name, struct GNUNET_CRYPTO_RsaPrivateKey *key, @@ -1594,7 +1606,7 @@ gns_resolver_lookup_record(GNUNET_HashCode zone, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ZKEY is %s!\n", string_hash); - if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string(string_hash, + if (GNUNET_OK != GNUNET_CRYPTO_short_hash_from_string(string_hash, &rh->authority)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, @@ -1698,8 +1710,8 @@ process_zone_to_name_shorten(void *cls, GNUNET_free(nsh); free_resolver_handle(rh); } - else if (GNUNET_CRYPTO_hash_cmp(&rh->authority_chain_head->zone, - &rh->authority_chain_tail->zone)) + else if (GNUNET_CRYPTO_short_hash_cmp(&rh->authority_chain_head->zone, + &rh->authority_chain_tail->zone)) { /* our zone, just append .gnunet */ answer_len = strlen(rh->name) + strlen(GNUNET_GNS_TLD) + 2; @@ -1774,8 +1786,8 @@ handle_delegation_ns_shorten(void* cls, GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "PKEY resolved as far as possible in ns up to %s!\n", rh->name); - if (GNUNET_CRYPTO_hash_cmp(&rh->authority_chain_head->zone, - &rh->authority_chain_tail->zone) == 0) + if (GNUNET_CRYPTO_short_hash_cmp(&rh->authority_chain_head->zone, + &rh->authority_chain_tail->zone) == 0) { /** * This is our zone append .gnunet unless name is empty @@ -1816,7 +1828,7 @@ handle_delegation_ns_shorten(void* cls, * @param cls closure to pass to proc */ void -gns_resolver_shorten_name(GNUNET_HashCode zone, +gns_resolver_shorten_name(struct GNUNET_CRYPTO_ShortHashCode zone, const char* name, ShortenResultProcessor proc, void* cls) @@ -1864,8 +1876,8 @@ gns_resolver_shorten_name(GNUNET_HashCode zone, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ZKEY is %s!\n", string_hash); - if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string(string_hash, - &rh->authority)) + if (GNUNET_OK != GNUNET_CRYPTO_short_hash_from_string(string_hash, + &rh->authority)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot convert ZKEY %s to hash!\n", string_hash); @@ -1985,7 +1997,7 @@ handle_delegation_result_ns_get_auth(void* cls, * @param cls the closure to pass to the processor */ void -gns_resolver_get_authority(GNUNET_HashCode zone, +gns_resolver_get_authority(struct GNUNET_CRYPTO_ShortHashCode zone, const char* name, GetAuthorityResultProcessor proc, void* cls) diff --git a/src/gns/gnunet-service-gns_resolver.h b/src/gns/gnunet-service-gns_resolver.h index 4f857825c..326aff22d 100644 --- a/src/gns/gnunet-service-gns_resolver.h +++ b/src/gns/gnunet-service-gns_resolver.h @@ -19,7 +19,7 @@ struct AuthorityChain struct AuthorityChain *next; /* the zone hash of the authority */ - GNUNET_HashCode zone; + struct GNUNET_CRYPTO_ShortHashCode zone; /* (local) name of the authority */ char name[MAX_DNS_LABEL_LENGTH]; @@ -99,7 +99,7 @@ struct ResolverHandle int answered; /* the authoritative zone to query */ - GNUNET_HashCode authority; + struct GNUNET_CRYPTO_ShortHashCode authority; /* the name of the authoritative zone to query */ char authority_name[MAX_DNS_LABEL_LENGTH]; @@ -200,10 +200,10 @@ struct GetPseuAuthorityHandle char new_name[MAX_DNS_LABEL_LENGTH]; /* the zone of discovered authority */ - GNUNET_HashCode new_zone; + struct GNUNET_CRYPTO_ShortHashCode new_zone; /* the zone of our authority */ - GNUNET_HashCode zone; + struct GNUNET_CRYPTO_ShortHashCode zone; /* the private key of the zone to store the pseu in */ struct GNUNET_CRYPTO_RsaPrivateKey *key; @@ -238,7 +238,7 @@ gns_resolver_init(struct GNUNET_NAMESTORE_Handle *nh, * @param cls the closure to pass to proc */ void -gns_resolver_lookup_record(GNUNET_HashCode zone, +gns_resolver_lookup_record(struct GNUNET_CRYPTO_ShortHashCode zone, uint32_t record_type, const char* name, struct GNUNET_CRYPTO_RsaPrivateKey *key, @@ -246,7 +246,7 @@ gns_resolver_lookup_record(GNUNET_HashCode zone, void* cls); void -gns_resolver_shorten_name(GNUNET_HashCode zone, +gns_resolver_shorten_name(struct GNUNET_CRYPTO_ShortHashCode zone, const char* name, ShortenResultProcessor proc, void* cls); @@ -261,7 +261,7 @@ gns_resolver_shorten_name(GNUNET_HashCode zone, * @param cls the closure to pass to the processor */ void -gns_resolver_get_authority(GNUNET_HashCode zone, +gns_resolver_get_authority(struct GNUNET_CRYPTO_ShortHashCode zone, const char* name, GetAuthorityResultProcessor proc, void* cls); diff --git a/src/gns/plugin_block_gns.c b/src/gns/plugin_block_gns.c index 19495f243..7dfaab0fa 100644 --- a/src/gns/plugin_block_gns.c +++ b/src/gns/plugin_block_gns.c @@ -63,11 +63,13 @@ block_plugin_gns_evaluate (void *cls, enum GNUNET_BLOCK_Type type, size_t reply_block_size) { char* name; - GNUNET_HashCode pkey_hash; + GNUNET_HashCode pkey_hash_double; GNUNET_HashCode query_key; - GNUNET_HashCode name_hash; + GNUNET_HashCode name_hash_double; GNUNET_HashCode mhash; GNUNET_HashCode chash; + struct GNUNET_CRYPTO_ShortHashCode pkey_hash; + struct GNUNET_CRYPTO_ShortHashCode name_hash; struct GNSNameRecordBlock *nrb; uint32_t rd_count; char* rd_data = NULL; @@ -95,13 +97,16 @@ block_plugin_gns_evaluate (void *cls, enum GNUNET_BLOCK_Type type, nrb = (struct GNSNameRecordBlock *)reply_block; name = (char*)&nrb[1]; - GNUNET_CRYPTO_hash(&nrb->public_key, + GNUNET_CRYPTO_short_hash(&nrb->public_key, sizeof(nrb->public_key), &pkey_hash); - GNUNET_CRYPTO_hash(name, strlen(name), &name_hash); + GNUNET_CRYPTO_short_hash(name, strlen(name), &name_hash); + + GNUNET_CRYPTO_short_hash_double(&name_hash, &name_hash_double); + GNUNET_CRYPTO_short_hash_double(&pkey_hash, &pkey_hash_double); - GNUNET_CRYPTO_hash_xor(&pkey_hash, &name_hash, &query_key); + GNUNET_CRYPTO_hash_xor(&pkey_hash_double, &name_hash_double, &query_key); struct GNUNET_CRYPTO_HashAsciiEncoded xor_exp; struct GNUNET_CRYPTO_HashAsciiEncoded xor_got; diff --git a/src/gns/test_gns_dht_delegated_lookup.c b/src/gns/test_gns_dht_delegated_lookup.c index 469ae36be..2a541e4eb 100644 --- a/src/gns/test_gns_dht_delegated_lookup.c +++ b/src/gns/test_gns_dht_delegated_lookup.c @@ -211,9 +211,11 @@ static void put_dht(void *cls, int32_t success, const char *emsg) { struct GNSNameRecordBlock *nrb; - GNUNET_HashCode name_hash; + struct GNUNET_CRYPTO_ShortHashCode name_hash; + struct GNUNET_CRYPTO_ShortHashCode zone_hash; GNUNET_HashCode xor_hash; - GNUNET_HashCode zone_hash; + GNUNET_HashCode name_hash_double; + GNUNET_HashCode zone_hash_double; uint32_t rd_payload_length; char* nrb_data = NULL; struct GNUNET_CRYPTO_RsaSignature *sig; @@ -250,11 +252,13 @@ put_dht(void *cls, int32_t success, const char *emsg) GNUNET_free (nrb); return; } - GNUNET_CRYPTO_hash(TEST_RECORD_NAME, strlen(TEST_RECORD_NAME), &name_hash); - GNUNET_CRYPTO_hash(&bob_pkey, + GNUNET_CRYPTO_short_hash(TEST_RECORD_NAME, strlen(TEST_RECORD_NAME), &name_hash); + GNUNET_CRYPTO_short_hash(&bob_pkey, sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &zone_hash); - GNUNET_CRYPTO_hash_xor(&zone_hash, &name_hash, &xor_hash); + GNUNET_CRYPTO_short_hash_double(&zone_hash, &zone_hash_double); + GNUNET_CRYPTO_short_hash_double(&name_hash, &name_hash_double); + GNUNET_CRYPTO_hash_xor(&zone_hash_double, &name_hash_double, &xor_hash); rd_payload_length += sizeof(struct GNSNameRecordBlock) + strlen(TEST_RECORD_NAME) + 1; @@ -280,7 +284,7 @@ do_lookup(void *cls, const struct GNUNET_PeerIdentity *id, char* alice_keyfile; - GNUNET_HashCode bob_hash; + struct GNUNET_CRYPTO_ShortHashCode bob_hash; GNUNET_SCHEDULER_cancel (die_task); @@ -319,11 +323,11 @@ do_lookup(void *cls, const struct GNUNET_PeerIdentity *id, GNUNET_CRYPTO_rsa_key_get_public (alice_key, &alice_pkey); GNUNET_CRYPTO_rsa_key_get_public (bob_key, &bob_pkey); - GNUNET_CRYPTO_hash(&bob_pkey, sizeof(bob_pkey), &bob_hash); + GNUNET_CRYPTO_short_hash(&bob_pkey, sizeof(bob_pkey), &bob_hash); struct GNUNET_NAMESTORE_RecordData rd; rd.expiration = GNUNET_TIME_absolute_get_forever (); - rd.data_size = sizeof(GNUNET_HashCode); + rd.data_size = sizeof(struct GNUNET_CRYPTO_ShortHashCode); rd.data = &bob_hash; rd.record_type = GNUNET_GNS_RECORD_PKEY; diff --git a/src/gns/test_gns_pseu_shorten.c b/src/gns/test_gns_pseu_shorten.c index ee19f59d0..ce2511f32 100644 --- a/src/gns/test_gns_pseu_shorten.c +++ b/src/gns/test_gns_pseu_shorten.c @@ -84,8 +84,8 @@ struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded our_pkey; struct GNUNET_CRYPTO_RsaPrivateKey *alice_key; struct GNUNET_CRYPTO_RsaPrivateKey *bob_key; struct GNUNET_CRYPTO_RsaPrivateKey *our_key; -GNUNET_HashCode alice_hash; -GNUNET_HashCode bob_hash; +struct GNUNET_CRYPTO_ShortHashCode alice_hash; +struct GNUNET_CRYPTO_ShortHashCode bob_hash; /** * Check whether peers successfully shut down. @@ -246,9 +246,11 @@ static void put_pseu_dht(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct GNSNameRecordBlock *nrb; - GNUNET_HashCode name_hash; + struct GNUNET_CRYPTO_ShortHashCode name_hash; + struct GNUNET_CRYPTO_ShortHashCode zone_hash; GNUNET_HashCode xor_hash; - GNUNET_HashCode zone_hash; + GNUNET_HashCode name_hash_double; + GNUNET_HashCode zone_hash_double; uint32_t rd_payload_length; char* nrb_data = NULL; struct GNUNET_CRYPTO_RsaSignature *sig; @@ -291,11 +293,14 @@ put_pseu_dht(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_free (nrb); return; } - GNUNET_CRYPTO_hash("+", strlen("+"), &name_hash); - GNUNET_CRYPTO_hash(&alice_pkey, + GNUNET_CRYPTO_short_hash("+", strlen("+"), &name_hash); + GNUNET_CRYPTO_short_hash(&alice_pkey, sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &zone_hash); - GNUNET_CRYPTO_hash_xor(&zone_hash, &name_hash, &xor_hash); + + GNUNET_CRYPTO_short_hash_double(&name_hash, &name_hash_double); + GNUNET_CRYPTO_short_hash_double(&zone_hash, &zone_hash_double); + GNUNET_CRYPTO_hash_xor(&zone_hash_double, &name_hash_double, &xor_hash); rd_payload_length += sizeof(struct GNSNameRecordBlock) + strlen("+") + 1; @@ -319,9 +324,11 @@ static void put_www_dht(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct GNSNameRecordBlock *nrb; - GNUNET_HashCode name_hash; + struct GNUNET_CRYPTO_ShortHashCode name_hash; + struct GNUNET_CRYPTO_ShortHashCode zone_hash; GNUNET_HashCode xor_hash; - GNUNET_HashCode zone_hash; + GNUNET_HashCode name_hash_double; + GNUNET_HashCode zone_hash_double; uint32_t rd_payload_length; char* nrb_data = NULL; struct GNUNET_CRYPTO_RsaSignature *sig; @@ -366,11 +373,13 @@ put_www_dht(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_free (nrb); return; } - GNUNET_CRYPTO_hash(TEST_RECORD_NAME, strlen(TEST_RECORD_NAME), &name_hash); - GNUNET_CRYPTO_hash(&alice_pkey, + GNUNET_CRYPTO_short_hash(TEST_RECORD_NAME, strlen(TEST_RECORD_NAME), &name_hash); + GNUNET_CRYPTO_short_hash(&alice_pkey, sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &zone_hash); - GNUNET_CRYPTO_hash_xor(&zone_hash, &name_hash, &xor_hash); + GNUNET_CRYPTO_short_hash_double(&zone_hash, &zone_hash_double); + GNUNET_CRYPTO_short_hash_double(&name_hash, &name_hash_double); + GNUNET_CRYPTO_hash_xor(&zone_hash_double, &name_hash_double, &xor_hash); rd_payload_length += sizeof(struct GNSNameRecordBlock) + strlen(TEST_RECORD_NAME) + 1; @@ -395,16 +404,18 @@ static void put_pkey_dht(void *cls, int32_t success, const char *emsg) { struct GNSNameRecordBlock *nrb; - GNUNET_HashCode name_hash; + struct GNUNET_CRYPTO_ShortHashCode name_hash; + struct GNUNET_CRYPTO_ShortHashCode zone_hash; GNUNET_HashCode xor_hash; - GNUNET_HashCode zone_hash; + GNUNET_HashCode name_hash_double; + GNUNET_HashCode zone_hash_double; uint32_t rd_payload_length; char* nrb_data = NULL; struct GNUNET_CRYPTO_RsaSignature *sig; struct GNUNET_NAMESTORE_RecordData rd; rd.expiration = GNUNET_TIME_absolute_get_forever (); - rd.data_size = sizeof(GNUNET_HashCode); + rd.data_size = sizeof(struct GNUNET_CRYPTO_ShortHashCode); rd.data = &alice_hash; rd.record_type = GNUNET_GNS_RECORD_PKEY; @@ -442,12 +453,14 @@ put_pkey_dht(void *cls, int32_t success, const char *emsg) } - GNUNET_CRYPTO_hash(TEST_AUTHORITY_ALICE, + GNUNET_CRYPTO_short_hash(TEST_AUTHORITY_ALICE, strlen(TEST_AUTHORITY_ALICE), &name_hash); - GNUNET_CRYPTO_hash(&bob_pkey, + GNUNET_CRYPTO_short_hash(&bob_pkey, sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &zone_hash); - GNUNET_CRYPTO_hash_xor(&zone_hash, &name_hash, &xor_hash); + GNUNET_CRYPTO_short_hash_double(&zone_hash, &zone_hash_double); + GNUNET_CRYPTO_short_hash_double(&name_hash, &name_hash_double); + GNUNET_CRYPTO_hash_xor(&zone_hash_double, &name_hash_double, &xor_hash); rd_payload_length += sizeof(struct GNSNameRecordBlock) + strlen(TEST_AUTHORITY_ALICE) + 1; @@ -513,12 +526,12 @@ do_lookup(void *cls, const struct GNUNET_PeerIdentity *id, GNUNET_CRYPTO_rsa_key_get_public (our_key, &our_pkey); GNUNET_CRYPTO_rsa_key_get_public (bob_key, &bob_pkey); GNUNET_CRYPTO_rsa_key_get_public (alice_key, &alice_pkey); - GNUNET_CRYPTO_hash(&bob_pkey, sizeof(bob_pkey), &bob_hash); - GNUNET_CRYPTO_hash(&alice_pkey, sizeof(alice_pkey), &alice_hash); + GNUNET_CRYPTO_short_hash(&bob_pkey, sizeof(bob_pkey), &bob_hash); + GNUNET_CRYPTO_short_hash(&alice_pkey, sizeof(alice_pkey), &alice_hash); struct GNUNET_NAMESTORE_RecordData rd; rd.expiration = GNUNET_TIME_absolute_get_forever (); - rd.data_size = sizeof(GNUNET_HashCode); + rd.data_size = sizeof(struct GNUNET_CRYPTO_ShortHashCode); rd.data = &bob_hash; rd.record_type = GNUNET_GNS_RECORD_PKEY; diff --git a/src/gns/test_gns_simple_delegated_lookup.c b/src/gns/test_gns_simple_delegated_lookup.c index ea1206b9b..2006754da 100644 --- a/src/gns/test_gns_simple_delegated_lookup.c +++ b/src/gns/test_gns_simple_delegated_lookup.c @@ -204,7 +204,7 @@ do_lookup(void *cls, const struct GNUNET_PeerIdentity *id, struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded bob_pkey; struct GNUNET_CRYPTO_RsaPrivateKey *alice_key; struct GNUNET_CRYPTO_RsaPrivateKey *bob_key; - GNUNET_HashCode bob_hash; + struct GNUNET_CRYPTO_ShortHashCode bob_hash; struct GNUNET_CRYPTO_RsaSignature *sig; char* alice_keyfile; @@ -240,9 +240,9 @@ do_lookup(void *cls, const struct GNUNET_PeerIdentity *id, rd.expiration = GNUNET_TIME_absolute_get_forever (); GNUNET_assert(1 == inet_pton (AF_INET, ip, web)); - GNUNET_CRYPTO_hash(&bob_pkey, sizeof(bob_pkey), &bob_hash); + GNUNET_CRYPTO_short_hash(&bob_pkey, sizeof(bob_pkey), &bob_hash); - rd.data_size = sizeof(GNUNET_HashCode); + rd.data_size = sizeof(struct GNUNET_CRYPTO_ShortHashCode); rd.data = &bob_hash; rd.record_type = GNUNET_GNS_RECORD_PKEY; diff --git a/src/gns/test_gns_simple_get_authority.c b/src/gns/test_gns_simple_get_authority.c index 32bb39463..7ad890d95 100644 --- a/src/gns/test_gns_simple_get_authority.c +++ b/src/gns/test_gns_simple_get_authority.c @@ -196,8 +196,8 @@ do_shorten(void *cls, const struct GNUNET_PeerIdentity *id, struct GNUNET_CRYPTO_RsaPrivateKey *our_key; struct GNUNET_CRYPTO_RsaPrivateKey *alice_key; struct GNUNET_CRYPTO_RsaPrivateKey *bob_key; - GNUNET_HashCode bob_hash; - GNUNET_HashCode alice_hash; + struct GNUNET_CRYPTO_ShortHashCode bob_hash; + struct GNUNET_CRYPTO_ShortHashCode alice_hash; struct GNUNET_CRYPTO_RsaSignature *sig; char* our_keyfile; @@ -237,9 +237,9 @@ do_shorten(void *cls, const struct GNUNET_PeerIdentity *id, rd.expiration = GNUNET_TIME_absolute_get_forever (); GNUNET_assert(1 == inet_pton (AF_INET, ip, web)); - GNUNET_CRYPTO_hash(&bob_pkey, sizeof(bob_pkey), &bob_hash); + GNUNET_CRYPTO_short_hash(&bob_pkey, sizeof(bob_pkey), &bob_hash); - rd.data_size = sizeof(GNUNET_HashCode); + rd.data_size = sizeof(struct GNUNET_CRYPTO_ShortHashCode); rd.data = &bob_hash; rd.record_type = GNUNET_GNS_RECORD_PKEY; @@ -252,7 +252,7 @@ do_shorten(void *cls, const struct GNUNET_PeerIdentity *id, NULL); /* put alice into bobs zone */ - GNUNET_CRYPTO_hash(&alice_pkey, sizeof(alice_pkey), &alice_hash); + GNUNET_CRYPTO_short_hash(&alice_pkey, sizeof(alice_pkey), &alice_hash); rd.data = &alice_hash; sig = GNUNET_NAMESTORE_create_signature(bob_key, GNUNET_TIME_absolute_get_forever(), TEST_AUTHORITY_ALICE, &rd, 1); diff --git a/src/gns/test_gns_simple_mx_lookup.c b/src/gns/test_gns_simple_mx_lookup.c index 7f854c6f3..dbdc5b6eb 100644 --- a/src/gns/test_gns_simple_mx_lookup.c +++ b/src/gns/test_gns_simple_mx_lookup.c @@ -220,7 +220,7 @@ do_lookup(void *cls, const struct GNUNET_PeerIdentity *id, struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded bob_pkey; struct GNUNET_CRYPTO_RsaPrivateKey *alice_key; struct GNUNET_CRYPTO_RsaPrivateKey *bob_key; - GNUNET_HashCode bob_hash; + struct GNUNET_CRYPTO_ShortHashCode bob_hash; struct GNUNET_CRYPTO_RsaSignature *sig; char* alice_keyfile; @@ -257,9 +257,9 @@ do_lookup(void *cls, const struct GNUNET_PeerIdentity *id, rd.expiration = GNUNET_TIME_absolute_get_forever (); GNUNET_assert(1 == inet_pton (AF_INET, ip, mail)); - GNUNET_CRYPTO_hash(&bob_pkey, sizeof(bob_pkey), &bob_hash); + GNUNET_CRYPTO_short_hash(&bob_pkey, sizeof(bob_pkey), &bob_hash); - rd.data_size = sizeof(GNUNET_HashCode); + rd.data_size = sizeof(struct GNUNET_CRYPTO_ShortHashCode); rd.data = &bob_hash; rd.record_type = GNUNET_GNS_RECORD_PKEY; diff --git a/src/gns/test_gns_simple_shorten.c b/src/gns/test_gns_simple_shorten.c index 27a0024dc..8a4dd2ec9 100644 --- a/src/gns/test_gns_simple_shorten.c +++ b/src/gns/test_gns_simple_shorten.c @@ -196,8 +196,8 @@ do_shorten(void *cls, const struct GNUNET_PeerIdentity *id, struct GNUNET_CRYPTO_RsaPrivateKey *our_key; struct GNUNET_CRYPTO_RsaPrivateKey *alice_key; struct GNUNET_CRYPTO_RsaPrivateKey *bob_key; - GNUNET_HashCode bob_hash; - GNUNET_HashCode alice_hash; + struct GNUNET_CRYPTO_ShortHashCode bob_hash; + struct GNUNET_CRYPTO_ShortHashCode alice_hash; struct GNUNET_CRYPTO_RsaSignature *sig; char* our_keyfile; @@ -237,9 +237,9 @@ do_shorten(void *cls, const struct GNUNET_PeerIdentity *id, rd.expiration = GNUNET_TIME_absolute_get_forever (); GNUNET_assert(1 == inet_pton (AF_INET, ip, web)); - GNUNET_CRYPTO_hash(&bob_pkey, sizeof(bob_pkey), &bob_hash); + GNUNET_CRYPTO_short_hash(&bob_pkey, sizeof(bob_pkey), &bob_hash); - rd.data_size = sizeof(GNUNET_HashCode); + rd.data_size = sizeof(struct GNUNET_CRYPTO_ShortHashCode); rd.data = &bob_hash; rd.record_type = GNUNET_GNS_RECORD_PKEY; @@ -252,7 +252,7 @@ do_shorten(void *cls, const struct GNUNET_PeerIdentity *id, NULL); /* put alice into bobs zone */ - GNUNET_CRYPTO_hash(&alice_pkey, sizeof(alice_pkey), &alice_hash); + GNUNET_CRYPTO_short_hash(&alice_pkey, sizeof(alice_pkey), &alice_hash); rd.data = &alice_hash; sig = GNUNET_NAMESTORE_create_signature(bob_key, GNUNET_TIME_absolute_get_forever(), @@ -289,7 +289,7 @@ do_shorten(void *cls, const struct GNUNET_PeerIdentity *id, NULL, NULL); - rd.data_size = sizeof(GNUNET_HashCode); + rd.data_size = sizeof(struct GNUNET_CRYPTO_ShortHashCode); rd.data = &alice_hash; rd.record_type = GNUNET_GNS_RECORD_PKEY; GNUNET_free(sig); diff --git a/src/gns/test_gns_simple_zkey_lookup.c b/src/gns/test_gns_simple_zkey_lookup.c index f8db33973..a24e605b9 100644 --- a/src/gns/test_gns_simple_zkey_lookup.c +++ b/src/gns/test_gns_simple_zkey_lookup.c @@ -70,7 +70,7 @@ static struct GNUNET_GNS_Handle *gns_handle; const struct GNUNET_CONFIGURATION_Handle *cfg; -GNUNET_HashCode bob_hash; +struct GNUNET_CRYPTO_ShortHashCode bob_hash; /** * Check whether peers successfully shut down. @@ -143,7 +143,7 @@ commence_testing (void *cls, int32_t success, const char *emsg) { char name[MAX_DNS_NAME_LENGTH]; char* pos; - struct GNUNET_CRYPTO_HashAsciiEncoded hash_str; + struct GNUNET_CRYPTO_ShortHashAsciiEncoded hash_str; GNUNET_NAMESTORE_disconnect(namestore_handle, GNUNET_YES); @@ -160,7 +160,7 @@ commence_testing (void *cls, int32_t success, const char *emsg) pos += strlen(TEST_RECORD_NAME); strcpy(pos, "."); pos++; - GNUNET_CRYPTO_hash_to_enc(&bob_hash, &hash_str); + GNUNET_CRYPTO_short_hash_to_enc(&bob_hash, &hash_str); strcpy(pos, (char*)&hash_str); pos += strlen((char*)&hash_str); strcpy(pos, "."); @@ -243,9 +243,9 @@ do_lookup(void *cls, const struct GNUNET_PeerIdentity *id, rd.expiration = GNUNET_TIME_absolute_get_forever (); GNUNET_assert(1 == inet_pton (AF_INET, ip, web)); - GNUNET_CRYPTO_hash(&bob_pkey, sizeof(bob_pkey), &bob_hash); + GNUNET_CRYPTO_short_hash(&bob_pkey, sizeof(bob_pkey), &bob_hash); - rd.data_size = sizeof(GNUNET_HashCode); + rd.data_size = sizeof(struct GNUNET_CRYPTO_ShortHashCode); rd.data = &bob_hash; rd.record_type = GNUNET_GNS_RECORD_PKEY; diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h index 86b862563..777ddd97e 100644 --- a/src/include/gnunet_crypto_lib.h +++ b/src/include/gnunet_crypto_lib.h @@ -512,6 +512,18 @@ GNUNET_CRYPTO_short_hash_from_string2 (const char *enc, size_t enclen, GNUNET_CRYPTO_short_hash_from_string2 (enc, strlen(enc), result) +/** + * Compare function for ShortHashCodes, producing a total ordering + * of all hashcodes. + * + * @param h1 some hash code + * @param h2 some hash code + * @return 1 if h1 > h2, -1 if h1 < h2 and 0 if h1 == h2. + */ +int +GNUNET_CRYPTO_short_hash_cmp (const struct GNUNET_CRYPTO_ShortHashCode * h1, + const struct GNUNET_CRYPTO_ShortHashCode * h2); + /** * Compute the distance between 2 hashcodes. * The computation must be fast, not involve diff --git a/src/util/crypto_hash.c b/src/util/crypto_hash.c index 57e37f3fd..9f8c4b9cf 100644 --- a/src/util/crypto_hash.c +++ b/src/util/crypto_hash.c @@ -669,6 +669,32 @@ GNUNET_CRYPTO_short_hash_to_enc (const struct GNUNET_CRYPTO_ShortHashCode * bloc *np = '\0'; } +/** + * Compare function for ShortHashCodes, producing a total ordering + * of all hashcodes. + * + * @param h1 some hash code + * @param h2 some hash code + * @return 1 if h1 > h2, -1 if h1 < h2 and 0 if h1 == h2. + */ +int +GNUNET_CRYPTO_short_hash_cmp (const struct GNUNET_CRYPTO_ShortHashCode * h1, + const struct GNUNET_CRYPTO_ShortHashCode * h2) +{ + unsigned int *i1; + unsigned int *i2; + int i; + i1 = (unsigned int *) h1; + i2 = (unsigned int *) h2; + for (i = (sizeof (struct GNUNET_CRYPTO_ShortHashCode) / sizeof (unsigned int)) - 1; i >= 0; i--) + { + if (i1[i] > i2[i]) + return 1; + if (i1[i] < i2[i]) + return -1; + } + return 0; +} /* end of crypto_hash.c */