Ejemplo n.º 1
0
/* This entry point is equivalent to crypt(3). */
char *
crypt_sha512(const char *key, const char *salt)
{
	/* We don't want to have an arbitrary limit in the size of the
	 * password. We can compute an upper bound for the size of the
	 * result in advance and so we can prepare the buffer we pass to
	 * `crypt_sha512_r'. */
	static char *buffer;
	static int buflen;
	int needed;
	char *new_buffer;

	needed = (sizeof(sha512_salt_prefix) - 1
	      + sizeof(sha512_rounds_prefix) + 9 + 1
	      + strlen(salt) + 1 + 86 + 1);

	if (buflen < needed) {
		new_buffer = (char *)realloc(buffer, needed);

		if (new_buffer == NULL)
			return NULL;

		buffer = new_buffer;
		buflen = needed;
	}

	return crypt_sha512_r(key, salt, buffer, buflen);
}
Ejemplo n.º 2
0
char* crypt_sha512(const char *key, const char *salt, size_t rounds)
{
    char *buffer;

    buffer = (char *) malloc(OUTPUT_SHA512_LEN + 1);
    if (buffer == NULL)
    {
        fprintf(stderr, "error : memory allocation failed\n");
        return NULL;
    }

    return crypt_sha512_r(key, salt, rounds, buffer, OUTPUT_SHA512_LEN + 1);
}