Exemplo n.º 1
0
Arquivo: ssha.c Projeto: endeav0r/rnpc
inline int ssha_compare (void * a, void * b)
{
	
	return sha1_compare(&(((struct ssha_context *) a)->context),
	                    &(((struct ssha_context *) b)->context));

}
Exemplo n.º 2
0
static void test_file_hash(unsigned int megs, const char *expect)
{
	int fd;
	size_t i;
	char name[32];
	uint8_t result[20];

	strcpy(name, "hashdata.XXXXXX");

	fd = gg_mkstemp(name);

	if (fd == -1) {
		fprintf(stderr, "Unable to create temporary file\n");
		exit(1);
	}

	for (i = 1; i <= megs; i++) {
		unsigned char j;

		if (lseek(fd, i * 1048756 - 1, SEEK_SET) == (off_t) -1) {
			fprintf(stderr, "Unable to seek past end of file\n");
			goto fail;
		}

		j = i;

		if (write(fd, &j, sizeof(j)) != sizeof(j)) {
			fprintf(stderr, "Unable to write past end of file\n");
			goto fail;
		}
	}

	if (gg_file_hash_sha1(fd, result) == -1) {
		fprintf(stderr, "gg_file_hash_sha1() failed for %d megs\n", megs);
		goto fail;
	}

	if (!sha1_compare(result, expect)) {
		printf("hash failed for %d mesgs, expected %s, got %s\n", megs, expect, sha1_to_string(result));
		goto fail;
	}

	close(fd);
	unlink(name);
	return;

fail:
	close(fd);
	unlink(name);
	exit(1);
}
Exemplo n.º 3
0
static void test_login_hash(const char *password, uint32_t seed, const char *expect)
{
	uint8_t result[20];

	if (gg_login_hash_sha1_2(password, seed, result) == -1) {
		fprintf(stderr, "gg_login_hash_sha1_2() failed for \"%s\", 0x%08x\n", password, seed);
		exit(1);
	}

	if (!sha1_compare(result, expect)) {
		printf("hash failed for \"%s\", 0x%08x, expected %s, got %s\n",
			password, seed, expect, sha1_to_string(result));
		exit(1);
	}
}