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

Diff for /src/usr.bin/openssl/prime.c between version 1.16 and 1.17

version 1.16, 2023/03/05 13:12:53 version 1.17, 2023/03/06 14:32:06
Line 62 
Line 62 
         int generate;          int generate;
         int hex;          int hex;
         int safe;          int safe;
 } prime_config;  } cfg;
   
 static const struct option prime_options[] = {  static const struct option prime_options[] = {
         {          {
Line 70 
Line 70 
                 .argname = "n",                  .argname = "n",
                 .desc = "Number of bits in the generated prime number",                  .desc = "Number of bits in the generated prime number",
                 .type = OPTION_ARG_INT,                  .type = OPTION_ARG_INT,
                 .opt.value = &prime_config.bits,                  .opt.value = &cfg.bits,
         },          },
         {          {
                 .name = "checks",                  .name = "checks",
                 .argname = "n",                  .argname = "n",
                 .desc = "Miller-Rabin probabilistic primality test iterations",                  .desc = "Miller-Rabin probabilistic primality test iterations",
                 .type = OPTION_ARG_INT,                  .type = OPTION_ARG_INT,
                 .opt.value = &prime_config.checks,                  .opt.value = &cfg.checks,
         },          },
         {          {
                 .name = "generate",                  .name = "generate",
                 .desc = "Generate a pseudo-random prime number",                  .desc = "Generate a pseudo-random prime number",
                 .type = OPTION_FLAG,                  .type = OPTION_FLAG,
                 .opt.flag = &prime_config.generate,                  .opt.flag = &cfg.generate,
         },          },
         {          {
                 .name = "hex",                  .name = "hex",
                 .desc = "Hexadecimal prime numbers",                  .desc = "Hexadecimal prime numbers",
                 .type = OPTION_FLAG,                  .type = OPTION_FLAG,
                 .opt.flag = &prime_config.hex,                  .opt.flag = &cfg.hex,
         },          },
         {          {
                 .name = "safe",                  .name = "safe",
                 .desc = "Generate only \"safe\" prime numbers",                  .desc = "Generate only \"safe\" prime numbers",
                 .type = OPTION_FLAG,                  .type = OPTION_FLAG,
                 .opt.flag = &prime_config.safe,                  .opt.flag = &cfg.safe,
         },          },
         {NULL},          {NULL},
 };  };
Line 123 
Line 123 
                 exit(1);                  exit(1);
         }          }
   
         memset(&prime_config, 0, sizeof(prime_config));          memset(&cfg, 0, sizeof(cfg));
   
         /* Default iterations for Miller-Rabin probabilistic primality test. */          /* Default iterations for Miller-Rabin probabilistic primality test. */
         prime_config.checks = 20;          cfg.checks = 20;
   
         if (options_parse(argc, argv, prime_options, &prime, NULL) != 0) {          if (options_parse(argc, argv, prime_options, &prime, NULL) != 0) {
                 prime_usage();                  prime_usage();
                 return (1);                  return (1);
         }          }
   
         if (prime == NULL && prime_config.generate == 0) {          if (prime == NULL && cfg.generate == 0) {
                 BIO_printf(bio_err, "No prime specified.\n");                  BIO_printf(bio_err, "No prime specified.\n");
                 prime_usage();                  prime_usage();
                 return (1);                  return (1);
Line 145 
Line 145 
         }          }
         BIO_set_fp(bio_out, stdout, BIO_NOCLOSE);          BIO_set_fp(bio_out, stdout, BIO_NOCLOSE);
   
         if (prime_config.generate != 0) {          if (cfg.generate != 0) {
                 if (prime_config.bits == 0) {                  if (cfg.bits == 0) {
                         BIO_printf(bio_err, "Specify the number of bits.\n");                          BIO_printf(bio_err, "Specify the number of bits.\n");
                         goto end;                          goto end;
                 }                  }
Line 155 
Line 155 
                         BIO_printf(bio_err, "Out of memory.\n");                          BIO_printf(bio_err, "Out of memory.\n");
                         goto end;                          goto end;
                 }                  }
                 if (!BN_generate_prime_ex(bn, prime_config.bits,                  if (!BN_generate_prime_ex(bn, cfg.bits,
                     prime_config.safe, NULL, NULL, NULL)) {                      cfg.safe, NULL, NULL, NULL)) {
                         BIO_printf(bio_err, "Prime generation error.\n");                          BIO_printf(bio_err, "Prime generation error.\n");
                         goto end;                          goto end;
                 }                  }
                 s = prime_config.hex ? BN_bn2hex(bn) : BN_bn2dec(bn);                  s = cfg.hex ? BN_bn2hex(bn) : BN_bn2dec(bn);
                 if (s == NULL) {                  if (s == NULL) {
                         BIO_printf(bio_err, "Out of memory.\n");                          BIO_printf(bio_err, "Out of memory.\n");
                         goto end;                          goto end;
Line 168 
Line 168 
                 BIO_printf(bio_out, "%s\n", s);                  BIO_printf(bio_out, "%s\n", s);
                 free(s);                  free(s);
         } else {          } else {
                 if (prime_config.hex) {                  if (cfg.hex) {
                         if (!BN_hex2bn(&bn, prime)) {                          if (!BN_hex2bn(&bn, prime)) {
                                 BIO_printf(bio_err, "%s is an invalid hex "                                  BIO_printf(bio_err, "%s is an invalid hex "
                                     "value.\n", prime);                                      "value.\n", prime);
Line 182 
Line 182 
                         }                          }
                 }                  }
   
                 is_prime = BN_is_prime_ex(bn, prime_config.checks, NULL, NULL);                  is_prime = BN_is_prime_ex(bn, cfg.checks, NULL, NULL);
                 if (is_prime < 0) {                  if (is_prime < 0) {
                         BIO_printf(bio_err, "BN_is_prime_ex failed.\n");                          BIO_printf(bio_err, "BN_is_prime_ex failed.\n");
                         goto end;                          goto end;

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