tools: Allow ndnsec-key-gen to generate ECDSA keys
Change-Id: I10bd91b1c13e180d4e6d6974431795e2e4e42fbd
Refs: #2248
diff --git a/docs/manpages/ndnsec-key-gen.rst b/docs/manpages/ndnsec-key-gen.rst
index 21bf3c4..d340128 100644
--- a/docs/manpages/ndnsec-key-gen.rst
+++ b/docs/manpages/ndnsec-key-gen.rst
@@ -1,19 +1,19 @@
ndnsec-key-gen
==============
-``ndnsec-key-gen`` is tool to generate a pair of RSA key.
+``ndnsec-key-gen`` is tool to generate a pair of key.
Usage
-----
::
- $ ndnsec-key-gen [-h] [-n] [-d] identity
+ $ ndnsec-key-gen [-h] [-n] [-d] [-t keyType] identity
Description
-----------
-``ndnsec-key-gen`` creates a RSA key pair for the specified ``identity`` and sets the key as the
+``ndnsec-key-gen`` creates a key pair for the specified ``identity`` and sets the key as the
identity's default key. ``ndnsec-key-gen`` will also create a signing request for the generated key.
The signing request will be written to standard output in base64 encoding.
@@ -28,6 +28,9 @@
``-d``
Generate Data-Signing-Key (DSK) instead of the default Key-Signing-Key (KSK).
+``-t keyType``
+ Specify the key type. ``r`` (default) for RSA key. ``e`` for ECDSA key.
+
Examples
--------
diff --git a/tools/ndnsec-key-gen.hpp b/tools/ndnsec-key-gen.hpp
index f68414f..efc63f0 100644
--- a/tools/ndnsec-key-gen.hpp
+++ b/tools/ndnsec-key-gen.hpp
@@ -35,7 +35,6 @@
std::string identityName;
bool isDefault = true;
char keyType = 'r';
- int keySize = 2048;
std::string outputFilename;
po::options_description description("General Usage\n"
@@ -49,8 +48,8 @@
"optional, if not specified, the target identity will be set as "
"the default identity of the system")
("dsk,d", "generate Data-Signing-Key (DSK) instead of the default Key-Signing-Key (KSK)")
- // ("type,t", po::value<char>(&keyType)->default_value('r'),
- // "optional, key type, r for RSA key (default)")
+ ("type,t", po::value<char>(&keyType)->default_value('r'),
+ "optional, key type, r for RSA key (default), e for ECDSA key")
// ("size,s", po::value<int>(&keySize)->default_value(2048),
// "optional, key size, 2048 (default)")
;
@@ -92,7 +91,11 @@
try {
switch (keyType) {
case 'r':
- keyName = keyChain.generateRsaKeyPair(Name(identityName), isKsk, keySize);
+ keyName = keyChain.generateRsaKeyPair(Name(identityName), isKsk, RsaKeyParams().getKeySize());
+ break;
+ case 'e':
+ keyName = keyChain.generateEcdsaKeyPair(Name(identityName), isKsk,
+ EcdsaKeyParams().getKeySize());
break;
default:
std::cerr << "Unrecongized key type" << "\n";
@@ -120,4 +123,4 @@
return 0;
}
-#endif //NDNSEC_KEY_GEN_HPP
+#endif // NDNSEC_KEY_GEN_HPP