Exemple #1
0
/*************************************************
* Derive a key                                   *
*************************************************/
SecureVector<byte> DH_PrivateKey::derive_key(const BigInt& w) const
   {
   const BigInt& p = group_p();
   if(w <= 1 || w >= p-1)
      throw Invalid_Argument(algo_name() + "::derive_key: Invalid key input");
   return BigInt::encode_1363(core.agree(w), p.bytes());
   }
Exemple #2
0
/*
* Load a DH private key
*/
DH_PrivateKey::DH_PrivateKey(const AlgorithmIdentifier& alg_id,
                             const secure_vector<uint8_t>& key_bits) :
   DL_Scheme_PrivateKey(alg_id, key_bits, DL_Group::ANSI_X9_42)
   {
   if(m_y == 0)
      m_y = power_mod(group_g(), m_x, group_p());
   }
Exemple #3
0
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);
   }
Exemple #4
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);
   }
Exemple #5
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);
   }
Exemple #6
0
/*
* Create a DH private key
*/
DH_PrivateKey::DH_PrivateKey(RandomNumberGenerator& rng,
                             const DL_Group& grp,
                             const BigInt& x_arg)
   {
   m_group = grp;

   if(x_arg == 0)
      {
      const BigInt& p = group_p();
      m_x.randomize(rng, dl_exponent_size(p.bits()));
      }
   else
      {
      m_x = x_arg;
      }

   if(m_y == 0)
      {
      m_y = power_mod(group_g(), m_x, group_p());
      }
   }
Exemple #7
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);
   }
Exemple #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()));
      PKCS8_load_hook(rng, true);
      }
   else
      PKCS8_load_hook(rng, false);
   }
Exemple #9
0
/*
* 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);
   }
Exemple #10
0
/*************************************************
* Return the public value for key agreement      *
*************************************************/
MemoryVector<byte> DH_PublicKey::public_value() const
   {
   return BigInt::encode_1363(y, group_p().bytes());
   }
Exemple #11
0
/*************************************************
* Return the maximum input size in bits          *
*************************************************/
u32bit DH_PublicKey::max_input_bits() const
   {
   return group_p().bits();
   }
Exemple #12
0
/*
* Return the public value for key agreement
*/
std::vector<uint8_t> DH_PublicKey::public_value() const
   {
   return unlock(BigInt::encode_1363(m_y, group_p().bytes()));
   }