PostgreSQL Source Code: contrib/pgcrypto/pgp-pubdec.c File Reference (original) (raw)
#include "[postgres.h](postgres%5F8h%5Fsource.html)"
#include "[pgp.h](pgp%5F8h%5Fsource.html)"
#include "[px.h](px%5F8h%5Fsource.html)"
Go to the source code of this file.
Functions | |
---|---|
static uint8 * | check_eme_pkcs1_v15 (uint8 *data, int len) |
static int | control_cksum (uint8 *msg, int msglen) |
static int | decrypt_elgamal (PGP_PubKey *pk, PullFilter *pkt, PGP_MPI **m_p) |
static int | decrypt_rsa (PGP_PubKey *pk, PullFilter *pkt, PGP_MPI **m_p) |
int | pgp_parse_pubenc_sesskey (PGP_Context *ctx, PullFilter *pkt) |
Variables | |
---|---|
static const uint8 | any_key [] = {0, 0, 0, 0, 0, 0, 0, 0} |
◆ check_eme_pkcs1_v15()
static uint8 * check_eme_pkcs1_v15 ( uint8 * data, int len ) | static |
---|
Definition at line 42 of file pgp-pubdec.c.
43{
46 int rnd = 0;
47
48 if (len < 1 + 8 + 1)
49 return NULL;
50
51 if (*p++ != 2)
52 return NULL;
53
54 while (p < data_end && *p)
55 {
56 p++;
57 rnd++;
58 }
59
60 if (p == data_end)
61 return NULL;
62 if (*p != 0)
63 return NULL;
64 if (rnd < 8)
65 return NULL;
66 return p + 1;
67}
Referenced by pgp_parse_pubenc_sesskey().
◆ control_cksum()
static int control_cksum ( uint8 * msg, int msglen ) | static |
---|
Definition at line 74 of file pgp-pubdec.c.
75{
76 int i;
77 unsigned my_cksum,
78 got_cksum;
79
80 if (msglen < 3)
82
83 my_cksum = 0;
84 for (i = 1; i < msglen - 2; i++)
85 my_cksum += msg[i];
86 my_cksum &= 0xFFFF;
87 got_cksum = ((unsigned) (msg[msglen - 2]) << 8) + msg[msglen - 1];
88 if (my_cksum != got_cksum)
89 {
90 px_debug("pubenc cksum failed");
92 }
93 return 0;
94}
void px_debug(const char *fmt,...)
#define PXE_PGP_WRONG_KEY
References i, px_debug(), and PXE_PGP_WRONG_KEY.
Referenced by pgp_parse_pubenc_sesskey().
◆ decrypt_elgamal()
◆ decrypt_rsa()
◆ pgp_parse_pubenc_sesskey()
Definition at line 150 of file pgp-pubdec.c.
151{
152 int ver;
153 int algo;
154 int res;
158 int msglen;
160
162 if (pk == NULL)
163 {
166 }
167
169 if (ver != 3)
170 {
171 px_debug("unknown pubenc_sesskey pkt ver=%d", ver);
173 }
174
175
176
177
179 if (res < 0)
180 return res;
181 if (memcmp(key_id, any_key, 8) != 0
182 && memcmp(key_id, pk->key_id, 8) != 0)
183 {
184 px_debug("key_id's does not match");
186 }
187
188
189
190
192 switch (algo)
193 {
196 break;
200 break;
201 default:
203 }
204 if (res < 0)
205 return res;
206
207
208
209
211 if (msg == NULL)
212 {
213 px_debug("check_eme_pkcs1_v15 failed");
215 goto out;
216 }
217 msglen = m->bytes - (msg - m->data);
218
220 if (res < 0)
221 goto out;
222
223
224
225
229
230out:
232 if (res < 0)
233 return res;
235}
int pullf_read_fixed(PullFilter *src, int len, uint8 *dst)
int pgp_expect_packet_end(PullFilter *pkt)
static int decrypt_rsa(PGP_PubKey *pk, PullFilter *pkt, PGP_MPI **m_p)
static const uint8 any_key[]
static int decrypt_elgamal(PGP_PubKey *pk, PullFilter *pkt, PGP_MPI **m_p)
static uint8 * check_eme_pkcs1_v15(uint8 *data, int len)
static int control_cksum(uint8 *msg, int msglen)
#define PXE_PGP_CORRUPT_DATA
#define PXE_PGP_UNKNOWN_PUBALGO
uint8 sess_key[PGP_MAX_KEY]
References any_key, PGP_MPI::bytes, check_eme_pkcs1_v15(), PGP_Context::cipher_algo, control_cksum(), PGP_MPI::data, decrypt_elgamal(), decrypt_rsa(), GETBYTE, PGP_PubKey::key_id, pgp_expect_packet_end(), pgp_mpi_free(), PGP_PUB_ELG_ENCRYPT, PGP_PUB_RSA_ENCRYPT, PGP_PUB_RSA_ENCRYPT_SIGN, PGP_Context::pub_key, pullf_read_fixed(), px_debug(), PXE_BUG, PXE_PGP_CORRUPT_DATA, PXE_PGP_UNKNOWN_PUBALGO, PXE_PGP_WRONG_KEY, PGP_Context::sess_key, and PGP_Context::sess_key_len.
Referenced by pgp_decrypt().
◆ any_key
const uint8 any_key[] = {0, 0, 0, 0, 0, 0, 0, 0} | static |
---|