Hello

We recently upgraded the version of OpenSSL used in our application from
0.9.6c to 0.9.8e.  Everything is fine except I have found that some of our
code was using memcpy() to 'save' and 'restore' EVP_CIPHER_CTX structures.
I understand now from looking at the OpenSSL code that this use was invalid
since we should not assume that an EVP_CIPHER_CTX can be correctly copied
via a simple memcpy().

My question: Is there a valid way to copy an EVP_CIPHER_CTX structure?  I
have created a function which does this as a hack to get us up and running:

int EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX *out, const EVP_CIPHER_CTX *in)
{
    int retval = EVP_CipherInit_ex(out, EVP_CIPHER_CTX_cipher(in),
in->engine,
                                NULL, /* key */
                                NULL, /* iv */
                                in->encrypt);
    if (retval == 1)
    {
        memcpy(out->cipher_data, in->cipher_data, in->cipher->ctx_size);
    }
    return retval;
}



Our goal is really to save and restore the cipher state of an RC4 cipher
context.  It does not seem to be possible to ask an EVP_CIPHER_CTX to save
and restore it's internal state.  Any ideas would be welcomed?

Sam Elstob
Product Developer
Triometric

e: [EMAIL PROTECTED]
t: +44 (0)1784 497 366
f: +44 (0)1494 400 077
w: http://www.triometric.net

Orchard Building, Royal Holloway, Egham, Surrey TW20 0EX UK
Triometric is the trading name of Hypertrak Limited.
Registered in England and Wales No. 3893713, VAT 727292030

Reply via email to