diff options
Diffstat (limited to 'contrib/pgcrypto/pgp.h')
-rw-r--r-- | contrib/pgcrypto/pgp.h | 203 |
1 files changed, 107 insertions, 96 deletions
diff --git a/contrib/pgcrypto/pgp.h b/contrib/pgcrypto/pgp.h index 769a248d18e..d23086f5335 100644 --- a/contrib/pgcrypto/pgp.h +++ b/contrib/pgcrypto/pgp.h @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $PostgreSQL: pgsql/contrib/pgcrypto/pgp.h,v 1.3 2005/08/13 02:06:20 momjian Exp $ + * $PostgreSQL: pgsql/contrib/pgcrypto/pgp.h,v 1.4 2005/10/15 02:49:06 momjian Exp $ */ enum @@ -55,7 +55,7 @@ enum PGP_PKT_USER_ATTR = 17, PGP_PKT_SYMENCRYPTED_DATA_MDC = 18, PGP_PKT_MDC = 19, - PGP_PKT_PRIV_61 = 61 /* occurs in gpg secring */ + PGP_PKT_PRIV_61 = 61 /* occurs in gpg secring */ } PGP_PKT_TYPE; enum @@ -93,11 +93,11 @@ enum enum { PGP_DIGEST_MD5 = 1, /* should, deprecated */ - PGP_DIGEST_SHA1 = 2, /* must */ + PGP_DIGEST_SHA1 = 2, /* must */ PGP_DIGEST_RIPEMD160 = 3, - PGP_DIGEST_XSHA = 4, /* obsolete */ + PGP_DIGEST_XSHA = 4, /* obsolete */ PGP_DIGEST_MD2 = 5, /* obsolete */ - PGP_DIGEST_TIGER192 = 6, /* obsolete */ + PGP_DIGEST_TIGER192 = 6, /* obsolete */ PGP_DIGEST_HAVAL5_160 = 7, /* obsolete */ PGP_DIGEST_SHA256 = 8, PGP_DIGEST_SHA384 = 9, @@ -114,14 +114,15 @@ typedef struct PGP_PubKey PGP_PubKey; typedef struct PGP_Context PGP_Context; typedef struct PGP_S2K PGP_S2K; -struct PGP_S2K { - uint8 mode; - uint8 digest_algo; - uint8 salt[8]; - uint8 iter; +struct PGP_S2K +{ + uint8 mode; + uint8 digest_algo; + uint8 salt[8]; + uint8 iter; /* calculated: */ - uint8 key[PGP_MAX_KEY]; - uint8 key_len; + uint8 key[PGP_MAX_KEY]; + uint8 key_len; }; @@ -151,9 +152,9 @@ struct PGP_Context int in_mdc_pkt; int use_mdcbuf_filter; PX_MD *mdc_ctx; - - PGP_PubKey *pub_key; /* ctx owns it*/ - const uint8 *sym_key; /* ctx does not own it */ + + PGP_PubKey *pub_key; /* ctx owns it */ + const uint8 *sym_key; /* ctx does not own it */ int sym_key_len; /* @@ -163,54 +164,64 @@ struct PGP_Context unsigned sess_key_len; }; -struct PGP_MPI { - uint8 *data; - int bits; - int bytes; +struct PGP_MPI +{ + uint8 *data; + int bits; + int bytes; }; -struct PGP_PubKey { - uint8 ver; - uint8 time[4]; - uint8 algo; +struct PGP_PubKey +{ + uint8 ver; + uint8 time[4]; + uint8 algo; /* public part */ - union { - struct { - PGP_MPI *p; - PGP_MPI *g; - PGP_MPI *y; - } elg; - struct { - PGP_MPI *n; - PGP_MPI *e; - } rsa; - struct { - PGP_MPI *p; - PGP_MPI *q; - PGP_MPI *g; - PGP_MPI *y; - } dsa; - } pub; + union + { + struct + { + PGP_MPI *p; + PGP_MPI *g; + PGP_MPI *y; + } elg; + struct + { + PGP_MPI *n; + PGP_MPI *e; + } rsa; + struct + { + PGP_MPI *p; + PGP_MPI *q; + PGP_MPI *g; + PGP_MPI *y; + } dsa; + } pub; /* secret part */ - union { - struct { - PGP_MPI *x; - } elg; - struct { - PGP_MPI *d; - PGP_MPI *p; - PGP_MPI *q; - PGP_MPI *u; - } rsa; - struct { - PGP_MPI *x; - } dsa; - } sec; - - uint8 key_id[8]; - int can_encrypt; + union + { + struct + { + PGP_MPI *x; + } elg; + struct + { + PGP_MPI *d; + PGP_MPI *p; + PGP_MPI *q; + PGP_MPI *u; + } rsa; + struct + { + PGP_MPI *x; + } dsa; + } sec; + + uint8 key_id[8]; + int can_encrypt; }; int pgp_init(PGP_Context ** ctx); @@ -236,11 +247,11 @@ int pgp_set_text_mode(PGP_Context * ctx, int mode); int pgp_set_unicode_mode(PGP_Context * ctx, int mode); int pgp_get_unicode_mode(PGP_Context * ctx); -int pgp_set_symkey(PGP_Context *ctx, const uint8 *key, int klen); -int pgp_set_pubkey(PGP_Context *ctx, MBuf *keypkt, - const uint8 *key, int klen, int pubtype); +int pgp_set_symkey(PGP_Context * ctx, const uint8 *key, int klen); +int pgp_set_pubkey(PGP_Context * ctx, MBuf * keypkt, + const uint8 *key, int klen, int pubtype); -int pgp_get_keyid(MBuf *pgp_data, char *dst); +int pgp_get_keyid(MBuf * pgp_data, char *dst); /* internal functions */ @@ -249,55 +260,55 @@ int pgp_load_cipher(int c, PX_Cipher ** res); int pgp_get_cipher_key_size(int c); int pgp_get_cipher_block_size(int c); -int pgp_s2k_fill(PGP_S2K *s2k, int mode, int digest_algo); -int pgp_s2k_read(PullFilter *src, PGP_S2K *s2k); -int pgp_s2k_process(PGP_S2K *s2k, int cipher, const uint8 *key, int klen); +int pgp_s2k_fill(PGP_S2K * s2k, int mode, int digest_algo); +int pgp_s2k_read(PullFilter * src, PGP_S2K * s2k); +int pgp_s2k_process(PGP_S2K * s2k, int cipher, const uint8 *key, int klen); typedef struct PGP_CFB PGP_CFB; -int pgp_cfb_create(PGP_CFB **ctx_p, int algo, - const uint8 *key, int key_len, int recync, uint8 *iv); -void pgp_cfb_free(PGP_CFB *ctx); -int pgp_cfb_encrypt(PGP_CFB *ctx, const uint8 *data, int len, uint8 *dst); -int pgp_cfb_decrypt(PGP_CFB *ctx, const uint8 *data, int len, uint8 *dst); +int +pgp_cfb_create(PGP_CFB ** ctx_p, int algo, + const uint8 *key, int key_len, int recync, uint8 *iv); +void pgp_cfb_free(PGP_CFB * ctx); +int pgp_cfb_encrypt(PGP_CFB * ctx, const uint8 *data, int len, uint8 *dst); +int pgp_cfb_decrypt(PGP_CFB * ctx, const uint8 *data, int len, uint8 *dst); int pgp_armor_encode(const uint8 *src, unsigned len, uint8 *dst); int pgp_armor_decode(const uint8 *src, unsigned len, uint8 *dst); unsigned pgp_armor_enc_len(unsigned len); unsigned pgp_armor_dec_len(unsigned len); -int pgp_compress_filter(PushFilter **res, PGP_Context *ctx, PushFilter *dst); -int pgp_decompress_filter(PullFilter **res, PGP_Context *ctx, PullFilter *src); +int pgp_compress_filter(PushFilter ** res, PGP_Context * ctx, PushFilter * dst); +int pgp_decompress_filter(PullFilter ** res, PGP_Context * ctx, PullFilter * src); -int pgp_key_alloc(PGP_PubKey **pk_p); -void pgp_key_free(PGP_PubKey *pk); -int _pgp_read_public_key(PullFilter *pkt, PGP_PubKey **pk_p); +int pgp_key_alloc(PGP_PubKey ** pk_p); +void pgp_key_free(PGP_PubKey * pk); +int _pgp_read_public_key(PullFilter * pkt, PGP_PubKey ** pk_p); -int pgp_parse_pubenc_sesskey(PGP_Context *ctx, PullFilter *pkt); -int pgp_create_pkt_reader(PullFilter **pf_p, PullFilter *src, int len, - int pkttype, PGP_Context *ctx); +int pgp_parse_pubenc_sesskey(PGP_Context * ctx, PullFilter * pkt); +int pgp_create_pkt_reader(PullFilter ** pf_p, PullFilter * src, int len, + int pkttype, PGP_Context * ctx); int pgp_parse_pkt_hdr(PullFilter * src, uint8 *tag, int *len_p, - int allow_ctx); + int allow_ctx); -int pgp_skip_packet(PullFilter *pkt); -int pgp_expect_packet_end(PullFilter *pkt); +int pgp_skip_packet(PullFilter * pkt); +int pgp_expect_packet_end(PullFilter * pkt); -int pgp_write_pubenc_sesskey(PGP_Context *ctx, PushFilter *dst); -int pgp_create_pkt_writer(PushFilter *dst, int tag, PushFilter **res_p); +int pgp_write_pubenc_sesskey(PGP_Context * ctx, PushFilter * dst); +int pgp_create_pkt_writer(PushFilter * dst, int tag, PushFilter ** res_p); -int pgp_mpi_alloc(int bits, PGP_MPI **mpi); -int pgp_mpi_create(uint8 *data, int bits, PGP_MPI **mpi); -int pgp_mpi_free(PGP_MPI *mpi); -int pgp_mpi_read(PullFilter *src, PGP_MPI **mpi); -int pgp_mpi_write(PushFilter *dst, PGP_MPI *n); -int pgp_mpi_hash(PX_MD *md, PGP_MPI *n); -unsigned pgp_mpi_cksum(unsigned cksum, PGP_MPI *n); +int pgp_mpi_alloc(int bits, PGP_MPI ** mpi); +int pgp_mpi_create(uint8 *data, int bits, PGP_MPI ** mpi); +int pgp_mpi_free(PGP_MPI * mpi); +int pgp_mpi_read(PullFilter * src, PGP_MPI ** mpi); +int pgp_mpi_write(PushFilter * dst, PGP_MPI * n); +int pgp_mpi_hash(PX_MD * md, PGP_MPI * n); +unsigned pgp_mpi_cksum(unsigned cksum, PGP_MPI * n); -int pgp_elgamal_encrypt(PGP_PubKey *pk, PGP_MPI *m, - PGP_MPI **c1, PGP_MPI **c2); -int pgp_elgamal_decrypt(PGP_PubKey *pk, PGP_MPI *c1, PGP_MPI *c2, - PGP_MPI **m); -int pgp_rsa_encrypt(PGP_PubKey *pk, PGP_MPI *m, PGP_MPI **c); -int pgp_rsa_decrypt(PGP_PubKey *pk, PGP_MPI *c, PGP_MPI **m); +int pgp_elgamal_encrypt(PGP_PubKey * pk, PGP_MPI * m, + PGP_MPI ** c1, PGP_MPI ** c2); +int pgp_elgamal_decrypt(PGP_PubKey * pk, PGP_MPI * c1, PGP_MPI * c2, + PGP_MPI ** m); +int pgp_rsa_encrypt(PGP_PubKey * pk, PGP_MPI * m, PGP_MPI ** c); +int pgp_rsa_decrypt(PGP_PubKey * pk, PGP_MPI * c, PGP_MPI ** m); extern struct PullFilterOps pgp_decrypt_filter; - |