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

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

version 1.17, 2019/07/24 14:23:25 version 1.18, 2021/11/20 18:10:48
Line 83 
Line 83 
   
 #define DEFBITS 2048  #define DEFBITS 2048
   
 static int genrsa_cb(int p, int n, BN_GENCB * cb);  static int genrsa_cb(int p, int n, BN_GENCB *cb);
   
 static struct {  static struct {
         const EVP_CIPHER *enc;          const EVP_CIPHER *enc;
Line 270 
Line 270 
 int  int
 genrsa_main(int argc, char **argv)  genrsa_main(int argc, char **argv)
 {  {
         BN_GENCB cb;          BN_GENCB *cb = NULL;
         int ret = 1;          int ret = 1;
         int i, num = DEFBITS;          int num = DEFBITS;
         char *numbits= NULL;          char *numbits = NULL;
         long l;  
         char *passout = NULL;          char *passout = NULL;
         BIO *out = NULL;          BIO *out = NULL;
         BIGNUM *bn = BN_new();          BIGNUM *bn = NULL;
         RSA *rsa = NULL;          RSA *rsa = NULL;
           const BIGNUM *rsa_e = NULL;
           char *rsa_e_hex = NULL, *rsa_e_dec = NULL;
   
         if (single_execution) {          if (single_execution) {
                 if (pledge("stdio cpath wpath rpath tty", NULL) == -1) {                  if (pledge("stdio cpath wpath rpath tty", NULL) == -1) {
Line 287 
Line 288 
                 }                  }
         }          }
   
         if (!bn)          if ((bn = BN_new()) == NULL)
                 goto err;                  goto err;
   
         BN_GENCB_set(&cb, genrsa_cb, bio_err);          if ((cb = BN_GENCB_new()) == NULL) {
                   BIO_printf(bio_err, "Error allocating BN_GENCB object\n");
                   goto err;
           }
   
           BN_GENCB_set(cb, genrsa_cb, bio_err);
   
         if ((out = BIO_new(BIO_s_file())) == NULL) {          if ((out = BIO_new(BIO_s_file())) == NULL) {
                 BIO_printf(bio_err, "unable to create BIO for output\n");                  BIO_printf(bio_err, "unable to create BIO for output\n");
                 goto err;                  goto err;
Line 333 
Line 339 
                 goto err;                  goto err;
   
         if (!BN_set_word(bn, genrsa_config.f4) ||          if (!BN_set_word(bn, genrsa_config.f4) ||
             !RSA_generate_key_ex(rsa, num, bn, &cb))              !RSA_generate_key_ex(rsa, num, bn, cb))
                 goto err;                  goto err;
   
         /*          RSA_get0_key(rsa, NULL, &rsa_e, NULL);
          * We need to do the following for when the base number size is <          if ((rsa_e_hex = BN_bn2hex(rsa_e)) == NULL)
          * long, esp windows 3.1 :-(.                  goto err;
          */          if ((rsa_e_dec = BN_bn2dec(rsa_e)) == NULL)
         l = 0L;                  goto err;
         for (i = 0; i < rsa->e->top; i++) {  
 #ifndef _LP64          BIO_printf(bio_err, "e is %s (0x%s)\n", rsa_e_hex, rsa_e_dec);
                 l <<= BN_BITS4;  
                 l <<= BN_BITS4;  
 #endif  
                 l += rsa->e->d[i];  
         }  
         BIO_printf(bio_err, "e is %ld (0x%lX)\n", l, l);  
         {          {
                 PW_CB_DATA cb_data;                  PW_CB_DATA cb_data;
                 cb_data.password = passout;                  cb_data.password = passout;
Line 361 
Line 361 
         ret = 0;          ret = 0;
  err:   err:
         BN_free(bn);          BN_free(bn);
           BN_GENCB_free(cb);
         RSA_free(rsa);          RSA_free(rsa);
         BIO_free_all(out);          BIO_free_all(out);
           free(rsa_e_dec);
           free(rsa_e_hex);
         free(passout);          free(passout);
   
         if (ret != 0)          if (ret != 0)
Line 372 
Line 375 
 }  }
   
 static int  static int
 genrsa_cb(int p, int n, BN_GENCB * cb)  genrsa_cb(int p, int n, BN_GENCB *cb)
 {  {
         char c = '*';          char c = '*';
   
Line 384 
Line 387 
                 c = '*';                  c = '*';
         if (p == 3)          if (p == 3)
                 c = '\n';                  c = '\n';
         BIO_write(cb->arg, &c, 1);          BIO_write(BN_GENCB_get_arg(cb), &c, 1);
         (void) BIO_flush(cb->arg);          (void) BIO_flush(BN_GENCB_get_arg(cb));
         return 1;          return 1;
 }  }

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