2
$\begingroup$

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: "127.0.0.1")
  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?

HMAC(key,input1|input2|input3)

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.

$\endgroup$
3
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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