On Monday, December 21, 2015 at 6:56:03 PM UTC-5, jh...@emocha.com wrote:
>
>
> Small amounts of data do not seem to crash it. In my app I either get a 
> very small amount of data, or a very large amount if data. A small amount 
> is 7-15kB. A large amount is over a 1MB
>
> Data size (in bytes), result:
>
> 1,180,504 locked
>
> 2,709,738 locked
>
> 8,727,128 locked
>
> 7,636 ok
>
> 11,429 ok
>
> 11,512 ok
>
> 11,961 ok
>
> 7,672 ok
>
> 11,460
>
> 975,913 ok (outlier)
>
> 11,600 ok
>

Yeah, the results look about right. Mobile devices only have 512MB to 1GB 
of memory, and they *don't* have page files. You should get an out of 
memory exception or similar if you try to read 2GB or 8GB into memory.

Mobile devices usually require you to decrypt a range (like a 64KB block), 
and then display the range (in a custom UIViewController). It can be tricky 
business.

Now, the lock you are seeing could be two things (maybe more). First, it 
could be CocoaTouch throwing an Objective-C exception. In this case, 
Crypto++ code would be no wiser because its not a C++ exception. Second, it 
could be the Crypto++ library spinning on placement operator new. I have 
never seen how the library performs in this situation.

Related to the second point, there's a brief discussion at 
AllocatorWithCleanup::allocate 
(http://www.cryptopp.com/docs/ref/class_allocator_with_cleanup.html#a213d3399b5e89e61f2bf4fc512da289f).
 
You need to look at misc.cpp, line 195 or so 
(http://www.cryptopp.com/docs/ref/misc_8cpp_source.html#l00195). Pay 
particular attention to the call to CallNewhandler around line 140 
(http://www.cryptopp.com/docs/ref/misc_8cpp_source.html#l00140).

Now, to work around all of this, I think you will need to Pump data in 
blocks of say, 4096. I *think* the source does this, but I don't believe it 
performs a Flush. So data accumulates in the Filter or Sink. This should be 
a non-hard flush. It should not be a MessageEnd() either. See the code 
below.

Jeff

**********

int main(int argc, char* argv[])
{
  static const unsigned int BIG_SIZE = 2U * 1024U * 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, meter = new MeterFilter(new 
FileSink("null.enc")));
  
    SecByteBlock data(BLOCK_SIZE);
    memset(data, 0x00, data.size());

    unsigned int remaining = BIG_SIZE;
    while(remaining)
    {
      if(remaining % (1024*1024) == 0)
      {
        cout << "Processed: " << meter->GetTotalBytes();
        cout << ", Available: " << stf.MaxRetrievable() << endl;
      }

      const unsigned int req = STDMIN(remaining, BLOCK_SIZE);
      stf.Put(data, req);
      stf.Flush(false);

      remaining -= req;
    }
  }
  catch(const Exception& ex)
  {
    cerr << ex.what() << endl;
  }

  return 0;
}

-- 
-- 
You received this message because you are subscribed to the "Crypto++ Users" 
Google Group.
To unsubscribe, send an email to cryptopp-users-unsubscr...@googlegroups.com.
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 cryptopp-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to