ecb.cpp
来自「含有多种公开密钥算法、多种块加密、多种数据流加密、多种HASH函数、多种Chec」· C++ 代码 · 共 98 行
CPP
98 行
/************************************************** ECB Mode Source File ** (C) 1999-2002 The Botan Project **************************************************/#include <botan/ecb.h>namespace Botan {/************************************************** ECB Constructor **************************************************/ECB::ECB(const std::string& cipher_name, const SymmetricKey& key, const std::string& n) : BlockCipherMode(cipher_name, n, key, BlockCipherModeIV()) { }/************************************************** Verify the IV is not set **************************************************/bool ECB::valid_iv_size(u32bit iv_size) const { if(iv_size == 0) return true; return false; }/************************************************** Encrypt or Decrypt in ECB mode **************************************************/void ECB::write(const byte input[], u32bit length) { buffer.copy(position, input, length); if(position + length >= BLOCK_SIZE) { process_block(buffer, buffer); send(buffer, BLOCK_SIZE); input += (BLOCK_SIZE - position); length -= (BLOCK_SIZE - position); while(length >= BLOCK_SIZE) { process_block(input, buffer); send(buffer, BLOCK_SIZE); input += BLOCK_SIZE; length -= BLOCK_SIZE; } buffer.copy(input, length); position = 0; } position += length; }/************************************************** Finish encrypting or decrypting in ECB mode **************************************************/void ECB::end_msg() { if(position) throw Exception(name() + ": input was not in full blocks"); }/************************************************** ECB Encryption Constructor **************************************************/ECB_Encryption::ECB_Encryption(const std::string& cipher_name, const SymmetricKey& key) : ECB(cipher_name, key, "ECB_Encryption") { }/************************************************** ECB Encryption Block Processing **************************************************/void ECB_Encryption::process_block(const byte in[], byte out[]) { cipher->encrypt(in, out); }/************************************************** ECB Decryption Constructor **************************************************/ECB_Decryption::ECB_Decryption(const std::string& cipher_name, const SymmetricKey& key) : ECB(cipher_name, key, "ECB_Decryption") { }/************************************************** ECB Decryption Block Processing **************************************************/void ECB_Decryption::process_block(const byte in[], byte out[]) { cipher->decrypt(in, out); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?