On Mon, Apr 28, 2008, Vishal Rao wrote:

> 
> C++ code using OpenSSL:
> 
> unsigned char testplaintext[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
> unsigned char ciphertext[100] = {0};
> int outlen, tmplen;
> 
> unsigned char key[56] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
> 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
> 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
> 48, 49, 50, 51, 52, 53, 54, 55, 56};
> unsigned char iv[8] = {1, 2, 3, 4, 5, 6, 7, 8};
> 
> EVP_CIPHER_CTX ctx;
> EVP_CIPHER_CTX_init(&ctx);
> EVP_EncryptInit_ex(&ctx, EVP_bf_cbc(), NULL, key, iv);
> EVP_EncryptUpdate(&ctx, ciphertext, &outlen, testplaintext, 10);
> EVP_EncryptFinal_ex(&ctx, ciphertext + outlen, &tmplen);
> outlen += tmplen;
> EVP_CIPHER_CTX_cleanup(&ctx);
> 

The call to EVP_EncryptInit_ex() uses the default key length for the cipher
unless told otherwise. For Blowfish this is 128 bits but you have a 56 byte
(?) key. You need to set the key length using EVP_CIPHER_CTX_set_key_length().
This involves a double call to EVP_EncryptInit_ex(). See the manual pages for
more information.

Steve.
--
Dr Stephen N. Henson. Email, S/MIME and PGP keys: see homepage
OpenSSL project core developer and freelance consultant.
Homepage: http://www.drh-consultancy.demon.co.uk
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to