Reimplementation of Pijul in C, for education, fun and absolutely no profit
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>

#include "common.h"
#include "scaffold.h"
#include "types.h"
#include "blake3.h"
#include "hash.h"
#include "base32.h"

void
hashprintln(struct hash *hash)
{
	hashprint(hash);
	printf("\n");
}

void
hashprint(struct hash *hash)
{
	char b32hash[54];

	memset(b32hash, 0, 54);
	switch (hash->variant) {
	case HASH_NONE:
		printf("(none)\n");
		break;
	case HASH_BLAKE3:
		b32enc(b32hash, hash->bytes);
		printf("%s", b32hash);
		break;
	default:
		die("unknown hash variant: %u", hash->variant);
	}
}

/* Return 1 if hashes are equal, 0 otherwise */
int
hasheq(struct hash *h1, struct hash *h2)
{
	size_t i;

	if (h1->variant != h2->variant)
		return 0;
	switch (h1->variant) {
	case HASH_NONE:
		return 1;
	case HASH_BLAKE3:
		for (i = 0; i < BLAKE3_LEN; i++)
			if (h1->bytes[i] != h2->bytes[i])
				return 0;
		return 1;
	default:
		die("unknown hash variant: %u", h1->variant);
	}
}

void
hashlist_free(struct hashlist *h)
{
	free(h->entries);
}