Skip to content

Instantly share code, notes, and snippets.

@schirrmacher
Last active February 5, 2020 12:42
Show Gist options
  • Save schirrmacher/bccd0155a4e4d1e9fc25acd871801035 to your computer and use it in GitHub Desktop.
Save schirrmacher/bccd0155a4e4d1e9fc25acd871801035 to your computer and use it in GitHub Desktop.
The WAHKDF class is used to derive keys, salts and nonces for initializing SRTP streams.
const crypto = require("crypto");
// master secret
const keyMaterial = new Buffer(
"09a38e76fe90e4f126ed66d05a6783bad48776b61daaf7c939c005ea2d8ccdf6",
"hex"
);
// JID param: [email protected]
const info = "3439313539303537373136323040732e77686174736170702e6e6574";
const salt = new Buffer(
"0000000000000000000000000000000000000000000000000000000000000000",
"hex"
);
const initialKey = crypto.createHmac("sha256", salt)
.update(keyMaterial)
.digest();
const temp1 = crypto.createHmac("sha256", initialKey)
.update(new Buffer(info + "01", "hex"))
.digest();
const temp2 = new Buffer(temp1.toString("hex") + info + "02", "hex");
const temp3 = crypto.createHmac("sha256", initialKey)
.update(temp2)
.digest();
const result = Buffer.concat([temp1, temp3.slice(0, 14)]);
console.log(result.toString("hex"));
// 4633c47f94d5ed5993a6dba8514d5fb85092ba904256f8d34d56e72e665bcd4c5b6c418bdb811e7f84a70c83f401
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment