fxa-auth-server/crypto/hkdf.js

35 строки
708 B
JavaScript
Исходник Обычный вид История

2013-07-26 05:46:16 +04:00
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
2013-07-23 22:16:44 +04:00
var HKDF = require('hkdf')
var P = require('../promise')
2013-07-23 22:16:44 +04:00
2014-01-08 01:48:59 +04:00
const NAMESPACE = 'identity.mozilla.com/picl/v1/'
function KWE(name, email) {
return Buffer(NAMESPACE + name + ':' + email)
}
function KW(name) {
return Buffer(NAMESPACE + name)
2013-07-23 22:16:44 +04:00
}
function hkdf(km, info, salt, len) {
var d = P.defer()
var df = new HKDF('sha256', salt, km)
df.derive(
2014-01-08 01:48:59 +04:00
KW(info),
2013-07-23 22:16:44 +04:00
len,
function(key) {
d.resolve(key)
}
)
return d.promise
}
2014-01-08 01:48:59 +04:00
hkdf.KW = KW
hkdf.KWE = KWE
2013-07-23 22:16:44 +04:00
module.exports = hkdf