> 1. [As discussed before] For some reason FileSource with the pump > argument=true attempts to allocate the entire size of the file? This is a > terrible idea. Why doesn't it pump() manageable chunks in a loop internally? >
I'm not sure. I have not stepped that code in a while. I just manually Pump() when its a concern to me. You can also avoid it all together, if you like. Just use Put(), MaxRetrievable() and Get(). That's all the pipeline and filters do for you. The upstream source or filter will call Put() on its AttachedTransformation(). There's nothing mystical about it. > 2. In order to not lock the GUI, I had to split the calls into a stateful > class, where I have Configure, Open and Pump. Then I realized there is no > Close(). I was going to cleanup in the Close(). > Most of the objects you are using follow the Init/Update/Final model. Init() is really just C++ RAII (https://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization). Update() is calls to Put(). Final() is a call to MessageEnd(). When its time to release the resource acquired during construction, delete the object and set its pointer to NULL. The dtor should call MessageEnd() for you. > 3. Also with 2, everything is set to automatically delete the attachments > automatically. This is a bad idea and confuses ownership. Then I tried > using Ref() but that doesn't work with pointers. > You should be able to use a Redirector (https://www.cryptopp.com/wiki/Redirector). See the example below. > 4. I'm targeting many platforms, so XCode specifics should not apply. > You might consider visiting https://wiki.qt.io/Profiling_and_Memory_Checking_Tools , and try to use some of them to locate memory problems. I'm fairly sure they are present. If you really feel there are no memory problems, then look at configuration issues (like mixing/matching C++ runtime and STL libraries), and platform issues (like running out of memory or C++ ofstream not flushing when its told to do so). Maybe its a hardware problem... I used to help the OpenSSL Foundation with their iOS FIPS Validations (their office was about 45 minutes from my house). The FIPS validation self tests would run for a day or two. The devices got so hot we had to prop them up and put a fan on them. Otherwise, the tablet would lock up after a few hours. ***** #include "filters.h" #include "osrng.h" #include "modes.h" #include "files.h" #include "aes.h" #include "hex.h" using namespace CryptoPP; #include <iostream> using namespace std; int main(int argc, char* argv[]) { static const unsigned int BIG_SIZE = 2U * 1024U * 1024U; static const unsigned int BLOCK_SIZE = 4096U; try { SecByteBlock key(32); OS_GenerateRandomBlock(false, key.data(), key.size()); // cout << "Key: "; // ArraySource as(key.data(), key.size(), true, new HexEncoder(new FileSink(cout))); // cout << endl; CFB_Mode<AES>::Encryption enc; enc.SetKeyWithIV(key.data(), key.size(), key.data()); MeterFilter meter; StreamTransformationFilter stf(enc); FileSource source("/dev/zero", false); FileSink sink("zero.enc"); source.Attach(new Redirector(stf)); stf.Attach(new Redirector(meter)); meter.Attach(new Redirector(sink)); unsigned int remaining = BIG_SIZE; while(remaining && !source.SourceExhausted()) { if(remaining % (1024) == 0) { cout << "Processed: " << meter.GetTotalBytes() << endl; } const unsigned int req = STDMIN(remaining, BLOCK_SIZE); source.Pump(req); source.Flush(false); remaining -= req; } } catch(const Exception& ex) { cerr << ex.what() << endl; } return 0; } ***** Here are the results of running it under a BeagleBone Black. Its resource constrained, too. I can duplicate these results everywhere, from a full fledged desktop to an Android tablet to a JB iOS device. beaglebone:cryptopp$ rm -f *.enc && ./test.exe Processed: 0 Processed: 4096 Processed: 8192 Processed: 12288 Processed: 16384 ... Processed: 2088960 Processed: 2093056 beaglebone:cryptopp$ ls -l *.enc -rw-r--r-- 1 jwalton jwalton 2097152 Dec 23 06:16 zero.enc beaglebone:cryptopp$ -- -- 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. --- You received this message because you are subscribed to the Google Groups "Crypto++ Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
