本文整理匯總了TypeScript中sjcl.bitArray類的典型用法代碼示例。如果您正苦於以下問題:TypeScript bitArray類的具體用法?TypeScript bitArray怎麽用?TypeScript bitArray使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了bitArray類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: bitsToBytes
function bitsToBytes(arr) {
var out = [], bl = sjcl.bitArray.bitLength(arr), i, tmp;
for (i = 0; i < bl / 8; i++) {
if ((i & 3) === 0) {
tmp = arr[i / 4];
}
out.push(tmp >>> 24);
tmp <<= 8;
}
return out;
}
示例2: 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);
}
示例3: bytesToBits
/** Convert from an array of bytes to a bitArray. */
function bytesToBits(bytes) {
var out = [], i, tmp = 0;
for (i = 0; i < bytes.length; i++) {
tmp = tmp << 8 | bytes[i];
if ((i & 3) === 3) {
out.push(tmp);
tmp = 0;
}
}
if (i & 3) {
out.push(sjcl.bitArray.partial(8 * (i & 3), tmp));
}
return out;
}