> I think part of my problem is that EVP_BytesToKey only returns a 16 byte key.
You will probably need to duplicate Crypt-CBC-2.30's algorithm for
creating or deriving the key. Blowfish uses a variable length key
(some hand waiving) [1], so there should be no algorithm to duplicate.
Use the 56 bytes directly.

If I'm wrong about Blowfish or the way Crypt-CBC-2.30 works, then my
apologies. I don't use either of them.

Jeff

[1] http://www.schneier.com/blowfish.html

On Thu, Sep 16, 2010 at 5:35 PM, Eric Nichols (DirWiz) <e...@dirwiz.com> wrote:
> I am working with a legacy app and need to use OpenSSL to decrypt
> Blowfish-cbc.  The library in question
> (http://search.cpan.org/~lds/Crypt-CBC-2.30/CBC.pm) uses a 56 byte key size
> while OpenSSL defaults to a 16 byte key size.
>
> I think part of my problem is that EVP_BytesToKey only returns a 16 byte key.
>
> Is there any way to change the key size to 56 bytes?  I've included my 16 byte
> code below.
>
> char *decrypt_bf(unsigned char *coded,int coded_len,unsigned char *keystr,int
> keystr_len)
> {
>   //Make sure to #include <openssl/evp.h>
>   //compile with -lcrypto if using gcc
>
>   char buffer[1024];
>   unsigned char key[16];
>   unsigned char iv[8];
>   unsigned char salt[8];
>   int i;
>   int plainlen;
>   int finallen;
>
>   memcpy(salt,coded+8,8);
>
>   fprintf(stderr,"salt=");
>   for (i=0; i<8; i++)
>      fprintf(stderr,"%02X",salt[i]);
>   fprintf(stderr,"\n");
>
>   EVP_BytesToKey(EVP_bf_cbc(),EVP_md5(),salt,keystr,keystr_len,1,key,iv);
>
>   EVP_CIPHER_CTX ctx;
>   EVP_CIPHER_CTX_init(&ctx);
>
>   EVP_DecryptInit(&ctx,EVP_bf_cbc(),key,iv);
>   EVP_CIPHER_CTX_set_key_length(&ctx,16);
>
>   fprintf(stderr,"IV=");
>   for (i=0; i<8; i++)
>      fprintf(stderr,"%02X",iv[i]);
>   fprintf(stderr,"\n");
>
>   fprintf(stderr,"KEY=");
>   for (i=0; i<16; i++)
>      fprintf(stderr,"%02X",key[i]);
>   fprintf(stderr,"\n");
>
>   EVP_DecryptInit(&ctx,NULL,key,NULL);
>   EVP_DecryptUpdate(&ctx,buffer,&plainlen,coded+16,coded_len-16);
>   EVP_DecryptFinal(&ctx,buffer+plainlen,&finallen);
>
>   char *retval=(char *)malloc(finallen+1);
>   retval[finallen]='\0';
>   memcpy(retval,buffer,finallen);
>
>   EVP_CIPHER_CTX_cleanup(&ctx);
>   return retval;
> }
>
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           majord...@openssl.org

Reply via email to