22#include "anch-crypto-export.hpp"
24#include "crypto/cipher/bcModOp.hpp"
37 template<
typename Cipher>
43 std::array<uint8_t,Cipher::getBlockSize()> _initVect;
46 std::array<uint8_t,Cipher::getBlockSize()> _ctxtVect;
59 OFB(
const std::array<uint8_t,Cipher::getBlockSize()>& initVect,
unsigned int nbThread = 1);
84 virtual std::size_t
cipherBlock(std::array<uint8_t,Cipher::getBlockSize()>& input,
85 std::streamsize nbRead,
86 std::array<uint8_t,Cipher::getBlockSize()>& output,
87 uint64_t, Cipher&
cipher)
override;
100 virtual std::size_t
decipherBlock(std::array<uint8_t,Cipher::getBlockSize()>& input,
101 std::array<uint8_t,Cipher::getBlockSize()>&,
102 std::streamsize nbRead,
104 std::array<uint8_t,Cipher::getBlockSize()>& output,
105 uint64_t, Cipher&
cipher)
override;
112 virtual const std::array<uint8_t,Cipher::getBlockSize()>&
reset()
override;
118 template<
typename Cipher>
119 OFB<Cipher>::OFB(
const std::array<uint8_t,Cipher::getBlockSize()>& initVect,
unsigned int nbThread):
129 template<
typename Cipher>
137 template<
typename Cipher>
140 std::streamsize nbRead,
141 std::array<uint8_t,Cipher::getBlockSize()>& output,
142 uint64_t, Cipher&
cipher) {
143 std::array<uint8_t,Cipher::getBlockSize()> data;
144 cipher.cipher(_ctxtVect, data);
145 for(std::size_t i = 0 ; i < static_cast<std::size_t>(nbRead) ; ++i) {
146 output[i] = input[i] ^ data[i];
147 _ctxtVect[i] = data[i];
149 return static_cast<std::size_t
>(nbRead);
152 template<
typename Cipher>
155 std::array<uint8_t,Cipher::getBlockSize()>&,
156 std::streamsize nbRead,
158 std::array<uint8_t,Cipher::getBlockSize()>& output,
159 uint64_t, Cipher&
cipher) {
160 std::array<uint8_t,Cipher::getBlockSize()> data;
161 cipher.cipher(_ctxtVect, data);
162 for(std::size_t i = 0 ; i < static_cast<std::size_t>(nbRead) ; ++i) {
163 output[i] = input[i] ^ data[i];
164 _ctxtVect[i] = data[i];
166 return static_cast<std::size_t
>(nbRead);
169 template<
typename Cipher>
170 const std::array<uint8_t,Cipher::getBlockSize()>&
172 _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
virtual const std::array< uint8_t, Cipher::getBlockSize()> & reset() override
Definition ofb.hpp:171
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 ofb.hpp:139
OFB(const std::array< uint8_t, Cipher::getBlockSize()> &initVect, unsigned int nbThread=1)
Definition ofb.hpp:119
virtual std::size_t decipherBlock(std::array< uint8_t, Cipher::getBlockSize()> &input, std::array< uint8_t, Cipher::getBlockSize()> &, std::streamsize nbRead, bool, std::array< uint8_t, Cipher::getBlockSize()> &output, uint64_t, Cipher &cipher) override
Definition ofb.hpp:154
virtual ~OFB()
Definition ofb.hpp:130
Cryptography namespace.
Definition base64.hpp:30