PostgreSQL Source Code  git master
px.h File Reference
#include <sys/param.h>
Include dependency graph for px.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  px_digest
 
struct  px_alias
 
struct  px_hmac
 
struct  px_cipher
 
struct  px_combo
 

Macros

#define PX_DEBUG
 
#define px_alloc(s)   palloc(s)
 
#define px_realloc(p, s)   repalloc(p, s)
 
#define px_free(p)   pfree(p)
 
#define PX_MAX_NAMELEN   128
 
#define PX_MAX_SALT_LEN   128
 
#define PXE_OK   0
 
#define PXE_ERR_GENERIC   -1
 
#define PXE_NO_HASH   -2
 
#define PXE_NO_CIPHER   -3
 
#define PXE_NOTBLOCKSIZE   -4
 
#define PXE_BAD_OPTION   -5
 
#define PXE_BAD_FORMAT   -6
 
#define PXE_KEY_TOO_BIG   -7
 
#define PXE_CIPHER_INIT   -8
 
#define PXE_HASH_UNUSABLE_FOR_HMAC   -9
 
#define PXE_DEV_READ_ERROR   -10
 
#define PXE_BUG   -12
 
#define PXE_ARGUMENT_ERROR   -13
 
#define PXE_UNKNOWN_SALT_ALGO   -14
 
#define PXE_BAD_SALT_ROUNDS   -15
 
#define PXE_MCRYPT_INTERNAL   -16
 
#define PXE_NO_RANDOM   -17
 
#define PXE_DECRYPT_FAILED   -18
 
#define PXE_PGP_CORRUPT_DATA   -100
 
#define PXE_PGP_CORRUPT_ARMOR   -101
 
#define PXE_PGP_UNSUPPORTED_COMPR   -102
 
#define PXE_PGP_UNSUPPORTED_CIPHER   -103
 
#define PXE_PGP_UNSUPPORTED_HASH   -104
 
#define PXE_PGP_COMPRESSION_ERROR   -105
 
#define PXE_PGP_NOT_TEXT   -106
 
#define PXE_PGP_UNEXPECTED_PKT   -107
 
#define PXE_PGP_MATH_FAILED   -109
 
#define PXE_PGP_SHORT_ELGAMAL_KEY   -110
 
#define PXE_PGP_UNKNOWN_PUBALGO   -112
 
#define PXE_PGP_WRONG_KEY   -113
 
#define PXE_PGP_MULTIPLE_KEYS   -114
 
#define PXE_PGP_EXPECT_PUBLIC_KEY   -115
 
#define PXE_PGP_EXPECT_SECRET_KEY   -116
 
#define PXE_PGP_NOT_V4_KEYPKT   -117
 
#define PXE_PGP_KEYPKT_CORRUPT   -118
 
#define PXE_PGP_NO_USABLE_KEY   -119
 
#define PXE_PGP_NEED_SECRET_PSW   -120
 
#define PXE_PGP_BAD_S2K_MODE   -121
 
#define PXE_PGP_UNSUPPORTED_PUBALGO   -122
 
#define PXE_PGP_MULTIPLE_SUBKEYS   -123
 
#define px_md_result_size(md)   (md)->result_size(md)
 
#define px_md_block_size(md)   (md)->block_size(md)
 
#define px_md_reset(md)   (md)->reset(md)
 
#define px_md_update(md, data, dlen)   (md)->update(md, data, dlen)
 
#define px_md_finish(md, buf)   (md)->finish(md, buf)
 
#define px_md_free(md)   (md)->free(md)
 
#define px_hmac_result_size(hmac)   (hmac)->result_size(hmac)
 
#define px_hmac_block_size(hmac)   (hmac)->block_size(hmac)
 
#define px_hmac_reset(hmac)   (hmac)->reset(hmac)
 
#define px_hmac_init(hmac, key, klen)   (hmac)->init(hmac, key, klen)
 
#define px_hmac_update(hmac, data, dlen)   (hmac)->update(hmac, data, dlen)
 
#define px_hmac_finish(hmac, buf)   (hmac)->finish(hmac, buf)
 
#define px_hmac_free(hmac)   (hmac)->free(hmac)
 
#define px_cipher_key_size(c)   (c)->key_size(c)
 
