Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it safe to use a 128 bits key in HMAC-SHA256?

Facebook app secret is a string of 32 characters (0-9, a-f) and thus it represents a 128 bits byte array. Facebook uses this as the key to generate signed request using HMAC-SHA256. Is this a correct usage? I thought HMAC-SHA256 should use 256 bits keys.

like image 628
Ethan Avatar asked Aug 31 '12 00:08

Ethan


2 Answers

HMAC takes the HASH(key) and uses it as the key if the length of the key is greater than the internal block size of the hash. Thus, a key larger than the internal block size of the hash provides no better security than one of equal size. Shorter keys are zero padded to be equal to the internal block size of the hash as per the HMAC specification.

It's impossible to use a 128-bit key with HMAC-SHA-256. If you mean 128 bits padded out to 512 bits with zeroes, then it's probably alright for short-term authentication. I'd recommend at least 256 bits and ideally you would want to use something equal to the internal block size of the underlying hash.

like image 135
Michael J. Gray Avatar answered Oct 01 '22 22:10

Michael J. Gray


The page says that the 256bit signature is derived from a payload (what facebook is signing) + your 128 bit salt.

So yes, it sounds like correct usage.

The secret 16 bytes (32 characters) isn't actually a key in the sense that it's used to encrypt and decrypt something. Rather, it's a bit of data (a salt) that is used to alter the result of the digital signature, by changing the input ever-so-slightly, so that only someone who knew the exact secret and the exact payload could have created the signature.

like image 45
antak Avatar answered Oct 01 '22 22:10

antak