build 2.5.1
This commit is contained in:
parent
5701881360
commit
4de924a186
|
@ -360,11 +360,14 @@ var bigintCryptoUtils = (function (exports) {
|
|||
throw new RangeError(`bitLength MUST be > 0 and it is ${bitLength}`);
|
||||
|
||||
const byteLength = Math.ceil(bitLength / 8);
|
||||
let rndBytes = randBytesSync(byteLength, false);
|
||||
const rndBytes = randBytesSync(byteLength, false);
|
||||
const bitLengthMod8 = bitLength % 8;
|
||||
if (bitLengthMod8) {
|
||||
// Fill with 0's the extra bits
|
||||
rndBytes[0] = rndBytes[0] & (2 ** (bitLength % 8) - 1);
|
||||
rndBytes[0] = rndBytes[0] & (2 ** bitLengthMod8 - 1);
|
||||
}
|
||||
if (forceLength) {
|
||||
let mask = (bitLength % 8) ? 2 ** ((bitLength % 8) - 1) : 128;
|
||||
const mask = bitLengthMod8 ? 2 ** (bitLengthMod8 - 1) : 128;
|
||||
rndBytes[0] = rndBytes[0] | mask;
|
||||
}
|
||||
return rndBytes;
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -357,11 +357,14 @@ function randBits(bitLength, forceLength = false) {
|
|||
throw new RangeError(`bitLength MUST be > 0 and it is ${bitLength}`);
|
||||
|
||||
const byteLength = Math.ceil(bitLength / 8);
|
||||
let rndBytes = randBytesSync(byteLength, false);
|
||||
const rndBytes = randBytesSync(byteLength, false);
|
||||
const bitLengthMod8 = bitLength % 8;
|
||||
if (bitLengthMod8) {
|
||||
// Fill with 0's the extra bits
|
||||
rndBytes[0] = rndBytes[0] & (2 ** (bitLength % 8) - 1);
|
||||
rndBytes[0] = rndBytes[0] & (2 ** bitLengthMod8 - 1);
|
||||
}
|
||||
if (forceLength) {
|
||||
let mask = (bitLength % 8) ? 2 ** ((bitLength % 8) - 1) : 128;
|
||||
const mask = bitLengthMod8 ? 2 ** (bitLengthMod8 - 1) : 128;
|
||||
rndBytes[0] = rndBytes[0] | mask;
|
||||
}
|
||||
return rndBytes;
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -376,11 +376,14 @@ function randBits(bitLength, forceLength = false) {
|
|||
throw new RangeError(`bitLength MUST be > 0 and it is ${bitLength}`);
|
||||
|
||||
const byteLength = Math.ceil(bitLength / 8);
|
||||
let rndBytes = randBytesSync(byteLength, false);
|
||||
const rndBytes = randBytesSync(byteLength, false);
|
||||
const bitLengthMod8 = bitLength % 8;
|
||||
if (bitLengthMod8) {
|
||||
// Fill with 0's the extra bits
|
||||
rndBytes[0] = rndBytes[0] & (2 ** (bitLength % 8) - 1);
|
||||
rndBytes[0] = rndBytes[0] & (2 ** bitLengthMod8 - 1);
|
||||
}
|
||||
if (forceLength) {
|
||||
let mask = (bitLength % 8) ? 2 ** ((bitLength % 8) - 1) : 128;
|
||||
const mask = bitLengthMod8 ? 2 ** (bitLengthMod8 - 1) : 128;
|
||||
rndBytes[0] = rndBytes[0] | mask;
|
||||
}
|
||||
return rndBytes;
|
||||
|
|
Loading…
Reference in New Issue