Example #1
0
	void CEncrypt::CreateEncryptionKey()
	{
        CryptoPP::RandomPool prng;

        CryptoPP::SecByteBlock key(32);
        CryptoPP::OS_GenerateRandomBlock(false, key, key.size());
        prng.IncorporateEntropy(key, key.size());

		memcpy(impl->m_anEncryptionKey, key.data(), key.size());
//-------------------------------------------------------------------

		unsigned long long extended_perms = 0xffffffff00000000LL | m_unPermission;
		for (int i = 0; i < 8; ++i)
		{
			m_anPermEncrypt[i] = static_cast<unsigned char>(extended_perms & 0xff);
			extended_perms >>= 8;
		}
		m_anPermEncrypt[8]	= /*m_bEncryptMetadata ? 'T' : */'F';
		m_anPermEncrypt[9]	= 'a';
		m_anPermEncrypt[10]	= 'd';
		m_anPermEncrypt[11]	= 'b';
        
        CryptoPP::SecByteBlock p(4);
        CryptoPP::OS_GenerateRandomBlock(false, p, p.size());
        prng.IncorporateEntropy(p, p.size());

		memcpy(m_anPermEncrypt + 12, p.data(), p.size());

		unsigned char empty[16] = {};
		
		CryptoPP::AES::Encryption aesEncryption(impl->m_anEncryptionKey, 32);
		
		CryptoPP::CipherModeFinalTemplate_ExternalCipher<CryptoPP::ECB_OneWay> ecbEncryption(aesEncryption, empty ); 

        CryptoPP::StreamTransformationFilter stfEncryption(ecbEncryption, new CryptoPP::ArraySink( m_anPermEncrypt, 16), CryptoPP::StreamTransformationFilter::NO_PADDING );
        stfEncryption.Put2(m_anPermEncrypt, 16, 1, true);
        stfEncryption.MessageEnd();
	}
Example #2
0
        void Reset()
        {
            if (streamEncryption)
                delete streamEncryption;
            if (aesEncryption)
                delete aesEncryption;

			CryptoPP::RandomPool prng;
			CryptoPP::SecByteBlock iv(16);
			CryptoPP::OS_GenerateRandomBlock(false, iv, iv.size());
			prng.IncorporateEntropy(iv, iv.size());

			memcpy(streamInitialization, iv, iv.size());
			
			aesEncryption       = new CryptoPP::AES::Encryption(m_anEncryptionKey, 32);
            streamEncryption    = new CryptoPP::CBC_Mode_ExternalCipher::Encryption( *aesEncryption, streamInitialization);
        }
Example #3
0
	void CEncrypt::CreateOwnerKey()
	{
        CryptoPP::RandomPool prng;

        CryptoPP::SecByteBlock salt(16);
        CryptoPP::OS_GenerateRandomBlock(false, salt, salt.size());
        prng.IncorporateEntropy(salt, salt.size());

        memcpy(m_anOwnerKey + 32, salt.data(), salt.size());

        CryptoPP::SHA256 hash;

        hash.Update( (unsigned char*) impl->m_sOwnerPassword.c_str(), impl->m_sOwnerPassword.length());
        hash.Update( m_anOwnerKey + 32, 8);
        hash.Update( m_anUserKey, 48);

        CryptoPP::SecByteBlock pHashData(hash.DigestSize());
        hash.Final(pHashData);

        if (MakeFileKey3(impl->m_sOwnerPassword, pHashData.data(), pHashData.size(), m_anUserKey, 48))
        {
            memcpy(m_anOwnerKey, pHashData.data(), pHashData.size());

            hash.Update( (unsigned char*) impl->m_sOwnerPassword.c_str(), impl->m_sOwnerPassword.length());
            hash.Update( m_anOwnerKey + 40, 8);
            hash.Update( m_anUserKey, 48);

            CryptoPP::SecByteBlock pHashKeyData(hash.DigestSize());
            hash.Final(pHashKeyData);

            MakeFileKey3(impl->m_sOwnerPassword, pHashKeyData.data(), pHashKeyData.size(), m_anUserKey, 48);
            unsigned char empty[16] = {};

            CryptoPP::AES::Encryption aesEncryption(pHashKeyData.data(), pHashKeyData.size());
            CryptoPP::CBC_Mode_ExternalCipher::Encryption cbcEncryption( aesEncryption, empty);

            CryptoPP::StreamTransformationFilter stfEncryption(cbcEncryption, new CryptoPP::ArraySink( m_anOwnerEncryptKey, 32), CryptoPP::StreamTransformationFilter::NO_PADDING );
            stfEncryption.Put2(impl->m_anEncryptionKey, 32, 1, true);
            stfEncryption.MessageEnd();
        }
	}