PR #11705 switched Node away from using using OpenSSL's legacy EVP_Sign* and EVP_Verify* APIs. Instead, it computes a hash normally via EVP_Digest* and then uses EVP_PKEY_sign and EVP_PKEY_verify to verify the hash directly. This change corrects two problems: 1. The documentation still recommends the signature algorithm EVP_MD names of OpenSSL's legacy APIs. OpenSSL has since moved away from thosee, which is why ECDSA was strangely inconsistent. (This is why "ecdsa-with-SHA256" was missing.) 2. Node_SignFinal copied some code from EVP_SignFinal's internals. This is problematic for OpenSSL 1.1.0 and is missing a critical check that prevents pkey->pkey.ptr from being cast to the wrong type. To resolve this, remove the non-EVP_PKEY_sign codepath. This codepath is no longer necessary. PR #11705's verify half was already assuming all EVP_PKEYs supported EVP_PKEY_sign and EVP_PKEY_verify. Also, in the documentation, point users towards using hash function names which are more consisent. This avoids an ECDSA special-case and some strangeness around RSA-PSS ("RSA-SHA256" is the OpenSSL name of the sha256WithRSAEncryption OID which is not used for RSA-PSS). PR-URL: https://github.com/nodejs/node/pull/15024 Reviewed-By: Shigeki Ohtsu <ohtsu@ohtsu.org> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
51 lines
1.4 KiB
JavaScript
51 lines
1.4 KiB
JavaScript
'use strict';
|
|
// throughput benchmark in signing and verifying
|
|
var common = require('../common.js');
|
|
var crypto = require('crypto');
|
|
var fs = require('fs');
|
|
var path = require('path');
|
|
var fixtures_keydir = path.resolve(__dirname, '../../test/fixtures/keys/');
|
|
var keylen_list = ['1024', '2048'];
|
|
var RSA_PublicPem = {};
|
|
var RSA_PrivatePem = {};
|
|
|
|
keylen_list.forEach(function(key) {
|
|
RSA_PublicPem[key] = fs.readFileSync(fixtures_keydir +
|
|
'/rsa_public_' + key + '.pem');
|
|
RSA_PrivatePem[key] = fs.readFileSync(fixtures_keydir +
|
|
'/rsa_private_' + key + '.pem');
|
|
});
|
|
|
|
var bench = common.createBenchmark(main, {
|
|
writes: [500],
|
|
algo: ['SHA1', 'SHA224', 'SHA256', 'SHA384', 'SHA512'],
|
|
keylen: keylen_list,
|
|
len: [1024, 102400, 2 * 102400, 3 * 102400, 1024 * 1024]
|
|
});
|
|
|
|
function main(conf) {
|
|
var message = Buffer.alloc(conf.len, 'b');
|
|
bench.start();
|
|
StreamWrite(conf.algo, conf.keylen, message, conf.writes, conf.len);
|
|
}
|
|
|
|
function StreamWrite(algo, keylen, message, writes, len) {
|
|
var written = writes * len;
|
|
var bits = written * 8;
|
|
var kbits = bits / (1024);
|
|
|
|
var privateKey = RSA_PrivatePem[keylen];
|
|
var s = crypto.createSign(algo);
|
|
var v = crypto.createVerify(algo);
|
|
|
|
while (writes-- > 0) {
|
|
s.update(message);
|
|
v.update(message);
|
|
}
|
|
|
|
s.sign(privateKey, 'binary');
|
|
s.end();
|
|
v.end();
|
|
|
|
bench.end(kbits);
|
|
}
|