#define px_cipher_block_size(c)   (c)->block_size(c)
 
#define px_cipher_iv_size(c)   (c)->iv_size(c)
 
#define px_cipher_init(c, k, klen, iv)   (c)->init(c, k, klen, iv)
 
#define px_cipher_encrypt(c, data, dlen, res)   (c)->encrypt(c, data, dlen, res)
 
#define px_cipher_decrypt(c, data, dlen, res)   (c)->decrypt(c, data, dlen, res)
 
#define px_cipher_free(c)   (c)->free(c)
 
#define px_combo_encrypt_len(c, dlen)   (c)->encrypt_len(c, dlen)
 
#define px_combo_decrypt_len(c, dlen)   (c)->decrypt_len(c, dlen)
 
#define px_combo_init(c, key, klen, iv, ivlen)   (c)->init(c, key, klen, iv, ivlen)
 
#define px_combo_encrypt(c, data, dlen, res, rlen)   (c)->encrypt(c, data, dlen, res, rlen)
 
#define px_combo_decrypt(c, data, dlen, res, rlen)   (c)->decrypt(c, data, dlen, res, rlen)
 
#define px_combo_free(c)   (c)->free(c)
 

Typedefs

typedef struct px_digest PX_MD
 
typedef struct px_alias PX_Alias
 
typedef struct px_hmac PX_HMAC
 
typedef struct px_cipher PX_Cipher
 
typedef struct px_combo PX_Combo
 

Functions

int px_find_digest (const char *name, PX_MD **res)
 
int px_find_hmac (const char *name, PX_HMAC **res)
 
int px_find_cipher (const char *name, PX_Cipher **res)
 
int px_find_combo (const char *name, PX_Combo **res)
 
void px_THROW_ERROR (int err) pg_attribute_noreturn()
 
const char * px_strerror (int err)
 
const char * px_resolve_alias (const PX_Alias *aliases, const char *name)
 
void px_set_debug_handler (void(*handler)(const char *))
 
void px_memset (void *ptr, int c, size_t len)
 
void px_debug (const char *fmt,...) pg_attribute_printf(1
 

Macro Definition Documentation

◆ px_alloc

◆ px_cipher_block_size

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

Definition at line 222 of file px.h.

Referenced by combo_decrypt(), combo_encrypt(), and pgp_cfb_create().

◆ px_cipher_decrypt

#define px_cipher_decrypt (   c,
  data,
  dlen,
  res 
)    (c)->decrypt(c, data, dlen, res)

Definition at line 227 of file px.h.

Referenced by combo_decrypt().

◆ px_cipher_encrypt

#define px_cipher_encrypt (   c,
  data,
  dlen,
  res 
)    (c)->encrypt(c, data, dlen, res)

Definition at line 225 of file px.h.

Referenced by cfb_process(), and combo_encrypt().

◆ px_cipher_free

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

Definition at line 229 of file px.h.

Referenced by combo_free(), pgp_cfb_create(), pgp_cfb_free(), and px_find_combo().

◆ px_cipher_init

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

Definition at line 224 of file px.h.

Referenced by combo_init(), and pgp_cfb_create().

◆ px_cipher_iv_size

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

Definition at line 223 of file px.h.

Referenced by combo_init().

◆ px_cipher_key_size

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

Definition at line 221 of file px.h.

Referenced by combo_init().

◆ px_combo_decrypt

#define px_combo_decrypt (   c,
  data,
  dlen,
  res,
  rlen 
)    (c)->decrypt(c, data, dlen, res, rlen)

Definition at line 238 of file px.h.

Referenced by pg_decrypt(), and pg_decrypt_iv().

◆ px_combo_decrypt_len

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

Definition at line 233 of file px.h.

Referenced by pg_decrypt(), and pg_decrypt_iv().

◆ px_combo_encrypt

#define px_combo_encrypt (   c,
  data,
  dlen,
  res,
  rlen 
)    (c)->encrypt(c, data, dlen, res, rlen)

Definition at line 236 of file px.h.

Referenced by pg_encrypt(), and pg_encrypt_iv().

◆ px_combo_encrypt_len

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

Definition at line 232 of file px.h.

