In a larger application (Qt Cryptographic Architecture), I'm trying to
wrap some  OpenSSL crypto primitives in C++. However I'm having
a problem with EVP_DecryptUpdate(). I've done up a quick'n'dirty
test case, see below. Now for EVP_EncryptUpdate, this gives me
16. But for EVP_DecryptUpdate(), it gives back zero. That isn't
what I expected from the man page. Now the data is there
(ie result points to a filled in char array), I just can't tell how
long it is. Can anyone give me a hint?

Brad

#include <string.h>
#include <stdlib.h>
#include <openssl/evp.h>

int main()
{

  unsigned char *key;
  unsigned char *iv;
  unsigned char *data;
  unsigned char *result;
  EVP_CIPHER_CTX context;
  unsigned int outputSize;

  key = (unsigned char *)malloc(16);
  memset( key, 0x0, 16 );
  iv = (unsigned char *)malloc(16);
  memset( iv, 0x0, 16 );
  data = (unsigned char *)malloc(16);
  memset( data, 0x0, 16 );
  result = (unsigned char *)malloc(16);

  EVP_CIPHER_CTX_init( &context );
  EVP_DecryptInit_ex( &context, EVP_aes_128_ecb(), 0, key,iv );
  if (0 == EVP_DecryptUpdate( &context, result, &(outputSize), data, 16 ) ) 
abort();
  printf( "Output len: %u\n",outputSize );

  free(key);
  free(data);
  free(iv);
  free(result);

  return 0;
}

Attachment: pgpVLnQpYbgz0.pgp
Description: PGP signature

Reply via email to