📄 ecb.cpp
字号:
/************************************************** 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -