I'm using an HMAC as a way to generate a deterministic challenge token for an authentication system.

I've effectively got three string inputs plus a key:

  1. Client IP address (string, eg: "")
  2. Client nonce (string, eg: "2325363F")
  3. Linux epoch (string, eg: "594077C6")

My key is 256 bit (32 bytes) array.

How should I be performing the HMAC, is it really just a simple case of using string concatenation?


I'm fairly confident the above is just as secure as a hash tree or doing multiple HMAC operations, but would like to confirm my suspicions.


1 Answer 1


Yes, you can simply concatenate unless the encoding is not canonical, e.g. when the order isn't set or when the dynamic size of the fields make it possible that there is room for overlap between the fields.

It does seem that you've chosen string representations while it would be easier to use encoding to bytes directly. E.g. an IP 4 address usually consists of just 4 bytes. The seconds since the Linux epoch could be a number encoded into 32 bits. That way the chance of overlap is also zero because the field boundaries would be well defined.

Another issue is that you need to make the character encoding explicit., e.g. aways use US-ASCII or UTF-8.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.