Commit 9d2244a6 authored by Tollef Fog Heen's avatar Tollef Fog Heen

Merge r3504: Make SHA256 digest standard and use it in hash_classic.c



git-svn-id: http://www.varnish-cache.org/svn/branches/2.0@3694 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 30fdb20e
...@@ -214,7 +214,6 @@ HSH_Prepare(struct sess *sp, unsigned nhashcount) ...@@ -214,7 +214,6 @@ HSH_Prepare(struct sess *sp, unsigned nhashcount)
if (u) if (u)
p += sizeof(const char *) - u; p += sizeof(const char *) - u;
sp->hashptr = (void*)p; sp->hashptr = (void*)p;
if (params->hash_sha256)
SHA256_Init(sp->wrk->sha256ctx); SHA256_Init(sp->wrk->sha256ctx);
} }
...@@ -238,10 +237,8 @@ HSH_AddString(struct sess *sp, const char *str) ...@@ -238,10 +237,8 @@ HSH_AddString(struct sess *sp, const char *str)
sp->hashptr[sp->ihashptr + 1] = str + l; sp->hashptr[sp->ihashptr + 1] = str + l;
sp->ihashptr += 2; sp->ihashptr += 2;
sp->lhashptr += l + 1; sp->lhashptr += l + 1;
if (params->hash_sha256) {
SHA256_Update(sp->wrk->sha256ctx, str, l); SHA256_Update(sp->wrk->sha256ctx, str, l);
SHA256_Update(sp->wrk->sha256ctx, "#", 1); SHA256_Update(sp->wrk->sha256ctx, "#", 1);
}
} }
struct object * struct object *
...@@ -260,10 +257,7 @@ HSH_Lookup(struct sess *sp) ...@@ -260,10 +257,7 @@ HSH_Lookup(struct sess *sp)
h = sp->http; h = sp->http;
HSH_Prealloc(sp); HSH_Prealloc(sp);
if (params->hash_sha256) {
SHA256_Final(sp->wrk->nobjhead->digest, sp->wrk->sha256ctx); SHA256_Final(sp->wrk->nobjhead->digest, sp->wrk->sha256ctx);
/* WSP(sp, SLT_Debug, "SHA256: <%.32s>", sha256); */
}
if (sp->objhead != NULL) { if (sp->objhead != NULL) {
CHECK_OBJ_NOTNULL(sp->objhead, OBJHEAD_MAGIC); CHECK_OBJ_NOTNULL(sp->objhead, OBJHEAD_MAGIC);
......
...@@ -120,19 +120,13 @@ hcl_lookup(const struct sess *sp, struct objhead *noh) ...@@ -120,19 +120,13 @@ hcl_lookup(const struct sess *sp, struct objhead *noh)
struct objhead *oh; struct objhead *oh;
struct hcl_hd *hp; struct hcl_hd *hp;
unsigned u1, digest; unsigned u1, digest;
unsigned u, v;
int i; int i;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
CHECK_OBJ_NOTNULL(noh, OBJHEAD_MAGIC); CHECK_OBJ_NOTNULL(noh, OBJHEAD_MAGIC);
digest = ~0U; assert(sizeof noh->digest > sizeof digest);
for (u = 0; u < sp->ihashptr; u += 2) { memcpy(&digest, noh->digest, sizeof digest);
v = pdiff(sp->hashptr[u], sp->hashptr[u + 1]);
digest = crc32(digest, sp->hashptr[u], v);
}
digest ^= ~0U;
u1 = digest % hcl_nhash; u1 = digest % hcl_nhash;
hp = &hcl_head[u1]; hp = &hcl_head[u1];
......
...@@ -367,7 +367,6 @@ hcb_start(void) ...@@ -367,7 +367,6 @@ hcb_start(void)
(void)oh; (void)oh;
AZ(pthread_create(&tp, NULL, hcb_cleaner, NULL)); AZ(pthread_create(&tp, NULL, hcb_cleaner, NULL));
assert(params->hash_sha256);
assert(sizeof(struct hcb_y) <= sizeof(oh->u)); assert(sizeof(struct hcb_y) <= sizeof(oh->u));
memset(&hcb_root, 0, sizeof hcb_root); memset(&hcb_root, 0, sizeof hcb_root);
hcb_build_bittbl(); hcb_build_bittbl();
...@@ -402,7 +401,6 @@ hcb_lookup(const struct sess *sp, struct objhead *noh) ...@@ -402,7 +401,6 @@ hcb_lookup(const struct sess *sp, struct objhead *noh)
struct objhead *oh; struct objhead *oh;
unsigned u; unsigned u;
assert(params->hash_sha256);
oh = hcb_insert(&hcb_root, noh, 0); oh = hcb_insert(&hcb_root, noh, 0);
if (oh != NULL) { if (oh != NULL) {
/* Assert that we didn't muck with the tree without lock */ /* Assert that we didn't muck with the tree without lock */
......
...@@ -174,9 +174,6 @@ struct params { ...@@ -174,9 +174,6 @@ struct params {
/* Default grace period */ /* Default grace period */
unsigned default_grace; unsigned default_grace;
/* Use sha256 hasing */
unsigned hash_sha256;
/* Log hash string to shm */ /* Log hash string to shm */
unsigned log_hash; unsigned log_hash;
......
...@@ -710,10 +710,6 @@ static const struct parspec input_parspec[] = { ...@@ -710,10 +710,6 @@ static const struct parspec input_parspec[] = {
"NB: Must be specified with -p to have effect.\n", "NB: Must be specified with -p to have effect.\n",
0, 0,
"8192", "bytes" }, "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_hashstring", tweak_bool, &master.log_hash, 0, 0,
"Log the hash string to shared memory log.\n", "Log the hash string to shared memory log.\n",
0, 0,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment