[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.4 and 1.5

version 1.4, 2014/12/28 15:48:52 version 1.5, 2015/01/13 03:42:36
Line 117 
Line 117 
         char *prime = NULL;          char *prime = NULL;
         BIO *bio_out;          BIO *bio_out;
         char *s;          char *s;
           int ret = 1;
   
         memset(&prime_config, 0, sizeof(prime_config));          memset(&prime_config, 0, sizeof(prime_config));
   
Line 134 
Line 135 
                 return (1);                  return (1);
         }          }
   
         if ((bio_out = BIO_new(BIO_s_file())) != NULL) {          if ((bio_out = BIO_new(BIO_s_file())) == NULL) {
                 BIO_set_fp(bio_out, stdout, BIO_NOCLOSE);                  ERR_print_errors(bio_err);
                   return (1);
         }          }
           BIO_set_fp(bio_out, stdout, BIO_NOCLOSE);
   
         if (prime_config.generate != 0) {          if (prime_config.generate != 0) {
                 if (prime_config.bits == 0) {                  if (prime_config.bits == 0) {
                         BIO_printf(bio_err, "Specify the number of bits.\n");                          BIO_printf(bio_err, "Specify the number of bits.\n");
                         return 1;                          goto end;
                 }                  }
                 bn = BN_new();  /* XXX - unchecked malloc. */                  bn = BN_new();
                 BN_generate_prime_ex(bn, prime_config.bits, prime_config.safe,                  if (!bn) {
                     NULL, NULL, NULL);                          BIO_printf(bio_err, "Out of memory.\n");
                           goto end;
                   }
                   if (!BN_generate_prime_ex(bn, prime_config.bits,
                       prime_config.safe, NULL, NULL, NULL)) {
                           BIO_printf(bio_err, "Prime generation error.\n");
                           goto end;
                   }
                 s = prime_config.hex ? BN_bn2hex(bn) : BN_bn2dec(bn);                  s = prime_config.hex ? BN_bn2hex(bn) : BN_bn2dec(bn);
                   if (s == NULL) {
                           BIO_printf(bio_err, "Out of memory.\n");
                           goto end;
                   }
                 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 (prime_config.hex) {
                         BN_hex2bn(&bn, prime);                          if (!BN_hex2bn(&bn, prime)) {
                 else                                  BIO_printf(bio_err, "%s is an invalid hex "
                         BN_dec2bn(&bn, prime);                                      "value.\n", prime);
                                   goto end;
                           }
                   } else {
                           if (!BN_dec2bn(&bn, prime)) {
                                   BIO_printf(bio_err, "%s is an invalid decimal "
                                       "value.\n", prime);
                                   goto end;
                           }
                   }
   
                 BN_print(bio_out, bn);                  BN_print(bio_out, bn);
                 BIO_printf(bio_out, " is %sprime\n",                  BIO_printf(bio_out, " is %sprime\n",
Line 161 
Line 184 
                         NULL, NULL) ? "" : "not ");                          NULL, NULL) ? "" : "not ");
         }          }
   
           ret = 0;
   
   end:
         BN_free(bn);          BN_free(bn);
         BIO_free_all(bio_out);          BIO_free_all(bio_out);
   
         return 0;          return (ret);
 }  }

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5