OPT_COMMON,
OPT_ENGINE, OPT_OUTFORM, OPT_OUT, OPT_PASS, OPT_PARAMFILE,
OPT_ALGORITHM, OPT_PKEYOPT, OPT_GENPARAM, OPT_TEXT, OPT_CIPHER,
- OPT_VERBOSE, OPT_QUIET, OPT_CONFIG,
+ OPT_VERBOSE, OPT_QUIET, OPT_CONFIG, OPT_OUTPUBKEY,
OPT_PROV_ENUM
} OPTION_CHOICE;
OPT_CONFIG_OPTION,
OPT_SECTION("Output"),
- {"out", OPT_OUT, '>', "Output file"},
+ {"out", OPT_OUT, '>', "Output (private key) file"},
+ {"outpubkey", OPT_OUTPUBKEY, '>', "Output public key file"},
{"outform", OPT_OUTFORM, 'F', "output format (DER or PEM)"},
{"pass", OPT_PASS, 's', "Output file pass phrase source"},
{"genparam", OPT_GENPARAM, '-', "Generate parameters, not key"},
- {"text", OPT_TEXT, '-', "Print the in text"},
+ {"text", OPT_TEXT, '-', "Print the private key in text"},
{"", OPT_CIPHER, '-', "Cipher to use to encrypt the key"},
OPT_PROV_OPTIONS,
int genpkey_main(int argc, char **argv)
{
CONF *conf = NULL;
- BIO *in = NULL, *out = NULL;
+ BIO *in = NULL, *out = NULL, *outpubkey = NULL;
ENGINE *e = NULL;
EVP_PKEY *pkey = NULL;
EVP_PKEY_CTX *ctx = NULL;
char *outfile = NULL, *passarg = NULL, *pass = NULL, *prog, *p;
+ char *outpubkeyfile = NULL;
const char *ciphername = NULL, *paramfile = NULL, *algname = NULL;
EVP_CIPHER *cipher = NULL;
OPTION_CHOICE o;
case OPT_OUT:
outfile = opt_arg();
break;
+ case OPT_OUTPUBKEY:
+ outpubkeyfile = opt_arg();
+ break;
case OPT_PASS:
passarg = opt_arg();
break;
if (out == NULL)
goto end;
+ if (outpubkeyfile != NULL) {
+ outpubkey = bio_open_owner(outpubkeyfile, outformat, private);
+ if (outpubkey == NULL)
+ goto end;
+ }
+
if (verbose)
EVP_PKEY_CTX_set_cb(ctx, progress_cb);
EVP_PKEY_CTX_set_app_data(ctx, bio_err);
} else if (outformat == FORMAT_PEM) {
assert(private);
rv = PEM_write_bio_PrivateKey(out, pkey, cipher, NULL, 0, NULL, pass);
+ if (rv > 0 && outpubkey != NULL)
+ rv = PEM_write_bio_PUBKEY(outpubkey, pkey);
} else if (outformat == FORMAT_ASN1) {
assert(private);
rv = i2d_PrivateKey_bio(out, pkey);
+ if (rv > 0 && outpubkey != NULL)
+ rv = i2d_PUBKEY_bio(outpubkey, pkey);
} else {
BIO_printf(bio_err, "Bad format specified for key\n");
goto end;
ret = 0;
if (rv <= 0) {
- BIO_puts(bio_err, "Error writing key\n");
+ BIO_puts(bio_err, "Error writing key(s)\n");
ret = 1;
}
EVP_PKEY_CTX_free(ctx);
EVP_CIPHER_free(cipher);
BIO_free_all(out);
+ BIO_free_all(outpubkey);
BIO_free(in);
release_engine(e);
OPENSSL_free(pass);
=head1 NAME
-openssl-genpkey - generate a private key
+openssl-genpkey - generate a private key or key pair
=head1 SYNOPSIS
B<openssl> B<genpkey>
[B<-help>]
[B<-out> I<filename>]
+[B<-outpubkey> I<filename>]
[B<-outform> B<DER>|B<PEM>]
[B<-verbose>]
[B<-quiet>]
=head1 DESCRIPTION
-This command generates a private key.
+This command generates a private key or key pair.
=head1 OPTIONS
=item B<-out> I<filename>
-Output the key to the specified file. If this argument is not specified then
-standard output is used.
+Output the private key to the specified file. If this argument is not
+specified then standard output is used.
+
+=item B<-outpubkey> I<filename>
+
+Output the public key to the specified file. If this argument is not
+specified then the public key is not output.
=item B<-outform> B<DER>|B<PEM>
Public key algorithm to use such as RSA, DSA, DH or DHX. If used this option must
precede any B<-pkeyopt> options. The options B<-paramfile> and B<-algorithm>
-are mutually exclusive. Engines may add algorithms in addition to the standard
-built-in ones.
+are mutually exclusive. Engines or providers may add algorithms in addition to
+the standard built-in ones.
Valid built-in algorithm names for private key generation are RSA, RSA-PSS, EC,
X25519, X448, ED25519 and ED448.