22#include "anch-crypto-export.hpp"
24#include "crypto/cipher/bcModOp.hpp"
40 template<
typename Cipher,
typename Padding>
46 std::array<uint8_t,Cipher::getBlockSize()> _initVect;
49 std::array<uint8_t,Cipher::getBlockSize()> _ctxtVect;
62 PCBC(
const std::array<uint8_t,Cipher::getBlockSize()>& initVect,
unsigned int nbThread = 1);
87 virtual std::size_t
cipherBlock(std::array<uint8_t,Cipher::getBlockSize()>& input,
88 std::streamsize nbRead,
89 std::array<uint8_t,Cipher::getBlockSize()>& output,
90 uint64_t, Cipher&
cipher)
override;
104 virtual std::size_t
decipherBlock(std::array<uint8_t,Cipher::getBlockSize()>& input,
105 std::array<uint8_t,Cipher::getBlockSize()>&,
106 std::streamsize nbRead,
108 std::array<uint8_t,Cipher::getBlockSize()>& output,
109 uint64_t, Cipher&
cipher)
override;
116 virtual const std::array<uint8_t,Cipher::getBlockSize()>&
reset()
override;
122 template<
typename Cipher,
typename Padding>
133 template<
typename Cipher,
typename Padding>
141 template<
typename Cipher,
typename Padding>
144 std::streamsize nbRead,
145 std::array<uint8_t,Cipher::getBlockSize()>& output,
146 uint64_t, Cipher&
cipher) {
147 if(
static_cast<std::size_t
>(nbRead) != Cipher::getBlockSize()) {
148 Padding::pad(input.data(),
static_cast<std::size_t
>(nbRead), Cipher::getBlockSize());
150 std::array<uint8_t,Cipher::getBlockSize()> data;
151 for(std::size_t i = 0 ; i < Cipher::getBlockSize() ; ++i) {
152 data[i] = input[i] ^ _ctxtVect[i];
154 cipher.cipher(data, output);
155 for(std::size_t i = 0 ; i < Cipher::getBlockSize() ; ++i) {
156 _ctxtVect[i] = input[i] ^ output[i];
158 return Cipher::getBlockSize();
161 template<
typename Cipher,
typename Padding>
164 std::array<uint8_t,Cipher::getBlockSize()>&,
165 std::streamsize nbRead,
167 std::array<uint8_t,Cipher::getBlockSize()>& output,
168 uint64_t, Cipher&
cipher) {
169 if(lastBlock &&
static_cast<std::size_t
>(nbRead) != Cipher::getBlockSize()) {
172 std::array<uint8_t,Cipher::getBlockSize()> data;
173 cipher.decipher(input, data);
174 for(std::size_t i = 0 ; i < Cipher::getBlockSize() ; ++i) {
175 output[i] = data[i] ^ _ctxtVect[i];
176 _ctxtVect[i] = input[i] ^ output[i];
179 return Padding::length(output.data(), Cipher::getBlockSize());
181 return Cipher::getBlockSize();
185 template<
typename Cipher,
typename Padding>
186 const std::array<uint8_t,Cipher::getBlockSize()>&
188 _ctxtVect = _initVect;
BlockCipherModeOfOperation(bool cipherParallelizable, bool decipherParallelizable, unsigned int nbThread=1)
Definition bcModOp.hpp:273
void cipher(std::istream &input, std::ostream &output, const std::string &key)
Definition bcModOp.hpp:304
InvalidBlockException(const std::string &message)
virtual std::size_t cipherBlock(std::array< uint8_t, Cipher::getBlockSize()> &input, std::streamsize nbRead, std::array< uint8_t, Cipher::getBlockSize()> &output, uint64_t, Cipher &cipher) override
Definition pcbc.hpp:143
virtual const std::array< uint8_t, Cipher::getBlockSize()> & reset() override
Definition pcbc.hpp:187
virtual ~PCBC()
Definition pcbc.hpp:134
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, uint64_t, Cipher &cipher) override
Definition pcbc.hpp:163
PCBC(const std::array< uint8_t, Cipher::getBlockSize()> &initVect, unsigned int nbThread=1)
Definition pcbc.hpp:123
Cryptography namespace.
Definition base64.hpp:30