Commit caa857fb authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Add code to calculate a SHA256 over the hash string if param hash_sha256

is set.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@3444 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent e4ccc3f1
......@@ -93,6 +93,8 @@ struct esi_bit;
struct vrt_backend;
struct cli_proto;
struct ban;
struct SHA256Context;
struct lock { void *priv; }; // Opaque
/*--------------------------------------------------------------------*/
......@@ -202,6 +204,8 @@ struct worker {
unsigned char *wlb, *wlp, *wle;
unsigned wlr;
struct SHA256Context *sha256ctx;
};
/* Work Request for worker thread ------------------------------------*/
......
......@@ -66,6 +66,7 @@
#include "cache.h"
#include "stevedore.h"
#include "hash_slinger.h"
#include "vsha256.h"
static const struct hash_slinger *hash;
......@@ -219,6 +220,8 @@ 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);
}
void
......@@ -241,6 +244,10 @@ 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);
}
}
struct object *
......@@ -250,6 +257,7 @@ HSH_Lookup(struct sess *sp)
struct http *h;
struct objhead *oh;
struct object *o, *busy_o, *grace_o;
unsigned char sha256[32];
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC);
......@@ -257,6 +265,10 @@ HSH_Lookup(struct sess *sp)
AN(hash);
w = sp->wrk;
h = sp->http;
if (params->hash_sha256) {
SHA256_Final(sha256, sp->wrk->sha256ctx);
/* WSP(sp, SLT_Debug, "SHA256: <%.32s>", sha256); */
}
HSH_Prealloc(sp);
if (sp->objhead != NULL) {
......
......@@ -72,6 +72,7 @@
#include "cache.h"
#include "stevedore.h"
#include "hash_slinger.h"
#include "vsha256.h"
VTAILQ_HEAD(workerhead, worker);
......@@ -269,6 +270,7 @@ wrk_thread(void *priv)
struct worker *w, ww;
struct wq *qp;
unsigned char wlog[params->shm_workspace];
struct SHA256Context sha256;
THR_SetName("cache-worker");
w = &ww;
......@@ -278,6 +280,7 @@ wrk_thread(void *priv)
w->lastused = NAN;
w->wlb = w->wlp = wlog;
w->wle = wlog + sizeof wlog;
w->sha256ctx = &sha256;
AZ(pthread_cond_init(&w->cond, NULL));
VSL(SLT_WorkThread, 0, "%p start", w);
......
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