torch::Data Bz2::Decompress(const torch::Data &data) { const int size100k = 100000; int bufsize = size100k * Bz2::block100k; int status = 0; bz_stream stream = {0}; Data buf(bufsize); Data dst; dst.HiddenAlloc(data.GetSize() * 2); /* next_in should point at the data to be compressed * avail_in should indicate how many bytes the library may read * BZ2_bzDecompress updates next_in, avail_in and total_in to reflect the number of bytes it has read */ stream.next_in = (char*) data.GetBytes(); stream.avail_in = (int)data.GetSize(); /* next_out should point to a buffer in which the compressed data is to be placed * avail_out indicating how much output space is available. * BZ2_bzDecompress updates next_out, avail_out and total_out to reflect the number of bytes output. */ stream.next_out = (char*)buf.GetBytes(); stream.avail_out = (int)buf.GetSize(); status = BZ2_bzDecompressInit(&stream, 0, 0); if (status != BZ_OK) { BZ2_bzDecompressEnd(&stream); return dst; } do { status = BZ2_bzDecompress(&stream); if (status != BZ_OK && status != BZ_STREAM_END) break; dst.Append(buf.GetBytes(), bufsize - stream.avail_out); stream.next_out = (char*)buf.GetBytes(); stream.avail_out = (int)buf.GetSize(); }while (status != BZ_STREAM_END); BZ2_bzDecompressEnd(&stream); return dst; }
void RC4::CryptoNoCopy(torch::Data &input) { arc4_setup(&m_rc4ctx, (unsigned char *)m_skey.GetBytes(), (int)m_skey.GetSize()); arc4_crypt(&m_rc4ctx, (unsigned char*)input.GetBytes(), (int)input.GetSize()); }
torch::Data AES::DecryptWithCopy(const torch::Data &input) { return this->DecryptWithCopy((unsigned char*)input.GetBytes(), (int)input.GetSize()); }