Commit f9027544 authored by Geoff Simmons's avatar Geoff Simmons

make the SHA256_CTX local to the inline digest function

parent 32cf40bc
...@@ -86,9 +86,10 @@ errmsg(VRT_CTX, const char *fmt, ...) ...@@ -86,9 +86,10 @@ errmsg(VRT_CTX, const char *fmt, ...)
} }
static inline void static inline void
digest(SHA256_CTX *restrict const ctx, VCL_BLOB restrict const b, digest(VCL_BLOB restrict const b, uint8_t *restrict digest)
uint8_t *restrict digest)
{ {
SHA256_CTX ctx[1];
SHA256_Init(ctx); SHA256_Init(ctx);
SHA256_Update(ctx, b->priv, b->len); SHA256_Update(ctx, b->priv, b->len);
SHA256_Final(digest, ctx); SHA256_Final(digest, ctx);
...@@ -114,10 +115,9 @@ vmod_hmac__init(VRT_CTX, struct vmod_blobsha256_hmac **hmacp, ...@@ -114,10 +115,9 @@ vmod_hmac__init(VRT_CTX, struct vmod_blobsha256_hmac **hmacp,
if (key->len <= SHA256_BLOCKSZ) if (key->len <= SHA256_BLOCKSZ)
memcpy(k, key->priv, key->len); memcpy(k, key->priv, key->len);
else { else
SHA256_CTX hctx[1]; digest(key, k);
digest(hctx, key, k);
}
for (int i = 0; i < SHA256_BLOCKSZ; i++) { for (int i = 0; i < SHA256_BLOCKSZ; i++) {
innerk[i] = k[i] ^ 0x36; innerk[i] = k[i] ^ 0x36;
outerk[i] = k[i] ^ 0x5c; outerk[i] = k[i] ^ 0x5c;
...@@ -185,7 +185,6 @@ vmod_blob__init(VRT_CTX, struct vmod_blobsha256_blob **blobp, ...@@ -185,7 +185,6 @@ vmod_blob__init(VRT_CTX, struct vmod_blobsha256_blob **blobp,
const char *vcl_name, VCL_BLOB b) const char *vcl_name, VCL_BLOB b)
{ {
struct vmod_blobsha256_blob *blob; struct vmod_blobsha256_blob *blob;
SHA256_CTX hctx[1];
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
AN(blobp); AN(blobp);
...@@ -203,7 +202,7 @@ vmod_blob__init(VRT_CTX, struct vmod_blobsha256_blob **blobp, ...@@ -203,7 +202,7 @@ vmod_blob__init(VRT_CTX, struct vmod_blobsha256_blob **blobp,
blob->hash.len = SHA256_LEN; blob->hash.len = SHA256_LEN;
blob->hash.free = NULL; blob->hash.free = NULL;
digest(hctx, b, blob->hash.priv); digest(b, blob->hash.priv);
} }
VCL_BLOB VCL_BLOB
...@@ -233,7 +232,6 @@ vmod_hash(VRT_CTX, VCL_BLOB msg) ...@@ -233,7 +232,6 @@ vmod_hash(VRT_CTX, VCL_BLOB msg)
{ {
struct vmod_priv *b; struct vmod_priv *b;
char *snap; char *snap;
SHA256_CTX hctx[1];
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
if (INIT_FINI(ctx)) { if (INIT_FINI(ctx)) {
...@@ -256,7 +254,7 @@ vmod_hash(VRT_CTX, VCL_BLOB msg) ...@@ -256,7 +254,7 @@ vmod_hash(VRT_CTX, VCL_BLOB msg)
} }
b->len = SHA256_LEN; b->len = SHA256_LEN;
b->free = NULL; b->free = NULL;
digest(hctx, msg, b->priv); digest(msg, b->priv);
return b; return b;
} }
......
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