While generating One Time Password, i used hmac-md5 algorithm(with respect to RFC 2104) and the hmac result is 128 bits. When hmac-SHA1 algorithm is used, the result will be 160 bits. I need to apply padding to my hmac-md5 result to make 20 byte. Which values should i use for padding?
Asked
Active
Viewed 332 times
0
-
4This question appears to be off-topic because it is about cryptographic practices – Thomas M. DuBuisson Jan 17 '14 at 12:49
-
I tagged cryptography. What should i do to relate with topic? – Emel Uras Jan 17 '14 at 14:16
-
3SO is for programming quesetions (including crypto programs) but not for crypto best practices. Perhaps crypto.stackexchange.com? – Thomas M. DuBuisson Jan 17 '14 at 14:34
-
@ThomasM.DuBuisson Yes, that's the perfect place to explain that this is not an OTP :) – Maarten Bodewes Jan 19 '14 at 00:47
1 Answers
1
I need to apply padding to my hmac-md5 result to make 20 byte. Which values should i use for padding?
Apply another iteration of the hash on the existing output. Then, use the leftmost l-bits needed. This is similar to moder KDFs when stretching is needed.
Visually, it might look like:
[ hash = HMAC(message) ][ HMAC(hash) ]

jww
- 97,681
- 90
- 411
- 885