Referenced by pg_encrypt(), and pg_encrypt_iv().

◆ px_combo_free

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

Definition at line 240 of file px.h.

Referenced by pg_decrypt(), pg_decrypt_iv(), pg_encrypt(), and pg_encrypt_iv().

◆ px_combo_init

#define px_combo_init (   c,
  key,
  klen,
  iv,
  ivlen 
)    (c)->init(c, key, klen, iv, ivlen)

Definition at line 234 of file px.h.

Referenced by pg_decrypt(), pg_decrypt_iv(), pg_encrypt(), and pg_encrypt_iv().

◆ PX_DEBUG

#define PX_DEBUG

Definition at line 38 of file px.h.

◆ px_free

◆ px_hmac_block_size

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

Definition at line 213 of file px.h.

◆ px_hmac_finish

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

Definition at line 217 of file px.h.

Referenced by pg_hmac().

◆ px_hmac_free

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

Definition at line 218 of file px.h.

Referenced by pg_hmac().

◆ px_hmac_init

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

Definition at line 215 of file px.h.

Referenced by pg_hmac().

◆ px_hmac_reset

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

Definition at line 214 of file px.h.

◆ px_hmac_result_size

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

Definition at line 212 of file px.h.

Referenced by pg_hmac().

◆ px_hmac_update

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

Definition at line 216 of file px.h.

Referenced by pg_hmac().

◆ PX_MAX_NAMELEN

#define PX_MAX_NAMELEN   128

Definition at line 54 of file px.h.

◆ PX_MAX_SALT_LEN

#define PX_MAX_SALT_LEN   128

Definition at line 57 of file px.h.

◆ px_md_block_size

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

Definition at line 206 of file px.h.

Referenced by hmac_block_size(), hmac_finish(), hmac_free(), hmac_init(), hmac_reset(), and px_find_hmac().

◆ px_md_finish

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

◆ px_md_free

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

◆ px_md_reset

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

◆ px_md_result_size

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

◆ px_md_update

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

◆ px_realloc

#define px_realloc (   p,
 
)    repalloc(p, s)

Definition at line 45 of file px.h.

Referenced by prepare_room(), and s_realloc().

◆ PXE_ARGUMENT_ERROR

#define PXE_ARGUMENT_ERROR   -13

◆ PXE_BAD_FORMAT

#define PXE_BAD_FORMAT   -6

Definition at line 68 of file px.h.

Referenced by parse_cipher_name().

◆ PXE_BAD_OPTION

#define PXE_BAD_OPTION   -5

Definition at line 67 of file px.h.

Referenced by parse_cipher_name().

◆ PXE_BAD_SALT_ROUNDS

#define PXE_BAD_SALT_ROUNDS   -15

Definition at line 76 of file px.h.

Referenced by px_gen_salt().

◆ PXE_BUG

◆ PXE_CIPHER_INIT

#define PXE_CIPHER_INIT   -8

◆ PXE_DECRYPT_FAILED

#define PXE_DECRYPT_FAILED   -18

Definition at line 79 of file px.h.

Referenced by combo_decrypt(), and gen_ossl_decrypt().

◆ PXE_DEV_READ_ERROR

#define PXE_DEV_READ_ERROR   -10

Definition at line 72 of file px.h.

◆ PXE_ERR_GENERIC

#define PXE_ERR_GENERIC   -1

Definition at line 63 of file px.h.

Referenced by gen_ossl_encrypt().

◆ PXE_HASH_UNUSABLE_FOR_HMAC

#define PXE_HASH_UNUSABLE_FOR_HMAC   -9

Definition at line 71 of file px.h.

Referenced by px_find_hmac().

◆ PXE_KEY_TOO_BIG

#define PXE_KEY_TOO_BIG   -7

Definition at line 69 of file px.h.

Referenced by bf_init(), ossl_aes_init(), and rj_init().

◆ PXE_MCRYPT_INTERNAL

#define PXE_MCRYPT_INTERNAL   -16

Definition at line 77 of file px.h.

◆ PXE_NO_CIPHER

#define PXE_NO_CIPHER   -3

Definition at line 65 of file px.h.

Referenced by px_find_cipher(), and px_find_combo().

◆ PXE_NO_HASH

