PostgreSQL Source Code: contrib/pgcrypto/pgcrypto.c 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

33

34#include <ctype.h>

35

39#include "px.h"

43

45 .name = "pgcrypto",

46 .version = PG_VERSION

47);

48

49

50

52 {"on", BC_ON, false},

53 {"off", BC_OFF, false},

55 {NULL, 0, false}

56};

57

58typedef int (*PFN) (const char *name, void **res);

60 int silent);

61

63

64

65

66

67void

69{

71 "Sets if builtin crypto functions are enabled.",

72 "\"on\" enables builtin crypto, \"off\" unconditionally disables and \"fips\" "

73 "will disable builtin crypto if OpenSSL is in FIPS mode",

78 0,

79 NULL,

80 NULL,

81 NULL);

83}

84

85

87

90{

93 unsigned len,

94 hlen;

97

99

100

102

104

107

110

114

117

119}

120

121

123

126{

130 unsigned len,

131 hlen,

132 klen;

135

137

138

140

142

145

150

155

159

161}

162

163

164

166

169{

173

176 if (len < 0)

178 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),

180

182

184}

185

186

188

191{

196

199 if (len < 0)

201 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),

203

205

207}

208

209

211

214{

217 char *buf0,

218 *buf1,

219 *cres,

220 *resbuf;

222

225

227

229

232

233 if (cres == NULL)

235 (errcode(ERRCODE_EXTERNAL_ROUTINE_INVOCATION_EXCEPTION),

236 errmsg("crypt(3) returned NULL")));

237

239

241

244

246}

247

248

250

253{

257 *res;

260 unsigned dlen,

261 klen,

262 rlen;

263

266

271

274

276 if (err)

280

284

286 {

289 (errcode(ERRCODE_EXTERNAL_ROUTINE_INVOCATION_EXCEPTION),

291 }

292

295}

296

297

299

302{

306 *res;

309 unsigned dlen,

310 klen,

311 rlen;

312

315

320

323

325 if (err)

328

330

333 (errcode(ERRCODE_EXTERNAL_ROUTINE_INVOCATION_EXCEPTION),

335

337

341

343}

344

345

347

350{

354 *iv,

355 *res;

358 unsigned dlen,

359 klen,

360 ivlen,

361 rlen;

362

365

372

375

378 if (err)

381

383

386 (errcode(ERRCODE_EXTERNAL_ROUTINE_INVOCATION_EXCEPTION),

388

390

395

397}

398

399

401

404{

408 *iv,

409 *res;

412 unsigned dlen,

413 klen,

414 rlen,

415 ivlen;

416

419

426

429

432 if (err)

435

437

440 (errcode(ERRCODE_EXTERNAL_ROUTINE_INVOCATION_EXCEPTION),

442

444

449

451}

452

453

455

458{

461

462 if (len < 1 || len > 1024)

464 (errcode(ERRCODE_EXTERNAL_ROUTINE_INVOCATION_EXCEPTION),

465 errmsg("Length not in range")));

466

469

470

473

475}

476

477

479

482{

483

485}

486

488

491{

493}

494

495static void *

497 PFN provider_lookup,

498 const char *desc, int silent)

499{

500 void *res;

501 char *buf;

503

506 false);

507

508 err = provider_lookup(buf, &res);

509

510 if (err && !silent)

512 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),

514

516

517 return err ? NULL : res;

518}

int errcode(int sqlerrcode)

int errmsg(const char *fmt,...)

#define ereport(elevel,...)

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

#define PG_FREE_IF_COPY(ptr, n)

#define PG_GETARG_BYTEA_PP(n)

#define PG_GETARG_TEXT_PP(n)

#define PG_RETURN_BYTEA_P(x)

#define PG_RETURN_TEXT_P(x)

#define PG_GETARG_INT32(n)

#define PG_RETURN_BOOL(x)

void DefineCustomEnumVariable(const char *name, const char *short_desc, const char *long_desc, int *valueAddr, int bootValue, const struct config_enum_entry *options, GucContext context, int flags, GucEnumCheckHook check_hook, GucEnumAssignHook assign_hook, GucShowHook show_hook)

void MarkGUCPrefixReserved(const char *className)

void pfree(void *pointer)

void * palloc0(Size size)

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

Datum pg_encrypt_iv(PG_FUNCTION_ARGS)

static const struct config_enum_entry builtin_crypto_options[]

Datum pg_encrypt(PG_FUNCTION_ARGS)

static void * find_provider(text *name, PFN provider_lookup, const char *desc, int silent)

Datum pg_check_fipsmode(PG_FUNCTION_ARGS)

Datum pg_gen_salt_rounds(PG_FUNCTION_ARGS)

Datum pg_decrypt_iv(PG_FUNCTION_ARGS)

PG_MODULE_MAGIC_EXT(.name="pgcrypto",.version=PG_VERSION)

Datum pg_random_uuid(PG_FUNCTION_ARGS)

Datum pg_hmac(PG_FUNCTION_ARGS)

Datum pg_crypt(PG_FUNCTION_ARGS)

int(* PFN)(const char *name, void **res)

Datum pg_random_bytes(PG_FUNCTION_ARGS)

PG_FUNCTION_INFO_V1(pg_digest)

Datum pg_gen_salt(PG_FUNCTION_ARGS)

int builtin_crypto_enabled

Datum pg_digest(PG_FUNCTION_ARGS)

Datum pg_decrypt(PG_FUNCTION_ARGS)

bool pg_strong_random(void *buf, size_t len)

int px_gen_salt(const char *salt_type, char *buf, int rounds)

char * px_crypt(const char *psw, const char *salt, char *buf, unsigned len)

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

void px_THROW_ERROR(int err)

const char * px_strerror(int err)

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

#define px_md_finish(md, buf)

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

#define px_hmac_result_size(hmac)

#define px_hmac_finish(hmac, buf)

#define px_combo_encrypt_len(c, dlen)

#define px_hmac_update(hmac, data, dlen)

#define px_hmac_init(hmac, key, klen)

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

#define px_hmac_free(hmac)

#define px_combo_decrypt_len(c, dlen)

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

#define px_md_update(md, data, dlen)

#define px_md_result_size(md)

char * downcase_truncate_identifier(const char *ident, int len, bool warn)

Datum gen_random_uuid(PG_FUNCTION_ARGS)

#define SET_VARSIZE(PTR, len)

#define VARSIZE_ANY_EXHDR(PTR)

text * cstring_to_text_with_len(const char *s, int len)

text * cstring_to_text(const char *s)

void text_to_cstring_buffer(const text *src, char *dst, size_t dst_len)

char * text_to_cstring(const text *t)