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_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 219 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 224 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 222 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 226 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 221 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 220 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 218 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 235 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 230 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 233 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 229 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 237 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 231 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 210 of file px.h.

◆ px_hmac_finish

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

Definition at line 214 of file px.h.

Referenced by pg_hmac().

◆ px_hmac_free

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

Definition at line 215 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 212 of file px.h.

Referenced by pg_hmac().

◆ px_hmac_reset

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

Definition at line 211 of file px.h.

◆ px_hmac_result_size

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

Definition at line 209 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 213 of file px.h.

Referenced by pg_hmac().

◆ PX_MAX_SALT_LEN

#define PX_MAX_SALT_LEN   128

Definition at line 54 of file px.h.

◆ px_md_block_size

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

Definition at line 203 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 65 of file px.h.

Referenced by parse_cipher_name().

◆ PXE_BAD_OPTION

#define PXE_BAD_OPTION   -5

Definition at line 64 of file px.h.

Referenced by parse_cipher_name().

◆ PXE_BAD_SALT_ROUNDS

#define PXE_BAD_SALT_ROUNDS   -15

Definition at line 73 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 76 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 69 of file px.h.

◆ PXE_ERR_GENERIC

#define PXE_ERR_GENERIC   -1

Definition at line 60 of file px.h.

Referenced by gen_ossl_encrypt().

◆ PXE_HASH_UNUSABLE_FOR_HMAC

#define PXE_HASH_UNUSABLE_FOR_HMAC   -9

Definition at line 68 of file px.h.

Referenced by px_find_hmac().

◆ PXE_KEY_TOO_BIG

#define PXE_KEY_TOO_BIG   -7

Definition at line 66 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 74 of file px.h.

◆ PXE_NO_CIPHER

#define PXE_NO_CIPHER   -3

Definition at line 62 of file px.h.

Referenced by px_find_cipher(), and px_find_combo().

◆ PXE_NO_HASH

#define PXE_NO_HASH   -2

Definition at line 61 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 63 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 59 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 99 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 83 of file px.h.

◆ PXE_PGP_CORRUPT_ARMOR

#define PXE_PGP_CORRUPT_ARMOR   -101

Definition at line 79 of file px.h.

Referenced by find_header(), pg_base64_decode(), 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 93 of file px.h.

Referenced by internal_read_key().

◆ PXE_PGP_EXPECT_SECRET_KEY

#define PXE_PGP_EXPECT_SECRET_KEY   -116

Definition at line 94 of file px.h.

Referenced by internal_read_key().

◆ PXE_PGP_KEYPKT_CORRUPT

#define PXE_PGP_KEYPKT_CORRUPT   -118

Definition at line 96 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 87 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 92 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 101 of file px.h.

Referenced by internal_read_key().

◆ PXE_PGP_NEED_SECRET_PSW

#define PXE_PGP_NEED_SECRET_PSW   -120

Definition at line 98 of file px.h.

Referenced by process_secret_key().

◆ PXE_PGP_NO_USABLE_KEY

#define PXE_PGP_NO_USABLE_KEY   -119

Definition at line 97 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 84 of file px.h.

Referenced by pgp_decrypt().

◆ PXE_PGP_NOT_V4_KEYPKT

#define PXE_PGP_NOT_V4_KEYPKT   -117

Definition at line 95 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 88 of file px.h.

◆ PXE_PGP_UNEXPECTED_PKT

#define PXE_PGP_UNEXPECTED_PKT   -107

Definition at line 85 of file px.h.

Referenced by internal_read_key().

◆ PXE_PGP_UNKNOWN_PUBALGO

#define PXE_PGP_UNKNOWN_PUBALGO   -112

Definition at line 90 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 81 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 80 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 82 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 100 of file px.h.

◆ PXE_PGP_WRONG_KEY

#define PXE_PGP_WRONG_KEY   -113

Definition at line 91 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 72 of file px.h.

Referenced by px_gen_salt().

Typedef Documentation

◆ PX_Alias

typedef struct px_alias PX_Alias

Definition at line 105 of file px.h.

◆ PX_Cipher

typedef struct px_cipher PX_Cipher

