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

📄 cfb.cpp

📁 含有多种公开密钥算法、多种块加密、多种数据流加密、多种HASH函数、多种CheckSum校验、多种MAC校验等几十种加密算法的程序
💻 CPP
字号:
/************************************************** CFB Mode Source File                           ** (C) 1999-2002 The Botan Project                **************************************************/#include <botan/cfb.h>namespace Botan {/************************************************** CFB Encryption Constructor                     **************************************************/CFB_Encryption::CFB_Encryption(const std::string& cipher_name,                               const SymmetricKey& key,                               const BlockCipherModeIV& iv, u32bit fback) :   BlockCipherMode(cipher_name, "CFB_Encryption", key, iv),   FEEDBACKSIZE(fback ? fback : BLOCK_SIZE)   {   if(!valid_iv_length(iv.length()))      throw Invalid_IV_Length(name(), iv.length());   if(FEEDBACKSIZE == 0 || FEEDBACKSIZE > BLOCK_SIZE)      throw Invalid_Argument(name() + ": Invalid feedback size");   cipher->encrypt(state, buffer);   }/************************************************** Encrypt data in CFB mode                       **************************************************/void CFB_Encryption::write(const byte input[], u32bit length)   {   while(length)      {      u32bit xored = std::min(FEEDBACKSIZE - position, length);      xor_buf(buffer + position, input, xored);      send(buffer + position, xored);      input += xored;      length -= xored;      position += xored;      if(position == FEEDBACKSIZE)         feedback();      }   }/************************************************** Do the feedback                                **************************************************/void CFB_Encryption::feedback()   {   for(u32bit j = 0; j != BLOCK_SIZE - FEEDBACKSIZE; j++)      state[j] = state[j + FEEDBACKSIZE];   state.copy(BLOCK_SIZE - FEEDBACKSIZE, buffer, FEEDBACKSIZE);   cipher->encrypt(state, buffer);   position = 0;   }/************************************************** CFB Decryption Constructor                     **************************************************/CFB_Decryption::CFB_Decryption(const std::string& cipher_name,                               const SymmetricKey& key,                               const BlockCipherModeIV& iv, u32bit fback) :   BlockCipherMode(cipher_name, "CFB_Decryption", key, iv),   FEEDBACKSIZE(fback ? fback : BLOCK_SIZE)   {   if(!valid_iv_length(iv.length()))      throw Invalid_IV_Length(name(), iv.length());   if(FEEDBACKSIZE == 0 || FEEDBACKSIZE > BLOCK_SIZE)      throw Invalid_Argument(name() + ": Invalid feedback size");   cipher->encrypt(state, buffer);   }/************************************************** Decrypt data in CFB mode                       **************************************************/void CFB_Decryption::write(const byte input[], u32bit length)   {   while(length)      {      u32bit xored = std::min(FEEDBACKSIZE - position, length);      xor_buf(buffer + position, input, xored);      send(buffer + position, xored);      buffer.copy(position, input, xored);      input += xored;      length -= xored;      position += xored;      if(position == FEEDBACKSIZE)         feedback();      }   }/************************************************** Do the feedback                                **************************************************/void CFB_Decryption::feedback()   {   for(u32bit j = 0; j != BLOCK_SIZE - FEEDBACKSIZE; j++)      state[j] = state[j + FEEDBACKSIZE];   state.copy(BLOCK_SIZE - FEEDBACKSIZE, buffer, FEEDBACKSIZE);   cipher->encrypt(state, buffer);   position = 0;   }}

⌨️ 快捷键说明

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