bigint-crypto-utils/test/prime.js

34 lines
1.2 KiB
JavaScript
Raw Normal View History

2019-04-19 07:42:28 +00:00
'use strict';
// For the browser test builder to work you MUST import the module in a variable that
2019-04-19 07:42:28 +00:00
// 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
];
describe('prime', function () {
2019-04-19 07:42:28 +00:00
for (const bitLength of bitLengths) {
describe(`prime(${bitLength})`, function () {
2019-04-19 07:42:28 +00:00
it(`should return a random ${bitLength}-bits probable prime`, async function () {
const prime = await bigintCryptoUtils.prime(bitLength);
const primeBitLength = bigintCryptoUtils.bitLength(prime);
chai.expect(primeBitLength).to.equal(bitLength);
2019-04-19 07:42:28 +00:00
});
});
}
2019-10-09 12:56:11 +00:00
describe('Testing sync (NOT-RECOMMENDED) version: primeSync()', function() {
2019-10-09 12:17:03 +00:00
it('should return a random 1024-bits probable prime', function () {
2019-10-09 12:56:11 +00:00
const prime = bigintCryptoUtils.primeSync(1024, 16);
2019-10-09 12:17:03 +00:00
const primeBitLength = bigintCryptoUtils.bitLength(prime);
chai.expect(primeBitLength).to.equal(1024);
});
});
2019-04-19 07:42:28 +00:00
});