PUB_ENCRYPT_BUFFER(3)

NAME
pub_encrypt_buffer - encrypt a buffer with a public key

SYNOPSIS
#include <pgplib.h>
int
pub_encrypt_buffer(PGPpubkey_t *key, u_char *inbuf, int inbuflen, int compress, u_char digest[16], int *outbuflen, u_char **outbuf);
int
pub_encrypt_session_key(PGPpubkey_t *key, u_char *skey, int *outbuflen, u_char **outbuf);

DESCRIPTION
Informally, the buffer pointed to by inbuf with the length inbuflen is encrypted with the public key key(). The location of the result is stored in outbuf. The size of this memory is stored in outbuflen.

More precisely, the data in inbuf is encrypted with IDEA under the key provided by the caller in digest. If compress is non-zero the data is compressed before encryption. This is usually a good idea. Then, the digest is encrypted with the publib key pointed to by key, by means of RSA. The resulting two packets, the DEK encrypted with RSA and the conventionally encrypted data are merged and written into a buffer. The resulting buffer will thus hold two packets.

The function pub_encrypt_session_key() is a higer level interface. It will encrypt, with the public key key the session key stored in skey and return the DEK, pointed to by outbuf. The length of outbuf is pointed to by outbuflen.

RETURN VALUES
If encryption of both packets were sucessful, 0 is returned. If an error occured, -1 is returned.

SEE ALSO
compress_buffer(PGPlib) PGPlib(3)

BUGS
The secrecy of the resulting packet hinges on the randomness of digest. The outmost care must be taken to provide a good session key. This is not at all trivial.

STANDARDS
All three packets (the RSA encrypted DEK, the IDEA encrypted data, and the optional compressed data) conform to RFC1991. The RSA encrypted packet contains data according to RFC1423.

HISTORY
Written by Tage Stabell-Kulų. First appeared in PGPlib 0.1.