#include "postgres.h"#include "px.h"#include "mbuf.h"#include "pgp.h"
Go to the source code of this file.
| static struct cipher_info* get_cipher_info | ( | int | code | ) | [static, read] |
Definition at line 94 of file pgp.c.
References cipher_info::code, i, and cipher_info::name.
Referenced by pgp_get_cipher_block_size(), pgp_get_cipher_key_size(), pgp_get_cipher_name(), and pgp_load_cipher().
{
const struct cipher_info *i;
for (i = cipher_list; i->name; i++)
if (i->code == code)
return i;
return NULL;
}
| int pgp_disable_mdc | ( | PGP_Context * | ctx, | |
| int | disable | |||
| ) |
Definition at line 234 of file pgp.c.
References PGP_Context::disable_mdc.
Referenced by set_arg().
{
ctx->disable_mdc = disable ? 1 : 0;
return 0;
}
| int pgp_free | ( | PGP_Context * | ctx | ) |
Definition at line 224 of file pgp.c.
References pgp_key_free(), PGP_Context::pub_key, and px_free.
Referenced by decrypt_internal(), and encrypt_internal().
{
if (ctx->pub_key)
pgp_key_free(ctx->pub_key);
memset(ctx, 0, sizeof *ctx);
px_free(ctx);
return 0;
}
| int pgp_get_cipher_block_size | ( | int | code | ) |
Definition at line 158 of file pgp.c.
References cipher_info::block_len, get_cipher_info(), i, and NULL.
Referenced by prefix_init(), process_secret_key(), and write_prefix().
{
const struct cipher_info *i = get_cipher_info(code);
if (i != NULL)
return i->block_len;
return 0;
}
| int pgp_get_cipher_code | ( | const char * | name | ) |
Definition at line 116 of file pgp.c.
References cipher_info::code, i, cipher_info::name, and pg_strcasecmp().
Referenced by pgp_set_cipher_algo(), pgp_set_s2k_cipher_algo(), and set_arg().
{
const struct cipher_info *i;
for (i = cipher_list; i->name; i++)
if (pg_strcasecmp(i->name, name) == 0)
return i->code;
return PXE_PGP_UNSUPPORTED_CIPHER;
}
| int pgp_get_cipher_key_size | ( | int | code | ) |
Definition at line 148 of file pgp.c.
References get_cipher_info(), i, cipher_info::key_len, and NULL.
Referenced by decrypt_key(), init_sess_key(), and pgp_s2k_process().
{
const struct cipher_info *i = get_cipher_info(code);
if (i != NULL)
return i->key_len;
return 0;
}
| const char* pgp_get_cipher_name | ( | int | code | ) |
Definition at line 138 of file pgp.c.
References get_cipher_info(), i, cipher_info::name, and NULL.
{
const struct cipher_info *i = get_cipher_info(code);
if (i != NULL)
return i->name;
return NULL;
}
| int pgp_get_digest_code | ( | const char * | name | ) |
Definition at line 105 of file pgp.c.
References digest_info::code, i, digest_info::name, and pg_strcasecmp().
Referenced by pgp_set_s2k_digest_algo(), and set_arg().
{
const struct digest_info *i;
for (i = digest_list; i->name; i++)
if (pg_strcasecmp(i->name, name) == 0)
return i->code;
return PXE_PGP_UNSUPPORTED_HASH;
}
| const char* pgp_get_digest_name | ( | int | code | ) |
Definition at line 127 of file pgp.c.
References digest_info::code, i, and digest_info::name.
Referenced by pgp_load_digest().
{
const struct digest_info *i;
for (i = digest_list; i->name; i++)
if (i->code == code)
return i->name;
return NULL;
}
| int pgp_get_unicode_mode | ( | PGP_Context * | ctx | ) |
Definition at line 340 of file pgp.c.
References PGP_Context::unicode_mode.
Referenced by decrypt_internal(), and encrypt_internal().
{
return ctx->unicode_mode;
}
| int pgp_init | ( | PGP_Context ** | ctx_p | ) |
Definition at line 200 of file pgp.c.
References PGP_Context::cipher_algo, PGP_Context::compress_algo, PGP_Context::compress_level, PGP_Context::convert_crlf, def_cipher_algo, def_compress_algo, def_compress_level, def_convert_crlf, def_disable_mdc, def_s2k_cipher_algo, def_s2k_digest_algo, def_s2k_mode, def_text_mode, def_unicode_mode, def_use_sess_key, PGP_Context::disable_mdc, px_alloc, PGP_Context::s2k_cipher_algo, PGP_Context::s2k_digest_algo, PGP_Context::s2k_mode, PGP_Context::text_mode, PGP_Context::unicode_mode, and PGP_Context::use_sess_key.
Referenced by init_work().
{
PGP_Context *ctx;
ctx = px_alloc(sizeof *ctx);
memset(ctx, 0, sizeof *ctx);
ctx->cipher_algo = def_cipher_algo;
ctx->s2k_cipher_algo = def_s2k_cipher_algo;
ctx->s2k_mode = def_s2k_mode;
ctx->s2k_digest_algo = def_s2k_digest_algo;
ctx->compress_algo = def_compress_algo;
ctx->compress_level = def_compress_level;
ctx->disable_mdc = def_disable_mdc;
ctx->use_sess_key = def_use_sess_key;
ctx->unicode_mode = def_unicode_mode;
ctx->convert_crlf = def_convert_crlf;
ctx->text_mode = def_text_mode;
*ctx_p = ctx;
return 0;
}
| int pgp_load_cipher | ( | int | code, | |
| PX_Cipher ** | res | |||
| ) |
Definition at line 168 of file pgp.c.
References get_cipher_info(), i, cipher_info::int_name, NULL, and px_find_cipher().
Referenced by pgp_cfb_create().
{
int err;
const struct cipher_info *i = get_cipher_info(code);
if (i == NULL)
return PXE_PGP_CORRUPT_DATA;
err = px_find_cipher(i->int_name, res);
if (err == 0)
return 0;
return PXE_PGP_UNSUPPORTED_CIPHER;
}
| int pgp_load_digest | ( | int | code, | |
| PX_MD ** | res | |||
| ) |
Definition at line 184 of file pgp.c.
References name, NULL, pgp_get_digest_name(), and px_find_digest().
Referenced by calc_key_id(), check_key_sha1(), mdc_init(), and pgp_s2k_process().
{
int err;
const char *name = pgp_get_digest_name(code);
if (name == NULL)
return PXE_PGP_CORRUPT_DATA;
err = px_find_digest(name, res);
if (err == 0)
return 0;
return PXE_PGP_UNSUPPORTED_HASH;
}
| int pgp_set_cipher_algo | ( | PGP_Context * | ctx, | |
| const char * | name | |||
| ) |
Definition at line 307 of file pgp.c.
References PGP_Context::cipher_algo, cipher_info::code, and pgp_get_cipher_code().
Referenced by set_arg().
{
int code = pgp_get_cipher_code(name);
if (code < 0)
return code;
ctx->cipher_algo = code;
return 0;
}
| int pgp_set_compress_algo | ( | PGP_Context * | ctx, | |
| int | algo | |||
| ) |
Definition at line 274 of file pgp.c.
References PGP_Context::compress_algo, PGP_COMPR_BZIP2, PGP_COMPR_NONE, PGP_COMPR_ZIP, and PGP_COMPR_ZLIB.
Referenced by set_arg().
{
switch (algo)
{
case PGP_COMPR_NONE:
case PGP_COMPR_ZIP:
case PGP_COMPR_ZLIB:
case PGP_COMPR_BZIP2:
ctx->compress_algo = algo;
return 0;
}
return PXE_ARGUMENT_ERROR;
}
| int pgp_set_compress_level | ( | PGP_Context * | ctx, | |
| int | level | |||
| ) |
Definition at line 289 of file pgp.c.
References PGP_Context::compress_level.
Referenced by set_arg().
{
if (level >= 0 && level <= 9)
{
ctx->compress_level = level;
return 0;
}
return PXE_ARGUMENT_ERROR;
}
| int pgp_set_convert_crlf | ( | PGP_Context * | ctx, | |
| int | doit | |||
| ) |
Definition at line 248 of file pgp.c.
References PGP_Context::convert_crlf.
Referenced by set_arg().
{
ctx->convert_crlf = doit ? 1 : 0;
return 0;
}
| int pgp_set_s2k_cipher_algo | ( | PGP_Context * | ctx, | |
| const char * | name | |||
| ) |
Definition at line 318 of file pgp.c.
References cipher_info::code, pgp_get_cipher_code(), and PGP_Context::s2k_cipher_algo.
Referenced by set_arg().
{
int code = pgp_get_cipher_code(name);
if (code < 0)
return code;
ctx->s2k_cipher_algo = code;
return 0;
}
| int pgp_set_s2k_digest_algo | ( | PGP_Context * | ctx, | |
| const char * | name | |||
| ) |
Definition at line 329 of file pgp.c.
References cipher_info::code, pgp_get_digest_code(), and PGP_Context::s2k_digest_algo.
Referenced by set_arg().
{
int code = pgp_get_digest_code(name);
if (code < 0)
return code;
ctx->s2k_digest_algo = code;
return 0;
}
| int pgp_set_s2k_mode | ( | PGP_Context * | ctx, | |
| int | mode | |||
| ) |
Definition at line 255 of file pgp.c.
References PGP_S2K_ISALTED, PGP_S2K_SALTED, PGP_S2K_SIMPLE, and PGP_Context::s2k_mode.
Referenced by set_arg().
{
int err = PXE_OK;
switch (mode)
{
case PGP_S2K_SIMPLE:
case PGP_S2K_SALTED:
case PGP_S2K_ISALTED:
ctx->s2k_mode = mode;
break;
default:
err = PXE_ARGUMENT_ERROR;
break;
}
return err;
}
| int pgp_set_sess_key | ( | PGP_Context * | ctx, | |
| int | use | |||
| ) |
Definition at line 241 of file pgp.c.
References PGP_Context::use_sess_key.
Referenced by set_arg().
{
ctx->use_sess_key = use ? 1 : 0;
return 0;
}
| int pgp_set_symkey | ( | PGP_Context * | ctx, | |
| const uint8 * | key, | |||
| int | len | |||
| ) |
Definition at line 353 of file pgp.c.
References NULL, PGP_Context::sym_key, and PGP_Context::sym_key_len.
Referenced by decrypt_internal(), and encrypt_internal().
{
if (key == NULL || len < 1)
return PXE_ARGUMENT_ERROR;
ctx->sym_key = key;
ctx->sym_key_len = len;
return 0;
}
| int pgp_set_text_mode | ( | PGP_Context * | ctx, | |
| int | mode | |||
| ) |
Definition at line 300 of file pgp.c.
References PGP_Context::text_mode.
Referenced by init_work().
{
ctx->text_mode = mode;
return 0;
}
| int pgp_set_unicode_mode | ( | PGP_Context * | ctx, | |
| int | mode | |||
| ) |
Definition at line 346 of file pgp.c.
References PGP_Context::unicode_mode.
Referenced by set_arg().
{
ctx->unicode_mode = mode ? 1 : 0;
return 0;
}
struct cipher_info cipher_list[] [static] |
{
{"3des", PGP_SYM_DES3, "3des-ecb", 192 / 8, 64 / 8},
{"cast5", PGP_SYM_CAST5, "cast5-ecb", 128 / 8, 64 / 8},
{"bf", PGP_SYM_BLOWFISH, "bf-ecb", 128 / 8, 64 / 8},
{"blowfish", PGP_SYM_BLOWFISH, "bf-ecb", 128 / 8, 64 / 8},
{"aes", PGP_SYM_AES_128, "aes-ecb", 128 / 8, 128 / 8},
{"aes128", PGP_SYM_AES_128, "aes-ecb", 128 / 8, 128 / 8},
{"aes192", PGP_SYM_AES_192, "aes-ecb", 192 / 8, 128 / 8},
{"aes256", PGP_SYM_AES_256, "aes-ecb", 256 / 8, 128 / 8},
{"twofish", PGP_SYM_TWOFISH, "twofish-ecb", 256 / 8, 128 / 8},
{NULL, 0, NULL}
}
int def_cipher_algo = PGP_SYM_AES_128 [static] |
Definition at line 41 of file pgp.c.
Referenced by pgp_init().
int def_compress_algo = PGP_COMPR_NONE [static] |
Definition at line 45 of file pgp.c.
Referenced by pgp_init().
int def_compress_level = 6 [static] |
Definition at line 46 of file pgp.c.
Referenced by pgp_init().
int def_convert_crlf = 0 [static] |
Definition at line 51 of file pgp.c.
Referenced by pgp_init().
int def_disable_mdc = 0 [static] |
Definition at line 47 of file pgp.c.
Referenced by pgp_init().
int def_s2k_cipher_algo = -1 [static] |
Definition at line 42 of file pgp.c.
Referenced by pgp_init().
int def_s2k_digest_algo = PGP_DIGEST_SHA1 [static] |
Definition at line 44 of file pgp.c.
Referenced by pgp_init().
int def_s2k_mode = PGP_S2K_ISALTED [static] |
Definition at line 43 of file pgp.c.
Referenced by pgp_init().
int def_text_mode = 0 [static] |
Definition at line 49 of file pgp.c.
Referenced by pgp_init().
int def_unicode_mode = 0 [static] |
Definition at line 50 of file pgp.c.
Referenced by pgp_init().
int def_use_sess_key = 0 [static] |
Definition at line 48 of file pgp.c.
Referenced by pgp_init().
struct digest_info digest_list[] [static] |
{
{"md5", PGP_DIGEST_MD5},
{"sha1", PGP_DIGEST_SHA1},
{"sha-1", PGP_DIGEST_SHA1},
{"ripemd160", PGP_DIGEST_RIPEMD160},
{"sha256", PGP_DIGEST_SHA256},
{"sha384", PGP_DIGEST_SHA384},
{"sha512", PGP_DIGEST_SHA512},
{NULL, 0}
}
1.7.1