* Calculate the HMAC-MD5, of a key and some data (raw strings)
(key, data)
| 525 | */ |
| 526 | |
| 527 | function rstr_hmac(key, data) { |
| 528 | var bkey, ipad, opad, hash, i; |
| 529 | |
| 530 | key = (utf8) ? utf8Encode(key) : key; |
| 531 | data = (utf8) ? utf8Encode(data) : data; |
| 532 | bkey = rstr2binl(key); |
| 533 | if (bkey.length > 16) { |
| 534 | bkey = binl(bkey, key.length * 8); |
| 535 | } |
| 536 | |
| 537 | ipad = Array(16); |
| 538 | opad = Array(16); |
| 539 | |
| 540 | for (i = 0; i < 16; i += 1) { |
| 541 | ipad[i] = bkey[i] ^ 0x36363636; |
| 542 | opad[i] = bkey[i] ^ 0x5C5C5C5C; |
| 543 | } |
| 544 | hash = binl(ipad.concat(rstr2binl(data)), 512 + data.length * 8); |
| 545 | return binl2rstr(binl(opad.concat(hash), 512 + 128)); |
| 546 | } |
| 547 | |
| 548 | /** |
| 549 | * Calculate the MD5 of an array of little-endian words, and a bit length. |