Hi All,

I have tried a simple test program in which I just read part of a
file, encrypt it and then print the cipher text to screen. However I
notice when a second thread comes in and work on other parts of the
file, the cipher output is start and this propagate to the rest of
the
files.


Code:
//parallelize
while (!EOF)
{
    ifstream.open();


    //obtain index - codes for obtaining index is correct
    {
        //read from file
        ifstream.seekg(index*size);
        ifstream.read(data,size);


        //encrypt data
        StreamTransformationFilter ab( encryptor,  new
CryptoPP::StringSink( CipherText ) );
        ab.Put( (const byte*)data, data_size );
        ab.MessageEnd();


        //print data
        printf(data);
    }
    ifstream.close();
}


encryptor is global variable.
encryptor is define as:
    CTR_Mode< AES >::Encryption encryptor;
    encryptor.SetKeyWithIV( key, sizeof( key ), iv );

output is correct only when one thread is running 1 thread. Tested by
decrpyting it and compared with original file.
If more than 1 thread is running, the output will be corrupted.


I have also tried encryptor to be private to thread and even variable
to data.
private to thread - every thread has one encrpytor
private to data - every data read, it has one encryptor


Anyone knows why?

On Dec 27, 3:46 pm, eva2002 <[EMAIL PROTECTED]> wrote:
> Hi All,
>
> I am trying out parallel encryption but without any success. Have any
> of you tried out parallel encryption?
>
> CODE:
> StreamTransformationFilter ab( encryptor,  new
> CryptoPP::StringSink( CipherText ) );
> ab.Put( (const byte*)data, data_size );
> ab.MessageEnd();
>
> Cipher: AES        Cipher mode: CTR
>
> I tried to parallelize the above code but once I set more than 1
> thread running the above code, the output (cipher text) will be wrong
> when I diff (linux command) with a correct file.
>
> I have even tried setting individual "StreamTransformationFilter" &
> "encryptor" for each thread.
>
> Can someone give back some feedback on how to work on parallel
> encryption?
>
> The flow of the data in the program should be correct as I have
> already tested my program with compression.
--~--~---------~--~----~------------~-------~--~----~
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