⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 emac.cpp

📁 含有多种公开密钥算法、多种块加密、多种数据流加密、多种HASH函数、多种CheckSum校验、多种MAC校验等几十种加密算法的程序
💻 CPP
字号:
/************************************************** EMAC Source File                               ** (C) 1999-2002 The Botan Project                **************************************************/#include <botan/emac.h>#include <botan/lookup.h>namespace Botan {/************************************************** Update an EMAC Calculation                     **************************************************/void EMAC::add_data(const byte input[], u32bit length)   {   while(length)      {      u32bit xored = std::min(state.size() - position, length);      xor_buf(state + position, input, xored);      input += xored;      length -= xored;      position += xored;      if(position == state.size())         {         f1->encrypt(state);         position = 0;         }      }   }/************************************************** Finalize an EMAC Calculation                   **************************************************/void EMAC::final_result(byte mac[])   {   for(u32bit j = position; j != state.size(); j++)      state[j] ^= (byte)(state.size()-position);   f1->encrypt(state);   f2->encrypt(state, mac);   state.clear();   position = 0;   }/************************************************** EMAC Key Schedule                              **************************************************/void EMAC::key(const byte key[], u32bit length)   {   SecureVector<byte> subkeys(2 * f1->MAXIMUM_KEYLENGTH);   SecureVector<byte> block(f1->BLOCK_SIZE), counter(f1->BLOCK_SIZE);   u32bit generated = 0;   f1->set_key(key, length);   while(generated < subkeys.size())      {      f1->encrypt(counter, block);      subkeys.copy(generated, block, block.size());      generated += block.size();      for(s32bit j = counter.size() - 1; j >= 0; j--)         if(++counter[j])            break;      }   f1->set_key(subkeys, subkeys.size() / 2);   f2->set_key(subkeys + subkeys.size() / 2, subkeys.size() / 2);   }/************************************************** Clear memory of sensitive data                 **************************************************/void EMAC::clear() throw()   {   f1->clear();   f2->clear();   state.clear();   position = 0;   }/************************************************** Return a clone of this object                  **************************************************/MessageAuthenticationCode* EMAC::clone() const   {   return new EMAC(f1->name());   }/************************************************** EMAC Constructor                               **************************************************/EMAC::EMAC(const std::string& bc_name) :   MessageAuthenticationCode(block_size_of(bc_name),                             min_keylength_of(bc_name),                             max_keylength_of(bc_name),                             keylength_multiple_of(bc_name))   {   f1 = get_block_cipher(bc_name);   f2 = get_block_cipher(bc_name);   state.create(OUTPUT_LENGTH);   position = 0;   }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -