MCPcopy
hub / github.com/IvanMathy/Boop / rstr_hmac

Function rstr_hmac

Boop/Boop/scripts/lib/hashes.js:527–546  ·  view source on GitHub ↗

* Calculate the HMAC-MD5, of a key and some data (raw strings)

(key, data)

Source from the content-addressed store, hash-verified

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.

Callers 1

hashes.jsFile · 0.85

Calls 7

utf8EncodeFunction · 0.85
rstr2binlFunction · 0.85
binlFunction · 0.85
binl2rstrFunction · 0.85
rstr2binbFunction · 0.85
binbFunction · 0.85
binb2rstrFunction · 0.85

Tested by

no test coverage detected