39 #define ALLOW_CTX_SIZE 1 49 #define MAX_CHUNK (16*1024*1024) 61 else if (b >= 192 && b <= 223)
63 len = ((unsigned) (b) - 192) << 8;
80 len = 1 << (b & 0x1F);
86 px_debug(
"parse_new_len: weird length");
106 len = (len << 8) | b;
108 else if (lentype == 2)
111 len = (len << 8) | b;
113 len = (len << 8) | b;
115 len = (len << 8) | b;
120 px_debug(
"parse_old_len: weird length");
142 if ((*p & 0x80) == 0)
144 px_debug(
"pgp_parse_pkt_hdr: not pkt hdr");
156 *tag = (*p >> 2) & 0x0F;
185 while (pkt->
len == 0)
253 if (len >
sizeof(tmpbuf))
261 px_debug(
"prefix_init: short read");
266 if (buf[len - 2] != buf[len] || buf[len - 1] != buf[len + 1])
268 px_debug(
"prefix_init: corrupt prefix");
374 px_debug(
"mdc_finish: read failed, res=%d", res);
382 res = memcmp(hash, data, 20);
410 px_debug(
"mdc_read: unexpected eof");
431 #define MDCBUF_LEN 8192 451 memset(st, 0,
sizeof(*st));
472 px_debug(
"mdcbuf_finish: bad MDC pkt hdr");
477 res = memcmp(hash, st->
mdc_buf + 2, 20);
481 px_debug(
"mdcbuf_finish: MDC does not match");
492 memcpy(dst, src, len);
613 px_debug(
"sesskey bad len: algo=%d, expected=%d, got=%d",
682 px_debug(
"expect key, but bad data");
709 while (data < data_end)
713 if (data + 1 < data_end)
715 if (*(data + 1) ==
'\n')
768 px_debug(
"parse_literal_data: unexpected eof");
776 px_debug(
"parse_literal_data: unexpected eof");
786 if (type !=
't' && type !=
'u')
788 px_debug(
"parse_literal_data: data type=%c", type);
808 if (res >= 0 && got_cr)
815 PullFilter *src,
int allow_compr,
int need_mdc);
846 px_debug(
"parse_compressed_data: bzip2 unsupported");
856 res =
pullf_read(pkt, 32 * 1024, &discard_buf);
864 px_debug(
"parse_compressed_data: unknown compr type");
873 int allow_compr,
int need_mdc)
892 px_debug(
"process_data_packets: data after mdc");
912 if (allow_compr == 0)
914 px_debug(
"process_data_packets: unexpected compression");
922 px_debug(
"process_data_packets: only one cmpr pkt allowed");
934 px_debug(
"process_data_packets: unexpected MDC");
944 px_debug(
"process_data_packets: unexpected pkt tag=%d", tag);
963 px_debug(
"process_data_packets: no data");
968 px_debug(
"process_data_packets: got no mdc");
987 res =
pullf_create(&pf_decrypt, &pgp_decrypt_filter, cfb, pkt);
991 res =
pullf_create(&pf_prefix, &prefix_filter, ctx, pf_decrypt);
1021 px_debug(
"parse_symenc_mdc_data: pkt ver != 1");
1030 res =
pullf_create(&pf_decrypt, &pgp_decrypt_filter, cfb, pkt);
1034 res =
pullf_create(&pf_mdc, &mdc_filter, ctx, pf_decrypt);
1038 res =
pullf_create(&pf_prefix, &prefix_filter, ctx, pf_mdc);
1083 px_debug(
"pgp_expect_packet_end: got data");
1131 px_debug(
"pgp_decrypt: using first of several keys");
1140 px_debug(
"pgp_decrypt: have data but no key");
1142 px_debug(
"pgp_decrypt: got second data packet");
1152 px_debug(
"pgp_decrypt: have data but no key");
1154 px_debug(
"pgp_decrypt: several data pkts not supported");
1163 px_debug(
"pgp_decrypt: unknown tag: 0x%02x", tag);
static int copy_crlf(MBuf *dst, uint8 *data, int len, int *got_cr)
static int parse_new_len(PullFilter *src, int *len_p)
static int decrypt_key(PGP_Context *ctx, const uint8 *src, int len)
#define PXE_PGP_CORRUPT_DATA
int pullf_read(PullFilter *pf, int len, uint8 **data_p)
static int parse_literal_data(PGP_Context *ctx, MBuf *dst, PullFilter *pkt)
void pullf_free(PullFilter *pf)
static struct PullFilterOps prefix_filter
int pullf_create(PullFilter **pf_p, const PullFilterOps *op, void *init_arg, PullFilter *src)
static int mdcbuf_finish(struct MDCBufData *st)
int pgp_parse_pkt_hdr(PullFilter *src, uint8 *tag, int *len_p, int allow_ctx)
#define px_md_update(md, data, dlen)
static int prefix_init(void **priv_p, void *arg, PullFilter *src)
int pgp_cfb_decrypt(PGP_CFB *ctx, const uint8 *data, int len, uint8 *dst)
static int decrypt_read(void *priv, PullFilter *src, int len, uint8 **data_p, uint8 *buf, int buflen)
static void mdcbuf_load_data(struct MDCBufData *st, uint8 *src, int len)
static int parse_symenc_mdc_data(PGP_Context *ctx, PullFilter *pkt, MBuf *dst)
int pullf_create_mbuf_reader(PullFilter **mp_p, MBuf *src)
int pgp_skip_packet(PullFilter *pkt)
int pgp_parse_pubenc_sesskey(PGP_Context *ctx, PullFilter *pkt)
#define px_md_finish(md, buf)
#define PXE_PGP_UNSUPPORTED_COMPR
uint8 sess_key[PGP_MAX_KEY]
int pgp_create_pkt_reader(PullFilter **pf_p, PullFilter *src, int len, int pkttype, PGP_Context *ctx)
static void mdc_free(void *priv)
static int parse_old_len(PullFilter *src, int *len_p, int lentype)
static void mdcbuf_free(void *priv)
static void pktreader_free(void *priv)
static int mdc_read(void *priv, PullFilter *src, int len, uint8 **data_p, uint8 *buf, int buflen)
int pgp_get_cipher_key_size(int code)
int pgp_expect_packet_end(PullFilter *pkt)
static int parse_symenc_sesskey(PGP_Context *ctx, PullFilter *src)
int pgp_s2k_process(PGP_S2K *s2k, int cipher, const uint8 *key, int key_len)
int mbuf_append(MBuf *dst, const uint8 *buf, int len)
struct PullFilterOps pgp_decrypt_filter
void pgp_cfb_free(PGP_CFB *ctx)
static int mdc_init(void **priv_p, void *arg, PullFilter *src)
int pgp_decompress_filter(PullFilter **res, PGP_Context *ctx, PullFilter *src)
int pgp_load_digest(int code, PX_MD **res)
int pgp_decrypt(PGP_Context *ctx, MBuf *msrc, MBuf *mdst)
static int mdcbuf_read(void *priv, PullFilter *src, int len, uint8 **data_p, uint8 *buf, int buflen)
static int pktreader_pull(void *priv, PullFilter *src, int len, uint8 **data_p, uint8 *buf, int buflen)
int pgp_s2k_read(PullFilter *src, PGP_S2K *s2k)
void px_debug(const char *fmt,...)
int pgp_get_cipher_block_size(int code)
static int mdc_finish(PGP_Context *ctx, PullFilter *src, int len)
int pgp_cfb_create(PGP_CFB **ctx_p, int algo, const uint8 *key, int key_len, int resync, uint8 *iv)
static StringInfoData tmpbuf
static int mdcbuf_init(void **priv_p, void *arg, PullFilter *src)
static struct PullFilterOps mdcbuf_filter
static int process_data_packets(PGP_Context *ctx, MBuf *dst, PullFilter *src, int allow_compr, int need_mdc)
static int parse_compressed_data(PGP_Context *ctx, MBuf *dst, PullFilter *pkt)
static int decrypt_init(void **priv_p, void *arg, PullFilter *src)
static struct PullFilterOps pktreader_filter
static int mdcbuf_refill(struct MDCBufData *st, PullFilter *src)
static int parse_symenc_data(PGP_Context *ctx, PullFilter *pkt, MBuf *dst)
#define s2k_decode_count(cval)
static unsigned hash(unsigned *uv, int n)
void px_memset(void *ptr, int c, size_t len)
static void mdcbuf_load_mdc(struct MDCBufData *st, uint8 *src, int len)
int pullf_read_max(PullFilter *pf, int len, uint8 **data_p, uint8 *tmpbuf)
static struct PullFilterOps mdc_filter