Padding not removed after decryption (Twofish)

47 views
Skip to first unread message

rajkosto

unread,
Jul 3, 2009, 12:10:51 PM7/3/09
to Crypto++ Users
Hello, i use crypto++ for encrypting/decrypting with Twofish.
The problem i have is, that after encrypting data, then decrypting
that exact data, the padding remains.
This is how i encrypt and decrypt

string input = { some hex bytes };

CryptoPP::CBC_Mode<CryptoPP::Twofish>::Encryption TFEncryptGTC;

//Set IV
TFEncryptGTC.Resynchronize(vector);

//encrypt
string encrypted;
CryptoPP::StringSource(input, true, new
CryptoPP::StreamTransformationFilter(TFEncryptGTC, new
CryptoPP::StringSink(encrypted)));

//After that, i do the reverse with the data i got after encrypting

CryptoPP::CBC_Mode<CryptoPP::Twofish>::Decryption TFDecryptGTC;

//Set IV (same as the one used for encryption ofcourse)
TFDecryptGTC.Resynchronize(vector);

//decrypt
string output;

CryptoPP::StringSource(encrypted, true, new
CryptoPP::StreamTransformationFilter(TFDecryptGTC, new
CryptoPP::StringSink(output)));

the output i get isnt the same as the input i put in ! instead, it's
input + some bytes like 0x00 0xcd 0xcd 0xcd or 0x00 0xfd 0xfd 0xfd...

if i run this output through encryption and decryption again, i will
get another trailing padding ! so it would have 2 times 0x00 0xcd 0xcd
0xcd at the end...

why isnt decryption removing the padding that streamtransformation
added to perform encryption properly ?

Jeffrey Walton

unread,
Jul 3, 2009, 3:01:46 PM7/3/09
to rajkosto, Crypto++ Users
> input + some bytes like 0x00 0xcd 0xcd 0xcd or
> 0x00 0xfd 0xfd 0xfd...
This appears to be is uninitialized memory in a Debug build. I suspect
it is coming form Visual Studio, and not Crypto++.

> string input = { some hex bytes };

Most likely the culprit

Jeff

rajkosto

unread,
Jul 3, 2009, 6:04:09 PM7/3/09
to Crypto++ Users
you were right. thanks.
and that wasnt the culprit, i was making length +4 more than it was
somewhere
i recoded the entire thing now, and it doesnt happen
Reply all
Reply to author
Forward
0 new messages