Header And Logo

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

Data Structures | Defines | Typedefs | Functions

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,...) __attribute__((format(PG_PRINTF_ATTRIBUTE

Define Documentation

#define px_alloc (   s  )     palloc(s)
#define px_cipher_block_size (   c  )     (c)->block_size(c)

Definition at line 231 of file px.h.

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

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

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

Referenced by cfb_process(), and combo_encrypt().

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

Definition at line 238 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 233 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 232 of file px.h.

Referenced by combo_init().

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

Definition at line 230 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 247 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 242 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 245 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 241 of file px.h.

Referenced by pg_encrypt(), and pg_encrypt_iv().

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

Definition at line 249 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 243 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 (   p  )     pfree(p)
#define px_hmac_block_size (   hmac  )     (hmac)->block_size(hmac)

Definition at line 222 of file px.h.

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

Definition at line 226 of file px.h.

Referenced by pg_hmac().

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

Definition at line 227 of file px.h.

Referenced by pg_hmac().

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

Definition at line 224 of file px.h.

Referenced by pg_hmac().

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

Definition at line 223 of file px.h.

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

Definition at line 221 of file px.h.

Referenced by pg_hmac().

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

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

Definition at line 215 of file px.h.

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

#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,
  s 
)    repalloc(p, s)

Definition at line 46 of file px.h.

Referenced by prepare_room(), and s_realloc().

#define PXE_ARGUMENT_ERROR   -13

Definition at line 76 of file px.h.

#define PXE_BAD_FORMAT   -6

Definition at line 69 of file px.h.

#define PXE_BAD_OPTION   -5

Definition at line 68 of file px.h.

#define PXE_BAD_SALT_ROUNDS   -15

Definition at line 78 of file px.h.

#define PXE_BUG   -12

Definition at line 75 of file px.h.

#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.

#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.

#define PXE_KEY_TOO_BIG   -7

Definition at line 70 of file px.h.

#define PXE_MBUF_SHORT_READ   -50

Definition at line 83 of file px.h.

#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.

#define PXE_NO_HASH   -2

Definition at line 65 of file px.h.

#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.

#define PXE_OK   0

Definition at line 63 of file px.h.

#define PXE_OSSL_RAND_ERROR   -11

Definition at line 74 of file px.h.

#define PXE_PGP_BAD_S2K_MODE   -121

Definition at line 106 of file px.h.

#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.

#define PXE_PGP_CORRUPT_DATA   -100

Definition at line 85 of file px.h.

#define PXE_PGP_EXPECT_PUBLIC_KEY   -115

Definition at line 100 of file px.h.

#define PXE_PGP_EXPECT_SECRET_KEY   -116

Definition at line 101 of file px.h.

#define PXE_PGP_KEYPKT_CORRUPT   -118

Definition at line 103 of file px.h.

#define PXE_PGP_MATH_FAILED   -109

Definition at line 94 of file px.h.

#define PXE_PGP_MULTIPLE_KEYS   -114

Definition at line 99 of file px.h.

#define PXE_PGP_MULTIPLE_SUBKEYS   -123

Definition at line 108 of file px.h.

#define PXE_PGP_NEED_SECRET_PSW   -120

Definition at line 105 of file px.h.

#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.

#define PXE_PGP_NOT_TEXT   -106

Definition at line 91 of file px.h.

#define PXE_PGP_NOT_V4_KEYPKT   -117

Definition at line 102 of file px.h.

#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.

#define PXE_PGP_UNKNOWN_PUBALGO   -112

Definition at line 97 of file px.h.

#define PXE_PGP_UNSUPPORTED_CIPHER   -103

Definition at line 88 of file px.h.

#define PXE_PGP_UNSUPPORTED_COMPR   -102

Definition at line 87 of file px.h.

#define PXE_PGP_UNSUPPORTED_HASH   -104

Definition at line 89 of file px.h.

#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.

#define PXE_UNKNOWN_SALT_ALGO   -14

Definition at line 77 of file px.h.


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().

{
    uint8      *p = dst;

#ifdef TRY_DEV_RANDOM
    p = try_dev_random(p);
#endif
#ifdef TRY_WIN32_GENRAND
    p = try_win32_genrand(p);
#endif
#ifdef TRY_WIN32_PERFC
    p = try_win32_perfc(p);
#endif
#ifdef TRY_UNIXSTD
    p = try_unix_std(p);
#endif
    return p - dst;
}

int px_add_entropy ( const uint8 data,
unsigned  count 
)

Definition at line 683 of file internal.c.

References fortuna_add_entropy(), and system_reseed().

Referenced by add_block_entropy().

{
    system_reseed();
    fortuna_add_entropy(data, count);
    return 0;
}

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 379 of file px.c.

References buf, px_combo::cipher, 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(), and px_free.

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

{
    int         err;
    char       *buf,
               *s_cipher,
               *s_pad;

    PX_Combo   *cx;

    cx = px_alloc(sizeof(*cx));
    memset(cx, 0, sizeof(*cx));

    buf = px_alloc(strlen(name) + 1);
    strcpy(buf, name);

    err = parse_cipher_name(buf, &s_cipher, &s_pad);
    if (err)
    {
        px_free(buf);
        px_free(cx);
        return err;
    }

    err = px_find_cipher(s_cipher, &cx->cipher);
    if (err)
        goto err1;

    if (s_pad != NULL)
    {
        if (strcmp(s_pad, "pkcs") == 0)
            cx->padding = 1;
        else if (strcmp(s_pad, "none") == 0)
            cx->padding = 0;
        else
            goto err1;
    }
    else
        cx->padding = 1;

    cx->init = combo_init;
    cx->encrypt = combo_encrypt;
    cx->decrypt = combo_decrypt;
    cx->encrypt_len = combo_encrypt_len;
    cx->decrypt_len = combo_decrypt_len;
    cx->free = combo_free;

    px_free(buf);

    *res = cx;

    return 0;

err1:
    if (cx->cipher)
        px_cipher_free(cx->cipher);
    px_free(cx);
    px_free(buf);
    return PXE_NO_CIPHER;
}

int px_find_digest ( const char *  name,
PX_MD **  res 
)
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, 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, px_hmac::reset, px_hmac::result_size, and px_hmac::update.

Referenced by pg_hmac().

{
    int         err;
    PX_MD      *md;
    PX_HMAC    *h;
    unsigned    bs;

    err = px_find_digest(name, &md);
    if (err)
        return err;

    bs = px_md_block_size(md);
    if (bs < 2)
    {
        px_md_free(md);
        return PXE_HASH_UNUSABLE_FOR_HMAC;
    }

    h = px_alloc(sizeof(*h));
    h->p.ipad = px_alloc(bs);
    h->p.opad = px_alloc(bs);
    h->md = md;

    h->result_size = hmac_result_size;
    h->block_size = hmac_block_size;
    h->reset = hmac_reset;
    h->update = hmac_update;
    h->finish = hmac_finish;
    h->free = hmac_free;
    h->init = hmac_init;

    *res = h;

    return 0;
}

int px_get_pseudo_random_bytes ( uint8 dst,
unsigned  count 
)

Definition at line 627 of file internal.c.

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

Referenced by pgp_s2k_fill(), and px_gen_salt().

{
    return px_get_random_bytes(dst, count);
}

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().

{
    while (list->name)
    {
        if (pg_strcasecmp(list->alias, name) == 0)
            return list->name;
        list++;
    }
    return name;
}

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().

{
    debug_handler = handler;
}

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().

{
    const struct error_desc *e;

    for (e = px_err_list; e->desc; e++)
        if (e->err == err)
            return e->desc;
    return "Bad error code";
}