Ejemplo n.º 1
0
Archivo: nr.cpp Proyecto: bogiord/botan
NR_PrivateKey::NR_PrivateKey(const AlgorithmIdentifier& alg_id,
                             const secure_vector<byte>& key_bits,
                             RandomNumberGenerator& rng) :
   DL_Scheme_PrivateKey(alg_id, key_bits, DL_Group::ANSI_X9_57)
   {
   m_y = power_mod(group_g(), m_x, group_p());

   load_check(rng);
   }
Ejemplo n.º 2
0
DSA_PrivateKey::DSA_PrivateKey(const AlgorithmIdentifier& alg_id,
                               const MemoryRegion<byte>& key_bits,
                               RandomNumberGenerator& rng) :
   DL_Scheme_PrivateKey(alg_id, key_bits, DL_Group::ANSI_X9_57)
   {
   y = power_mod(group_g(), x, group_p());

   load_check(rng);
   }
Ejemplo n.º 3
0
void 
check_mainloop(void)
{
	time_t          now = 0, then = 0;
	useconds_t      sleeptime;
	int        	delta = 0;
	
	/* init */
	status_alerted.alert_load = false;
	status_alerted.alert_disk = false;
	status_alerted.alert_cpu = false;
	sleeptime = 100000;
	
	numcpus = num_cpus();
	http_fetch_url(hburl);

	vbprintf("Found %d cpus\n", numcpus);

	database_init();

	/*
	 * XXX: Right here we're just spinning in place. The reason for this
	 * is to be able to have different intervals for the checking process
	 * (disk/cpu/load), and also for the heartbeat-process, which might
	 * check at different intervals. I might separate this out into
	 * another file so we have a rudimentary timer-based scheduler that
	 * can shoot off different functions at variable intervals.
	 */

	time(&then);	
	while (1) {
		int sampletrig = 0, hbtrig = 0;

		time(&now);

		delta = (int) now - (int) then;
		sampletrig = delta % interval;
		hbtrig = delta % hbinterval;
		
		if (!sampletrig) {
			load_check();
			disk_check(diskpaths);
			cpu_check();
			check_alert();
			sleep(1); /* make sure trig status is over */
		}		
		
		if (!hbtrig) {
			http_fetch_url(hburl);
			sleep(1); /* make sure trig status is over */
		}	
		usleep(sleeptime);	
	}
}
Ejemplo n.º 4
0
/*************************************************
* Algorithm Specific PKCS #8 Initialization Code *
*************************************************/
void DH_PrivateKey::PKCS8_load_hook(RandomNumberGenerator& rng,
                                    bool generated)
   {
   if(y == 0)
      y = power_mod(group_g(), x, group_p());
   core = DH_Core(rng, group, x);

   if(generated)
      gen_check(rng);
   else
      load_check(rng);
   }
Ejemplo n.º 5
0
Curve25519_PrivateKey::Curve25519_PrivateKey(const AlgorithmIdentifier&,
                                             const secure_vector<byte>& key_bits,
                                             RandomNumberGenerator& rng)
   {
   BER_Decoder(key_bits)
      .start_cons(SEQUENCE)
      .decode(m_public, OCTET_STRING)
      .decode(m_private, OCTET_STRING)
      .verify_end()
   .end_cons();

   size_check(m_public.size(), "public key");
   size_check(m_private.size(), "private key");

   load_check(rng);
   }
Ejemplo n.º 6
0
Archivo: nr.cpp Proyecto: bogiord/botan
/*
* Create a NR private key
*/
NR_PrivateKey::NR_PrivateKey(RandomNumberGenerator& rng,
                             const DL_Group& grp,
                             const BigInt& x_arg)
   {
   m_group = grp;
   m_x = x_arg;

   if(m_x == 0)
      m_x = BigInt::random_integer(rng, 2, group_q() - 1);

   m_y = power_mod(group_g(), m_x, group_p());

   if(x_arg == 0)
      gen_check(rng);
   else
      load_check(rng);
   }
Ejemplo n.º 7
0
IF_Scheme_PrivateKey::IF_Scheme_PrivateKey(RandomNumberGenerator& rng,
                                           const AlgorithmIdentifier&,
                                           const secure_vector<byte>& key_bits)
   {
   BER_Decoder(key_bits)
      .start_cons(SEQUENCE)
         .decode_and_check<size_t>(0, "Unknown PKCS #1 key format version")
         .decode(m_n)
         .decode(m_e)
         .decode(m_d)
         .decode(m_p)
         .decode(m_q)
         .decode(m_d1)
         .decode(m_d2)
         .decode(m_c)
      .end_cons();

   load_check(rng);
   }
Ejemplo n.º 8
0
/*
* Create a DH private key
*/
DH_PrivateKey::DH_PrivateKey(RandomNumberGenerator& rng,
                             const DL_Group& grp,
                             const BigInt& x_arg)
   {
   group = grp;
   x = x_arg;

   if(x == 0)
      {
      const BigInt& p = group_p();
      x.randomize(rng, 2 * dl_work_factor(p.bits()));
      }

   if(y == 0)
      y = power_mod(group_g(), x, group_p());

   if(x == 0)
      gen_check(rng);
   else
      load_check(rng);
   }