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

Diff for /src/usr.bin/ssh/moduli.c between version 1.12 and 1.12.2.2

version 1.12, 2005/07/17 07:17:55 version 1.12.2.2, 2006/11/08 00:44:05
Line 37 
Line 37 
  * Second step: test primes' safety (processor intensive)   * Second step: test primes' safety (processor intensive)
  */   */
   
 #include "includes.h"  #include <sys/types.h>
 #include "xmalloc.h"  
 #include "log.h"  
   
 #include <openssl/bn.h>  #include <openssl/bn.h>
   
   #include <stdio.h>
   #include <stdlib.h>
   #include <string.h>
   #include <stdarg.h>
   #include <time.h>
   
   #include "xmalloc.h"
   #include "log.h"
   
 /*  /*
  * File output defines   * File output defines
  */   */
Line 301 
Line 308 
                 largewords = (largememory << SHIFT_MEGAWORD);                  largewords = (largememory << SHIFT_MEGAWORD);
         }          }
   
         TinySieve = calloc(tinywords, sizeof(u_int32_t));          TinySieve = xcalloc(tinywords, sizeof(u_int32_t));
         if (TinySieve == NULL) {  
                 error("Insufficient memory for tiny sieve: need %u bytes",  
                     tinywords << SHIFT_BYTE);  
                 exit(1);  
         }  
         tinybits = tinywords << SHIFT_WORD;          tinybits = tinywords << SHIFT_WORD;
   
         SmallSieve = calloc(smallwords, sizeof(u_int32_t));          SmallSieve = xcalloc(smallwords, sizeof(u_int32_t));
         if (SmallSieve == NULL) {  
                 error("Insufficient memory for small sieve: need %u bytes",  
                     smallwords << SHIFT_BYTE);  
                 xfree(TinySieve);  
                 exit(1);  
         }  
         smallbits = smallwords << SHIFT_WORD;          smallbits = smallwords << SHIFT_WORD;
   
         /*          /*
Line 329 
Line 325 
   
         /* validation check: count the number of primes tried */          /* validation check: count the number of primes tried */
         largetries = 0;          largetries = 0;
         q = BN_new();          if ((q = BN_new()) == NULL)
                   fatal("BN_new failed");
   
         /*          /*
          * Generate random starting point for subprime search, or use           * Generate random starting point for subprime search, or use
          * specified parameter.           * specified parameter.
          */           */
         largebase = BN_new();          if ((largebase = BN_new()) == NULL)
         if (start == NULL)                  fatal("BN_new failed");
                 BN_rand(largebase, power, 1, 1);          if (start == NULL) {
         else                  if (BN_rand(largebase, power, 1, 1) == 0)
                 BN_copy(largebase, start);                          fatal("BN_rand failed");
           } else {
                   if (BN_copy(largebase, start) == NULL)
                           fatal("BN_copy: failed");
           }
   
         /* ensure odd */          /* ensure odd */
         BN_set_bit(largebase, 0);          if (BN_set_bit(largebase, 0) == 0)
                   fatal("BN_set_bit: failed");
   
         time(&time_start);          time(&time_start);
   
Line 426 
Line 428 
                         continue; /* Definitely composite, skip */                          continue; /* Definitely composite, skip */
   
                 debug2("test q = largebase+%u", 2 * j);                  debug2("test q = largebase+%u", 2 * j);
                 BN_set_word(q, 2 * j);                  if (BN_set_word(q, 2 * j) == 0)
                 BN_add(q, q, largebase);                          fatal("BN_set_word failed");
                   if (BN_add(q, q, largebase) == 0)
                           fatal("BN_add failed");
                 if (qfileout(out, QTYPE_SOPHIE_GERMAIN, QTEST_SIEVE,                  if (qfileout(out, QTYPE_SOPHIE_GERMAIN, QTEST_SIEVE,
                     largetries, (power - 1) /* MSB */, (0), q) == -1) {                      largetries, (power - 1) /* MSB */, (0), q) == -1) {
                         ret = -1;                          ret = -1;
Line 472 
Line 476 
   
         time(&time_start);          time(&time_start);
   
         p = BN_new();          if ((p = BN_new()) == NULL)
         q = BN_new();                  fatal("BN_new failed");
         ctx = BN_CTX_new();          if ((q = BN_new()) == NULL)
                   fatal("BN_new failed");
           if ((ctx = BN_CTX_new()) == NULL)
                   fatal("BN_CTX_new failed");
   
         debug2("%.24s Final %u Miller-Rabin trials (%x generator)",          debug2("%.24s Final %u Miller-Rabin trials (%x generator)",
             ctime(&time_start), trials, generator_wanted);              ctime(&time_start), trials, generator_wanted);
Line 522 
Line 529 
                 case QTYPE_SOPHIE_GERMAIN:                  case QTYPE_SOPHIE_GERMAIN:
                         debug2("%10u: (%u) Sophie-Germain", count_in, in_type);                          debug2("%10u: (%u) Sophie-Germain", count_in, in_type);
                         a = q;                          a = q;
                         BN_hex2bn(&a, cp);                          if (BN_hex2bn(&a, cp) == 0)
                                   fatal("BN_hex2bn failed");
                         /* p = 2*q + 1 */                          /* p = 2*q + 1 */
                         BN_lshift(p, q, 1);                          if (BN_lshift(p, q, 1) == 0)
                         BN_add_word(p, 1);                                  fatal("BN_lshift failed");
                           if (BN_add_word(p, 1) == 0)
                                   fatal("BN_add_word failed");
                         in_size += 1;                          in_size += 1;
                         generator_known = 0;                          generator_known = 0;
                         break;                          break;
Line 536 
Line 546 
                 case QTYPE_UNKNOWN:                  case QTYPE_UNKNOWN:
                         debug2("%10u: (%u)", count_in, in_type);                          debug2("%10u: (%u)", count_in, in_type);
                         a = p;                          a = p;
                         BN_hex2bn(&a, cp);                          if (BN_hex2bn(&a, cp) == 0)
                                   fatal("BN_hex2bn failed");
                         /* q = (p-1) / 2 */                          /* q = (p-1) / 2 */
                         BN_rshift(q, p, 1);                          if (BN_rshift(q, p, 1) == 0)
                                   fatal("BN_rshift failed");
                         break;                          break;
                 default:                  default:
                         debug2("Unknown prime type");                          debug2("Unknown prime type");

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.12.2.2