Hello,
newbie question regarding the Blowfish algorithm: why do my
encrypt/decypt functions fail on Windows XP SP3 with OpenSSL 1.0.0e?
The same functions work on my Linux workstation.
Windows output:
============
Encrypt:
encrypting 7680 bytes
EVP_DecryptUpdate 1024 bytes
EVP_DecryptFinal 8 bytes
EVP_DecryptUpdate 1024 bytes
EVP_DecryptFinal 8 bytes
EVP_DecryptUpdate 1024 bytes
EVP_DecryptFinal 8 bytes
EVP_DecryptUpdate 1024 bytes
EVP_DecryptFinal 8 bytes
EVP_DecryptUpdate 1024 bytes
EVP_DecryptFinal 8 bytes
EVP_DecryptUpdate 1024 bytes
EVP_DecryptFinal 8 bytes
EVP_DecryptUpdate 1024 bytes
EVP_DecryptFinal 8 bytes
EVP_DecryptUpdate 512 bytes
EVP_DecryptFinal 8 bytes
encrypted 7744 bytes
Decrypt:
decrypting 7744 bytes
EVP_DecryptUpdate 1024 bytes
EVP_DecryptFinal 0 bytes
EVP_DecryptUpdate 1032 bytes <= why 1032 instead of 1024?
EVP_DecryptFinal 0 bytes
EVP_DecryptUpdate 1032 bytes
EVP_DecryptFinal 0 bytes
EVP_DecryptUpdate 1032 bytes
EVP_DecryptFinal 0 bytes
EVP_DecryptUpdate 1032 bytes
EVP_DecryptFinal 0 bytes
EVP_DecryptUpdate 1032 bytes
EVP_DecryptFinal 0 bytes
EVP_DecryptUpdate 1032 bytes
EVP_DecryptFinal 0 bytes
EVP_DecryptUpdate 520 bytes
EVP_DecryptFinal 0 bytes
decrypted 7736 bytes
Linux output:
==========
encrypting 7680 bytes
EVP_DecryptUpdate 1024 bytes
EVP_DecryptFinal 8 bytes
EVP_DecryptUpdate 1024 bytes
EVP_DecryptFinal 8 bytes
EVP_DecryptUpdate 1024 bytes
EVP_DecryptFinal 8 bytes
EVP_DecryptUpdate 1024 bytes
EVP_DecryptFinal 8 bytes
EVP_DecryptUpdate 1024 bytes
EVP_DecryptFinal 8 bytes
EVP_DecryptUpdate 1024 bytes
EVP_DecryptFinal 8 bytes
EVP_DecryptUpdate 1024 bytes
EVP_DecryptFinal 8 bytes
EVP_DecryptUpdate 512 bytes
EVP_DecryptFinal 8 bytes
encrypted 7744 bytes
decrypting 7744 bytes
EVP_DecryptUpdate 1024 bytes
EVP_DecryptFinal 0 bytes
EVP_DecryptUpdate 1024 bytes
EVP_DecryptFinal 0 bytes
EVP_DecryptUpdate 1024 bytes
EVP_DecryptFinal 0 bytes
EVP_DecryptUpdate 1024 bytes
EVP_DecryptFinal 0 bytes
EVP_DecryptUpdate 1024 bytes
EVP_DecryptFinal 0 bytes
EVP_DecryptUpdate 1024 bytes
EVP_DecryptFinal 0 bytes
EVP_DecryptUpdate 1024 bytes
EVP_DecryptFinal 0 bytes
EVP_DecryptUpdate 512 bytes
EVP_DecryptFinal 0 bytes
decrypted 7680 bytes
Source code:
static int
decrypt (unsigned char *inbuf, int size, unsigned char *outbuf,
int *outsz)
{
int olen, tlen, n, left;
unsigned char *inp = inbuf;
unsigned char *outp = outbuf;
EVP_CIPHER_CTX ctx;
printf("decrypting %d bytes\n", size);
EVP_CIPHER_CTX_init (&ctx);
EVP_DecryptInit (&ctx, EVP_bf_cbc (), key, iv);
left = size;
*outsz = 0;
while (left > 0)
{
n = (left > OP_SIZE ? OP_SIZE : left);
olen = 0;
memset((void *)outp, 0, IP_SIZE);
if (EVP_DecryptUpdate (&ctx, outp, &olen, inp, n) != 1)
{
return -1;
}
printf("EVP_DecryptUpdate %d bytes\n", olen);
if (EVP_DecryptFinal (&ctx, outp + olen, &tlen) != 1)
{
return -1;
}
printf("EVP_DecryptFinal %d bytes\n", tlen);
*outsz = ((*outsz) + olen + tlen);
inp += n;
left -= n;
outp += (olen + tlen);
}
printf("decrypted %d bytes\n", *outsz);
EVP_CIPHER_CTX_cleanup (&ctx);
return 0;
}
static int
encrypt (unsigned char *inbuf, int size, unsigned char *outbuf, int *outsz)
{
int olen, tlen, n, left;
unsigned char *inp = inbuf;
unsigned char *outp = outbuf;
EVP_CIPHER_CTX ctx;
printf("encrypting %d bytes\n", size);
EVP_CIPHER_CTX_init (&ctx);
EVP_EncryptInit (&ctx, EVP_bf_cbc (), key, iv);
left = size;
*outsz = 0;
while (left > 0)
{
n = (left > IP_SIZE ? IP_SIZE : left);
olen = 0;
if (EVP_EncryptUpdate (&ctx, outp, &olen, inp, n) != 1)
{
return -1;
}
printf("EVP_DecryptUpdate %d bytes\n", olen);
if (EVP_EncryptFinal (&ctx, outp + olen, &tlen) != 1)
{
return -1;
}
printf("EVP_DecryptFinal %d bytes\n", tlen);
*outsz = ((*outsz) + olen + tlen);
inp += n;
left -= n;
outp += (olen + tlen);
}
printf("encrypted %d bytes\n", *outsz);
EVP_CIPHER_CTX_cleanup (&ctx);
return 0;
}
Cheers,
Jussi
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List [email protected]
Automated List Manager [email protected]