Hi Mikhail,

> Any comments/suggestions/criticisms would be greatly
> appreciated.
Here goes...

> memcpy(Key(),key,CryptoPP::AES::DEFAULT_KEYLENGTH);
> memcpy(IV(),iv,CryptoPP::AES::BLOCKSIZE);
I believe these will produce incorrect results, since Key() and IV()
should evaluate to functions. Are you not receiving a compile warning
or error?

> GetMaximumCypherTextLength() ...
Perhaps changing this to GetMaximumCypherTextLength() would be more appropriate.

> char KEYBLOCK[KEYBLOCKSIZE];
I'm not sure what this character's role might be...

> char *Key()...
> char *IV()...
Do you not have a byte data type available?

> AESResult Encrypt(const char* src, unsigned length)
Then, during the encryption, you can return the actual size of the
cipher text (is AESResult a structure or class?) so that a client will
decrypt the actual number of bytes, rather than a maximum.

I don't believe the problem is that hard... I would define my message
format (perhaps a type/size/data tuple), agree on a Key and IV, snatch
code from the FAQ (http://www.cryptopp.com/fom-serve/cache/79.html) or
Wiki (http://www.cryptopp.com/wiki/Symmetric_Cipher), and let TCP
handle the rest...

Jeff

On 10/17/07, Mikhail Davidov <[EMAIL PROTECTED]> wrote:
>
> Hello everyone,
>
> I was wondering if I could get some feedback on a wrapper that I wrote
> to simplify CBC AES.  Right now the only problem that I see is that
> I'm over-allocating the array on the decrypt method by a maximum of 15
> bytes (AES::BLOCKSIZE-1)
>
> This email is kinda stemming from the confusion about the initial IV values.
>
> A little background on the usage of the class:  It is used to encrypt
> packet data for a game I am working on.  The plaintext of the packet
> gets encrypted with the Encrypt() method and then RSAES<OAEP<SHA>> is
> used to encrypt the AES Key and IV which is added to the packet
> header.  Any comments/suggestions/criticisms would be greatly
> appreciated.
>
>
> #include "crypt/aes.h"
> #include "crypt/modes.h"
>
> typedef boost::shared_array<char> SHCHAR;
> class CAESProvider
> {
>        static CryptoPP::AutoSeededRandomPool  m_RPool; //instantiated in .cpp
>
> public:
>        struct AESResult
>        {
>                static const size_t KEYBLOCKSIZE =
> CryptoPP::AES::DEFAULT_KEYLENGTH+CryptoPP::AES::BLOCKSIZE;
>                AESResult(const char *key,const char *iv)
>                {
>                        if(key && iv)
>                        {
>                                
> memcpy(Key(),key,CryptoPP::AES::DEFAULT_KEYLENGTH);
>                                memcpy(IV(),iv,CryptoPP::AES::BLOCKSIZE);
>                        }
>                }
>                char KEYBLOCK[KEYBLOCKSIZE];
>
>                char *Key() { return KEYBLOCK; }
>                char *IV() { return KEYBLOCK+CryptoPP::AES::DEFAULT_KEYLENGTH; 
> }
>                SHCHAR Data;
>                unsigned DataLength;
>
>        };
>        static unsigned GetCypherTextLength(unsigned size)
>        {
>                return size+size%CryptoPP::AES::BLOCKSIZE;
>        }
>        static AESResult Encrypt(const char* src,unsigned length)
>        {
>                AESResult result(NULL,NULL);
>
>                m_RPool.GenerateBlock((byte 
> *)result.Key(),CryptoPP::AES::DEFAULT_KEYLENGTH);
>                m_RPool.GenerateBlock((byte 
> *)result.IV(),CryptoPP::AES::BLOCKSIZE);
>
>                result.DataLength = GetCypherTextLength(length);
>                result.Data = SHCHAR(new char[result.DataLength]);
>
>                CryptoPP::AES::Encryption aesEncryption((byte *)result.Key(),
> CryptoPP::AES::DEFAULT_KEYLENGTH);
>                CryptoPP::CBC_Mode_ExternalCipher::Encryption
> cbcEncryption(aesEncryption, (byte *)result.IV());
>
>                CryptoPP::ArraySink *buffSink = new CryptoPP::ArraySink((byte
> *)result.Data.get(),result.DataLength);
>                CryptoPP::StreamTransformationFilter 
> cbcFilter(cbcEncryption,buffSink);
>
>                cbcFilter.Put((byte *)src,length);
>                cbcFilter.MessageEnd();
>
>                _ASSERTE(buffSink->TotalPutLength() == result.DataLength);
>
>                return result;
>
>        }
>        static AESResult Decrypt(const char *src,unsigned length,const char
> *Key,const char *IV)
>        {
>                AESResult result(NULL,NULL);
>                result.Data = SHCHAR(new char[length]);
>                CryptoPP::AES::Decryption aesDecryption((byte *)Key,
> CryptoPP::AES::DEFAULT_KEYLENGTH);
>                CryptoPP::CBC_Mode_ExternalCipher::Decryption cbcDecryption(
> aesDecryption, (byte *)IV);
>
>                CryptoPP::ArraySink *buffSink = new CryptoPP::ArraySink((byte
> *)result.Data.get(),length);
>
>                CryptoPP::StreamTransformationFilter 
> stfDecryptor(cbcDecryption, buffSink);
>                stfDecryptor.Put((byte *)src,length );
>                stfDecryptor.MessageEnd();
>
>                result.DataLength = (unsigned)buffSink->TotalPutLength();
>
>                return result;
>
>        }
>
> };
>
> Thanks,
>
> Mikhail Davidov
> DigiPen '09

--~--~---------~--~----~------------~-------~--~----~
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.
-~----------~----~----~----~------~----~------~--~---

Reply via email to