From e8e6ed49bf648b32bc811d9006db0df5776d752b Mon Sep 17 00:00:00 2001 From: Cosmin Apreutesei Date: Wed, 6 Nov 2019 16:34:48 +0200 Subject: [PATCH] unimportant --- md5.lua | 17 ++++++++++++++--- md5_hmac_test.lua | 6 ++++++ 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 md5_hmac_test.lua diff --git a/md5.lua b/md5.lua index 4e0999d..4fc3739 100644 --- a/md5.lua +++ b/md5.lua @@ -2,6 +2,12 @@ local ffi = require "ffi" local C = ffi.load'md5' +if not ... then + require'md5_test' + require'md5_hmac_test' + return +end + ffi.cdef[[ typedef struct { uint32_t lo, hi; @@ -33,11 +39,16 @@ local function sum(data, size) local d = digest(); d(data, size); return d() end -if not ... then require'md5_test' end - -return { +local md5 = { digest = digest, sum = sum, C = C, } +function md5.hmac(message, key) + local hmac = require'hmac' + md5.hmac = hmac.new(sum, 64) + return md5.hmac(message, key) +end + +return md5 diff --git a/md5_hmac_test.lua b/md5_hmac_test.lua new file mode 100644 index 0000000..375f9d3 --- /dev/null +++ b/md5_hmac_test.lua @@ -0,0 +1,6 @@ +local hmac = require'md5'.hmac +local glue = require'glue' +local unit = require'unit' + +test(glue.tohex(hmac('dude', 'key')), 'e9ecd7d5b2d9dc558d1c2cd173be7c38') +test(glue.tohex(hmac('what do ya want for nothing?', 'Jefe')), '750c783e6ab0b503eaa86e310a5db738')