#define PXE_NO_HASH   -2

Definition at line 64 of file px.h.

Referenced by px_find_digest().

◆ PXE_NO_RANDOM

#define PXE_NO_RANDOM   -17

◆ PXE_NOTBLOCKSIZE

#define PXE_NOTBLOCKSIZE   -4

Definition at line 66 of file px.h.

Referenced by bf_decrypt(), bf_encrypt(), combo_decrypt(), rj_decrypt(), and rj_encrypt().

◆ PXE_OK

#define PXE_OK   0

Definition at line 62 of file px.h.

Referenced by pgp_set_s2k_count(), and pgp_set_s2k_mode().

◆ PXE_PGP_BAD_S2K_MODE

#define PXE_PGP_BAD_S2K_MODE   -121

Definition at line 102 of file px.h.

Referenced by pgp_s2k_fill(), pgp_s2k_process(), and pgp_s2k_read().

◆ PXE_PGP_COMPRESSION_ERROR

#define PXE_PGP_COMPRESSION_ERROR   -105

Definition at line 86 of file px.h.

◆ PXE_PGP_CORRUPT_ARMOR

#define PXE_PGP_CORRUPT_ARMOR   -101

Definition at line 82 of file px.h.

Referenced by b64_decode(), find_header(), pgp_armor_decode(), and pgp_extract_armor_headers().

◆ PXE_PGP_CORRUPT_DATA

◆ PXE_PGP_EXPECT_PUBLIC_KEY

#define PXE_PGP_EXPECT_PUBLIC_KEY   -115

Definition at line 96 of file px.h.

Referenced by internal_read_key().

◆ PXE_PGP_EXPECT_SECRET_KEY

#define PXE_PGP_EXPECT_SECRET_KEY   -116

Definition at line 97 of file px.h.

Referenced by internal_read_key().

◆ PXE_PGP_KEYPKT_CORRUPT

#define PXE_PGP_KEYPKT_CORRUPT   -118

Definition at line 99 of file px.h.

Referenced by check_key_cksum(), check_key_sha1(), and process_secret_key().

◆ PXE_PGP_MATH_FAILED

#define PXE_PGP_MATH_FAILED   -109

Definition at line 90 of file px.h.

Referenced by pgp_elgamal_decrypt(), pgp_elgamal_encrypt(), pgp_rsa_decrypt(), and pgp_rsa_encrypt().

◆ PXE_PGP_MULTIPLE_KEYS

#define PXE_PGP_MULTIPLE_KEYS   -114

Definition at line 95 of file px.h.

Referenced by internal_read_key(), and pgp_get_keyid().

◆ PXE_PGP_MULTIPLE_SUBKEYS

#define PXE_PGP_MULTIPLE_SUBKEYS   -123

Definition at line 104 of file px.h.

Referenced by internal_read_key().

◆ PXE_PGP_NEED_SECRET_PSW

#define PXE_PGP_NEED_SECRET_PSW   -120

Definition at line 101 of file px.h.

Referenced by process_secret_key().

◆ PXE_PGP_NO_USABLE_KEY

#define PXE_PGP_NO_USABLE_KEY   -119

Definition at line 100 of file px.h.

Referenced by internal_read_key(), and pgp_get_keyid().

◆ PXE_PGP_NOT_TEXT

#define PXE_PGP_NOT_TEXT   -106

Definition at line 87 of file px.h.

Referenced by pgp_decrypt().

◆ PXE_PGP_NOT_V4_KEYPKT

#define PXE_PGP_NOT_V4_KEYPKT   -117

Definition at line 98 of file px.h.

Referenced by _pgp_read_public_key().

◆ PXE_PGP_SHORT_ELGAMAL_KEY

#define PXE_PGP_SHORT_ELGAMAL_KEY   -110

Definition at line 91 of file px.h.

◆ PXE_PGP_UNEXPECTED_PKT

#define PXE_PGP_UNEXPECTED_PKT   -107

Definition at line 88 of file px.h.

Referenced by internal_read_key().

◆ PXE_PGP_UNKNOWN_PUBALGO

#define PXE_PGP_UNKNOWN_PUBALGO   -112

Definition at line 93 of file px.h.

