I wanted to report a bug with Mac OS X 10.2.4. This may be the same problem that was reported yesterday by Jason Arnold. I don't have a bugfix for this but when I have time I'll continue to investigate.
The code I'm pasting below will compile and execute without errors on Linux, but on Mac OS X it simply prints "Abort" and exits. More commentary and a backtrace to follow the source code.
#include <iostream.h>
#include "aes.h"
#include "modes.h"
#include "files.h"
#include "osrng.h"
int main(int argc, char *argv[])
{
using namespace CryptoPP;
AutoSeededRandomPool rng;
byte key[AES::DEFAULT_KEYLENGTH], iv[AES::BLOCKSIZE];
rng.GenerateBlock(key, AES::DEFAULT_KEYLENGTH);
rng.GenerateBlock(iv, AES::BLOCKSIZE);
std::string strEncrypted, strCiphertext1, strCiphertext2;
std::string strPlaintext1 = "Hello, world!", strPlaintext2 = "Second string";
CBC_Mode<AES >::Encryption cbcEncryption(key, AES::DEFAULT_KEYLENGTH, iv);
StreamTransformationFilter cbcEncryptor(cbcEncryption, new StringSink(strEncrypted));
cbcEncryptor.Put((const unsigned char *)strPlaintext1.c_str(), strPlaintext1.size());
cbcEncryptor.MessageEnd();
strCiphertext1 = strEncrypted;
strEncrypted = "";
// Should I call GetNextIV() or do something with the IV before doing this?
cbcEncryptor.Put((const unsigned char *)strPlaintext2.c_str(), strPlaintext2.size());
cbcEncryptor.MessageEnd();
strCiphertext2 = strEncrypted;
std::string strDecrypt, strDecrypted1, strDecrypted2;
CBC_Mode<AES >::Decryption cbcDecryption(key, AES::DEFAULT_KEYLENGTH, iv);
StreamTransformationFilter cbcDecryptor(cbcDecryption, new StringSink(strDecrypt));
cbcDecryptor.Put((const unsigned char *)strCiphertext1.c_str(), strCiphertext1.size());
cbcDecryptor.MessageEnd();
strDecrypted1 = strDecrypt;
strDecrypt = "";
cbcDecryptor.Put((const unsigned char *)strCiphertext2.c_str(), strCiphertext2.size());
cbcDecryptor.MessageEnd();
strDecrypted2 = strDecrypt;
cout << strPlaintext1 << " : " << strDecrypted1 << endl;
cout << strPlaintext2 << " : " << strDecrypted2 << endl;
return 0;
}
Using gdb I've found that it dies on line 25, in the call to MessageEnd().
I'm pasting a backtrace of the error. It seems to indicate that there may be a bug in std::string on Mac OS X? I have to admit that the backtrace doesn't seem to make much sense to me, and I'm not very familiar with debugging programs on UNIX. Perhaps somebody can give me some suggestions as to what to try from this point on, or how to continue debugging this.
#0 0x9001b52c in kill ()
#1 0x9005ceec in abort ()
#2 0x000639e0 in __cxxabiv1::__terminate(void (*)()) () at asn.h:554
#3 0x00063a4c in std::terminate() () at asn.h:554
#4 0x00057170 in __cxa_throw () at asn.h:554
#5 0x000554c8 in std::__throw_logic_error(char const*) () at asn.h:554
#6 0x000474a8 in char* std::string::_S_construct<char const*>(char const*, char const*, std::allocator<char> const&, std::forward_iterator_tag) () at asn.h:554
#7 0x00046c80 in std::string::string<char const*>(char const*, char const*, std::allocator<char> const&) () at asn.h:554
#8 0x00046f7c in std::string& std::string::_M_replace<char const*>(__gnu_cxx::__normal_iterator<char*, std::string>, __gnu_cxx::__normal_iterator<char*, std::string>, char const*, char const*, std::input_iterator_tag) () at asn.h:554
#9 0x00071434 in std::string& std::string::replace<char const*>(__gnu_cxx::__normal_iterator<char*, std::string>, __gnu_cxx::__normal_iterator<char*, std::string>, char const*, char const*) (this=0xbffffb20, __i1={<iterator<std::random_access_iterator_tag,char,int,char*,char&>> = {<No data fields>}, _M_current = 0x43765c ""}, __i2={<iterator<std::random_access_iterator_tag,char,int,char*,char&>> = {<No data fields>}, _M_current = 0x43765c ""}, __k1=0x0, __k2=0x0) at /usr/include/gcc/darwin/3.1/g++-v3/bits/basic_string.h:685
#10 0x000707e4 in std::string& std::string::append<char const*>(char const*, char const*) (this=0xbffffb20, __first=0x0, __last=0x0) at /usr/include/gcc/darwin/3.1/g++-v3/bits/basic_string.h:472
#11 0x0006f794 in CryptoPP::StringSinkTemplate<std::string>::Put2(unsigned char const*, unsigned, int, bool) (this=0x437bf0, begin=0x0, length=0, messageEnd=-2, blocking=true) at ../crypto++/filters.h:496
#12 0x0000de7c in CryptoPP::Filter::Output(int, unsigned char const*, unsigned, int, bool, std::string const&) (this=0xbffffbc0, outputSite=1, inString=0x0, length=0, messageEnd=-2, blocking=true, [EMAIL PROTECTED]) at filters.cpp:105
#13 0x0000f56c in CryptoPP::FilterWithBufferedInput::PutMaybeModifiable(unsigned char*, unsigned, int, bool, bool) (this=0xbffffbc0, inString=0x0, length=0, messageEnd=-1, blocking=true, modifiable=false) at filters.cpp:338
#14 0x00088114 in CryptoPP::FilterWithBufferedInput::Put2(unsigned char const*, unsigned, int, bool) (this=0xbffffbc0, inString=0x0, length=0, messageEnd=-1, blocking=true) at filters.cpp:138
#15 0x0006e4a4 in CryptoPP::BufferedTransformation::MessageEnd(int, bool) (this=0xbffffbc0, propagation=-1, blocking=true) at ../crypto++/cryptlib.h:705
#16 0x00002a6c in main (argc=1, argv=0xbffffde8) at testcrypto++.cpp:25
#17 0x000025f0 in _start (argc=1, argv=0xbffffde8, envp=0xbffffdf0) at /SourceCache/Csu/Csu-45/crt.c:267
#18 0x00002470 in start ()
--
Michael Monsen
There are 10 kinds of people in this world.
Those who understand binary, and those who don't.
- Re: Mac OS X compiles cleanly, but execution fails Michael Monsen
