Skip to content

Commit

Permalink
test: use smaller keys for a faster keygen test
Browse files Browse the repository at this point in the history
On my machine, this brings test execution time down from about 2
seconds to 0.2 seconds.

PR-URL: #23430
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
sam-github authored and MylesBorins committed Oct 30, 2018
1 parent e8ca330 commit f82611a
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions test/parallel/test-crypto-keygen.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function convertDERToPEM(label, der) {
// with a relatively small key.
const ret = generateKeyPairSync('rsa', {
publicExponent: 0x10001,
modulusLength: 1024,
modulusLength: 512,
publicKeyEncoding: {
type: 'pkcs1',
format: 'pem'
Expand All @@ -103,10 +103,10 @@ function convertDERToPEM(label, der) {

assert.strictEqual(typeof publicKey, 'string');
assert(pkcs1PubExp.test(publicKey));
assertApproximateSize(publicKey, 272);
assertApproximateSize(publicKey, 162);
assert.strictEqual(typeof privateKey, 'string');
assert(pkcs8Exp.test(privateKey));
assertApproximateSize(privateKey, 912);
assertApproximateSize(privateKey, 512);

testEncryptDecrypt(publicKey, privateKey);
testSignVerify(publicKey, privateKey);
Expand All @@ -116,7 +116,7 @@ function convertDERToPEM(label, der) {
// Test async RSA key generation.
generateKeyPair('rsa', {
publicExponent: 0x10001,
modulusLength: 4096,
modulusLength: 512,
publicKeyEncoding: {
type: 'pkcs1',
format: 'der'
Expand All @@ -132,11 +132,11 @@ function convertDERToPEM(label, der) {
// will still need to convert it to PEM for testing.
assert(Buffer.isBuffer(publicKeyDER));
const publicKey = convertDERToPEM('RSA PUBLIC KEY', publicKeyDER);
assertApproximateSize(publicKey, 720);
assertApproximateSize(publicKey, 180);

assert.strictEqual(typeof privateKey, 'string');
assert(pkcs1PrivExp.test(privateKey));
assertApproximateSize(privateKey, 3272);
assertApproximateSize(privateKey, 512);

testEncryptDecrypt(publicKey, privateKey);
testSignVerify(publicKey, privateKey);
Expand All @@ -145,7 +145,7 @@ function convertDERToPEM(label, der) {
// Now do the same with an encrypted private key.
generateKeyPair('rsa', {
publicExponent: 0x10001,
modulusLength: 4096,
modulusLength: 512,
publicKeyEncoding: {
type: 'pkcs1',
format: 'der'
Expand All @@ -163,7 +163,7 @@ function convertDERToPEM(label, der) {
// will still need to convert it to PEM for testing.
assert(Buffer.isBuffer(publicKeyDER));
const publicKey = convertDERToPEM('RSA PUBLIC KEY', publicKeyDER);
assertApproximateSize(publicKey, 720);
assertApproximateSize(publicKey, 180);

assert.strictEqual(typeof privateKey, 'string');
assert(pkcs1EncExp('AES-256-CBC').test(privateKey));
Expand All @@ -182,7 +182,7 @@ function convertDERToPEM(label, der) {
{
// Test async DSA key generation.
generateKeyPair('dsa', {
modulusLength: 2048,
modulusLength: 256,
divisorLength: 256,
publicKeyEncoding: {
type: 'spki',
Expand All @@ -203,8 +203,8 @@ function convertDERToPEM(label, der) {
assert(Buffer.isBuffer(privateKeyDER));
const privateKey = convertDERToPEM('ENCRYPTED PRIVATE KEY', privateKeyDER);

assertApproximateSize(publicKey, 1194);
assertApproximateSize(privateKey, 1054);
assertApproximateSize(publicKey, 440);
assertApproximateSize(privateKey, 512);

// Since the private key is encrypted, signing shouldn't work anymore.
assert.throws(() => {
Expand Down Expand Up @@ -279,7 +279,7 @@ function convertDERToPEM(label, der) {
// Test async elliptic curve key generation, e.g. for ECDSA, with an encrypted
// private key.
generateKeyPair('ec', {
namedCurve: 'P-256',
namedCurve: 'P-192',
paramEncoding: 'named',
publicKeyEncoding: {
type: 'spki',
Expand Down Expand Up @@ -315,7 +315,7 @@ function convertDERToPEM(label, der) {
// Test the util.promisified API with async RSA key generation.
promisify(generateKeyPair)('rsa', {
publicExponent: 0x10001,
modulusLength: 3072,
modulusLength: 512,
publicKeyEncoding: {
type: 'pkcs1',
format: 'pem'
Expand All @@ -328,15 +328,15 @@ function convertDERToPEM(label, der) {
const { publicKey, privateKey } = keys;
assert.strictEqual(typeof publicKey, 'string');
assert(pkcs1PubExp.test(publicKey));
assertApproximateSize(publicKey, 600);
assertApproximateSize(publicKey, 180);

assert.strictEqual(typeof privateKey, 'string');
assert(pkcs1PrivExp.test(privateKey));
assertApproximateSize(privateKey, 2455);
assertApproximateSize(privateKey, 512);

testEncryptDecrypt(publicKey, privateKey);
testSignVerify(publicKey, privateKey);
})).catch(common.mustNotCall());
}));
}

{
Expand Down Expand Up @@ -545,7 +545,7 @@ function convertDERToPEM(label, der) {
// Test invalid callbacks.
for (const cb of [undefined, null, 0, {}]) {
common.expectsError(() => generateKeyPair('rsa', {
modulusLength: 4096,
modulusLength: 512,
publicKeyEncoding: { type: 'pkcs1', format: 'pem' },
privateKeyEncoding: { type: 'pkcs1', format: 'pem' }
}, cb), {
Expand Down Expand Up @@ -627,7 +627,7 @@ function convertDERToPEM(label, der) {

// It should recognize both NIST and standard curve names.
generateKeyPair('ec', {
namedCurve: 'P-256',
namedCurve: 'P-192',
publicKeyEncoding: { type: 'spki', format: 'pem' },
privateKeyEncoding: { type: 'pkcs8', format: 'pem' }
}, common.mustCall((err, publicKey, privateKey) => {
Expand Down

0 comments on commit f82611a

Please sign in to comment.