Referenced by _pgp_read_public_key(), and pgp_parse_pubenc_sesskey().

◆ PXE_PGP_UNSUPPORTED_CIPHER

#define PXE_PGP_UNSUPPORTED_CIPHER   -103

Definition at line 84 of file px.h.

Referenced by pgp_get_cipher_code(), pgp_load_cipher(), pgp_s2k_process(), and process_secret_key().

◆ PXE_PGP_UNSUPPORTED_COMPR

#define PXE_PGP_UNSUPPORTED_COMPR   -102

Definition at line 83 of file px.h.

Referenced by pgp_compress_filter(), pgp_decompress_filter(), and pgp_decrypt().

◆ PXE_PGP_UNSUPPORTED_HASH

#define PXE_PGP_UNSUPPORTED_HASH   -104

Definition at line 85 of file px.h.

Referenced by pgp_get_digest_code(), and pgp_load_digest().

◆ PXE_PGP_UNSUPPORTED_PUBALGO

#define PXE_PGP_UNSUPPORTED_PUBALGO   -122

Definition at line 103 of file px.h.

◆ PXE_PGP_WRONG_KEY

#define PXE_PGP_WRONG_KEY   -113

Definition at line 94 of file px.h.

Referenced by control_cksum(), decrypt_elgamal(), decrypt_rsa(), and pgp_parse_pubenc_sesskey().

◆ PXE_UNKNOWN_SALT_ALGO

#define PXE_UNKNOWN_SALT_ALGO   -14

Definition at line 75 of file px.h.

Referenced by px_gen_salt().

Typedef Documentation

◆ PX_Alias

Definition at line 108 of file px.h.

◆ PX_Cipher

Definition at line 110 of file px.h.

◆ PX_Combo

Definition at line 111 of file px.h.

◆ PX_HMAC

Definition at line 109 of file px.h.

◆ PX_MD

Definition at line 107 of file px.h.

Function Documentation

◆ px_debug()

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

◆ px_find_cipher()

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

Definition at line 597 of file internal.c.

References px_cipher::block_size, OSSLCipher::ciph, ossl_cipher_lookup::ciph, cipher_free_callback(), ossl_cipher::cipher_func, cipher_resowner_callback_registered, OSSLDigest::ctx, CurrentResourceOwner, px_cipher::decrypt, px_cipher::encrypt, OSSLCipher::evp_ciph, OSSLCipher::evp_ctx, px_cipher::free, gen_ossl_block_size(), gen_ossl_decrypt(), gen_ossl_encrypt(), gen_ossl_free(), gen_ossl_iv_size(), gen_ossl_key_size(), i, px_cipher::init, ossl_cipher::init, px_cipher::iv_size, px_cipher::key_size, int_cipher::load, MemoryContextAllocZero(), int_cipher::name, ossl_cipher_lookup::name, OSSLCipher::next, open_ciphers, OSSLCipher::owner, pfree(), OSSLCipher::prev, px_cipher::ptr, px_alloc, px_resolve_alias(), PXE_CIPHER_INIT, PXE_NO_CIPHER, RegisterResourceReleaseCallback(), and TopMemoryContext.

Referenced by pgp_load_cipher(), and px_find_combo().

598 {
599  int i;
600  PX_Cipher *c = NULL;
601 
603 
604  for (i = 0; int_ciphers[i].name; i++)
605  if (strcmp(int_ciphers[i].name, name) == 0)
606  {
607  c = int_ciphers[i].load();
608  break;
609  }
610 
611  if (c == NULL)
612  return PXE_NO_CIPHER;
613 
614  *res = c;
615  return 0;
616 }
static const struct int_cipher int_ciphers[]
Definition: internal.c:555
PX_Cipher *(* load)(void)
Definition: internal.c:551
char * name
Definition: internal.c:550
const char * px_resolve_alias(const PX_Alias *list, const char *name)
Definition: px.c:140
char * c
Definition: px.h:154
const char * name
Definition: encode.c:521
int i
#define PXE_NO_CIPHER
Definition: px.h:65
static const PX_Alias int_aliases[]
Definition: internal.c:563

◆ px_find_combo()

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

Definition at line 410 of file px.c.

