[BACK]Return to genpkey.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / openssl

Diff for /src/usr.bin/openssl/genpkey.c between version 1.15 and 1.16

version 1.15, 2023/03/05 13:12:53 version 1.16, 2023/03/06 14:32:06
Line 76 
Line 76 
         int outformat;          int outformat;
         char *passarg;          char *passarg;
         int text;          int text;
 } genpkey_config;  } cfg;
   
 static int  static int
 genpkey_opt_algorithm(char *arg)  genpkey_opt_algorithm(char *arg)
 {  {
         if (!init_gen_str(bio_err, genpkey_config.ctx, arg,          if (!init_gen_str(bio_err, cfg.ctx, arg,
             genpkey_config.do_param))              cfg.do_param))
                 return (1);                  return (1);
   
         return (0);          return (0);
Line 96 
Line 96 
         if (*name++ != '-')          if (*name++ != '-')
                 return (1);                  return (1);
   
         if (genpkey_config.do_param == 1)          if (cfg.do_param == 1)
                 return (1);                  return (1);
   
         if (strcmp(name, "none") == 0) {          if (strcmp(name, "none") == 0) {
                 genpkey_config.cipher = NULL;                  cfg.cipher = NULL;
                 *argsused = 1;                  *argsused = 1;
                 return (0);                  return (0);
         }          }
   
         if ((genpkey_config.cipher = EVP_get_cipherbyname(name)) != NULL) {          if ((cfg.cipher = EVP_get_cipherbyname(name)) != NULL) {
                 *argsused = 1;                  *argsused = 1;
                 return (0);                  return (0);
         }          }
Line 116 
Line 116 
 static int  static int
 genpkey_opt_paramfile(char *arg)  genpkey_opt_paramfile(char *arg)
 {  {
         if (genpkey_config.do_param == 1)          if (cfg.do_param == 1)
                 return (1);                  return (1);
         if (!init_keygen_file(bio_err, genpkey_config.ctx, arg))          if (!init_keygen_file(bio_err, cfg.ctx, arg))
                 return (1);                  return (1);
   
         return (0);          return (0);
Line 127 
Line 127 
 static int  static int
 genpkey_opt_pkeyopt(char *arg)  genpkey_opt_pkeyopt(char *arg)
 {  {
         if (*genpkey_config.ctx == NULL) {          if (*cfg.ctx == NULL) {
                 BIO_puts(bio_err, "No keytype specified\n");                  BIO_puts(bio_err, "No keytype specified\n");
                 return (1);                  return (1);
         }          }
   
         if (pkey_ctrl_string(*genpkey_config.ctx, arg) <= 0) {          if (pkey_ctrl_string(*cfg.ctx, arg) <= 0) {
                 BIO_puts(bio_err, "parameter setting error\n");                  BIO_puts(bio_err, "parameter setting error\n");
                 ERR_print_errors(bio_err);                  ERR_print_errors(bio_err);
                 return (1);                  return (1);
Line 153 
Line 153 
                 .name = "genparam",                  .name = "genparam",
                 .desc = "Generate a set of parameters instead of a private key",                  .desc = "Generate a set of parameters instead of a private key",
                 .type = OPTION_FLAG,                  .type = OPTION_FLAG,
                 .opt.flag = &genpkey_config.do_param,                  .opt.flag = &cfg.do_param,
         },          },
         {          {
                 .name = "out",                  .name = "out",
                 .argname = "file",                  .argname = "file",
                 .desc = "Output file to write to (default stdout)",                  .desc = "Output file to write to (default stdout)",
                 .type = OPTION_ARG,                  .type = OPTION_ARG,
                 .opt.arg = &genpkey_config.outfile,                  .opt.arg = &cfg.outfile,
         },          },
         {          {
                 .name = "outform",                  .name = "outform",
                 .argname = "format",                  .argname = "format",
                 .desc = "Output format (DER or PEM)",                  .desc = "Output format (DER or PEM)",
                 .type = OPTION_ARG_FORMAT,                  .type = OPTION_ARG_FORMAT,
                 .opt.value = &genpkey_config.outformat,                  .opt.value = &cfg.outformat,
         },          },
         {          {
                 .name = "paramfile",                  .name = "paramfile",
Line 182 
Line 182 
                 .argname = "arg",                  .argname = "arg",
                 .desc = "Output file password source",                  .desc = "Output file password source",
                 .type = OPTION_ARG,                  .type = OPTION_ARG,
                 .opt.arg = &genpkey_config.passarg,                  .opt.arg = &cfg.passarg,
         },          },
         {          {
                 .name = "pkeyopt",                  .name = "pkeyopt",
Line 195 
Line 195 
                 .name = "text",                  .name = "text",
                 .desc = "Print the private/public key in human readable form",                  .desc = "Print the private/public key in human readable form",
                 .type = OPTION_FLAG,                  .type = OPTION_FLAG,
                 .opt.flag = &genpkey_config.text,                  .opt.flag = &cfg.text,
         },          },
         {          {
                 .name = NULL,                  .name = NULL,
Line 229 
Line 229 
                 exit(1);                  exit(1);
         }          }
   
         memset(&genpkey_config, 0, sizeof(genpkey_config));          memset(&cfg, 0, sizeof(cfg));
         genpkey_config.ctx = &ctx;          cfg.ctx = &ctx;
         genpkey_config.outformat = FORMAT_PEM;          cfg.outformat = FORMAT_PEM;
   
         if (options_parse(argc, argv, genpkey_options, NULL, NULL) != 0) {          if (options_parse(argc, argv, genpkey_options, NULL, NULL) != 0) {
                 genpkey_usage();                  genpkey_usage();
Line 243 
Line 243 
                 goto end;                  goto end;
         }          }
   
         if (!app_passwd(bio_err, genpkey_config.passarg, NULL, &pass, NULL)) {          if (!app_passwd(bio_err, cfg.passarg, NULL, &pass, NULL)) {
                 BIO_puts(bio_err, "Error getting password\n");                  BIO_puts(bio_err, "Error getting password\n");
                 goto end;                  goto end;
         }          }
         if (genpkey_config.outfile != NULL) {          if (cfg.outfile != NULL) {
                 if ((out = BIO_new_file(genpkey_config.outfile, "wb")) ==                  if ((out = BIO_new_file(cfg.outfile, "wb")) ==
                     NULL) {                      NULL) {
                         BIO_printf(bio_err, "Can't open output file %s\n",                          BIO_printf(bio_err, "Can't open output file %s\n",
                             genpkey_config.outfile);                              cfg.outfile);
                         goto end;                          goto end;
                 }                  }
         } else {          } else {
Line 261 
Line 261 
         EVP_PKEY_CTX_set_cb(ctx, genpkey_cb);          EVP_PKEY_CTX_set_cb(ctx, genpkey_cb);
         EVP_PKEY_CTX_set_app_data(ctx, bio_err);          EVP_PKEY_CTX_set_app_data(ctx, bio_err);
   
         if (genpkey_config.do_param) {          if (cfg.do_param) {
                 if (EVP_PKEY_paramgen(ctx, &pkey) <= 0) {                  if (EVP_PKEY_paramgen(ctx, &pkey) <= 0) {
                         BIO_puts(bio_err, "Error generating parameters\n");                          BIO_puts(bio_err, "Error generating parameters\n");
                         ERR_print_errors(bio_err);                          ERR_print_errors(bio_err);
Line 275 
Line 275 
                 }                  }
         }          }
   
         if (genpkey_config.do_param)          if (cfg.do_param)
                 rv = PEM_write_bio_Parameters(out, pkey);                  rv = PEM_write_bio_Parameters(out, pkey);
         else if (genpkey_config.outformat == FORMAT_PEM)          else if (cfg.outformat == FORMAT_PEM)
                 rv = PEM_write_bio_PrivateKey(out, pkey, genpkey_config.cipher,                  rv = PEM_write_bio_PrivateKey(out, pkey, cfg.cipher,
                     NULL, 0, NULL, pass);                      NULL, 0, NULL, pass);
         else if (genpkey_config.outformat == FORMAT_ASN1)          else if (cfg.outformat == FORMAT_ASN1)
                 rv = i2d_PrivateKey_bio(out, pkey);                  rv = i2d_PrivateKey_bio(out, pkey);
         else {          else {
                 BIO_printf(bio_err, "Bad format specified for key\n");                  BIO_printf(bio_err, "Bad format specified for key\n");
Line 291 
Line 291 
                 BIO_puts(bio_err, "Error writing key\n");                  BIO_puts(bio_err, "Error writing key\n");
                 ERR_print_errors(bio_err);                  ERR_print_errors(bio_err);
         }          }
         if (genpkey_config.text) {          if (cfg.text) {
                 if (genpkey_config.do_param)                  if (cfg.do_param)
                         rv = EVP_PKEY_print_params(out, pkey, 0, NULL);                          rv = EVP_PKEY_print_params(out, pkey, 0, NULL);
                 else                  else
                         rv = EVP_PKEY_print_private(out, pkey, 0, NULL);                          rv = EVP_PKEY_print_private(out, pkey, 0, NULL);

Legend:
Removed from v.1.15  
changed lines
  Added in v.1.16