Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libvmod-blobdigest
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
2
Issues
2
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
uplex-varnish
libvmod-blobdigest
Commits
a9f58f0f
Commit
a9f58f0f
authored
Nov 01, 2016
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
consolidate code for allocating space for a digest in workspace
parent
58858a78
Pipeline
#47
skipped
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
44 deletions
+42
-44
vmod_blobdigest.c
src/vmod_blobdigest.c
+42
-44
No files found.
src/vmod_blobdigest.c
View file @
a9f58f0f
...
...
@@ -48,6 +48,9 @@
#define VERR(ctx, fmt, ...) \
errmsg((ctx), "vmod blobdigest error: " fmt, __VA_ARGS__)
#define VERRNOMEM(ctx, fmt, ...) \
VERR((ctx), fmt ", out of space", __VA_ARGS__)
#define ERRNOMEM(ctx, msg) \
ERR((ctx), msg ", out of space")
...
...
@@ -73,11 +76,12 @@ struct vmod_blobdigest_digest {
};
struct
vmod_blobdigest_hmac
{
unsigned
magic
;
unsigned
magic
;
#define VMOD_BLOBDIGEST_HMAC_MAGIC 0x85678153
hash_ctx
inner_ctx
;
hash_ctx
outer_ctx
;
enum
algorithm
hash
;
hash_ctx
inner_ctx
;
hash_ctx
outer_ctx
;
char
*
vcl_name
;
enum
algorithm
hash
;
};
static
void
...
...
@@ -211,6 +215,31 @@ digest(const enum algorithm hash, hash_ctx *restrict const hctx,
final
(
hash
,
hctx
,
digest
);
}
static
struct
vmod_priv
*
ws_alloc_digest
(
VRT_CTX
,
const
size_t
digestsz
,
const
char
*
const
restrict
context
,
const
char
*
const
restrict
caller
)
{
struct
vmod_priv
*
b
;
char
*
snap
;
CHECK_OBJ_NOTNULL
(
ctx
->
ws
,
WS_MAGIC
);
snap
=
WS_Snapshot
(
ctx
->
ws
);
if
((
b
=
WS_Alloc
(
ctx
->
ws
,
sizeof
(
struct
vmod_priv
)))
==
NULL
)
{
VERRNOMEM
(
ctx
,
"allocating blob in %s.%s()"
,
context
,
caller
);
return
NULL
;
}
if
((
b
->
priv
=
WS_Alloc
(
ctx
->
ws
,
digestsz
))
==
NULL
)
{
WS_Reset
(
ctx
->
ws
,
snap
);
VERRNOMEM
(
ctx
,
"allocating hash result in %s.%s()"
,
context
,
caller
);
return
NULL
;
}
b
->
len
=
digestsz
;
b
->
free
=
NULL
;
return
b
;
}
/* Objects */
static
void
...
...
@@ -323,7 +352,6 @@ vmod_digest_final(VRT_CTX, struct vmod_blobdigest_digest *h)
{
struct
vmod_priv
*
b
;
struct
digest_task
*
task
;
char
*
snap
;
enum
algorithm
hash
;
size_t
digestsz
;
...
...
@@ -353,20 +381,9 @@ vmod_digest_final(VRT_CTX, struct vmod_blobdigest_digest *h)
if
(
task
->
result
!=
NULL
)
return
task
->
result
;
CHECK_OBJ_NOTNULL
(
ctx
->
ws
,
WS_MAGIC
);
snap
=
WS_Snapshot
(
ctx
->
ws
);
/* XXX: use vcl_name in err messages */
if
((
b
=
WS_Alloc
(
ctx
->
ws
,
sizeof
(
struct
vmod_priv
)))
==
NULL
)
{
ERRNOMEM
(
ctx
,
"allocating blob in digest.final()"
);
b
=
ws_alloc_digest
(
ctx
,
digestsz
,
h
->
vcl_name
,
"final"
);
if
(
b
==
NULL
)
return
NULL
;
}
if
((
b
->
priv
=
WS_Alloc
(
ctx
->
ws
,
digestsz
))
==
NULL
)
{
WS_Reset
(
ctx
->
ws
,
snap
);
ERRNOMEM
(
ctx
,
"allocating hash result in digest.final()"
);
return
NULL
;
}
b
->
len
=
digestsz
;
b
->
free
=
NULL
;
final
(
hash
,
&
task
->
ctx
,
b
->
priv
);
task
->
result
=
b
;
return
b
;
...
...
@@ -389,6 +406,7 @@ vmod_hmac__init(VRT_CTX, struct vmod_blobdigest_hmac **hmacp,
AN
(
hmac
);
*
hmacp
=
hmac
;
hmac
->
hash
=
hash
;
hmac
->
vcl_name
=
strdup
(
vcl_name
);
memset
(
k
,
0
,
blocksz
);
if
(
key
->
len
<=
blocksz
)
...
...
@@ -413,7 +431,6 @@ VCL_BLOB
vmod_hmac_hmac
(
VRT_CTX
,
struct
vmod_blobdigest_hmac
*
h
,
VCL_BLOB
msg
)
{
struct
vmod_priv
*
b
;
char
*
snap
;
hash_ctx
inner_ctx
,
outer_ctx
;
enum
algorithm
hash
;
size_t
digestsz
;
...
...
@@ -423,19 +440,9 @@ vmod_hmac_hmac(VRT_CTX, struct vmod_blobdigest_hmac *h, VCL_BLOB msg)
hash
=
h
->
hash
;
digestsz
=
hashspec
[
hash
].
digestsz
;
CHECK_OBJ_NOTNULL
(
ctx
->
ws
,
WS_MAGIC
);
snap
=
WS_Snapshot
(
ctx
->
ws
);
if
((
b
=
WS_Alloc
(
ctx
->
ws
,
sizeof
(
struct
vmod_priv
)))
==
NULL
)
{
ERRNOMEM
(
ctx
,
"allocating blob in hmac.hmac()"
);
b
=
ws_alloc_digest
(
ctx
,
digestsz
,
h
->
vcl_name
,
"hmac"
);
if
(
b
==
NULL
)
return
NULL
;
}
if
((
b
->
priv
=
WS_Alloc
(
ctx
->
ws
,
digestsz
))
==
NULL
)
{
WS_Reset
(
ctx
->
ws
,
snap
);
ERRNOMEM
(
ctx
,
"allocating hash result in hmac.hmac()"
);
return
NULL
;
}
b
->
len
=
digestsz
;
b
->
free
=
NULL
;
uint8_t
inner_digest
[
digestsz
];
memcpy
(
&
inner_ctx
,
&
h
->
inner_ctx
,
sizeof
(
hash_ctx
));
...
...
@@ -460,6 +467,8 @@ vmod_hmac__fini(struct vmod_blobdigest_hmac **hmacp)
hmac
=
*
hmacp
;
*
hmacp
=
NULL
;
CHECK_OBJ_NOTNULL
(
hmac
,
VMOD_BLOBDIGEST_HMAC_MAGIC
);
if
(
hmac
->
vcl_name
!=
NULL
)
free
(
hmac
->
vcl_name
);
FREE_OBJ
(
hmac
);
}
...
...
@@ -470,7 +479,6 @@ vmod_hash(VRT_CTX, VCL_ENUM hashs, VCL_BLOB msg)
{
enum
algorithm
hash
=
parse_algorithm
(
hashs
);
struct
vmod_priv
*
b
;
char
*
snap
;
hash_ctx
hctx
[
1
];
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
...
...
@@ -481,19 +489,9 @@ vmod_hash(VRT_CTX, VCL_ENUM hashs, VCL_BLOB msg)
if
(
msg
==
NULL
)
return
NULL
;
CHECK_OBJ_NOTNULL
(
ctx
->
ws
,
WS_MAGIC
);
snap
=
WS_Snapshot
(
ctx
->
ws
);
if
((
b
=
WS_Alloc
(
ctx
->
ws
,
sizeof
(
struct
vmod_priv
)))
==
NULL
)
{
ERRNOMEM
(
ctx
,
"allocating blob in hash()"
);
return
NULL
;
}
if
((
b
->
priv
=
WS_Alloc
(
ctx
->
ws
,
hashspec
[
hash
].
digestsz
))
==
NULL
)
{
WS_Reset
(
ctx
->
ws
,
snap
);
ERRNOMEM
(
ctx
,
"allocating hash result in hash()"
);
b
=
ws_alloc_digest
(
ctx
,
hashspec
[
hash
].
digestsz
,
"blobdigest"
,
"hash"
);
if
(
b
==
NULL
)
return
NULL
;
}
b
->
len
=
hashspec
[
hash
].
digestsz
;
b
->
free
=
NULL
;
digest
(
hash
,
hctx
,
msg
,
b
->
priv
);
return
b
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment