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_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_ENCRYPT_FAILED   -19
 
#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_cipher_block_size

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

Definition at line 207 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 212 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 210 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 214 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 209 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 208 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 206 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 223 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 218 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 221 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 217 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 225 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 219 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_hmac_block_size

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

Definition at line 198 of file px.h.

◆ px_hmac_finish

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

Definition at line 202 of file px.h.

Referenced by pg_hmac().

◆ px_hmac_free

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

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

Referenced by pg_hmac().

◆ px_hmac_reset

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

Definition at line 199 of file px.h.

◆ px_hmac_result_size

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

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

Referenced by pg_hmac().

◆ PX_MAX_SALT_LEN

#define PX_MAX_SALT_LEN   128

Definition at line 41 of file px.h.

◆ px_md_block_size

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

Definition at line 191 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)

◆ PXE_ARGUMENT_ERROR

#define PXE_ARGUMENT_ERROR   -13

◆ PXE_BAD_FORMAT

#define PXE_BAD_FORMAT   -6

Definition at line 52 of file px.h.

Referenced by parse_cipher_name().

◆ PXE_BAD_OPTION

#define PXE_BAD_OPTION   -5

Definition at line 51 of file px.h.

Referenced by parse_cipher_name().

◆ PXE_BAD_SALT_ROUNDS

#define PXE_BAD_SALT_ROUNDS   -15

Definition at line 60 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 63 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 56 of file px.h.

◆ PXE_ENCRYPT_FAILED

#define PXE_ENCRYPT_FAILED   -19

Definition at line 64 of file px.h.

Referenced by gen_ossl_encrypt().

◆ PXE_ERR_GENERIC

#define PXE_ERR_GENERIC   -1

Definition at line 47 of file px.h.

◆ PXE_HASH_UNUSABLE_FOR_HMAC

#define PXE_HASH_UNUSABLE_FOR_HMAC   -9

Definition at line 55 of file px.h.

Referenced by px_find_hmac().

◆ PXE_KEY_TOO_BIG

#define PXE_KEY_TOO_BIG   -7

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

◆ PXE_NO_CIPHER

#define PXE_NO_CIPHER   -3

Definition at line 49 of file px.h.

Referenced by px_find_cipher(), and px_find_combo().

◆ PXE_NO_HASH

#define PXE_NO_HASH   -2

Definition at line 48 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 50 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 46 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 87 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 71 of file px.h.

◆ PXE_PGP_CORRUPT_ARMOR

#define PXE_PGP_CORRUPT_ARMOR   -101

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

Referenced by internal_read_key().

◆ PXE_PGP_EXPECT_SECRET_KEY

#define PXE_PGP_EXPECT_SECRET_KEY   -116

Definition at line 82 of file px.h.

Referenced by internal_read_key().

◆ PXE_PGP_KEYPKT_CORRUPT

#define PXE_PGP_KEYPKT_CORRUPT   -118

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

Referenced by internal_read_key().

◆ PXE_PGP_NEED_SECRET_PSW

#define PXE_PGP_NEED_SECRET_PSW   -120

Definition at line 86 of file px.h.

Referenced by process_secret_key().

◆ PXE_PGP_NO_USABLE_KEY

#define PXE_PGP_NO_USABLE_KEY   -119

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

Referenced by pgp_decrypt().

◆ PXE_PGP_NOT_V4_KEYPKT

#define PXE_PGP_NOT_V4_KEYPKT   -117

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

◆ PXE_PGP_UNEXPECTED_PKT

#define PXE_PGP_UNEXPECTED_PKT   -107

Definition at line 73 of file px.h.

Referenced by internal_read_key().

◆ PXE_PGP_UNKNOWN_PUBALGO

#define PXE_PGP_UNKNOWN_PUBALGO   -112

Definition at line 78 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 69 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 68 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 70 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 88 of file px.h.

◆ PXE_PGP_WRONG_KEY

#define PXE_PGP_WRONG_KEY   -113

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

Referenced by px_gen_salt().

Typedef Documentation

◆ PX_Alias

typedef struct px_alias PX_Alias

Definition at line 93 of file px.h.

◆ PX_Cipher

typedef struct px_cipher PX_Cipher