Definition at line 107 of file px.h.

◆ PX_Combo

typedef struct px_combo PX_Combo

Definition at line 108 of file px.h.

◆ PX_HMAC

typedef struct px_hmac PX_HMAC

Definition at line 106 of file px.h.

◆ PX_MD

typedef struct px_digest PX_MD

Definition at line 104 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 578 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().

579 {
580  int i;
581  PX_Cipher *c = NULL;
582 
584 
585  for (i = 0; int_ciphers[i].name; i++)
586  if (strcmp(int_ciphers[i].name, name) == 0)
587  {
588  c = int_ciphers[i].load();
589  break;
590  }
591 
592  if (c == NULL)
593  return PXE_NO_CIPHER;
594 
595  *res = c;
596  return 0;
597 }
static const struct int_cipher int_ciphers[]
Definition: internal.c:536
PX_Cipher *(* load)(void)
Definition: internal.c:532
char * name
Definition: internal.c:531
const char * px_resolve_alias(const PX_Alias *list, const char *name)
Definition: px.c:132
char * c
Definition: px.h:151
const char * name
Definition: encode.c:521
int i
#define PXE_NO_CIPHER
Definition: px.h:62
static const PX_Alias int_aliases[]
Definition: internal.c:544

◆ px_find_combo()

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

Definition at line 402 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().

403 {
404  int err;
405  char *buf,
406  *s_cipher,
407  *s_pad;
408 
409  PX_Combo *cx;
410 
411  cx = px_alloc(sizeof(*cx));
412  memset(cx, 0, sizeof(*cx));
413 
414  buf = px_alloc(strlen(name) + 1);
415  strcpy(buf, name);
416 
417  err = parse_cipher_name(buf, &s_cipher, &s_pad);
418  if (err)
419  {
420  px_free(buf);
421  px_free(cx);
422  return err;
423  }
424 
425  err = px_find_cipher(s_cipher, &cx->cipher);
426  if (err)
427  goto err1;
428 
429  if (s_pad != NULL)
430  {
431  if (strcmp(s_pad, "pkcs") == 0)
432  cx->padding = 1;
433  else if (strcmp(s_pad, "none") == 0)
434  cx->padding = 0;
435  else
436  goto err1;
437  }
438  else
439  cx->padding = 1;
440 
441  cx->init = combo_init;
442  cx->encrypt = combo_encrypt;
443  cx->decrypt = combo_decrypt;
446  cx->free = combo_free;
447 
448  px_free(buf);
449 
450  *res = cx;
451 
452  return 0;
453 
454 err1:
455  if (cx->cipher)
456  px_cipher_free(cx->cipher);
457  px_free(cx);
458  px_free(buf);
459  return PXE_NO_CIPHER;
460 }
static unsigned combo_encrypt_len(PX_Combo *cx, unsigned dlen)
Definition: px.c:172
unsigned padding
Definition: px.h:179
static int combo_encrypt(PX_Combo *cx, const uint8 *data, unsigned dlen, uint8 *res, unsigned *rlen)
Definition: px.c:223
int err
Definition: px.c:38
#define px_free(p)
Definition: px.h:46
void(* free)(PX_Combo *cx)
Definition: px.h:176
#define px_cipher_free(c)
Definition: px.h:226
Definition: px.h:166
static unsigned combo_decrypt_len(PX_Combo *cx, unsigned dlen)
Definition: px.c:178
PX_Cipher * cipher
Definition: px.h:178
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:360
static char * buf
Definition: pg_test_fsync.c:67
unsigned(* decrypt_len)(PX_Combo *cx, unsigned dlen)
Definition: px.h:175
int(* init)(PX_Combo *cx, const uint8 *key, unsigned klen, const uint8 *iv, unsigned ivlen)
Definition: px.h:168
int(* encrypt)(PX_Combo *cx, const uint8 *data, unsigned dlen, uint8 *res, unsigned *rlen)
Definition: px.h:170
unsigned(* encrypt_len)(PX_Combo *cx, unsigned dlen)
Definition: px.h:174
static int combo_init(PX_Combo *cx, const uint8 *key, unsigned klen, const uint8 *iv, unsigned ivlen)
Definition: px.c:184
static void combo_free(PX_Combo *cx)
Definition: px.c:349
static bool s_pad(mp_int z, mp_size min)
Definition: imath.c:2253
const char * name
Definition: encode.c:521
#define px_alloc(s)
Definition: px.h:44
#define PXE_NO_CIPHER
Definition: px.h:62
static int combo_decrypt(PX_Combo *cx, const uint8 *data, unsigned dlen, uint8 *res, unsigned *rlen)
Definition: px.c:292
int(* decrypt)(PX_Combo *cx, const uint8 *data, unsigned dlen, uint8 *res, unsigned *rlen)
Definition: px.h:172
int px_find_cipher(const char *name, PX_Cipher **res)
Definition: internal.c:578

