Header And Logo

PostgreSQL
| The world's most advanced open source database.

px.h File Reference

#include <sys/types.h>
#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

Defines

#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_OSSL_RAND_ERROR   -11
#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_MBUF_SHORT_READ   -50
#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_NO_BIGNUM   -108
#define PXE_PGP_MATH_FAILED   -109
#define PXE_PGP_SHORT_ELGAMAL_KEY   -110
#define PXE_PGP_RSA_UNSUPPORTED   -111
#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)
int px_get_random_bytes (uint8 *dst, unsigned count)
int px_get_pseudo_random_bytes (uint8 *dst, unsigned count)
int px_add_entropy (const uint8 *data, unsigned count)
unsigned px_acquire_system_randomness (uint8 *dst)
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_debug (const char *fmt,...)


Define Documentation

#define px_alloc (  )     palloc(s)

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

Definition at line 229 of file px.h.

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

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

Definition at line 234 of file px.h.

Referenced by combo_decrypt().

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

Definition at line 232 of file px.h.

Referenced by cfb_process(), and combo_encrypt().

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

Definition at line 236 of file px.h.

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

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

Definition at line 231 of file px.h.

Referenced by combo_init(), and pgp_cfb_create().

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

Definition at line 230 of file px.h.

Referenced by combo_init().

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

Definition at line 228 of file px.h.

Referenced by combo_init().

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

Definition at line 245 of file px.h.

Referenced by pg_decrypt(), and pg_decrypt_iv().

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

Definition at line 240 of file px.h.

Referenced by pg_decrypt(), and pg_decrypt_iv().

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

Definition at line 243 of file px.h.

Referenced by pg_encrypt(), and pg_encrypt_iv().

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

Definition at line 239 of file px.h.

Referenced by pg_encrypt(), and pg_encrypt_iv().

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

Definition at line 247 of file px.h.

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

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

Definition at line 241 of file px.h.

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

#define PX_DEBUG

Definition at line 39 of file px.h.

#define px_free (  )     pfree(p)

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

Definition at line 220 of file px.h.

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

Definition at line 224 of file px.h.

Referenced by pg_hmac().

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

Definition at line 225 of file px.h.

Referenced by pg_hmac().

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

Definition at line 222 of file px.h.

Referenced by pg_hmac().

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

Definition at line 221 of file px.h.

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

Definition at line 219 of file px.h.

Referenced by pg_hmac().

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

Definition at line 223 of file px.h.

Referenced by pg_hmac().

#define PX_MAX_NAMELEN   128

Definition at line 55 of file px.h.

#define PX_MAX_SALT_LEN   128

Definition at line 58 of file px.h.

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

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

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

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

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

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

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

Definition at line 46 of file px.h.

Referenced by prepare_room(), and s_realloc().

#define PXE_ARGUMENT_ERROR   -13

#define PXE_BAD_FORMAT   -6

Definition at line 69 of file px.h.

Referenced by parse_cipher_name().

#define PXE_BAD_OPTION   -5

Definition at line 68 of file px.h.

Referenced by parse_cipher_name().

#define PXE_BAD_SALT_ROUNDS   -15

Definition at line 78 of file px.h.

Referenced by px_gen_salt().

#define PXE_BUG   -12

#define PXE_CIPHER_INIT   -8

Definition at line 71 of file px.h.

Referenced by rj_decrypt(), and rj_encrypt().

#define PXE_DECRYPT_FAILED   -18

Definition at line 81 of file px.h.

Referenced by combo_decrypt().

#define PXE_DEV_READ_ERROR   -10

Definition at line 73 of file px.h.

#define PXE_ERR_GENERIC   -1

Definition at line 64 of file px.h.

#define PXE_HASH_UNUSABLE_FOR_HMAC   -9

Definition at line 72 of file px.h.

Referenced by px_find_hmac().

#define PXE_KEY_TOO_BIG   -7

Definition at line 70 of file px.h.

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

#define PXE_MBUF_SHORT_READ   -50

Definition at line 83 of file px.h.

Referenced by pullf_read_fixed().

#define PXE_MCRYPT_INTERNAL   -16

Definition at line 79 of file px.h.

#define PXE_NO_CIPHER   -3

Definition at line 66 of file px.h.

Referenced by px_find_cipher(), and px_find_combo().

#define PXE_NO_HASH   -2

Definition at line 65 of file px.h.

Referenced by compat_find_digest(), and px_find_digest().

#define PXE_NO_RANDOM   -17

Definition at line 80 of file px.h.

#define PXE_NOTBLOCKSIZE   -4

Definition at line 67 of file px.h.

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

#define PXE_OK   0

