MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / PRF

Function PRF

modules/crypt/ssl/ssl_prf.js:63–79  ·  view source on GitHub ↗
(session, secret, label, seed, n, hash)

Source from the content-addressed store, hash-verified

61}
62
63function PRF(session, secret, label, seed, n, hash)
64{
65 let result;
66 label = ArrayBuffer.fromString(label).concat(seed);
67 if (session.protocolVersion <= 0x302)
68 result = Bin.xor(
69 p_hash(new Crypt.Digest("MD5"), secret.slice(0, iceil(secret.byteLength, 2)), label, n),
70 p_hash(new Crypt.Digest("SHA1"), secret.slice(Math.idiv(secret.byteLength, 2)), label, n)
71 );
72 else {
73 if (!hash)
74 hash = session.chosenCipher.hashAlgorithm == SHA384 ? "SHA384" : "SHA256";
75 result = p_hash(new Crypt.Digest(hash), secret, label, n);
76 }
77 result.buffer.resize(n); // p_hash > getChunk returns resizable buffer
78 return result;
79}
80
81export default PRF;

Callers 3

SetupCipherFunction · 0.85
generateMasterSecretFunction · 0.85
calculateVerifyDataFunction · 0.85

Calls 7

p_hashFunction · 0.85
iceilFunction · 0.85
fromStringMethod · 0.80
idivMethod · 0.80
concatMethod · 0.65
xorMethod · 0.65
sliceMethod · 0.65

Tested by

no test coverage detected