References buf, px_combo::cipher, combo_decrypt(), combo_decrypt_len(), combo_encrypt(), combo_encrypt_len(), combo_free(), combo_init(), cx(), px_combo::decrypt, px_combo::decrypt_len, px_combo::encrypt, px_combo::encrypt_len, error_desc::err, px_combo::free, px_combo::init, px_combo::padding, parse_cipher_name(), px_alloc, px_cipher_free, px_find_cipher(), px_free, PXE_NO_CIPHER, and s_pad().

Referenced by pg_decrypt(), pg_decrypt_iv(), pg_encrypt(), and pg_encrypt_iv().

411 {
412  int err;
413  char *buf,
414  *s_cipher,
415  *s_pad;
416 
417  PX_Combo *cx;
418 
419  cx = px_alloc(sizeof(*cx));
420  memset(cx, 0, sizeof(*cx));
421 
422  buf = px_alloc(strlen(name) + 1);
423  strcpy(buf, name);
424 
425  err = parse_cipher_name(buf, &s_cipher, &s_pad);
426  if (err)
427  {
428  px_free(buf);
429  px_free(cx);
430  return err;
431  }
432 
433  err = px_find_cipher(s_cipher, &cx->cipher);
434  if (err)
435  goto err1;
436 
437  if (s_pad != NULL)
438  {
439  if (strcmp(s_pad, "pkcs") == 0)
440  cx->padding = 1;
441  else if (strcmp(s_pad, "none") == 0)
442  cx->padding = 0;
443  else
444  goto err1;
445  }
446  else
447  cx->padding = 1;
448 
449  cx->init = combo_init;
450  cx->encrypt = combo_encrypt;
451  cx->decrypt = combo_decrypt;
454  cx->free = combo_free;
455 
456  px_free(buf);
457 
458  *res = cx;
459 
460  return 0;
461 
462 err1:
463  if (cx->cipher)
464  px_cipher_free(cx->cipher);
465  px_free(cx);
466  px_free(buf);
467  return PXE_NO_CIPHER;
468 }
static int s_pad(mp_int z, mp_size min)
Definition: imath.c:2324
static unsigned combo_encrypt_len(PX_Combo *cx, unsigned dlen)
Definition: px.c:180
unsigned padding
Definition: px.h:182
static int combo_encrypt(PX_Combo *cx, const uint8 *data, unsigned dlen, uint8 *res, unsigned *rlen)
Definition: px.c:231
int err
Definition: px.c:38
#define px_free(p)
Definition: px.h:46
void(* free)(PX_Combo *cx)
Definition: px.h:179
#define px_cipher_free(c)
Definition: px.h:229
Definition: px.h:169
static unsigned combo_decrypt_len(PX_Combo *cx, unsigned dlen)
Definition: px.c:186
PX_Cipher * cipher
Definition: px.h:181
int cx(PlannerInfo *root, Gene *tour1, Gene *tour2, Gene *offspring, int num_gene, City *city_table)
static int parse_cipher_name(char *full, char **cipher, char **pad)
Definition: px.c:368
static char * buf
Definition: pg_test_fsync.c:67
unsigned(* decrypt_len)(PX_Combo *cx, unsigned dlen)
Definition: px.h:178
int(* init)(PX_Combo *cx, const uint8 *key, unsigned klen, const uint8 *iv, unsigned ivlen)
Definition: px.h:171
int(* encrypt)(PX_Combo *cx, const uint8 *data, unsigned dlen, uint8 *res, unsigned *rlen)
Definition: px.h:173
unsigned(* encrypt_len)(PX_Combo *cx, unsigned dlen)
Definition: px.h:177
static int combo_init(PX_Combo *cx, const uint8 *key, unsigned klen, const uint8 *iv, unsigned ivlen)
Definition: px.c:192
static void combo_free(PX_Combo *cx)
Definition: px.c:357
const char * name
Definition: encode.c:521
#define px_alloc(s)
Definition: px.h:44
#define PXE_NO_CIPHER
Definition: px.h:65
static int combo_decrypt(PX_Combo *cx, const uint8 *data, unsigned dlen, uint8 *res, unsigned *rlen)
Definition: px.c:300
int(* decrypt)(PX_Combo *cx, const uint8 *data, unsigned dlen, uint8 *res, unsigned *rlen)
Definition: px.h:175
int px_find_cipher(const char *name, PX_Cipher **res)
Definition: internal.c:597