Definition at line 95 of file px.h.

◆ PX_Combo

typedef struct px_combo PX_Combo

Definition at line 96 of file px.h.

◆ PX_HMAC

typedef struct px_hmac PX_HMAC

Definition at line 94 of file px.h.

◆ PX_MD

typedef struct px_digest PX_MD

Definition at line 92 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 566 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, palloc(), pfree(), OSSLCipher::prev, px_cipher::ptr, px_resolve_alias(), PXE_CIPHER_INIT, PXE_NO_CIPHER, RegisterResourceReleaseCallback(), and TopMemoryContext.

Referenced by pgp_load_cipher(), and px_find_combo().

567 {
568  int i;
569  PX_Cipher *c = NULL;
570 
572 
573  for (i = 0; int_ciphers[i].name; i++)
574  if (strcmp(int_ciphers[i].name, name) == 0)
575  {
576  c = int_ciphers[i].load();
577  break;
578  }
579 
580  if (c == NULL)
581  return PXE_NO_CIPHER;
582 
583  *res = c;
584  return 0;
585 }
static const struct int_cipher int_ciphers[]
Definition: internal.c:524
PX_Cipher *(* load)(void)
Definition: internal.c:520
char * name
Definition: internal.c:519
const char * px_resolve_alias(const PX_Alias *list, const char *name)
Definition: px.c:133
char * c
Definition: px.h:139
const char * name
Definition: encode.c:515
int i
#define PXE_NO_CIPHER
Definition: px.h:49
static const PX_Alias int_aliases[]
Definition: internal.c:532

◆ 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, palloc0(), parse_cipher_name(), pfree(), pstrdup(), px_cipher_free, px_find_cipher(), 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 = palloc0(sizeof(*cx));
412  buf = pstrdup(name);
413 
414  err = parse_cipher_name(buf, &s_cipher, &s_pad);
415  if (err)
416  {
417  pfree(buf);
418  pfree(cx);
419  return err;
420  }
421 
422  err = px_find_cipher(s_cipher, &cx->cipher);
423  if (err)
424  goto err1;
425 
426  if (s_pad != NULL)
427  {
428  if (strcmp(s_pad, "pkcs") == 0)
429  cx->padding = 1;
430  else if (strcmp(s_pad, "none") == 0)
431  cx->padding = 0;
432  else
433  goto err1;
434  }
435  else
436  cx->padding = 1;
437 
438  cx->init = combo_init;
439  cx->encrypt = combo_encrypt;
440  cx->decrypt = combo_decrypt;
443  cx->free = combo_free;
444 
445  pfree(buf);
446 
447  *res = cx;
448 
449  return 0;
450 
451 err1:
452  if (cx->cipher)
453  px_cipher_free(cx->cipher);
454  pfree(cx);
455  pfree(buf);
456  return PXE_NO_CIPHER;
457 }
static unsigned combo_encrypt_len(PX_Combo *cx, unsigned dlen)
Definition: px.c:173
unsigned padding
Definition: px.h:167
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
char * pstrdup(const char *in)
Definition: mcxt.c:1187
void(* free)(PX_Combo *cx)
Definition: px.h:164
#define px_cipher_free(c)
Definition: px.h:214
Definition: px.h:154
static unsigned combo_decrypt_len(PX_Combo *cx, unsigned dlen)
Definition: px.c:179
PX_Cipher * cipher
Definition: px.h:166
void pfree(void *pointer)
Definition: mcxt.c:1057
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:68
unsigned(* decrypt_len)(PX_Combo *cx, unsigned dlen)
Definition: px.h:163
int(* init)(PX_Combo *cx, const uint8 *key, unsigned klen, const uint8 *iv, unsigned ivlen)
Definition: px.h:156
int(* encrypt)(PX_Combo *cx, const uint8 *data, unsigned dlen, uint8 *res, unsigned *rlen)
Definition: px.h:158
void * palloc0(Size size)
Definition: mcxt.c:981
unsigned(* encrypt_len)(PX_Combo *cx, unsigned dlen)
Definition: px.h:162
static int combo_init(PX_Combo *cx, const uint8 *key, unsigned klen, const uint8 *iv, unsigned ivlen)
Definition: px.c:185
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:515
#define PXE_NO_CIPHER
Definition: px.h:49
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:160
int px_find_cipher(const char *name, PX_Cipher **res)
Definition: internal.c:566

