#include "postgres.h"
#include "pgp.h"
#include "px.h"
Go to the source code of this file.
|
static int | pad_eme_pkcs1_v15 (uint8 *data, int data_len, int res_len, uint8 **res_p) |
|
static int | create_secmsg (PGP_Context *ctx, PGP_MPI **msg_p, int full_bytes) |
|
static int | encrypt_and_write_elgamal (PGP_Context *ctx, PGP_PubKey *pk, PushFilter *pkt) |
|
static int | encrypt_and_write_rsa (PGP_Context *ctx, PGP_PubKey *pk, PushFilter *pkt) |
|
int | pgp_write_pubenc_sesskey (PGP_Context *ctx, PushFilter *dst) |
|
◆ create_secmsg()
Definition at line 83 of file pgp-pubenc.c.
84{
86 int res,
88 unsigned cksum = 0;
92
93
94 for (
i = 0;
i < klen;
i++)
96
97
98
99
100 secmsg =
palloc(klen + 3);
102 memcpy(secmsg + 1, ctx->
sess_key, klen);
103 secmsg[klen + 1] = (cksum >> 8) & 0xFF;
104 secmsg[klen + 2] = cksum & 0xFF;
105
106
107
108
110 if (res >= 0)
111 {
112
113 int full_bits = full_bytes * 8 - 6;
114
116 }
117
118 if (padded)
119 {
122 }
125
126 if (res >= 0)
127 *msg_p = m;
128
129 return res;
130}
void pfree(void *pointer)
int pgp_mpi_create(uint8 *data, int bits, PGP_MPI **mpi)
static int pad_eme_pkcs1_v15(uint8 *data, int data_len, int res_len, uint8 **res_p)
void px_memset(void *ptr, int c, size_t len)
uint8 sess_key[PGP_MAX_KEY]
References PGP_Context::cipher_algo, i, pad_eme_pkcs1_v15(), palloc(), pfree(), pgp_mpi_create(), px_memset(), PGP_Context::sess_key, and PGP_Context::sess_key_len.
Referenced by encrypt_and_write_elgamal(), and encrypt_and_write_rsa().
◆ encrypt_and_write_elgamal()
Definition at line 133 of file pgp-pubenc.c.
134{
135 int res;
137 *c1 = NULL,
138 *c2 = NULL;
139
140
142 if (res < 0)
144
145
147 if (res < 0)
149
150
152 if (res < 0)
155
160 return res;
161}
void err(int eval, const char *fmt,...)
int pgp_elgamal_encrypt(PGP_PubKey *pk, PGP_MPI *_m, PGP_MPI **c1_p, PGP_MPI **c2_p)
int pgp_mpi_free(PGP_MPI *mpi)
int pgp_mpi_write(PushFilter *dst, PGP_MPI *n)
static int create_secmsg(PGP_Context *ctx, PGP_MPI **msg_p, int full_bytes)
struct PGP_PubKey::@0::@2 elg
References PGP_MPI::bytes, create_secmsg(), PGP_PubKey::elg, err(), PGP_PubKey::p, pgp_elgamal_encrypt(), pgp_mpi_free(), pgp_mpi_write(), and PGP_PubKey::pub.
Referenced by pgp_write_pubenc_sesskey().
◆ encrypt_and_write_rsa()
Definition at line 164 of file pgp-pubenc.c.
165{
166 int res;
169
170
172 if (res < 0)
174
175
177 if (res < 0)
179
180
182
186 return res;
187}
int pgp_rsa_encrypt(PGP_PubKey *pk, PGP_MPI *_m, PGP_MPI **c_p)
struct PGP_PubKey::@0::@3 rsa
References PGP_MPI::bytes, create_secmsg(), err(), PGP_PubKey::n, pgp_mpi_free(), pgp_mpi_write(), pgp_rsa_encrypt(), PGP_PubKey::pub, and PGP_PubKey::rsa.
Referenced by pgp_write_pubenc_sesskey().
◆ pad_eme_pkcs1_v15()
static int pad_eme_pkcs1_v15 |
( |
uint8 * |
data, |
|
|
int |
data_len, |
|
|
int |
res_len, |
|
|
uint8 ** |
res_p |
|
) |
| |
|
static |
Definition at line 40 of file pgp-pubenc.c.
41{
43 *p;
44 int pad_len = res_len - 2 - data_len;
45
46 if (pad_len < 8)
48
51
53 {
56 }
57
58
60 while (p <
buf + 1 + pad_len)
61 {
62 if (*p == 0)
63 {
65 {
69 }
70 }
71 if (*p != 0)
72 p++;
73 }
74
76 memcpy(
buf + pad_len + 2,
data, data_len);
78
79 return 0;
80}
bool pg_strong_random(void *buf, size_t len)
References buf, data, palloc(), pfree(), pg_strong_random(), px_memset(), PXE_BUG, and PXE_NO_RANDOM.
Referenced by create_secmsg().
◆ pgp_write_pubenc_sesskey()
Definition at line 190 of file pgp-pubenc.c.
191{
192 int res;
197
198 if (pk == NULL)
199 {
202 }
203
205
206
207
208
210 if (res < 0)
213 if (res < 0)
216 if (res < 0)
219 if (res < 0)
221
222 switch (algo)
223 {
226 break;
230 break;
231 }
232 if (res < 0)
234
235
236
237
240 if (pkt)
242
243 return res;
244}
int pushf_write(PushFilter *mp, const uint8 *data, int len)
int pushf_flush(PushFilter *mp)
void pushf_free(PushFilter *mp)
int pgp_create_pkt_writer(PushFilter *dst, int tag, PushFilter **res_p)
static int encrypt_and_write_elgamal(PGP_Context *ctx, PGP_PubKey *pk, PushFilter *pkt)
static int encrypt_and_write_rsa(PGP_Context *ctx, PGP_PubKey *pk, PushFilter *pkt)
@ PGP_PKT_PUBENCRYPTED_SESSKEY
@ PGP_PUB_RSA_ENCRYPT_SIGN
void px_debug(const char *fmt,...)
References PGP_PubKey::algo, encrypt_and_write_elgamal(), encrypt_and_write_rsa(), err(), PGP_PubKey::key_id, pgp_create_pkt_writer(), PGP_PKT_PUBENCRYPTED_SESSKEY, PGP_PUB_ELG_ENCRYPT, PGP_PUB_RSA_ENCRYPT, PGP_PUB_RSA_ENCRYPT_SIGN, PGP_Context::pub_key, pushf_flush(), pushf_free(), pushf_write(), px_debug(), and PXE_BUG.
Referenced by pgp_encrypt().