function p_hash(hash, secret, seed, sz) { var hmac = new Crypt.HMAC(hash, secret); var niter = iceil(sz, hash.outputSize); var A = hmac.process(seed); // start from A(1) = hmac(seed) var p = new SSLStream(); while (--niter >= 0) { var c = hmac.process(A, seed); p.writeChunk(c); if (niter > 0) A = hmac.process(A); } return p.getChunk(); }
packetize(session, type, fragment) { session.traceProtocol(this); // unsupported -- just pass through return recordProtocol.tlsCipherText.packetize(session, type, fragment); }, }, tlsCipherText: { name: "tlsCipherText", calculateMac(hmac, seqNum, type, version, content) { hmac.reset(); var c = seqNum.toChunk(); var tmps = new SSLStream(); for (var i = 0, len = 8 - c.byteLength; i < len; i++) tmps.writeChar(0); tmps.writeChunk(c); tmps.writeChar(type); tmps.writeChar(version.major); tmps.writeChar(version.minor); tmps.writeChars(content.byteLength, 2); hmac.update(tmps.getChunk()); hmac.update(content); return hmac.close(); }, unpacketize(session, s) { session.traceProtocol(this); var type = s.readChar(); var version = {major: s.readChar(), minor: s.readChar()}; var fragmentLen = s.readChars(2); var fragment = s.readChunk(fragmentLen); var cipher = session.connectionEnd ? session.serverCipher : session.clientCipher;