2019-04-19 07:42:28 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
// For the browser test builder to work you MUST import them module in a variable that
|
|
|
|
// is the camelised version of the package name.
|
2019-04-19 10:04:06 +00:00
|
|
|
const bigintCryptoUtils = require('../dist/bigint-crypto-utils-latest.node');
|
2019-04-19 07:42:28 +00:00
|
|
|
const chai = require('chai');
|
|
|
|
|
|
|
|
const bitLengths = [
|
|
|
|
1024,
|
|
|
|
2048,
|
2019-04-19 10:04:06 +00:00
|
|
|
3072,
|
|
|
|
4096
|
2019-04-19 07:42:28 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
describe('Testing generation of prime numbers', function () {
|
|
|
|
for (const bitLength of bitLengths) {
|
|
|
|
describe(`Executing prime(${bitLength})`, function () {
|
|
|
|
it(`should return a random ${bitLength}-bits probable prime`, async function () {
|
2019-04-19 10:04:06 +00:00
|
|
|
let prime = await bigintCryptoUtils.prime(bitLength);
|
2019-04-19 07:42:28 +00:00
|
|
|
let bits = 1;
|
|
|
|
do {
|
|
|
|
bits++;
|
|
|
|
} while ((prime >>= BigInt(1)) > BigInt(1));
|
|
|
|
chai.expect(bits).to.equal(bitLength);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|