◆ px_find_digest()

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

Definition at line 559 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().

560 {
561  const struct int_digest *p;
562  PX_MD *h;
563 
564  for (p = int_digest_list; p->name; p++)
565  if (pg_strcasecmp(p->name, name) == 0)
566  {
567  h = px_alloc(sizeof(*h));
568  p->init(h);
569 
570  *res = h;
571 
572  return 0;
573  }
574  return PXE_NO_HASH;
575 }
static const struct int_digest int_digest_list[]
Definition: internal.c:72
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
Definition: px.h:110
#define PXE_NO_HASH
Definition: px.h:61
char * name
Definition: internal.c:67
const char * name
Definition: encode.c:521
#define px_alloc(s)
Definition: px.h:44
void(* init)(PX_MD *h)
Definition: internal.c:68

◆ 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:68
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:139
static void hmac_free(PX_HMAC *h)
Definition: px-hmac.c:125
unsigned(* result_size)(PX_HMAC *h)
Definition: px.h:134
#define px_md_block_size(md)
Definition: px.h:203
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:142
void(* reset)(PX_HMAC *h)
Definition: px.h:136
Definition: px.h:110
void(* update)(PX_HMAC *h, const uint8 *data, unsigned dlen)
Definition: px.h:137
void(* finish)(PX_HMAC *h, uint8 *dst)
Definition: px.h:138
uint8 * opad
Definition: px.h:147
static void hmac_reset(PX_HMAC *h)
Definition: px-hmac.c:85
#define px_md_free(md)
Definition: px.h:207
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:140
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:146
unsigned(* block_size)(PX_HMAC *h)
Definition: px.h:135
Definition: px.h:132
int px_find_digest(const char *name, PX_MD **res)
Definition: internal.c:559

◆ px_memset()

◆ px_resolve_alias()

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

Definition at line 132 of file px.c.

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

Referenced by px_find_cipher().

133 {
134  while (list->name)
135  {
136  if (pg_strcasecmp(list->alias, name) == 0)
137  return list->name;
138  list++;
139  }
140  return name;
141 }
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 146 of file px.c.

References debug_handler.

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

147 {
148  debug_handler = handler;
149 }
static void(* debug_handler)(const char *)
Definition: px.c:143

◆ px_strerror()

const char* px_strerror ( int  err)

Definition at line 114 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().

115 {
116  const struct error_desc *e;
117 
118  for (e = px_err_list; e->desc; e++)
119  if (e->err == err)
120  return e->desc;
121  return "Bad error code";
122 }
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(), errmsg(), ERROR, px_strerror(), and PXE_NO_RANDOM.

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

97 {
98  if (err == PXE_NO_RANDOM)
99  {
100  ereport(ERROR,
101  (errcode(ERRCODE_INTERNAL_ERROR),
102  errmsg("could not generate a random number")));
103  }
104  else
105  {
106  /* For other errors, use the message from the above list. */
107  ereport(ERROR,
108  (errcode(ERRCODE_EXTERNAL_ROUTINE_INVOCATION_EXCEPTION),
109  errmsg("%s", px_strerror(err))));
110  }
111 }
int err
Definition: px.c:38
int errcode(int sqlerrcode)
Definition: elog.c:608
#define PXE_NO_RANDOM
Definition: px.h:75
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
const char * px_strerror(int err)
Definition: px.c:114
int errmsg(const char *fmt,...)
Definition: elog.c:822