22#include "crypto/cipher/bcModOp.hpp"
39 template<
typename Cipher,
typename Padding>
45 std::array<uint8_t,Cipher::getBlockSize()> _initVect;
48 std::array<uint8_t,Cipher::getBlockSize()> _ctxtVect;
61 PCBC(
const std::array<uint8_t,Cipher::getBlockSize()>& initVect,
unsigned int nbThread = 1);
86 virtual std::size_t
cipherBlock(std::array<uint8_t,Cipher::getBlockSize()>& input,
87 std::streamsize nbRead,
88 std::array<uint8_t,Cipher::getBlockSize()>& output,
89 uint32_t, Cipher&
cipher)
override;
103 virtual std::size_t
decipherBlock(std::array<uint8_t,Cipher::getBlockSize()>& input,
104 std::array<uint8_t,Cipher::getBlockSize()>&,
105 std::streamsize nbRead,
107 std::array<uint8_t,Cipher::getBlockSize()>& output,
108 uint32_t, Cipher&
cipher)
override;
115 virtual const std::array<uint8_t,Cipher::getBlockSize()>&
reset();
121 template<
typename Cipher,
typename Padding>
132 template<
typename Cipher,
typename Padding>
140 template<
typename Cipher,
typename Padding>
143 std::streamsize nbRead,
144 std::array<uint8_t,Cipher::getBlockSize()>& output,
145 uint32_t, Cipher&
cipher) {
146 if(
static_cast<std::size_t
>(nbRead) != Cipher::getBlockSize()) {
147 Padding::pad(input.data(),
static_cast<std::size_t
>(nbRead), Cipher::getBlockSize());
149 std::array<uint8_t,Cipher::getBlockSize()> data;
150 for(std::size_t i = 0 ; i < Cipher::getBlockSize() ; ++i) {
151 data[i] = input[i] ^ _ctxtVect[i];
153 cipher.cipher(data, output);
154 for(std::size_t i = 0 ; i < Cipher::getBlockSize() ; ++i) {
155 _ctxtVect[i] = input[i] ^ output[i];
157 return Cipher::getBlockSize();
160 template<
typename Cipher,
typename Padding>
163 std::array<uint8_t,Cipher::getBlockSize()>&,
164 std::streamsize nbRead,
166 std::array<uint8_t,Cipher::getBlockSize()>& output,
167 uint32_t, Cipher&
cipher) {
168 if(lastBlock &&
static_cast<std::size_t
>(nbRead) != Cipher::getBlockSize()) {
171 std::array<uint8_t,Cipher::getBlockSize()> data;
172 cipher.decipher(input, data);
173 for(std::size_t i = 0 ; i < Cipher::getBlockSize() ; ++i) {
174 output[i] = data[i] ^ _ctxtVect[i];
175 _ctxtVect[i] = input[i] ^ output[i];
178 return Padding::length(output.data(), Cipher::getBlockSize());
180 return Cipher::getBlockSize();
184 template<
typename Cipher,
typename Padding>
185 const std::array<uint8_t,Cipher::getBlockSize()>&
187 _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
Exception on receiving an invalid block.
Definition invalidBlockException.hpp:38
virtual ~PCBC()
Definition pcbc.hpp:133
virtual const std::array< uint8_t, Cipher::getBlockSize()> & reset()
Definition pcbc.hpp:186
virtual std::size_t decipherBlock(std::array< uint8_t, Cipher::getBlockSize()> &input, std::array< uint8_t, Cipher::getBlockSize()> &, std::streamsize nbRead, bool lastBlock, std::array< uint8_t, Cipher::getBlockSize()> &output, uint32_t, Cipher &cipher) override
Definition pcbc.hpp:162
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 pcbc.hpp:142
PCBC(const std::array< uint8_t, Cipher::getBlockSize()> &initVect, unsigned int nbThread=1)
Definition pcbc.hpp:122
Cryptography namespace.
Definition base64.hpp:28
AnCH framework base namespace.
Definition app.hpp:28