◆ px_find_digest()

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

Definition at line 578 of file internal.c.

References OSSLDigest::algo, px_digest::block_size, OSSLDigest::ctx, CurrentResourceOwner, digest_block_size(), digest_finish(), digest_free(), digest_free_callback(), digest_reset(), digest_resowner_callback_registered, digest_result_size(), digest_update(), px_digest::finish, px_digest::free, int_digest::init, MemoryContextAlloc(), int_digest::name, OSSLDigest::next, open_digests, OSSLDigest::owner, px_digest::p, pfree(), pg_strcasecmp(), OSSLDigest::prev, px_digest::ptr, px_alloc, px_openssl_initialized, PXE_NO_HASH, RegisterResourceReleaseCallback(), px_digest::reset, px_digest::result_size, TopMemoryContext, and px_digest::update.

Referenced by pg_digest(), pgp_load_digest(), px_crypt_md5(), and px_find_hmac().

579 {
580  const struct int_digest *p;
581  PX_MD *h;
582 
583  for (p = int_digest_list; p->name; p++)
584  if (pg_strcasecmp(p->name, name) == 0)
585  {
586  h = px_alloc(sizeof(*h));
587  p->init(h);
588 
589  *res = h;
590 
591  return 0;
592  }
593  return PXE_NO_HASH;
594 }
static const struct int_digest int_digest_list[]
Definition: internal.c:91
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
Definition: px.h:113
#define PXE_NO_HASH
Definition: px.h:64
char * name
Definition: internal.c:86
const char * name
Definition: encode.c:521
#define px_alloc(s)
Definition: px.h:44
void(* init)(PX_MD *h)
Definition: internal.c:87

◆ px_find_hmac()

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

Definition at line 143 of file px-hmac.c.

References px_hmac::block_size, px_hmac::finish, px_hmac::free, hmac_block_size(), hmac_finish(), hmac_free(), hmac_init(), hmac_reset(), hmac_result_size(), hmac_update(), px_hmac::init, px_hmac::ipad, px_hmac::md, px_hmac::opad, px_hmac::p, px_alloc, px_find_digest(), px_md_block_size, px_md_free, PXE_HASH_UNUSABLE_FOR_HMAC, px_hmac::reset, px_hmac::result_size, and px_hmac::update.

Referenced by pg_hmac().

144 {
145  int err;
146  PX_MD *md;
147  PX_HMAC *h;
148  unsigned bs;
149 
150  err = px_find_digest(name, &md);
151  if (err)
152  return err;
153 
154  bs = px_md_block_size(md);
155  if (bs < 2)
156  {
157  px_md_free(md);
159  }
160 
161  h = px_alloc(sizeof(*h));
162  h->p.ipad = px_alloc(bs);
163  h->p.opad = px_alloc(bs);
164  h->md = md;
165 
168  h->reset = hmac_reset;
169  h->update = hmac_update;
170  h->finish = hmac_finish;
171  h->free = hmac_free;
172  h->init = hmac_init;
173 
174  *res = h;
175 
176  return 0;
177 }
#define PXE_HASH_UNUSABLE_FOR_HMAC
Definition: px.h:71
static void hmac_init(PX_HMAC *h, const uint8 *key, unsigned klen)
Definition: px-hmac.c:52
struct px_hmac::@14 p
void(* free)(PX_HMAC *h)
Definition: px.h:142
static void hmac_free(PX_HMAC *h)
Definition: px-hmac.c:125
unsigned(* result_size)(PX_HMAC *h)
Definition: px.h:137
#define px_md_block_size(md)
Definition: px.h:206
static void hmac_update(PX_HMAC *h, const uint8 *data, unsigned dlen)
Definition: px-hmac.c:95
static void hmac_finish(PX_HMAC *h, uint8 *dst)
Definition: px-hmac.c:101
PX_MD * md
Definition: px.h:145
void(* reset)(PX_HMAC *h)
Definition: px.h:139
Definition: px.h:113
void(* update)(PX_HMAC *h, const uint8 *data, unsigned dlen)
Definition: px.h:140
void(* finish)(PX_HMAC *h, uint8 *dst)
Definition: px.h:141
uint8 * opad
Definition: px.h:150
static void hmac_reset(PX_HMAC *h)
Definition: px-hmac.c:85
#define px_md_free(md)
Definition: px.h:210
static unsigned hmac_result_size(PX_HMAC *h)
Definition: px-hmac.c:40
void(* init)(PX_HMAC *h, const uint8 *key, unsigned klen)
Definition: px.h:143
static unsigned hmac_block_size(PX_HMAC *h)
Definition: px-hmac.c:46
const char * name
Definition: encode.c:521
#define px_alloc(s)
Definition: px.h:44
uint8 * ipad
Definition: px.h:149
unsigned(* block_size)(PX_HMAC *h)
Definition: px.h:138
Definition: px.h:135
int px_find_digest(const char *name, PX_MD **res)
Definition: internal.c:578

