PostgreSQL Source Code: contrib/pgcrypto/px.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32#ifndef __PX_H

33#define __PX_H

34

36

37

38#define PX_DEBUG

39

40

41#define PX_MAX_SALT_LEN 128

42

43

44

45

46#define PXE_OK 0

47

48#define PXE_NO_HASH -2

49#define PXE_NO_CIPHER -3

50

51#define PXE_BAD_OPTION -5

52#define PXE_BAD_FORMAT -6

53#define PXE_KEY_TOO_BIG -7

54#define PXE_CIPHER_INIT -8

55#define PXE_HASH_UNUSABLE_FOR_HMAC -9

56

57

58#define PXE_BUG -12

59#define PXE_ARGUMENT_ERROR -13

60#define PXE_UNKNOWN_SALT_ALGO -14

61#define PXE_BAD_SALT_ROUNDS -15

62

63#define PXE_NO_RANDOM -17

64#define PXE_DECRYPT_FAILED -18

65#define PXE_ENCRYPT_FAILED -19

66

67#define PXE_PGP_CORRUPT_DATA -100

68#define PXE_PGP_CORRUPT_ARMOR -101

69#define PXE_PGP_UNSUPPORTED_COMPR -102

70#define PXE_PGP_UNSUPPORTED_CIPHER -103

71#define PXE_PGP_UNSUPPORTED_HASH -104

72#define PXE_PGP_COMPRESSION_ERROR -105

73#define PXE_PGP_NOT_TEXT -106

74#define PXE_PGP_UNEXPECTED_PKT -107

75

76#define PXE_PGP_MATH_FAILED -109

77#define PXE_PGP_SHORT_ELGAMAL_KEY -110

78

79#define PXE_PGP_UNKNOWN_PUBALGO -112

80#define PXE_PGP_WRONG_KEY -113

81#define PXE_PGP_MULTIPLE_KEYS -114

82#define PXE_PGP_EXPECT_PUBLIC_KEY -115

83#define PXE_PGP_EXPECT_SECRET_KEY -116

84#define PXE_PGP_NOT_V4_KEYPKT -117

85#define PXE_PGP_KEYPKT_CORRUPT -118

86#define PXE_PGP_NO_USABLE_KEY -119

87#define PXE_PGP_NEED_SECRET_PSW -120

88#define PXE_PGP_BAD_S2K_MODE -121

89#define PXE_PGP_UNSUPPORTED_PUBALGO -122

90#define PXE_PGP_MULTIPLE_SUBKEYS -123

91

93{

98

104

106

108{

115

116 union

117 {

121};

122

124{

127};

128

130{

138

140

141 struct

142 {

146};

147

149{

153

158

160 int pstat;

161};

162

164{

166 const uint8 *iv, unsigned ivlen);

168 uint8 *res, unsigned *rlen);

170 uint8 *res, unsigned *rlen);

174

177};

178

183

186

188

190

192

195

196#ifdef PX_DEBUG

198#else

199#define px_debug(...)

200#endif

201

202#define px_md_result_size(md) (md)->result_size(md)

203#define px_md_block_size(md) (md)->block_size(md)

204#define px_md_reset(md) (md)->reset(md)

205#define px_md_update(md, data, dlen) (md)->update(md, data, dlen)

206#define px_md_finish(md, buf) (md)->finish(md, buf)

207#define px_md_free(md) (md)->free(md)

208

209#define px_hmac_result_size(hmac) (hmac)->result_size(hmac)

210#define px_hmac_block_size(hmac) (hmac)->block_size(hmac)

211#define px_hmac_reset(hmac) (hmac)->reset(hmac)

212#define px_hmac_init(hmac, key, klen) (hmac)->init(hmac, key, klen)

213#define px_hmac_update(hmac, data, dlen) (hmac)->update(hmac, data, dlen)

214#define px_hmac_finish(hmac, buf) (hmac)->finish(hmac, buf)

215#define px_hmac_free(hmac) (hmac)->free(hmac)

216

217

