Skip to content

Commit

Permalink
Add AESLZ4 and AESLZ4HC modes
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Chapman <[email protected]>
  • Loading branch information
richardkchapman committed Nov 8, 2023
1 parent 797a119 commit 8f3e079
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 16 deletions.
56 changes: 44 additions & 12 deletions system/jlib/jlzw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2608,10 +2608,10 @@ ICompressedFileIO *createCompressedFileWriter(IFile *file,size32_t recordsize,bo

#define AES_PADDING_SIZE 32


class CAESCompressor : implements ICompressor, public CInterface
{
Owned<ICompressor> comp; // base compressor
private:
Owned<ICompressor> comp;
MemoryBuffer compattr; // compressed buffer
MemoryAttr outattr; // compressed and encrypted (if outblk NULL)
void *outbuf; // dest
Expand All @@ -2620,13 +2620,11 @@ class CAESCompressor : implements ICompressor, public CInterface
size32_t originalMax = 0;
MemoryAttr key;
MemoryBuffer *outBufMb;

public:
IMPLEMENT_IINTERFACE;
CAESCompressor(const void *_key, unsigned _keylen)
: key(_keylen,_key)
CAESCompressor(const void *_key, unsigned _keylen, ICompressor *_comp)
: comp(_comp), key(_keylen,_key)
{
comp.setown(createLZWCompressor(true));
outlen = 0;
outmax = 0;
outBufMb = NULL;
Expand Down Expand Up @@ -2726,10 +2724,10 @@ class CAESExpander : implements CExpanderBase
MemoryBuffer compbuf;
MemoryAttr key;
public:
CAESExpander(const void *_key, unsigned _keylen)
CAESExpander(const void *_key, unsigned _keylen, IExpander *_exp)
: key(_keylen,_key)
{
exp.setown(createLZWExpander(true));
exp.setown(_exp);
}
size32_t init(const void *blk)
{
Expand Down Expand Up @@ -2759,11 +2757,11 @@ class CAESExpander : implements CExpanderBase

ICompressor *createAESCompressor(const void *key, unsigned keylen)
{
return new CAESCompressor(key,keylen);
return new CAESCompressor(key,keylen,createLZWCompressor(true));
}
IExpander *createAESExpander(const void *key, unsigned keylen)
{
return new CAESExpander(key,keylen);
return new CAESExpander(key,keylen,createLZWExpander(true));
}

#define ROTATE_BYTE_LEFT(x, n) (((x) << (n)) | ((x) >> (8 - (n))))
Expand All @@ -2790,14 +2788,14 @@ ICompressor *createAESCompressor256(size32_t len, const void *key)
{
byte k[32];
padKey32(k,len,(const byte *)key);
return new CAESCompressor(k,32);
return new CAESCompressor(k,32,createLZWCompressor(true));
}

IExpander *createAESExpander256(size32_t len, const void *key)
{
byte k[32];
padKey32(k,len,(const byte *)key);
return new CAESExpander(k,32);
return new CAESExpander(k,32,createLZWExpander(true));
}


Expand Down Expand Up @@ -2940,6 +2938,38 @@ MODULE_INIT(INIT_PRIORITY_STANDARD)
return createAESExpander(options, strlen(options));
}
};
class CAESLZ4CompressHandler : public CCompressHandlerBase
{
public:
virtual const char *queryType() const { return "AESLZ4"; }
virtual CompressionMethod queryMethod() const { return (CompressionMethod) (COMPRESS_METHOD_AES|COMPRESS_METHOD_LZ4); }
virtual ICompressor *getCompressor(const char *options)
{
assertex(options);
return new CAESCompressor(options, strlen(options),createLZ4Compressor(nullptr));
}
virtual IExpander *getExpander(const char *options)
{
assertex(options);
return new CAESExpander(options, strlen(options), createLZ4Expander());
}
};
class CAESLZ4HCCompressHandler : public CCompressHandlerBase
{
public:
virtual const char *queryType() const { return "AESLZ4HC"; }
virtual CompressionMethod queryMethod() const { return (CompressionMethod) (COMPRESS_METHOD_AES|COMPRESS_METHOD_LZ4HC); }
virtual ICompressor *getCompressor(const char *options)
{
assertex(options);
return new CAESCompressor(options, strlen(options),createLZ4Compressor(nullptr, true));
}
virtual IExpander *getExpander(const char *options)
{
assertex(options);
return new CAESExpander(options, strlen(options), createLZ4Expander());
}
};
class CDiffCompressHandler : public CCompressHandlerBase
{
public:
Expand Down Expand Up @@ -2974,6 +3004,8 @@ MODULE_INIT(INIT_PRIORITY_STANDARD)
};
addCompressorHandler(new CLZWCompressHandler());
addCompressorHandler(new CAESCompressHandler());
addCompressorHandler(new CAESLZ4CompressHandler());
addCompressorHandler(new CAESLZ4HCCompressHandler());
addCompressorHandler(new CDiffCompressHandler());
addCompressorHandler(new CRDiffCompressHandler());
addCompressorHandler(new CRandRDiffCompressHandler());
Expand Down
8 changes: 4 additions & 4 deletions testing/unittests/jlibtests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3146,15 +3146,15 @@ class JlibCompressionTestsStress : public CppUnit::TestFixture
if (c2b)
{
CCycleTimer timer;
compressToBuffer(compressed, src.length(), src.bytes(), handler.queryMethod(), streq("AES", handler.queryType()) ? aesKey: nullptr);
compressToBuffer(compressed, src.length(), src.bytes(), handler.queryMethod(), handler.queryMethod() & COMPRESS_METHOD_AES ? aesKey: nullptr);
compressCycles = timer.elapsedCycles();
timer.reset();
decompressToBuffer(tgt, compressed, streq("AES", handler.queryType()) ? aesKey: nullptr);
decompressToBuffer(tgt, compressed, handler.queryMethod() & COMPRESS_METHOD_AES ? aesKey: nullptr);
decompressCycles = timer.elapsedCycles();
}
else
{
Owned<ICompressor> compressor = handler.getCompressor(streq("AES", handler.queryType()) ? aesKey: nullptr);
Owned<ICompressor> compressor = handler.getCompressor(handler.queryMethod() & COMPRESS_METHOD_AES ? aesKey: nullptr);

CCycleTimer timer;
compressor->open(compressed, sz);
Expand All @@ -3170,7 +3170,7 @@ class JlibCompressionTestsStress : public CppUnit::TestFixture
compressor->close();
compressCycles = timer.elapsedCycles();

Owned<IExpander> expander = handler.getExpander(streq("AES", handler.queryType()) ? aesKey: nullptr);
Owned<IExpander> expander = handler.getExpander(handler.queryMethod() & COMPRESS_METHOD_AES ? aesKey: nullptr);

timer.reset();
size32_t required = expander->init(compressed.bytes());
Expand Down

0 comments on commit 8f3e079

Please sign in to comment.