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

Diff for /src/usr.bin/openssl/dsa.c between version 1.17 and 1.18

version 1.17, 2022/11/11 17:07:38 version 1.18, 2023/03/06 14:32:06
Line 87 
Line 87 
         int pubout;          int pubout;
         int pvk_encr;          int pvk_encr;
         int text;          int text;
 } dsa_config;  } cfg;
   
 static int  static int
 dsa_opt_enc(int argc, char **argv, int *argsused)  dsa_opt_enc(int argc, char **argv, int *argsused)
Line 97 
Line 97 
         if (*name++ != '-')          if (*name++ != '-')
                 return (1);                  return (1);
   
         if ((dsa_config.enc = EVP_get_cipherbyname(name)) != NULL) {          if ((cfg.enc = EVP_get_cipherbyname(name)) != NULL) {
                 *argsused = 1;                  *argsused = 1;
                 return (0);                  return (0);
         }          }
Line 111 
Line 111 
                 .argname = "file",                  .argname = "file",
                 .desc = "Input file (default stdin)",                  .desc = "Input file (default stdin)",
                 .type = OPTION_ARG,                  .type = OPTION_ARG,
                 .opt.arg = &dsa_config.infile,                  .opt.arg = &cfg.infile,
         },          },
         {          {
                 .name = "inform",                  .name = "inform",
Line 119 
Line 119 
                 .desc = "Input format (PEM (default) or any other supported"                  .desc = "Input format (PEM (default) or any other supported"
                     " format)",                      " format)",
                 .type = OPTION_ARG_FORMAT,                  .type = OPTION_ARG_FORMAT,
                 .opt.value = &dsa_config.informat,                  .opt.value = &cfg.informat,
         },          },
         {          {
                 .name = "modulus",                  .name = "modulus",
                 .desc = "Print the DSA public value",                  .desc = "Print the DSA public value",
                 .type = OPTION_FLAG,                  .type = OPTION_FLAG,
                 .opt.flag = &dsa_config.modulus,                  .opt.flag = &cfg.modulus,
         },          },
         {          {
                 .name = "noout",                  .name = "noout",
                 .desc = "No output",                  .desc = "No output",
                 .type = OPTION_FLAG,                  .type = OPTION_FLAG,
                 .opt.flag = &dsa_config.noout,                  .opt.flag = &cfg.noout,
         },          },
         {          {
                 .name = "out",                  .name = "out",
                 .argname = "file",                  .argname = "file",
                 .desc = "Output file (default stdout)",                  .desc = "Output file (default stdout)",
                 .type = OPTION_ARG,                  .type = OPTION_ARG,
                 .opt.arg = &dsa_config.outfile,                  .opt.arg = &cfg.outfile,
         },          },
         {          {
                 .name = "outform",                  .name = "outform",
                 .argname = "format",                  .argname = "format",
                 .desc = "Output format (DER, MSBLOB, PEM (default) or PVK)",                  .desc = "Output format (DER, MSBLOB, PEM (default) or PVK)",
                 .type = OPTION_ARG_FORMAT,                  .type = OPTION_ARG_FORMAT,
                 .opt.value = &dsa_config.outformat,                  .opt.value = &cfg.outformat,
         },          },
         {          {
                 .name = "passin",                  .name = "passin",
                 .argname = "source",                  .argname = "source",
                 .desc = "Input file passphrase source",                  .desc = "Input file passphrase source",
                 .type = OPTION_ARG,                  .type = OPTION_ARG,
                 .opt.arg = &dsa_config.passargin,                  .opt.arg = &cfg.passargin,
         },          },
         {          {
                 .name = "passout",                  .name = "passout",
                 .argname = "source",                  .argname = "source",
                 .desc = "Output file passphrase source",                  .desc = "Output file passphrase source",
                 .type = OPTION_ARG,                  .type = OPTION_ARG,
                 .opt.arg = &dsa_config.passargout,                  .opt.arg = &cfg.passargout,
         },          },
         {          {
                 .name = "pubin",                  .name = "pubin",
                 .desc = "Read a public key from the input file instead of"                  .desc = "Read a public key from the input file instead of"
                     " private key",                      " private key",
                 .type = OPTION_FLAG,                  .type = OPTION_FLAG,
                 .opt.flag = &dsa_config.pubin,                  .opt.flag = &cfg.pubin,
         },          },
         {          {
                 .name = "pubout",                  .name = "pubout",
                 .desc = "Output a public key instead of private key",                  .desc = "Output a public key instead of private key",
                 .type = OPTION_FLAG,                  .type = OPTION_FLAG,
                 .opt.flag = &dsa_config.pubout,                  .opt.flag = &cfg.pubout,
         },          },
         {          {
                 .name = "pvk-none",                  .name = "pvk-none",
                 .desc = "PVK encryption level",                  .desc = "PVK encryption level",
                 .type = OPTION_VALUE,                  .type = OPTION_VALUE,
                 .value = 0,                  .value = 0,
                 .opt.value = &dsa_config.pvk_encr,                  .opt.value = &cfg.pvk_encr,
         },          },
         {          {
                 .name = "pvk-strong",                  .name = "pvk-strong",
                 .desc = "PVK encryption level (default)",                  .desc = "PVK encryption level (default)",
                 .type = OPTION_VALUE,                  .type = OPTION_VALUE,
                 .value = 2,                  .value = 2,
                 .opt.value = &dsa_config.pvk_encr,                  .opt.value = &cfg.pvk_encr,
         },          },
         {          {
                 .name = "pvk-weak",                  .name = "pvk-weak",
                 .desc = "PVK encryption level",                  .desc = "PVK encryption level",
                 .type = OPTION_VALUE,                  .type = OPTION_VALUE,
                 .value = 1,                  .value = 1,
                 .opt.value = &dsa_config.pvk_encr,                  .opt.value = &cfg.pvk_encr,
         },          },
         {          {
                 .name = "text",                  .name = "text",
                 .desc = "Print the key in text form",                  .desc = "Print the key in text form",
                 .type = OPTION_FLAG,                  .type = OPTION_FLAG,
                 .opt.flag = &dsa_config.text,                  .opt.flag = &cfg.text,
         },          },
         {          {
                 .name = NULL,                  .name = NULL,
Line 241 
Line 241 
                 exit(1);                  exit(1);
         }          }
   
         memset(&dsa_config, 0, sizeof(dsa_config));          memset(&cfg, 0, sizeof(cfg));
   
         dsa_config.pvk_encr = 2;          cfg.pvk_encr = 2;
         dsa_config.informat = FORMAT_PEM;          cfg.informat = FORMAT_PEM;
         dsa_config.outformat = FORMAT_PEM;          cfg.outformat = FORMAT_PEM;
   
         if (options_parse(argc, argv, dsa_options, NULL, NULL) != 0) {          if (options_parse(argc, argv, dsa_options, NULL, NULL) != 0) {
                 dsa_usage();                  dsa_usage();
                 goto end;                  goto end;
         }          }
   
         if (!app_passwd(bio_err, dsa_config.passargin, dsa_config.passargout,          if (!app_passwd(bio_err, cfg.passargin, cfg.passargout,
             &passin, &passout)) {              &passin, &passout)) {
                 BIO_printf(bio_err, "Error getting passwords\n");                  BIO_printf(bio_err, "Error getting passwords\n");
                 goto end;                  goto end;
Line 264 
Line 264 
                 ERR_print_errors(bio_err);                  ERR_print_errors(bio_err);
                 goto end;                  goto end;
         }          }
         if (dsa_config.infile == NULL)          if (cfg.infile == NULL)
                 BIO_set_fp(in, stdin, BIO_NOCLOSE);                  BIO_set_fp(in, stdin, BIO_NOCLOSE);
         else {          else {
                 if (BIO_read_filename(in, dsa_config.infile) <= 0) {                  if (BIO_read_filename(in, cfg.infile) <= 0) {
                         perror(dsa_config.infile);                          perror(cfg.infile);
                         goto end;                          goto end;
                 }                  }
         }          }
