Example #1
0
/*************************************************
* Randpool Constructor                           *
*************************************************/
Randpool::Randpool(const std::string& cipher_name,
                   const std::string& mac_name) :
   ITERATIONS_BEFORE_RESEED(128), POOL_BLOCKS(32)
   {
   cipher = get_block_cipher(cipher_name);
   mac = get_mac(mac_name);

   const u32bit BLOCK_SIZE = cipher->BLOCK_SIZE;
   const u32bit OUTPUT_LENGTH = mac->OUTPUT_LENGTH;

   if(OUTPUT_LENGTH < BLOCK_SIZE ||
      !cipher->valid_keylength(OUTPUT_LENGTH) ||
      !mac->valid_keylength(OUTPUT_LENGTH))
      {
      delete cipher;
      delete mac;
      throw Internal_Error("Randpool: Invalid algorithm combination " +
                           cipher_name + "/" + mac_name);
      }

   buffer.create(BLOCK_SIZE);
   pool.create(POOL_BLOCKS * BLOCK_SIZE);
   counter.create(12);
   entropy = 0;
   }
Example #2
0
/*************************************************
* ANSI X931 RNG Constructor                      *
*************************************************/
ANSI_X931_RNG::ANSI_X931_RNG(const std::string& cipher_name,
                             RandomNumberGenerator* prng_ptr)
   {
   if(cipher_name == "")
      cipher = get_block_cipher("AES-256");
   else
      cipher = get_block_cipher(cipher_name);

   const u32bit BLOCK_SIZE = cipher->BLOCK_SIZE;

   V.create(BLOCK_SIZE);
   R.create(BLOCK_SIZE);

   prng = (prng_ptr ? prng_ptr : new Randpool);

   position = 0;
   }
Example #3
0
File: ecb.cpp Project: AlexNk/botan
Transform* make_ecb_mode(const Transform::Spec& spec)
   {
   std::unique_ptr<BlockCipher> bc(get_block_cipher(spec.arg(0)));
   std::unique_ptr<BlockCipherModePaddingMethod> pad(get_bc_pad(spec.arg(1, "NoPadding")));
   if(bc && pad)
      return new T(bc.release(), pad.release());
   return nullptr;
   }
Example #4
0
OFB* OFB::make(const Spec& spec)
   {
   if(spec.algo_name() == "OFB" && spec.arg_count() == 1)
      {
      if(BlockCipher* c = get_block_cipher(spec.arg(0)))
         return new OFB(c);
      }
   return nullptr;
   }