tuning DSA key generation
This commit is contained in:
		
							parent
							
								
									e271b9fdbe
								
							
						
					
					
						commit
						3908c70d68
					
				@ -29,7 +29,7 @@
 | 
			
		||||
int dsa_make_key(prng_state *prng, int wprng, int group_size, int modulus_size, dsa_key *key)
 | 
			
		||||
{
 | 
			
		||||
   void           *tmp, *tmp2;
 | 
			
		||||
   int            err, res, q_size;
 | 
			
		||||
   int            err, res, qbits;
 | 
			
		||||
   unsigned char *buf;
 | 
			
		||||
 | 
			
		||||
   LTC_ARGCHK(key  != NULL);
 | 
			
		||||
@ -104,14 +104,11 @@ int dsa_make_key(prng_state *prng, int wprng, int group_size, int modulus_size,
 | 
			
		||||
   /* so now we have our DH structure, generator g, order q, modulus p 
 | 
			
		||||
      Now we need a random exponent [mod q] and it's power g^x mod p 
 | 
			
		||||
    */
 | 
			
		||||
   q_size = mp_unsigned_bin_size(key->q);
 | 
			
		||||
   qbits = mp_count_bits(key->q);
 | 
			
		||||
   do {
 | 
			
		||||
      if (prng_descriptor[wprng].read(buf, q_size, prng) != (unsigned long)q_size) {
 | 
			
		||||
         err = CRYPT_ERROR_READPRNG;
 | 
			
		||||
         goto error;
 | 
			
		||||
      }
 | 
			
		||||
      if ((err = mp_read_unsigned_bin(key->x, buf, q_size)) != CRYPT_OK)           { goto error; }
 | 
			
		||||
   } while (mp_cmp_d(key->x, 1) != LTC_MP_GT || mp_cmp(key->x, key->q) != LTC_MP_LT);
 | 
			
		||||
      if ((err = rand_bn_bits(key->x, qbits, prng, wprng)) != CRYPT_OK)                { goto error; }
 | 
			
		||||
      /* private key x should be from range: 1 <= x <= q-1 */
 | 
			
		||||
   } while (mp_cmp_d(key->x, 0) != LTC_MP_GT || mp_cmp(key->x, key->q) != LTC_MP_LT);
 | 
			
		||||
   if ((err = mp_exptmod(key->g, key->x, key->p, key->y)) != CRYPT_OK)                 { goto error; }
 | 
			
		||||
  
 | 
			
		||||
   key->type = PK_PRIVATE;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user