Line 278 
Line 278 
         {          {
                 EVP_PKEY *pkey;                  EVP_PKEY *pkey;
   
                 if (dsa_config.pubin)                  if (cfg.pubin)
                         pkey = load_pubkey(bio_err, dsa_config.infile,                          pkey = load_pubkey(bio_err, cfg.infile,
                             dsa_config.informat, 1, passin, "Public Key");                              cfg.informat, 1, passin, "Public Key");
                 else                  else
                         pkey = load_key(bio_err, dsa_config.infile,                          pkey = load_key(bio_err, cfg.infile,
                             dsa_config.informat, 1, passin, "Private Key");                              cfg.informat, 1, passin, "Private Key");
   
                 if (pkey) {                  if (pkey) {
                         dsa = EVP_PKEY_get1_DSA(pkey);                          dsa = EVP_PKEY_get1_DSA(pkey);
Line 295 
Line 295 
                 ERR_print_errors(bio_err);                  ERR_print_errors(bio_err);
                 goto end;                  goto end;
         }          }
         if (dsa_config.outfile == NULL) {          if (cfg.outfile == NULL) {
                 BIO_set_fp(out, stdout, BIO_NOCLOSE);                  BIO_set_fp(out, stdout, BIO_NOCLOSE);
         } else {          } else {
                 if (BIO_write_filename(out, dsa_config.outfile) <= 0) {                  if (BIO_write_filename(out, cfg.outfile) <= 0) {
                         perror(dsa_config.outfile);                          perror(cfg.outfile);
                         goto end;                          goto end;
                 }                  }
         }          }
   
         if (dsa_config.text) {          if (cfg.text) {
                 if (!DSA_print(out, dsa, 0)) {                  if (!DSA_print(out, dsa, 0)) {
                         perror(dsa_config.outfile);                          perror(cfg.outfile);
                         ERR_print_errors(bio_err);                          ERR_print_errors(bio_err);
                         goto end;                          goto end;
                 }                  }
         }          }
         if (dsa_config.modulus) {          if (cfg.modulus) {
                 fprintf(stdout, "Public Key=");                  fprintf(stdout, "Public Key=");
                 BN_print(out, DSA_get0_pub_key(dsa));                  BN_print(out, DSA_get0_pub_key(dsa));
                 fprintf(stdout, "\n");                  fprintf(stdout, "\n");
         }          }
         if (dsa_config.noout)          if (cfg.noout)
                 goto end;                  goto end;
         BIO_printf(bio_err, "writing DSA key\n");          BIO_printf(bio_err, "writing DSA key\n");
         if (dsa_config.outformat == FORMAT_ASN1) {          if (cfg.outformat == FORMAT_ASN1) {
                 if (dsa_config.pubin || dsa_config.pubout)                  if (cfg.pubin || cfg.pubout)
                         i = i2d_DSA_PUBKEY_bio(out, dsa);                          i = i2d_DSA_PUBKEY_bio(out, dsa);
                 else                  else
                         i = i2d_DSAPrivateKey_bio(out, dsa);                          i = i2d_DSAPrivateKey_bio(out, dsa);
         } else if (dsa_config.outformat == FORMAT_PEM) {          } else if (cfg.outformat == FORMAT_PEM) {
                 if (dsa_config.pubin || dsa_config.pubout)                  if (cfg.pubin || cfg.pubout)
                         i = PEM_write_bio_DSA_PUBKEY(out, dsa);                          i = PEM_write_bio_DSA_PUBKEY(out, dsa);
                 else                  else
                         i = PEM_write_bio_DSAPrivateKey(out, dsa, dsa_config.enc,                          i = PEM_write_bio_DSAPrivateKey(out, dsa, cfg.enc,
                             NULL, 0, NULL, passout);                              NULL, 0, NULL, passout);
 #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_RC4)  #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_RC4)
         } else if (dsa_config.outformat == FORMAT_MSBLOB ||          } else if (cfg.outformat == FORMAT_MSBLOB ||
             dsa_config.outformat == FORMAT_PVK) {              cfg.outformat == FORMAT_PVK) {
                 EVP_PKEY *pk;                  EVP_PKEY *pk;
                 pk = EVP_PKEY_new();                  pk = EVP_PKEY_new();
                 EVP_PKEY_set1_DSA(pk, dsa);                  EVP_PKEY_set1_DSA(pk, dsa);
                 if (dsa_config.outformat == FORMAT_PVK)                  if (cfg.outformat == FORMAT_PVK)
                         i = i2b_PVK_bio(out, pk, dsa_config.pvk_encr, 0,                          i = i2b_PVK_bio(out, pk, cfg.pvk_encr, 0,
                             passout);                              passout);
                 else if (dsa_config.pubin || dsa_config.pubout)                  else if (cfg.pubin || cfg.pubout)
                         i = i2b_PublicKey_bio(out, pk);                          i = i2b_PublicKey_bio(out, pk);
                 else                  else
                         i = i2b_PrivateKey_bio(out, pk);                          i = i2b_PrivateKey_bio(out, pk);

Legend:
Removed from v.1.17  
changed lines
  Added in v.1.18