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

Diff for /src/usr.bin/openssl/rand.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 66 
Line 66 
         int base64;          int base64;
         int hex;          int hex;
         char *outfile;          char *outfile;
 } rand_config;  } cfg;
   
 static const struct option rand_options[] = {  static const struct option rand_options[] = {
         {          {
                 .name = "base64",                  .name = "base64",
                 .desc = "Perform base64 encoding on output",                  .desc = "Perform base64 encoding on output",
                 .type = OPTION_FLAG,                  .type = OPTION_FLAG,
                 .opt.flag = &rand_config.base64,                  .opt.flag = &cfg.base64,
         },          },
         {          {
                 .name = "hex",                  .name = "hex",
                 .desc = "Hexadecimal output",                  .desc = "Hexadecimal output",
                 .type = OPTION_FLAG,                  .type = OPTION_FLAG,
                 .opt.flag = &rand_config.hex,                  .opt.flag = &cfg.hex,
         },          },
         {          {
                 .name = "out",                  .name = "out",
                 .argname = "file",                  .argname = "file",
                 .desc = "Write to the given file instead of standard output",                  .desc = "Write to the given file instead of standard output",
                 .type = OPTION_ARG,                  .type = OPTION_ARG,
                 .opt.arg = &rand_config.outfile,                  .opt.arg = &cfg.outfile,
         },          },
         {NULL},          {NULL},
 };  };
Line 114 
Line 114 
                 exit(1);                  exit(1);
         }          }
   
         memset(&rand_config, 0, sizeof(rand_config));          memset(&cfg, 0, sizeof(cfg));
   
         if (options_parse(argc, argv, rand_options, &num_bytes, NULL) != 0) {          if (options_parse(argc, argv, rand_options, &num_bytes, NULL) != 0) {
                 rand_usage();                  rand_usage();
Line 128 
Line 128 
         } else          } else
                 badopt = 1;                  badopt = 1;
   
         if (rand_config.hex && rand_config.base64)          if (cfg.hex && cfg.base64)
                 badopt = 1;                  badopt = 1;
   
         if (badopt) {          if (badopt) {
Line 139 
Line 139 
         out = BIO_new(BIO_s_file());          out = BIO_new(BIO_s_file());
         if (out == NULL)          if (out == NULL)
                 goto err;                  goto err;
         if (rand_config.outfile != NULL)          if (cfg.outfile != NULL)
                 r = BIO_write_filename(out, rand_config.outfile);                  r = BIO_write_filename(out, cfg.outfile);
         else          else
                 r = BIO_set_fp(out, stdout, BIO_NOCLOSE | BIO_FP_TEXT);                  r = BIO_set_fp(out, stdout, BIO_NOCLOSE | BIO_FP_TEXT);
         if (r <= 0)          if (r <= 0)
                 goto err;                  goto err;
         if (rand_config.base64) {          if (cfg.base64) {
                 BIO *b64 = BIO_new(BIO_f_base64());                  BIO *b64 = BIO_new(BIO_f_base64());
                 if (b64 == NULL)                  if (b64 == NULL)
                         goto err;                          goto err;
Line 160 
Line 160 
                 if (chunk > (int) sizeof(buf))                  if (chunk > (int) sizeof(buf))
                         chunk = sizeof(buf);                          chunk = sizeof(buf);
                 arc4random_buf(buf, chunk);                  arc4random_buf(buf, chunk);
                 if (rand_config.hex) {                  if (cfg.hex) {
                         for (i = 0; i < chunk; i++)                          for (i = 0; i < chunk; i++)
                                 BIO_printf(out, "%02x", buf[i]);                                  BIO_printf(out, "%02x", buf[i]);
                 } else                  } else
Line 168 
Line 168 
                 num -= chunk;                  num -= chunk;
         }          }
   
         if (rand_config.hex)          if (cfg.hex)
                 BIO_puts(out, "\n");                  BIO_puts(out, "\n");
         (void) BIO_flush(out);          (void) BIO_flush(out);
   

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