#include "postgres.h"#include "px.h"#include "px-crypt.h"
Go to the source code of this file.
Data Structures | |
| struct | px_crypt_algo |
| struct | generator |
Functions | |
| static char * | run_crypt_des (const char *psw, const char *salt, char *buf, unsigned len) |
| static char * | run_crypt_md5 (const char *psw, const char *salt, char *buf, unsigned len) |
| static char * | run_crypt_bf (const char *psw, const char *salt, char *buf, unsigned len) |
| char * | px_crypt (const char *psw, const char *salt, char *buf, unsigned len) |
| int | px_gen_salt (const char *salt_type, char *buf, int rounds) |
Variables | |
| static struct px_crypt_algo | px_crypt_list [] |
| static struct generator | gen_list [] |
| char* px_crypt | ( | const char * | psw, | |
| const char * | salt, | |||
| char * | buf, | |||
| unsigned | len | |||
| ) |
Definition at line 91 of file px-crypt.c.
References px_crypt_algo::crypt, px_crypt_algo::id, px_crypt_algo::id_len, and NULL.
Referenced by pg_crypt().
{
const struct px_crypt_algo *c;
for (c = px_crypt_list; c->id; c++)
{
if (!c->id_len)
break;
if (strncmp(salt, c->id, c->id_len) == 0)
break;
}
if (c->crypt == NULL)
return NULL;
return c->crypt(psw, salt, buf, len);
}
| int px_gen_salt | ( | const char * | salt_type, | |
| char * | buf, | |||
| int | rounds | |||
| ) |
Definition at line 133 of file px-crypt.c.
References generator::def_rounds, generator::gen, generator::input_len, generator::max_rounds, generator::min_rounds, generator::name, NULL, pg_strcasecmp(), px_get_pseudo_random_bytes(), and PX_MAX_SALT_LEN.
Referenced by pg_gen_salt(), and pg_gen_salt_rounds().
{
int res;
struct generator *g;
char *p;
char rbuf[16];
for (g = gen_list; g->name; g++)
if (pg_strcasecmp(g->name, salt_type) == 0)
break;
if (g->name == NULL)
return PXE_UNKNOWN_SALT_ALGO;
if (g->def_rounds)
{
if (rounds == 0)
rounds = g->def_rounds;
if (rounds < g->min_rounds || rounds > g->max_rounds)
return PXE_BAD_SALT_ROUNDS;
}
res = px_get_pseudo_random_bytes((uint8 *) rbuf, g->input_len);
if (res < 0)
return res;
p = g->gen(rounds, rbuf, g->input_len, buf, PX_MAX_SALT_LEN);
memset(rbuf, 0, sizeof(rbuf));
if (p == NULL)
return PXE_BAD_SALT_ROUNDS;
return strlen(p);
}
| static char* run_crypt_bf | ( | const char * | psw, | |
| const char * | salt, | |||
| char * | buf, | |||
| unsigned | len | |||
| ) | [static] |
Definition at line 62 of file px-crypt.c.
References _crypt_blowfish_rn().
{
char *res;
res = _crypt_blowfish_rn(psw, salt, buf, len);
return res;
}
| static char* run_crypt_des | ( | const char * | psw, | |
| const char * | salt, | |||
| char * | buf, | |||
| unsigned | len | |||
| ) | [static] |
Definition at line 39 of file px-crypt.c.
References px_crypt_des().
{
char *res;
res = px_crypt_des(psw, salt);
if (strlen(res) > len - 1)
return NULL;
strcpy(buf, res);
return buf;
}
| static char* run_crypt_md5 | ( | const char * | psw, | |
| const char * | salt, | |||
| char * | buf, | |||
| unsigned | len | |||
| ) | [static] |
Definition at line 52 of file px-crypt.c.
References px_crypt_md5().
{
char *res;
res = px_crypt_md5(psw, salt, buf, len);
return res;
}
{
{"des", _crypt_gensalt_traditional_rn, 2, 0, 0, 0},
{"md5", _crypt_gensalt_md5_rn, 6, 0, 0, 0},
{"xdes", _crypt_gensalt_extended_rn, 3, PX_XDES_ROUNDS, 1, 0xFFFFFF},
{"bf", _crypt_gensalt_blowfish_rn, 16, PX_BF_ROUNDS, 4, 31},
{NULL, NULL, 0, 0, 0, 0}
}
Definition at line 124 of file px-crypt.c.
struct px_crypt_algo px_crypt_list[] [static] |
{
{"$2a$", 4, run_crypt_bf},
{"$2x$", 4, run_crypt_bf},
{"$2$", 3, NULL},
{"$1$", 3, run_crypt_md5},
{"_", 1, run_crypt_des},
{"", 0, run_crypt_des},
{NULL, 0, NULL}
}
Definition at line 80 of file px-crypt.c.
1.7.1