218#define px_cipher_key_size(c) (c)->key_size(c)

219#define px_cipher_block_size(c) (c)->block_size(c)

220#define px_cipher_iv_size(c) (c)->iv_size(c)

221#define px_cipher_init(c, k, klen, iv) (c)->init(c, k, klen, iv)

222#define px_cipher_encrypt(c, padding, data, dlen, res, rlen) \

223 (c)->encrypt(c, padding, data, dlen, res, rlen)

224#define px_cipher_decrypt(c, padding, data, dlen, res, rlen) \

225 (c)->decrypt(c, padding, data, dlen, res, rlen)

226#define px_cipher_free(c) (c)->free(c)

227

228

229#define px_combo_encrypt_len(c, dlen) (c)->encrypt_len(c, dlen)

230#define px_combo_decrypt_len(c, dlen) (c)->decrypt_len(c, dlen)

231#define px_combo_init(c, key, klen, iv, ivlen) \

232 (c)->init(c, key, klen, iv, ivlen)

233#define px_combo_encrypt(c, data, dlen, res, rlen) \

234 (c)->encrypt(c, data, dlen, res, rlen)

235#define px_combo_decrypt(c, data, dlen, res, rlen) \

236 (c)->decrypt(c, data, dlen, res, rlen)

237#define px_combo_free(c) (c)->free(c)

238

239#endif

#define pg_attribute_printf(f, a)

void err(int eval, const char *fmt,...)

int cx(PlannerInfo *root, Gene *tour1, Gene *tour2, Gene *offspring, int num_gene, City *city_table)

int px_find_digest(const char *name, PX_MD **res)

void CheckBuiltinCryptoMode(void)

int px_find_hmac(const char *name, PX_HMAC **res)

pg_noreturn void px_THROW_ERROR(int err)

const char * px_strerror(int err)

int px_find_cipher(const char *name, PX_Cipher **res)

void px_set_debug_handler(void(*handler)(const char *))

int builtin_crypto_enabled

void px_debug(const char *fmt,...) pg_attribute_printf(1

const char * px_resolve_alias(const PX_Alias *list, const char *name)

int px_find_combo(const char *name, PX_Combo **res)

void px_memset(void *ptr, int c, size_t len)

void(* free)(PX_Cipher *c)

unsigned(* block_size)(PX_Cipher *c)

unsigned(* iv_size)(PX_Cipher *c)

int(* encrypt)(PX_Cipher *c, int padding, const uint8 *data, unsigned dlen, uint8 *res, unsigned *rlen)

int(* init)(PX_Cipher *c, const uint8 *key, unsigned klen, const uint8 *iv)

unsigned(* key_size)(PX_Cipher *c)

int(* decrypt)(PX_Cipher *c, int padding, const uint8 *data, unsigned dlen, uint8 *res, unsigned *rlen)

int(* decrypt)(PX_Combo *cx, const uint8 *data, unsigned dlen, uint8 *res, unsigned *rlen)

unsigned(* decrypt_len)(PX_Combo *cx, unsigned dlen)

int(* encrypt)(PX_Combo *cx, const uint8 *data, unsigned dlen, uint8 *res, unsigned *rlen)

void(* free)(PX_Combo *cx)

unsigned(* encrypt_len)(PX_Combo *cx, unsigned dlen)

int(* init)(PX_Combo *cx, const uint8 *key, unsigned klen, const uint8 *iv, unsigned ivlen)

void(* update)(PX_MD *h, const uint8 *data, unsigned dlen)

unsigned(* result_size)(PX_MD *h)

unsigned(* block_size)(PX_MD *h)

void(* finish)(PX_MD *h, uint8 *dst)

unsigned(* block_size)(PX_HMAC *h)

void(* finish)(PX_HMAC *h, uint8 *dst)

void(* init)(PX_HMAC *h, const uint8 *key, unsigned klen)

unsigned(* result_size)(PX_HMAC *h)

void(* update)(PX_HMAC *h, const uint8 *data, unsigned dlen)

void(* reset)(PX_HMAC *h)