22#include "crypto/cipher/bcModOp.hpp"
36 template<
typename Cipher,
typename Padding>
42 std::array<uint8_t,Cipher::getBlockSize()> _initVect;
45 std::array<uint8_t,Cipher::getBlockSize()> _ctxtVect;
58 CBC(
const std::array<uint8_t,Cipher::getBlockSize()>& initVect,
unsigned int nbThread = 1);
83 virtual std::size_t
cipherBlock(std::array<uint8_t,Cipher::getBlockSize()>& input,
84 std::streamsize nbRead,
85 std::array<uint8_t,Cipher::getBlockSize()>& output,
86 uint32_t, Cipher&
cipher)
override;
101 virtual std::size_t
decipherBlock(std::array<uint8_t,Cipher::getBlockSize()>& input,
102 std::array<uint8_t,Cipher::getBlockSize()>& prevInput,
103 std::streamsize nbRead,
105 std::array<uint8_t,Cipher::getBlockSize()>& output,
106 uint32_t, Cipher&
cipher)
override;
113 virtual const std::array<uint8_t,Cipher::getBlockSize()>&
reset();
119 template<
typename Cipher,
typename Padding>
130 template<
typename Cipher,
typename Padding>
138 template<
typename Cipher,
typename Padding>
141 std::streamsize nbRead,
142 std::array<uint8_t,Cipher::getBlockSize()>& output,
143 uint32_t, Cipher&
cipher) {
144 if(
static_cast<std::size_t
>(nbRead) != Cipher::getBlockSize()) {
145 Padding::pad(input.data(),
static_cast<std::size_t
>(nbRead), Cipher::getBlockSize());
147 std::array<uint8_t,Cipher::getBlockSize()> data;
148 for(std::size_t i = 0 ; i < Cipher::getBlockSize() ; ++i) {
149 data[i] = input[i] ^ _ctxtVect[i];
151 cipher.cipher(data, output);
152 for(std::size_t i = 0 ; i < Cipher::getBlockSize() ; ++i) {
153 _ctxtVect[i] = output[i];
155 return Cipher::getBlockSize();
158 template<
typename Cipher,
typename Padding>
161 std::array<uint8_t,Cipher::getBlockSize()>& prevInput,
162 std::streamsize nbRead,
164 std::array<uint8_t,Cipher::getBlockSize()>& output,
165 uint32_t, Cipher&
cipher) {
166 if(lastBlock &&
static_cast<std::size_t
>(nbRead) != Cipher::getBlockSize()) {
169 std::array<uint8_t,Cipher::getBlockSize()> data;
170 cipher.decipher(input, data);
171 for(std::size_t i = 0 ; i < Cipher::getBlockSize() ; ++i) {
172 output[i] = data[i] ^ prevInput[i];
175 return Padding::length(output.data(), Cipher::getBlockSize());
177 return Cipher::getBlockSize();
181 template<
typename Cipher,
typename Padding>
182 const std::array<uint8_t,Cipher::getBlockSize()>&
184 _ctxtVect = _initVect;
BlockCipherModeOfOperation(bool cipherParallelizable, bool decipherParallelizable, unsigned int nbThread=1)
Definition bcModOp.hpp:269
void cipher(std::istream &input, std::ostream &output, const std::string &key)
Definition bcModOp.hpp:300
CBC(const std::array< uint8_t, Cipher::getBlockSize()> &initVect, unsigned int nbThread=1)
Definition cbc.hpp:120
virtual const std::array< uint8_t, Cipher::getBlockSize()> & reset()
Definition cbc.hpp:183
virtual std::size_t decipherBlock(std::array< uint8_t, Cipher::getBlockSize()> &input, std::array< uint8_t, Cipher::getBlockSize()> &prevInput, std::streamsize nbRead, bool lastBlock, std::array< uint8_t, Cipher::getBlockSize()> &output, uint32_t, Cipher &cipher) override
Definition cbc.hpp:160
virtual ~CBC()
Definition cbc.hpp:131
virtual std::size_t cipherBlock(std::array< uint8_t, Cipher::getBlockSize()> &input, std::streamsize nbRead, std::array< uint8_t, Cipher::getBlockSize()> &output, uint32_t, Cipher &cipher) override
Definition cbc.hpp:140
Exception on receiving an invalid block.
Definition invalidBlockException.hpp:38
Cryptography namespace.
Definition base64.hpp:28
AnCH framework base namespace.
Definition app.hpp:28