On Thu, Jul 17, 2003, Reza Curtmola wrote: > My problem is that when I do public encryption, the first time I run the > following piece of code, it works OK, but then when I run the program for > the second time, the EVP_SealInit function fails and returns -1. > > I seed the random number generator before calling the following piece of > code. > > EVP_CIPHER_CTX ctx; /* the context used for PK encryption */ > EVP_CIPHER *cipher_type; > unsigned char **ek; > int *ekl; > unsigned char *iv; > EVP_PKEY **pubk; > int npubk; > int outl; /* length of encrypted data buffer */ > RSA *pkey; > > > /* I load the public key from a file into 'pkey' */ > > EVP_CIPHER_CTX_init(&ctx); > cipher_type = EVP_bf_cbc(); > npubk = 1; > > ek = (unsigned char **) malloc (sizeof(unsigned char *) * npubk); > ekl = (int *) malloc (sizeof(int) * npubk); > > pubk = (EVP_PKEY **) malloc (sizeof(EVP_PKEY *) * npubk); > pubk[0] = EVP_PKEY_new(); > EVP_PKEY_set1_RSA(pubk[0], (RSA*)pub_key); > > ek[0] = (unsigned char *) malloc (EVP_PKEY_size(pubk[0])); > iv = (unsigned char *) malloc (sizeof(unsigned char) * > EVP_CIPHER_iv_length(cipher_type)); > > EVP_SealInit(&ctx, cipher_type, ek, ekl, iv, pubk, npubk); > > /* isc_buffer_* functions give a reference to the beggining of some buffer > */ > EVP_SealUpdate(&ctx, isc_buffer_used(buffer), &outl, > isc_buffer_base(source), isc_buffer_usedlength(source)); > > /* here I move forward the 'used' pointer for the 'buffer' buffer, so now > isc_buffer_used points 'outl' bytes more than before */ > isc_buffer_add(buffer, outl); > > EVP_SealFinal(&ctx, isc_buffer_used(buffer), &outl); > >
Do you get an error message after you call EVP_SealInit() the second time? Steve. -- Dr Stephen N. Henson. Core developer of the OpenSSL project: http://www.openssl.org/ Freelance consultant see: http://www.drh-consultancy.demon.co.uk/ Email: [EMAIL PROTECTED], PGP key: via homepage. ______________________________________________________________________ OpenSSL Project http://www.openssl.org User Support Mailing List [EMAIL PROTECTED] Automated List Manager [EMAIL PROTECTED]