From: phk Date: Mon, 12 Jan 2009 13:09:51 +0000 (+0000) Subject: Make SHA256 digest standard and use it in hash_classic.c X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0d062ee2bb66b40112877eac38a7390f44c8de0a;p=varnish Make SHA256 digest standard and use it in hash_classic.c git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3504 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/cache_hash.c b/varnish-cache/bin/varnishd/cache_hash.c index 9f49c465..e8b28b4b 100644 --- a/varnish-cache/bin/varnishd/cache_hash.c +++ b/varnish-cache/bin/varnishd/cache_hash.c @@ -214,8 +214,7 @@ HSH_Prepare(struct sess *sp, unsigned nhashcount) if (u) p += sizeof(const char *) - u; sp->hashptr = (void*)p; - if (params->hash_sha256) - SHA256_Init(sp->wrk->sha256ctx); + SHA256_Init(sp->wrk->sha256ctx); } void @@ -238,10 +237,8 @@ HSH_AddString(struct sess *sp, const char *str) sp->hashptr[sp->ihashptr + 1] = str + l; sp->ihashptr += 2; sp->lhashptr += l + 1; - if (params->hash_sha256) { - SHA256_Update(sp->wrk->sha256ctx, str, l); - SHA256_Update(sp->wrk->sha256ctx, "#", 1); - } + SHA256_Update(sp->wrk->sha256ctx, str, l); + SHA256_Update(sp->wrk->sha256ctx, "#", 1); } struct object * @@ -260,10 +257,7 @@ HSH_Lookup(struct sess *sp) h = sp->http; HSH_Prealloc(sp); - if (params->hash_sha256) { - SHA256_Final(sp->wrk->nobjhead->digest, sp->wrk->sha256ctx); - /* WSP(sp, SLT_Debug, "SHA256: <%.32s>", sha256); */ - } + SHA256_Final(sp->wrk->nobjhead->digest, sp->wrk->sha256ctx); if (sp->objhead != NULL) { CHECK_OBJ_NOTNULL(sp->objhead, OBJHEAD_MAGIC); diff --git a/varnish-cache/bin/varnishd/hash_classic.c b/varnish-cache/bin/varnishd/hash_classic.c index f7f109c3..9f2ee04a 100644 --- a/varnish-cache/bin/varnishd/hash_classic.c +++ b/varnish-cache/bin/varnishd/hash_classic.c @@ -120,19 +120,13 @@ hcl_lookup(const struct sess *sp, struct objhead *noh) struct objhead *oh; struct hcl_hd *hp; unsigned u1, digest; - unsigned u, v; int i; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(noh, OBJHEAD_MAGIC); - digest = ~0U; - for (u = 0; u < sp->ihashptr; u += 2) { - v = pdiff(sp->hashptr[u], sp->hashptr[u + 1]); - digest = crc32(digest, sp->hashptr[u], v); - } - digest ^= ~0U; - + assert(sizeof noh->digest > sizeof digest); + memcpy(&digest, noh->digest, sizeof digest); u1 = digest % hcl_nhash; hp = &hcl_head[u1]; diff --git a/varnish-cache/bin/varnishd/hash_critbit.c b/varnish-cache/bin/varnishd/hash_critbit.c index cce96c90..e37efcca 100644 --- a/varnish-cache/bin/varnishd/hash_critbit.c +++ b/varnish-cache/bin/varnishd/hash_critbit.c @@ -367,7 +367,6 @@ hcb_start(void) (void)oh; AZ(pthread_create(&tp, NULL, hcb_cleaner, NULL)); - assert(params->hash_sha256); assert(sizeof(struct hcb_y) <= sizeof(oh->u)); memset(&hcb_root, 0, sizeof hcb_root); hcb_build_bittbl(); @@ -402,7 +401,6 @@ hcb_lookup(const struct sess *sp, struct objhead *noh) struct objhead *oh; unsigned u; - assert(params->hash_sha256); oh = hcb_insert(&hcb_root, noh, 0); if (oh != NULL) { /* Assert that we didn't muck with the tree without lock */ diff --git a/varnish-cache/bin/varnishd/heritage.h b/varnish-cache/bin/varnishd/heritage.h index 7a7c2193..8be6f7af 100644 --- a/varnish-cache/bin/varnishd/heritage.h +++ b/varnish-cache/bin/varnishd/heritage.h @@ -174,9 +174,6 @@ struct params { /* Default grace period */ unsigned default_grace; - /* Use sha256 hasing */ - unsigned hash_sha256; - /* Log hash string to shm */ unsigned log_hash; diff --git a/varnish-cache/bin/varnishd/mgt_param.c b/varnish-cache/bin/varnishd/mgt_param.c index 6b6bc41f..56c434da 100644 --- a/varnish-cache/bin/varnishd/mgt_param.c +++ b/varnish-cache/bin/varnishd/mgt_param.c @@ -710,10 +710,6 @@ static const struct parspec input_parspec[] = { "NB: Must be specified with -p to have effect.\n", 0, "8192", "bytes" }, - { "hash_sha256", tweak_bool, &master.hash_sha256, 0, 0, - "Use SHA256 compression of hash-strings", - 0, - "on", "bool" }, { "log_hashstring", tweak_bool, &master.log_hash, 0, 0, "Log the hash string to shared memory log.\n", 0,