本文整理汇总了TypeScript中sjcl.bitArray.clamp方法的典型用法代码示例。如果您正苦于以下问题:TypeScript bitArray.clamp方法的具体用法?TypeScript bitArray.clamp怎么用?TypeScript bitArray.clamp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sjcl.bitArray
的用法示例。
在下文中一共展示了bitArray.clamp方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: hkdf2
/** HKDF with the specified hash function.
* @param {bitArray} ikm The input keying material.
* @param {Number} keyBitLength The output key length, in bits.
* @param {String|bitArray} salt The salt for HKDF.
* @param {String|bitArray} info The info for HKDF.
* @param {Object} [Hash=sjcl.hash.sha256] The hash function to use.
* @return {bitArray} derived key.
*/
private static hkdf2(ikm, keyBitLength, salt, info, Hash) {
var hmac, key, i, hashLen, loops, curOut, ret = [];
// Hash = Hash || sjcl.hash.sha256;
if (typeof info === "string") {
info = sjcl.codec.utf8String.toBits(info);
} else if (!info) {
info = sjcl.codec.utf8String.toBits('');
}
if (typeof salt === "string") {
salt = sjcl.codec.utf8String.toBits(salt);
} else if (!salt) {
salt = [];
}
hmac = new sjcl.misc.hmac(salt, Hash);
//key = hmac.mac(ikm);
hmac.update(ikm);
key = hmac.digest();
// debug("prk: %j", new Buffer(bitsToBytes(key)).toString('hex'));
hashLen = sjcl.bitArray.bitLength(key);
loops = Math.ceil(keyBitLength / hashLen);
if (loops > 255) {
throw new sjcl.exception.invalid("key bit length is too large for hkdf");
}
curOut = [];
for (i = 1; i <= loops; i++) {
hmac = new sjcl.misc.hmac(key, Hash);
hmac.update(curOut);
hmac.update(info);
// debug('sjcl.bitArray.partial(8, i): %j', sjcl.bitArray.partial(8, i));
hmac.update(bytesToBits([i]));
// hmac.update([sjcl.bitArray.partial(8, i)]);
curOut = hmac.digest();
ret = sjcl.bitArray.concat(ret, curOut);
}
return sjcl.bitArray.clamp(ret, keyBitLength);
}