diff options
Diffstat (limited to 'contrib/pgcrypto/px-crypt.c')
-rw-r--r-- | contrib/pgcrypto/px-crypt.c | 49 |
1 files changed, 25 insertions, 24 deletions
diff --git a/contrib/pgcrypto/px-crypt.c b/contrib/pgcrypto/px-crypt.c index 2ac043f0cf4..8b398c38a0c 100644 --- a/contrib/pgcrypto/px-crypt.c +++ b/contrib/pgcrypto/px-crypt.c @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $PostgreSQL: pgsql/contrib/pgcrypto/px-crypt.c,v 1.9 2005/03/21 05:18:45 neilc Exp $ + * $PostgreSQL: pgsql/contrib/pgcrypto/px-crypt.c,v 1.10 2005/03/21 05:19:55 neilc Exp $ */ #include <postgres.h> @@ -147,39 +147,40 @@ static struct generator gen_list[] = { {NULL, NULL, 0, 0, 0, 0} }; -unsigned +int px_gen_salt(const char *salt_type, char *buf, int rounds) { - int i, - res; + int res; struct generator *g; char *p; char rbuf[16]; - for (i = 0; gen_list[i].name; i++) - { - g = &gen_list[i]; - if (pg_strcasecmp(g->name, salt_type) != 0) - continue; + for (g = gen_list; g->name; g++) + if (pg_strcasecmp(g->name, salt_type) == 0) + break; - if (g->def_rounds) - { - if (rounds == 0) - rounds = g->def_rounds; + if (g->name == NULL) + return PXE_UNKNOWN_SALT_ALGO; - if (rounds < g->min_rounds || rounds > g->max_rounds) - return 0; - } + if (g->def_rounds) + { + if (rounds == 0) + rounds = g->def_rounds; - res = px_get_random_bytes(rbuf, g->input_len); - if (res != g->input_len) - return 0; + if (rounds < g->min_rounds || rounds > g->max_rounds) + return PXE_BAD_SALT_ROUNDS; + } - p = g->gen(rounds, rbuf, g->input_len, buf, PX_MAX_SALT_LEN); - memset(rbuf, 0, sizeof(rbuf)); + res = px_get_random_bytes(rbuf, g->input_len); + if (res < 0) + return res; - return p != NULL ? strlen(p) : 0; - } + 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 0; + return strlen(p); } + |