◆ px_memset()

◆ px_resolve_alias()

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

Definition at line 140 of file px.c.

References px_alias::alias, px_alias::name, name, and pg_strcasecmp().

Referenced by px_find_cipher().

141 {
142  while (list->name)
143  {
144  if (pg_strcasecmp(list->alias, name) == 0)
145  return list->name;
146  list++;
147  }
148  return name;
149 }
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
const char * name
Definition: encode.c:521

◆ px_set_debug_handler()

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

Definition at line 154 of file px.c.

References debug_handler.

Referenced by decrypt_internal(), encrypt_internal(), and init_work().

155 {
156  debug_handler = handler;
157 }
static void(* debug_handler)(const char *)
Definition: px.c:151

◆ px_strerror()

const char* px_strerror ( int  err)

Definition at line 122 of file px.c.

References error_desc::desc, and error_desc::err.

Referenced by find_provider(), pg_decrypt(), pg_decrypt_iv(), pg_encrypt(), pg_encrypt_iv(), pg_gen_salt(), pg_gen_salt_rounds(), and px_THROW_ERROR().

123 {
124  const struct error_desc *e;
125 
126  for (e = px_err_list; e->desc; e++)
127  if (e->err == err)
128  return e->desc;
129  return "Bad error code";
130 }
int err
Definition: px.c:38
const char * desc
Definition: px.c:39
static const struct error_desc px_err_list[]
Definition: px.c:42
e
Definition: preproc-init.c:82
Definition: px.c:36

◆ px_THROW_ERROR()

void px_THROW_ERROR ( int  err)

Definition at line 96 of file px.c.

References ereport, errcode(), errdetail(), errhint(), errmsg(), ERROR, px_strerror(), and PXE_NO_RANDOM.

Referenced by decrypt_internal(), encrypt_internal(), init_work(), pg_dearmor(), pg_random_bytes(), pg_random_uuid(), pgp_armor_headers(), and pgp_key_id_w().

97 {
98  if (err == PXE_NO_RANDOM)
99  {
100 #ifdef HAVE_STRONG_RANDOM
101  ereport(ERROR,
102  (errcode(ERRCODE_INTERNAL_ERROR),
103  errmsg("could not generate a random number")));
104 #else
105  ereport(ERROR,
106  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
107  errmsg("generating random data is not supported by this build"),
108  errdetail("This functionality requires a source of strong random numbers"),
109  errhint("You need to rebuild PostgreSQL using --enable-strong-random")));
110 #endif
111  }
112  else
113  {
114  /* For other errors, use the message from the above list. */
115  ereport(ERROR,
116  (errcode(ERRCODE_EXTERNAL_ROUTINE_INVOCATION_EXCEPTION),
117  errmsg("%s", px_strerror(err))));
118  }
119 }
int errhint(const char *fmt,...)
Definition: elog.c:987
int err
Definition: px.c:38
int errcode(int sqlerrcode)
Definition: elog.c:575
#define PXE_NO_RANDOM
Definition: px.h:78
#define ERROR
Definition: elog.h:43
int errdetail(const char *fmt,...)
Definition: elog.c:873
#define ereport(elevel, rest)
Definition: elog.h:122
const char * px_strerror(int err)
Definition: px.c:122
int errmsg(const char *fmt,...)
Definition: elog.c:797