Definition at line 63 of file px.h.

Referenced by pgp_set_s2k_mode().

#define PXE_OSSL_RAND_ERROR   -11

Definition at line 74 of file px.h.

Referenced by px_get_pseudo_random_bytes(), and px_get_random_bytes().

#define PXE_PGP_BAD_S2K_MODE   -121

Definition at line 106 of file px.h.

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

#define PXE_PGP_COMPRESSION_ERROR   -105

Definition at line 90 of file px.h.

#define PXE_PGP_CORRUPT_ARMOR   -101

Definition at line 86 of file px.h.

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

#define PXE_PGP_CORRUPT_DATA   -100

#define PXE_PGP_EXPECT_PUBLIC_KEY   -115

Definition at line 100 of file px.h.

Referenced by internal_read_key().

#define PXE_PGP_EXPECT_SECRET_KEY   -116

Definition at line 101 of file px.h.

Referenced by internal_read_key().

#define PXE_PGP_KEYPKT_CORRUPT   -118

Definition at line 103 of file px.h.

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

#define PXE_PGP_MATH_FAILED   -109

Definition at line 94 of file px.h.

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

#define PXE_PGP_MULTIPLE_KEYS   -114

Definition at line 99 of file px.h.

Referenced by internal_read_key(), and pgp_get_keyid().

#define PXE_PGP_MULTIPLE_SUBKEYS   -123

Definition at line 108 of file px.h.

Referenced by internal_read_key().

#define PXE_PGP_NEED_SECRET_PSW   -120

Definition at line 105 of file px.h.

Referenced by process_secret_key().

#define PXE_PGP_NO_BIGNUM   -108

Definition at line 93 of file px.h.

#define PXE_PGP_NO_USABLE_KEY   -119

Definition at line 104 of file px.h.

Referenced by internal_read_key(), and pgp_get_keyid().

#define PXE_PGP_NOT_TEXT   -106

Definition at line 91 of file px.h.

Referenced by parse_literal_data().

#define PXE_PGP_NOT_V4_KEYPKT   -117

Definition at line 102 of file px.h.

Referenced by _pgp_read_public_key().

#define PXE_PGP_RSA_UNSUPPORTED   -111

Definition at line 96 of file px.h.

#define PXE_PGP_SHORT_ELGAMAL_KEY   -110

Definition at line 95 of file px.h.

#define PXE_PGP_UNEXPECTED_PKT   -107

Definition at line 92 of file px.h.

Referenced by internal_read_key().

#define PXE_PGP_UNKNOWN_PUBALGO   -112

Definition at line 97 of file px.h.

Referenced by _pgp_read_public_key(), and pgp_parse_pubenc_sesskey().

#define PXE_PGP_UNSUPPORTED_CIPHER   -103

Definition at line 88 of file px.h.

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

#define PXE_PGP_UNSUPPORTED_COMPR   -102

Definition at line 87 of file px.h.

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

#define PXE_PGP_UNSUPPORTED_HASH   -104

Definition at line 89 of file px.h.

Referenced by pgp_get_digest_code(), and pgp_load_digest().

#define PXE_PGP_UNSUPPORTED_PUBALGO   -122

Definition at line 107 of file px.h.

#define PXE_PGP_WRONG_KEY   -113

Definition at line 98 of file px.h.

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

#define PXE_UNKNOWN_SALT_ALGO   -14

Definition at line 77 of file px.h.

Referenced by px_gen_salt().


Typedef Documentation

typedef struct px_alias PX_Alias

Definition at line 112 of file px.h.

typedef struct px_cipher PX_Cipher

Definition at line 114 of file px.h.

typedef struct px_combo PX_Combo

Definition at line 115 of file px.h.

typedef struct px_hmac PX_HMAC

Definition at line 113 of file px.h.

typedef struct px_digest PX_MD

Definition at line 111 of file px.h.


Function Documentation

unsigned px_acquire_system_randomness ( uint8 dst  ) 

Definition at line 227 of file random.c.

References try_unix_std().

Referenced by system_reseed().

00228 {
00229     uint8      *p = dst;
00230 
00231 #ifdef TRY_DEV_RANDOM
00232     p = try_dev_random(p);
00233 #endif
00234 #ifdef TRY_WIN32_GENRAND
00235     p = try_win32_genrand(p);
00236 #endif
00237 #ifdef TRY_WIN32_PERFC
00238     p = try_win32_perfc(p);
00239 #endif
00240 #ifdef TRY_UNIXSTD
00241     p = try_unix_std(p);
00242 #endif
00243     return p - dst;
00244 }

int px_add_entropy ( const uint8 data,
unsigned  count 
)

