summaryrefslogtreecommitdiff
path: root/lib/internal/crypto
diff options
context:
space:
mode:
authorTobias Nießen <tniessen@tnie.de>2019-03-10 00:51:56 +0100
committerTobias Nießen <tniessen@tnie.de>2019-03-18 21:59:47 +0100
commit3a9592496cbb2b4667a72f53126ec626da104f53 (patch)
tree1f127ca630c40394cbc172b69a2464366a1cda79 /lib/internal/crypto
parent1a6fb71f71faf37e0b213cfc69021a5a27faea1f (diff)
downloadandroid-node-v8-3a9592496cbb2b4667a72f53126ec626da104f53.tar.gz
android-node-v8-3a9592496cbb2b4667a72f53126ec626da104f53.tar.bz2
android-node-v8-3a9592496cbb2b4667a72f53126ec626da104f53.zip
crypto: add support for EdDSA key pair generation
PR-URL: https://github.com/nodejs/node/pull/26554 Refs: https://github.com/nodejs/node/pull/26319 Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Diffstat (limited to 'lib/internal/crypto')
-rw-r--r--lib/internal/crypto/keygen.js51
1 files changed, 37 insertions, 14 deletions
diff --git a/lib/internal/crypto/keygen.js b/lib/internal/crypto/keygen.js
index 21dbf5ff8a..efa6c6c31b 100644
--- a/lib/internal/crypto/keygen.js
+++ b/lib/internal/crypto/keygen.js
@@ -5,6 +5,9 @@ const {
generateKeyPairRSA,
generateKeyPairDSA,
generateKeyPairEC,
+ generateKeyPairEdDSA,
+ EVP_PKEY_ED25519,
+ EVP_PKEY_ED448,
OPENSSL_EC_NAMED_CURVE,
OPENSSL_EC_EXPLICIT_CURVE
} = internalBinding('crypto');
@@ -119,18 +122,25 @@ function parseKeyEncoding(keyType, options) {
function check(type, options, callback) {
validateString(type, 'type');
- if (options == null || typeof options !== 'object')
- throw new ERR_INVALID_ARG_TYPE('options', 'object', options);
// These will be set after parsing the type and type-specific options to make
// the order a bit more intuitive.
let cipher, passphrase, publicType, publicFormat, privateType, privateFormat;
+ if (options !== undefined && typeof options !== 'object')
+ throw new ERR_INVALID_ARG_TYPE('options', 'object', options);
+
+ function needOptions() {
+ if (options == null)
+ throw new ERR_INVALID_ARG_TYPE('options', 'object', options);
+ return options;
+ }
+
let impl;
switch (type) {
case 'rsa':
{
- const { modulusLength } = options;
+ const { modulusLength } = needOptions();
if (!isUint32(modulusLength))
throw new ERR_INVALID_OPT_VALUE('modulusLength', modulusLength);
@@ -149,7 +159,7 @@ function check(type, options, callback) {
break;
case 'dsa':
{
- const { modulusLength } = options;
+ const { modulusLength } = needOptions();
if (!isUint32(modulusLength))
throw new ERR_INVALID_OPT_VALUE('modulusLength', modulusLength);
@@ -168,7 +178,7 @@ function check(type, options, callback) {
break;
case 'ec':
{
- const { namedCurve } = options;
+ const { namedCurve } = needOptions();
if (typeof namedCurve !== 'string')
throw new ERR_INVALID_OPT_VALUE('namedCurve', namedCurve);
let { paramEncoding } = options;
@@ -185,19 +195,32 @@ function check(type, options, callback) {
cipher, passphrase, wrap);
}
break;
+ case 'ed25519':
+ case 'ed448':
+ {
+ const id = type === 'ed25519' ? EVP_PKEY_ED25519 : EVP_PKEY_ED448;
+ impl = (wrap) => generateKeyPairEdDSA(id,
+ publicFormat, publicType,
+ privateFormat, privateType,
+ cipher, passphrase, wrap);
+ }
+ break;
default:
throw new ERR_INVALID_ARG_VALUE('type', type,
- "must be one of 'rsa', 'dsa', 'ec'");
+ "must be one of 'rsa', 'dsa', 'ec', " +
+ "'ed25519', 'ed448'");
}
- ({
- cipher,
- passphrase,
- publicType,
- publicFormat,
- privateType,
- privateFormat
- } = parseKeyEncoding(type, options));
+ if (options) {
+ ({
+ cipher,
+ passphrase,
+ publicType,
+ publicFormat,
+ privateType,
+ privateFormat
+ } = parseKeyEncoding(type, options));
+ }
return impl;
}