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 = [
|
2019-05-27 14:42:46 +00:00
|
|
|
256,
|
|
|
|
512,
|
2019-04-19 07:42:28 +00:00
|
|
|
1024,
|
|
|
|
2048,
|
2019-04-19 10:04:06 +00:00
|
|
|
3072,
|
|
|
|
4096
|
2019-04-19 07:42:28 +00:00
|
|
|
];
|
|
|
|
|
2019-05-04 16:08:30 +00:00
|
|
|
describe('prime', function () {
|
2019-04-19 07:42:28 +00:00
|
|
|
for (const bitLength of bitLengths) {
|
2019-05-04 16:08:30 +00:00
|
|
|
describe(`prime(${bitLength})`, function () {
|
2019-04-19 07:42:28 +00:00
|
|
|
it(`should return a random ${bitLength}-bits probable prime`, async function () {
|
2019-05-29 15:44:18 +00:00
|
|
|
const prime = await bigintCryptoUtils.prime(bitLength);
|
|
|
|
const primeBitLength = bigintCryptoUtils.bitLength(prime);
|
2019-05-04 16:08:30 +00:00
|
|
|
chai.expect(primeBitLength).to.equal(bitLength);
|
2019-04-19 07:42:28 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2019-10-09 12:17:03 +00:00
|
|
|
describe('Testing sync (NOT-RECOMMENDED) version of prime', function() {
|
|
|
|
it('should return a random 1024-bits probable prime', function () {
|
|
|
|
const prime = bigintCryptoUtils.prime(1024, 16, true);
|
|
|
|
const primeBitLength = bigintCryptoUtils.bitLength(prime);
|
|
|
|
chai.expect(primeBitLength).to.equal(1024);
|
|
|
|
});
|
|
|
|
});
|
2019-04-19 07:42:28 +00:00
|
|
|
});
|