#include <sys/types.h>
#include <sys/param.h>
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 px_alloc | ( | s | ) | palloc(s) |
Definition at line 45 of file px.h.
Referenced by bf_load(), combo_encrypt(), combo_init(), compat_find_digest(), create_secmsg(), encrypt_init(), hmac_finish(), hmac_init(), init_md5(), init_sha1(), init_sha224(), init_sha256(), init_sha384(), init_sha512(), mbuf_create(), mbuf_create_from_data(), mdcbuf_init(), mp_int_alloc(), mp_px_rand(), pad_eme_pkcs1_v15(), pgp_cfb_create(), pgp_create_pkt_reader(), pgp_init(), pgp_key_alloc(), pgp_mpi_alloc(), pkt_stream_init(), pullf_create(), pushf_create(), px_find_cipher(), px_find_combo(), px_find_digest(), px_find_hmac(), rj_load(), s_alloc(), and try_unix_std().
#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().
Definition at line 236 of file px.h.
Referenced by combo_decrypt().
Definition at line 234 of file px.h.
Referenced by cfb_process(), and combo_encrypt().
Definition at line 238 of file px.h.
Referenced by combo_free(), pgp_cfb_create(), pgp_cfb_free(), and px_find_combo().
Definition at line 233 of file px.h.
Referenced by combo_init(), and pgp_cfb_create().
Definition at line 232 of file px.h.
Referenced by combo_init().
Definition at line 230 of file px.h.
Referenced by combo_init().
Definition at line 247 of file px.h.
Referenced by pg_decrypt(), and pg_decrypt_iv().
Definition at line 242 of file px.h.
Referenced by pg_decrypt(), and pg_decrypt_iv().
Definition at line 245 of file px.h.
Referenced by pg_encrypt(), and pg_encrypt_iv().
Definition at line 241 of file px.h.
Referenced by pg_encrypt(), and pg_encrypt_iv().
Definition at line 249 of file px.h.
Referenced by pg_decrypt(), pg_decrypt_iv(), pg_encrypt(), and pg_encrypt_iv().
Definition at line 243 of file px.h.
Referenced by pg_decrypt(), pg_decrypt_iv(), pg_encrypt(), and pg_encrypt_iv().
#define px_free | ( | p | ) | pfree(p) |
Definition at line 47 of file px.h.
Referenced by combo_encrypt(), combo_free(), combo_init(), create_secmsg(), digest_free(), encrypt_free(), gen_ossl_free(), hmac_finish(), hmac_free(), hmac_init(), int_md5_free(), int_sha1_free(), int_sha224_free(), int_sha256_free(), int_sha384_free(), int_sha512_free(), intctx_free(), mbuf_free(), mdcbuf_free(), mp_int_free(), mp_px_rand(), pad_eme_pkcs1_v15(), pgp_cfb_free(), pgp_create_pkt_reader(), pgp_free(), pgp_key_free(), pgp_mpi_free(), pkt_stream_free(), pktreader_free(), pullf_free(), pushf_free(), px_find_combo(), s_ksqr(), and try_unix_std().
#define px_hmac_block_size | ( | hmac | ) | (hmac)->block_size(hmac) |
#define px_hmac_free | ( | hmac | ) | (hmac)->free(hmac) |
#define px_hmac_init | ( | hmac, | ||
key, | ||||
klen | ||||
) | (hmac)->init(hmac, key, klen) |
#define px_hmac_result_size | ( | hmac | ) | (hmac)->result_size(hmac) |
#define px_hmac_update | ( | hmac, | ||
data, | ||||
dlen | ||||
) | (hmac)->update(hmac, data, dlen) |
#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().
Definition at line 218 of file px.h.
Referenced by add_block_entropy(), calc_key_id(), calc_s2k_iter_salted(), calc_s2k_salted(), calc_s2k_simple(), check_key_sha1(), hmac_finish(), hmac_init(), mdc_finish(), mdc_flush(), mdcbuf_finish(), pg_digest(), px_crypt_md5(), and try_unix_std().
#define px_md_free | ( | md | ) | (md)->free(md) |
Definition at line 219 of file px.h.
Referenced by add_entropy(), calc_key_id(), check_key_sha1(), hmac_free(), mdc_free(), mdcbuf_free(), pg_digest(), pgp_s2k_process(), px_crypt_md5(), px_find_hmac(), and try_unix_std().
#define px_md_reset | ( | md | ) | (md)->reset(md) |
Definition at line 216 of file px.h.
Referenced by add_block_entropy(), calc_s2k_iter_salted(), calc_s2k_salted(), calc_s2k_simple(), hmac_finish(), hmac_init(), hmac_reset(), and px_crypt_md5().
#define px_md_result_size | ( | md | ) | (md)->result_size(md) |
Definition at line 214 of file px.h.
Referenced by calc_s2k_iter_salted(), calc_s2k_salted(), calc_s2k_simple(), hmac_finish(), hmac_result_size(), and pg_digest().
#define px_md_update | ( | md, | ||
data, | ||||
dlen | ||||
) | (md)->update(md, data, dlen) |
Definition at line 217 of file px.h.
Referenced by add_block_entropy(), calc_key_id(), calc_s2k_iter_salted(), calc_s2k_salted(), calc_s2k_simple(), hmac_finish(), hmac_init(), hmac_reset(), hmac_update(), mdc_flush(), mdc_read(), mdc_write(), mdcbuf_finish(), mdcbuf_load_data(), pg_digest(), pgp_mpi_hash(), px_crypt_md5(), and try_unix_std().
#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_CIPHER_INIT -8 |
Definition at line 71 of file px.h.
Referenced by rj_decrypt(), and rj_encrypt().
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 | |||
) |
Definition at line 598 of file internal.c.
References px_cipher::block_size, ossl_cipher_lookup::ciph, ossldata::ciph, ossl_cipher::decrypt, px_cipher::decrypt, ossl_cipher::encrypt, px_cipher::encrypt, px_cipher::free, i, ossl_cipher::init, px_cipher::init, px_cipher::iv_size, px_cipher::key_size, int_cipher::load, ossl_cipher_lookup::name, int_cipher::name, NULL, px_cipher::ptr, px_alloc, and px_resolve_alias().
Referenced by pgp_load_cipher(), and px_find_combo().
{ int i; PX_Cipher *c = NULL; name = px_resolve_alias(int_aliases, name); for (i = 0; int_ciphers[i].name; i++) if (strcmp(int_ciphers[i].name, name) == 0) { c = int_ciphers[i].load(); break; } if (c == NULL) return PXE_NO_CIPHER; *res = c; return 0; }
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 | |||
) |
Definition at line 579 of file internal.c.
References OSSLDigest::algo, px_digest::block_size, compat_find_digest(), OSSLDigest::ctx, EVP_DigestInit_ex(), EVP_MD_CTX_init(), px_digest::finish, px_digest::free, int_digest::init, int_digest::name, NULL, px_digest::p, pg_strcasecmp(), px_digest::ptr, px_alloc, px_openssl_initialized, px_digest::reset, px_digest::result_size, and px_digest::update.
Referenced by add_entropy(), pg_digest(), pgp_load_digest(), px_crypt_md5(), px_find_hmac(), and try_unix_std().
{ const struct int_digest *p; PX_MD *h; for (p = int_digest_list; p->name; p++) if (pg_strcasecmp(p->name, name) == 0) { h = px_alloc(sizeof(*h)); p->init(h); *res = h; return 0; } return PXE_NO_HASH; }
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 | |||
) |
Definition at line 675 of file internal.c.
References fortuna_get_bytes(), init_openssl_rand(), openssl_random_init, and system_reseed().
Referenced by add_entropy(), init_sess_key(), mp_px_rand(), pad_eme_pkcs1_v15(), pg_random_bytes(), px_get_pseudo_random_bytes(), system_reseed(), and write_prefix().
{ system_reseed(); fortuna_get_bytes(count, dst); return 0; }
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().
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"; }