Honestly, I am out of ideas.
Here is the code that causes the problem and everything that is needed to
understand it:
-------------------------------------------------------------------------------------------------------------------
byte key[16], iv[16];
if(mode == Encrypt)
{
/** ENCRYPTION **/
*//Generating and writing the IV*
AutoSeededRandomPool rnd; rnd.GenerateBlock(iv, sizeof(iv));
Out.write(iv, sizeof(iv)); *//See >1*
*//Deriving the key*
DeriveKey(key, sizeof(key), iv, sizeof(iv), password); *//See >2*
*//Getting file size*
fsize = file_sizes[task_index];
*//Creating the Entangle header*
Header MakeHeader(fsize); *//See >3*
/** Encrypting and writing the header **/
try
{
*//New AES Encryption object*
GCM<AES>::Encryption e;
*//Setting user key and random IV*
e.SetKeyWithIV(key, sizeof(key), iv, sizeof(iv));
*//Filter with an EntangleSink*
AuthenticatedEncryptionFilter ef(e,
new EntangleSink(Out), false, TAG_SIZE); *//See >4*
*//Encrypting MakeHeader*
ef.ChannelPut("", (const byte*)&MakeHeader, sizeof(MakeHeader));
ef.ChannelMessageEnd(""); *//This line is shown as assert's
reason, although the call stack points to GCM_Final's destructor.*
}
...............
}
*--------------- Extra #1 --------------*
// A simple fstream wrapper
bool BinFile::write(const byte* data, int size, bool flush)
{
if(!(mode & ios_base::out)) return false;
try
{
cfile.write(reinterpret_cast<const char*>(data), size);
if(flush) cfile.flush();
}
catch(ios_base::failure & except)
{
return false;
}
return true;
}
*--------------- Extra #2 --------------*
void DeriveKey(byte key[], size_t key_size, byte iv[], size_t iv_size,
wxString & password)
{
/** Deriving a key from password **/
//Convert password to UTF-8
wxCharBuffer cbuff = password.mb_str(wxMBConvUTF8());
//Derive the key
PKCS5_PBKDF2_HMAC<SHA512> KeyDeriver;
KeyDeriver.DeriveKey(key, key_size, (byte)0, (byte*)cbuff.data(),
cbuff.length(), iv, iv_size, 1);
}
*--------------- Extra #3 --------------*
struct Header
{
//Constructors
Header() { }
Header(unsigned long long file_size);
//Data
int core_version; /* Header format version */
unsigned long long file_size; /* Size of original file */
byte keys[32]; /* AES-256 key storage area */
};
Header::Header(unsigned long long fsize)
{
//Clean the header
memset(this, 0x00, sizeof(Header));
//Set the file size
file_size = fsize;
//Write the version of my lovely program \(^_^)/
core_version = ENTANGLE_CORE;
//Generate random keys
RandomGenerator rnd;
rnd.GenerateBlock(keys, 32);
}
*--------------- Extra #4 --------------*
/* A sink class; writes data from a AES/GCM filter to a binary file */
class EntangleSink : public Bufferless<Sink>
{
public:
//Constructor (accepts link to a BinFile object)
EntangleSink(BinFile & g_output) : output(g_output) { }
//Destructor
~EntangleSink() { }
//Function which accepts data from AES/GCM and writes to the file
size_t Put2(const byte *inString, size_t length, int, bool);
private:
BinFile & output;
};
//Function which accepts data from AES/GCM and writes to the file
size_t EntangleSink::Put2(const byte *inString, size_t length, int, bool)
{
if(!inString || !length) return length;
//Writing the data
assert(output.is_open());
output.write(inString, length, true);
return 0;
}
*------------ Assert info -------------*
class FixedSizeAllocatorWithCleanup::void deallocate(void *p, size_type n)
{
if (p == GetAlignedArray())
{
assert(n <= S); *//Shown only in Release builds, causes a crash*
assert(m_allocated); *//Shown in both Debug and Release builds, can be
skipped without any trouble*
m_allocated = false;
SecureWipeArray((pointer)p, n);
}
else
m_fallbackAllocator.deallocate(p, n);
}
*The element that is deallocated always has 44 byte size.*
Header: 48
TAG_SIZE: 16
*Call stack:*
<https://lh3.googleusercontent.com/-xEKtX1bcI84/VbDBoyBiiVI/AAAAAAAAAyA/WWcG-jMvoFk/s1600/2015-07-22%2B04-36-02%2B%25D0%25A1%25D0%25BA%25D1%2580%25D0%25B8%25D0%25BD%25D1%2588%25D0%25BE%25D1%2582%2B%25D1%258D%25D0%25BA%25D1%2580%25D0%25B0%25D0%25BD%25D0%25B0.png>
Same thing happens on decryption.
*Please, help me to solve this problem! *
--
--
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.