(key)
| 44 | this.hashLen = bitlen >> 3; // in byte |
| 45 | }; |
| 46 | init(key) { |
| 47 | const h = this.h; |
| 48 | if (key.byteLength > h.blockSize) { |
| 49 | // truncate the key |
| 50 | h.reset(); |
| 51 | h.write(key); |
| 52 | key = new Uint8Array(h.close()); |
| 53 | } |
| 54 | else { |
| 55 | key = new Uint8Array(key); |
| 56 | } |
| 57 | |
| 58 | this.ipad = new Uint8Array(h.blockSize); |
| 59 | this.opad = new Uint8Array(h.blockSize); |
| 60 | |
| 61 | let l = key.length; |
| 62 | if (l > h.blockSize) |
| 63 | l = h.blockSize; |
| 64 | let i = 0; |
| 65 | for (; i < l; i++) { |
| 66 | this.ipad[i] = key[i] ^ 0x36; |
| 67 | this.opad[i] = key[i] ^ 0x5c; |
| 68 | } |
| 69 | this.ipad.fill(0x36, i); |
| 70 | this.opad.fill(0x5c, i); |
| 71 | h.reset(); |
| 72 | h.write(this.ipad.buffer); |
| 73 | }; |
| 74 | update() { |
| 75 | for (let i = 0; i < arguments.length; i++) |
| 76 | this.h.write(arguments[i]); |
no test coverage detected