Definition at line 684 of file internal.c.

References fortuna_add_entropy(), and system_reseed().

Referenced by add_block_entropy().

00685 {
00686     system_reseed();
00687     fortuna_add_entropy(data, count);
00688     return 0;
00689 }

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

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

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

Definition at line 383 of file px.c.

References 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, NULL, 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().

00384 {
00385     int         err;
00386     char       *buf,
00387                *s_cipher,
00388                *s_pad;
00389 
00390     PX_Combo   *cx;
00391 
00392     cx = px_alloc(sizeof(*cx));
00393     memset(cx, 0, sizeof(*cx));
00394 
00395     buf = px_alloc(strlen(name) + 1);
00396     strcpy(buf, name);
00397 
00398     err = parse_cipher_name(buf, &s_cipher, &s_pad);
00399     if (err)
00400     {
00401         px_free(buf);
00402         px_free(cx);
00403         return err;
00404     }
00405 
00406     err = px_find_cipher(s_cipher, &cx->cipher);
00407     if (err)
00408         goto err1;
00409 
00410     if (s_pad != NULL)
00411     {
00412         if (!strcmp(s_pad, "pkcs"))
00413             cx->padding = 1;
00414         else if (!strcmp(s_pad, "none"))
00415             cx->padding = 0;
00416         else
00417             goto err1;
00418     }
00419     else
00420         cx->padding = 1;
00421 
00422     cx->init = combo_init;
00423     cx->encrypt = combo_encrypt;
00424     cx->decrypt = combo_decrypt;
00425     cx->encrypt_len = combo_encrypt_len;
00426     cx->decrypt_len = combo_decrypt_len;
00427     cx->free = combo_free;
00428 
00429     px_free(buf);
00430 
00431     *res = cx;
00432 
00433     return 0;
00434 
00435 err1:
00436     if (cx->cipher)
00437         px_cipher_free(cx->cipher);
00438     px_free(cx);
00439     px_free(buf);
00440     return PXE_NO_CIPHER;
00441 }

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

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

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

00146 {
00147     int         err;
00148     PX_MD      *md;
00149     PX_HMAC    *h;
00150     unsigned    bs;
00151 
00152     err = px_find_digest(name, &md);
00153     if (err)
00154         return err;
00155 
00156     bs = px_md_block_size(md);
00157     if (bs < 2)
00158     {
00159         px_md_free(md);
00160         return PXE_HASH_UNUSABLE_FOR_HMAC;
00161     }
00162 
00163     h = px_alloc(sizeof(*h));
00164     h->p.ipad = px_alloc(bs);
00165     h->p.opad = px_alloc(bs);
00166     h->md = md;
00167 
00168     h->result_size = hmac_result_size;
00169     h->block_size = hmac_block_size;
00170     h->reset = hmac_reset;
00171     h->update = hmac_update;
00172     h->finish = hmac_finish;
00173     h->free = hmac_free;
00174     h->init = hmac_init;
00175 
00176     *res = h;
00177 
00178     return 0;
00179 }

int px_get_pseudo_random_bytes ( uint8 dst,
unsigned  count 
)

Definition at line 628 of file internal.c.

References init_openssl_rand(), openssl_random_init, px_get_random_bytes(), and PXE_OSSL_RAND_ERROR.

Referenced by pgp_s2k_fill(), and px_gen_salt().

00629 {
00630     return px_get_random_bytes(dst, count);
00631 }

int px_get_random_bytes ( uint8 dst,
unsigned  count 
)

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

Definition at line 109 of file px.c.

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

Referenced by px_find_cipher().

00110 {
00111     while (list->name)
00112     {
00113         if (pg_strcasecmp(list->alias, name) == 0)
00114             return list->name;
00115         list++;
00116     }
00117     return name;
00118 }

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

Definition at line 123 of file px.c.

References debug_handler.

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

00124 {
00125     debug_handler = handler;
00126 }

const char* px_strerror ( int  err  ) 

Definition at line 97 of file px.c.

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

Referenced by decrypt_internal(), encrypt_internal(), find_provider(), init_work(), pg_dearmor(), pg_decrypt(), pg_decrypt_iv(), pg_encrypt(), pg_encrypt_iv(), pg_gen_salt(), pg_gen_salt_rounds(), pg_random_bytes(), and pgp_key_id_w().

00098 {
00099     const struct error_desc *e;
00100 
00101     for (e = px_err_list; e->desc; e++)
00102         if (e->err == err)
00103             return e->desc;
00104     return "Bad error code";
00105 }


Generated on Thu Mar 18 03:10:36 2010 for PostgreSQL Source Code by  doxygen 1.5.8