◆ px_find_digest()

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

Definition at line 547 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, palloc(), pfree(), pg_strcasecmp(), OSSLDigest::prev, px_digest::ptr, 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().

548 {
549  const struct int_digest *p;
550  PX_MD *h;
551 
552  for (p = int_digest_list; p->name; p++)
553  if (pg_strcasecmp(p->name, name) == 0)
554  {
555  h = palloc(sizeof(*h));
556  p->init(h);
557 
558  *res = h;
559 
560  return 0;
561  }
562  return PXE_NO_HASH;
563 }
static const struct int_digest int_digest_list[]
Definition: internal.c:62
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
Definition: px.h:98
#define PXE_NO_HASH
Definition: px.h:48
char * name
Definition: internal.c:57
const char * name
Definition: encode.c:515
void * palloc(Size size)
Definition: mcxt.c:950
void(* init)(PX_MD *h)
Definition: internal.c:58

◆ px_find_hmac()

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

Definition at line 142 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, palloc(), 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().

143 {
144  int err;
145  PX_MD *md;
146  PX_HMAC *h;
147  unsigned bs;
148 
149  err = px_find_digest(name, &md);
150  if (err)
151  return err;
152 
153  bs = px_md_block_size(md);
154  if (bs < 2)
155  {
156  px_md_free(md);
158  }
159 
160  h = palloc(sizeof(*h));
161  h->p.ipad = palloc(bs);
162  h->p.opad = palloc(bs);
163  h->md = md;
164 
167  h->reset = hmac_reset;
168  h->update = hmac_update;
169  h->finish = hmac_finish;
170  h->free = hmac_free;
171  h->init = hmac_init;
172 
173  *res = h;
174 
175  return 0;
176 }
#define PXE_HASH_UNUSABLE_FOR_HMAC
Definition: px.h:55
struct px_hmac::@10 p
static void hmac_init(PX_HMAC *h, const uint8 *key, unsigned klen)
Definition: px-hmac.c:52
void(* free)(PX_HMAC *h)
Definition: px.h:127
static void hmac_free(PX_HMAC *h)
Definition: px-hmac.c:124
unsigned(* result_size)(PX_HMAC *h)
Definition: px.h:122
#define px_md_block_size(md)
Definition: px.h:191
static void hmac_update(PX_HMAC *h, const uint8 *data, unsigned dlen)
Definition: px-hmac.c:94
static void hmac_finish(PX_HMAC *h, uint8 *dst)
Definition: px-hmac.c:100
PX_MD * md
Definition: px.h:130
void(* reset)(PX_HMAC *h)
Definition: px.h:124
Definition: px.h:98
void(* update)(PX_HMAC *h, const uint8 *data, unsigned dlen)
Definition: px.h:125
void(* finish)(PX_HMAC *h, uint8 *dst)
Definition: px.h:126
uint8 * opad
Definition: px.h:135
static void hmac_reset(PX_HMAC *h)
Definition: px-hmac.c:84
#define px_md_free(md)
Definition: px.h:195
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:128
static unsigned hmac_block_size(PX_HMAC *h)
Definition: px-hmac.c:46
const char * name
Definition: encode.c:515
uint8 * ipad
Definition: px.h:134
void * palloc(Size size)
Definition: mcxt.c:950
unsigned(* block_size)(PX_HMAC *h)
Definition: px.h:123
Definition: px.h:120
int px_find_digest(const char *name, PX_MD **res)
Definition: internal.c:547

◆ px_memset()

◆ px_resolve_alias()

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

Definition at line 133 of file px.c.

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

Referenced by px_find_cipher().

134 {
135  while (list->name)
136  {
137  if (pg_strcasecmp(list->alias, name) == 0)
138  return list->name;
139  list++;
140  }
141  return name;
142 }
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
const char * name
Definition: encode.c:515

◆ px_set_debug_handler()

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

Definition at line 147 of file px.c.

References debug_handler.

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

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

◆ px_strerror()

const char* px_strerror ( int  err)

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

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

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