-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
79bcc3f
commit 43b2bad
Showing
3 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
struct HMAC_CTX{CTX<:SHA_CTX} | ||
context::CTX | ||
outer::Vector{UInt8} | ||
|
||
function HMAC_CTX(ctx::CTX, key::Vector{UInt8}, blocksize::Integer=blocklen(CTX)) where CTX | ||
if length(key) > blocksize | ||
_ctx = CTX() | ||
update!(_ctx, key) | ||
key = digest!(_ctx) | ||
end | ||
|
||
pad = blocksize - length(key) | ||
|
||
if pad > 0 | ||
key = [key; fill(0x00, pad)] | ||
end | ||
|
||
update!(ctx, key .⊻ 0x36) | ||
new{CTX}(ctx, key .⊻ 0x5c) | ||
end | ||
end | ||
|
||
function update!(ctx::HMAC_CTX, data) | ||
update!(ctx.context, data) | ||
end | ||
|
||
function digest!(ctx::HMAC_CTX{CTX}) where CTX | ||
digest = digest!(ctx.context) | ||
_ctx = CTX() | ||
update!(_ctx, ctx.outer) | ||
update!(_ctx, digest) | ||
digest!(_ctx) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters