On Thu, Apr 22, 2004, Eric Morris wrote: > I have a situation where an application may switch from reading to > writing and back again at random. Do I need a ctx context each for > decryption / encryption, or can I use the same ctx in sequence on the file? > > When switching from reading to writing (and vice versa), do I need to > detect this change and call EVP_CipherInit_ex to alter the context ctx > accordingly? Furthermore, do I need to call EVP_CipherFinal before the > call to EVP_CipherInit to finalize the ctx for the prior mode? > > My next question involves the encryption of very short strings (less > than the cipher block size)... does the ctx "buffer" these short strings > until either another call to the Update function fills out the block > and/or the Final function is called? I will have unpredictable string > lengths being encrypted, and I do not want to introduce padding into the > middle of the encrypted files. >
It would be best to have two contexts. Any partial block is buffered when you call EVP_CipherUpdate(). The data is written out when a full block is received. Padding only occurs when you call EVP_CipherFinal(). Steve. -- Dr Stephen N. Henson. Email, S/MIME and PGP keys: see homepage OpenSSL project core developer and freelance consultant. Funding needed! Details on homepage. Homepage: http://www.drh-consultancy.demon.co.uk ______________________________________________________________________ OpenSSL Project http://www.openssl.org User Support Mailing List [EMAIL PROTECTED] Automated List Manager [EMAIL PROTECTED]