Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9136503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:57:40+00:00 2026-06-17T08:57:40+00:00

I need to write a HMAC-MD5 algorithm in pure Lua.. I got this algorithm

  • 0

I need to write a HMAC-MD5 algorithm in pure Lua..

I got this algorithm from Wikipedia

function hmac (key, message)
    if (length(key) > blocksize) then
        key = hash(key) // keys longer than blocksize are shortened
    end if
    if (length(key) < blocksize) then
        key = key ∥ [0x00 * (blocksize - length(key))] // keys shorter than blocksize are zero-padded ('∥' is concatenation) 
    end if

    o_key_pad = [0x5c * blocksize] ⊕ key // Where blocksize is that of the underlying hash function
    i_key_pad = [0x36 * blocksize] ⊕ key // Where ⊕ is exclusive or (XOR)

    return hash(o_key_pad ∥ hash(i_key_pad ∥ message)) // Where '∥' is concatenation
end function

and I have the md5 code from here. The md5 calculation function works correctly..

Implementing the algorithm in lua, so far I have the following code

local function hmac_md5(key,msg)
    local blocksize = 64

    if string.len(key) > blocksize then 
        key = calculateMD5(key)
    end 

    while string.len(key)<blocksize do 
        key = key .. "0"
    end 

    -- local o_key_pad = bit_xor((0x5c * blocksize),key) 
    -- local i_key_pad = bit_xor((0x36 * blocksize),key)

    return calculateMD5(o_key_pad..calculateMD5(i_key_pad..message))
end 

--calculateMD5 is the md5.Calc function in the Stackoverflow link specifed

I am stuck in the part where o_key_pad and i_key_pad are calculated.. do I just XOR the 2 values? The python implementation in the wikipedia link had some weird calculations..
Please help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:57:41+00:00Added an answer on June 17, 2026 at 8:57 am

    Yes, “⊕” is the symbol for “exclusive or”.

    • Remember: once you compute the final hash, DO NOT use an ordinary string comparison to check if a hash is correct. This WILL allow attackers to sign arbitrary messages.

    • Note that 0x5c * blocksize is probably not what you are looking for, since that multiplies 0x5c by blocksize. You want to create an array of length blocksize containing 0x5c in each position.

    • Note that you must pad with zero bytes, not the character "0". So key = key .. "0" is wrong. It should be key = key .. "\0", or however you create NUL bytes in Lua.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need to write a java program from pseudo code, I've got a bit of
I need to write a script in Matlab, which will read some data from
I need to write objects, sent to me from another process, to several files
I'm using Delphi 2007. I need write a FormatDateTime function that always return 01/01/
I need to write a extended version of the StringUtils.commaDelimitedListToStringArray function which gets an
Need to write a function that will convert a string to a double without
Need to write batch script which copies file from FTP to local drive I'm
I need to write a regular expression to remove a large number from the
I need to write a a query that gets a set of information from
I need to write a method like this: -(void)doStuff:(int)options; Based in the a typedef

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.