I managed to identify the issues with this code (there were a few). I
will post the completed code when it's a bit neater. Basically the
definition should be more along these lines I think. (problem
understanding why the constructor detaches the attachment).
/// XOR transformation class for pipe-lining
class XORFilter : public CryptoPP::Bufferless<CryptoPP::Filter> {
public:
XORFilter(CryptoPP::BufferedTransformation *attachment = NULL,
std::string pad = ""):
pad_(pad) {
CryptoPP::Filter::Detach(attachment);
};
size_t Put2(const byte* inString,
size_t length,
int messageEnd,
bool blocking);
bool IsolatedFlush(bool, bool) { return false; }
private:
std::string pad_;
};
Thanks everyone
David
On Jul 11, 10:26 pm, dirvine <[email protected]> wrote:
> Hi
>
> I am trying to create a simple transformation that will be pipelined,
> however I think I may be approaching this all wrong. Basically I am
> looking to (ideally) pass a key (or pad) to the stream and xor this
> (repeating the pad if necessary up to size of data stream). Ideally
> non blocking and streaming.
>
> I have been hacking about and think I am going insane doing so :-)
> Here is some examples of what I have been attempting. Please feel free
> to ignore and provide an example of this. Problem seem to perhaps be
> passing the pad or key into the XOR stream, that plus the fact I am
> trying to get used to the library and language. Sorry if it seems a
> bit on the wild side.
>
> I am also looking to pass the xor'ed data down through a pipeline and
> perhaps pass in a string pointer to be populated with a hash of the
> data that was passed through the filter, either that or somehow have
> more than one sink (but that seems very insane :D.
>
> Any help / examples appreciated. I am very new to cryptopp and am not
> getting time to digest all the information properly so please be
> gentle.
>
> Anyway I defined this
> ======================================
> class XORFilter : public CryptoPP::Filter {
> public:
> XORFilter(CryptoPP::BufferedTransformation *attachment = NULL,
> std::string pad = "", // was a pointer to start with
> std::string *result_hash = NULL): Filter(attachment),
> pad_(pad),
> result_hash_(result_hash) {
> // CryptoPP::Filter::Detach(attachment); // unsure of why this
> exists in examples, need to wrap head around terminology
> };
> size_t Put2(const byte* inString,
> size_t length,
> int messageEnd,
> bool blocking);
> bool IsolatedFlush(bool, bool) { return false; }
> private:
> std::string pad_;
> std::string *result_hash_;};
>
> ==================================================
> and implemented something like this (extreme messiness but you get the
> point).
>
> /**
> * Implementation of XOR transformation filter to allow pipe-lining
> *
> */
> size_t XORFilter::Put2(const byte* inString,
> size_t length,
> int messageEnd,
> bool blocking) {
> // Anything to process? If not, we will pass it on
> // to the lower filter just in case... from example
> if((length == 0) || (pad_.length() < length ))
> return AttachedTransformation()->Put2(inString,
> length,
> messageEnd,
> blocking);
> // Do XOR
> byte *buffer;
> byte *pad = new byte[length]; // assuming pad_ is == length for now
> as a test
> memcpy(pad, pad_.c_str(), pad_.length()); / OK dangerous but for
> testing !!
>
> //CryptoPP::xorbuf(pad, inString, length); // tried both xorbuf
> methods
> size_t padlength = pad_.length(); // debugging
>
> for (size_t i = 0; i <= length; ++i) {
> buffer[i] = inString[i] ^ pad[i];
> }
>
> return AttachedTransformation()->Put2(buffer,
> length,
> messageEnd,
> blocking );
>
> }
>
> Anyhow, hope you can help!
>
> David
--
You received this message because you are subscribed to the "Crypto++ Users"
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at
http://www.cryptopp.com.