aboutsummaryrefslogblamecommitdiffstats
path: root/t/misc-tests.c
blob: 3d1bb2dc090d5d437eb5cfb4f34793a92619f16e (plain) (tree)
1
2
3
4
5
6
7
8
9
                                                         
                      






                                                                                             
                         














                                                                         
                                       




























                                                                                    



















                                                                                                                                  
































                                                                                                      
      
                      












































































































































































































































































































































                                                                                                                    



                                                                                                           




















































                                                                                                                   



                                                                                                          




















































                                                                                                                     



                                                                                                            










































































































                                                                                                                   
                                                                              









                                                                                                             







                                                                                                                   

                                                                                                                                  
                                                                                              
                                                                                      







                                                                                                   
                                                                                                                 




                                                                                                
                                                                                                                                  
                                                                                              
                                                                                      

                                                                                              
                                                                                                



            

                                                                                                      
                                                                                                        




                                                                                                                     








                                                                                                                
                                                                                                      








                                                                                                         







































                                                                                                                           


                 
/* See LICENSE file for copyright and license details. */
#include "../common.h"


#define ASSERT(ASSERTION)\
	do {\
		if ((ASSERTION))\
			break;\
		fprintf(stderr, "assertion `%s` at line %i failed\n", #ASSERTION, __LINE__);\
		exit(2);\
	} while (0)


static int
eq(struct libhashsum_hasher *a, struct libhashsum_hasher *b)
{
	if (a->algorithm != b->algorithm ||
	    !a->algorithm_string != !b->algorithm_string ||
	    a->input_block_size != b->input_block_size ||
	    a->hash_size != b->hash_size ||
	    !a->hash_output != !b->hash_output ||
	    a->supports_non_whole_bytes != b->supports_non_whole_bytes ||
	    a->process != b->process ||
	    a->finalise_const != b->finalise_const ||
	    a->finalise != b->finalise ||
	    a->stretch != b->stretch ||
	    a->destroy != b->destroy)
		return 0;
	if (a->hash_output && memcpy(a->hash_output, b->hash_output, a->hash_size))
		return 0;
	if (a->algorithm_string && strcmp(a->algorithm_string, b->algorithm_string))
		return 0;
	switch (a->algorithm) {
	case LIBHASHSUM_MD2:
	case LIBHASHSUM_MD4:
	case LIBHASHSUM_MD5:
	case LIBHASHSUM_RIPEMD_128:
	case LIBHASHSUM_RIPEMD_160:
	case LIBHASHSUM_RIPEMD_256:
	case LIBHASHSUM_RIPEMD_320:
	case LIBHASHSUM_SHA0:
	case LIBHASHSUM_SHA1:
	case LIBHASHSUM_SHA_224:
	case LIBHASHSUM_SHA_256:
	case LIBHASHSUM_SHA_384:
	case LIBHASHSUM_SHA_512:
	case LIBHASHSUM_SHA_512_224:
	case LIBHASHSUM_SHA_512_256:
	case LIBHASHSUM_BLAKE224:
	case LIBHASHSUM_BLAKE256:
	case LIBHASHSUM_BLAKE384:
	case LIBHASHSUM_BLAKE512:
		if (memcmp(&a->state, &b->state, sizeof(a->state)))
			return 0;
		break;
	case LIBHASHSUM_BLAKE2S:
#ifdef LIBHASHSUM_INCLUDE_LIBBLAKE_STATE
		if (memcmp(&a->state.blake2s.s, &b->state.blake2s.s, sizeof(a->state.blake2s.s)))
			return 0;
		if (a->state.blake2s.keybytes != b->state.blake2s.keybytes)
			return 0;
		if (a->state.blake2s.keybytes && memcmp(a->state.blake2s.buf, b->state.blake2s.buf, sizeof(a->state.blake2s.buf)))
			return 0;
#endif
		break;
	case LIBHASHSUM_BLAKE2B:
#ifdef LIBHASHSUM_INCLUDE_LIBBLAKE_STATE
		if (memcmp(&a->state.blake2b.s, &b->state.blake2b.s, sizeof(a->state.blake2b.s)))
			return 0;
		if (a->state.blake2b.keybytes != b->state.blake2b.keybytes)
			return 0;
		if (a->state.blake2b.keybytes && memcmp(a->state.blake2b.buf, b->state.blake2b.buf, sizeof(a->state.blake2b.buf)))
			return 0;
#endif
		break;
	case LIBHASHSUM_KECCAK:
	case LIBHASHSUM_KECCAK_224:
	case LIBHASHSUM_KECCAK_256:
	case LIBHASHSUM_KECCAK_384:
	case LIBHASHSUM_KECCAK_512:
	case LIBHASHSUM_SHA3_224:
	case LIBHASHSUM_SHA3_256:
	case LIBHASHSUM_SHA3_384:
	case LIBHASHSUM_SHA3_512:
	case LIBHASHSUM_SHAKE128:
	case LIBHASHSUM_SHAKE256:
	case LIBHASHSUM_SHAKE512:
	case LIBHASHSUM_RAWSHAKE128:
	case LIBHASHSUM_RAWSHAKE256:
	case LIBHASHSUM_RAWSHAKE512:
#ifdef LIBHASHSUM_INCLUDE_LIBKECCAK_STATE
		{
			unsigned char *aM, *bM;
			int r;
			if (a->state.keccak.squeezes != b->state.keccak.squeezes ||
			    a->state.keccak.suffix != b->state.keccak.suffix ||
			    !a->state.keccak.s.M != !b->state.keccak.s.M)
				return 0;
			aM = a->state.keccak.s.M;
			bM = b->state.keccak.s.M;
			a->state.keccak.s.M = NULL;
			b->state.keccak.s.M = NULL;
			r = memcmp(&a->state.keccak.s, &b->state.keccak.s, sizeof(a->state.keccak.s));
			a->state.keccak.s.M = aM;
			b->state.keccak.s.M = bM;
			if (r)
				return 0;
		}
#endif
		break;
	default:
		abort();
	}
	return 1;
}


static void
test_blake(const char *salt)
{
	struct libhashsum_hasher hasher1, hasher2, hasher3;
	int r;

	memset(&hasher1, 0xBC, sizeof(hasher1));
	memset(&hasher2, 0xBC, sizeof(hasher2));
	memset(&hasher3, 0xBC, sizeof(hasher3));
	errno = 0;
	r = libhashsum_init_blake224_hasher(&hasher1, salt);
	if (r) {
		ASSERT(r == -1);
		ASSERT(errno == ENOSYS);
		errno = 0;
		ASSERT(libhashsum_init_blakes_hasher(&hasher2, 224, salt) == -1);
		ASSERT(errno == ENOSYS);
		errno = 0;
		ASSERT(libhashsum_init_blake_hasher(&hasher3, 224, salt, 16) == -1);
		ASSERT(errno == ENOSYS);
	} else {
		ASSERT(r == 0);
		ASSERT(libhashsum_init_blakes_hasher(&hasher2, 224, salt) == 0);
		ASSERT(libhashsum_init_blake_hasher(&hasher3, 224, salt, 16) == 0);
		ASSERT(eq(&hasher1, &hasher2));
		ASSERT(eq(&hasher1, &hasher3));
		if (salt) {
			errno = 0;
			ASSERT(libhashsum_init_blake_hasher(&hasher3, 224, salt, 0) == -1);
			ASSERT(errno == EINVAL);
			errno = 0;
			ASSERT(libhashsum_init_blake_hasher(&hasher3, 224, salt, 8) == -1);
			ASSERT(errno == EINVAL);
			errno = 0;
			ASSERT(libhashsum_init_blake_hasher(&hasher3, 224, salt, 17) == -1);
			ASSERT(errno == EINVAL);
			errno = 0;
			ASSERT(libhashsum_init_blake_hasher(&hasher3, 224, salt, 32) == -1);
			ASSERT(errno == EINVAL);
		} else {
			memset(&hasher3, 0xBC, sizeof(hasher3));
			ASSERT(libhashsum_init_blake_hasher(&hasher3, 224, salt, 0) == 0);
			ASSERT(libhashsum_init_blake_hasher(&hasher3, 224, salt, 8) == 0);
			ASSERT(libhashsum_init_blake_hasher(&hasher3, 224, salt, 17) == 0);
			ASSERT(libhashsum_init_blake_hasher(&hasher3, 224, salt, 32) == 0);
			ASSERT(eq(&hasher1, &hasher3));
		}
	}

	memset(&hasher1, 0xBC, sizeof(hasher1));
	memset(&hasher2, 0xBC, sizeof(hasher2));
	memset(&hasher3, 0xBC, sizeof(hasher3));
	errno = 0;
	r = libhashsum_init_blake256_hasher(&hasher1, salt);
	if (r) {
		ASSERT(r == -1);
		ASSERT(errno == ENOSYS);
		errno = 0;
		ASSERT(libhashsum_init_blakes_hasher(&hasher2, 256, salt) == -1);
		ASSERT(errno == ENOSYS);
		errno = 0;
		ASSERT(libhashsum_init_blake_hasher(&hasher3, 256, salt, 16) == -1);
		ASSERT(errno == ENOSYS);
	} else {
		ASSERT(r == 0);
		ASSERT(libhashsum_init_blakes_hasher(&hasher2, 256, salt) == 0);
		ASSERT(libhashsum_init_blake_hasher(&hasher3, 256, salt, 16) == 0);
		ASSERT(eq(&hasher1, &hasher2));
		ASSERT(eq(&hasher1, &hasher3));
		if (salt) {
			errno = 0;
			ASSERT(libhashsum_init_blake_hasher(&hasher3, 256, salt, 0) == -1);
			ASSERT(errno == EINVAL);
			errno = 0;
			ASSERT(libhashsum_init_blake_hasher(&hasher3, 256, salt, 8) == -1);
			ASSERT(errno == EINVAL);
			errno = 0;
			ASSERT(libhashsum_init_blake_hasher(&hasher3, 256, salt, 17) == -1);
			ASSERT(errno == EINVAL);
			errno = 0;
			ASSERT(libhashsum_init_blake_hasher(&hasher3, 256, salt, 32) == -1);
			ASSERT(errno == EINVAL);
		} else {
			memset(&hasher3, 0xBC, sizeof(hasher3));
			ASSERT(libhashsum_init_blake_hasher(&hasher3, 256, salt, 0) == 0);
			ASSERT(libhashsum_init_blake_hasher(&hasher3, 256, salt, 8) == 0);
			ASSERT(libhashsum_init_blake_hasher(&hasher3, 256, salt, 17) == 0);
			ASSERT(libhashsum_init_blake_hasher(&hasher3, 256, salt, 32) == 0);
			ASSERT(eq(&hasher1, &hasher3));
		}
	}

	memset(&hasher1, 0xBC, sizeof(hasher1));
	memset(&hasher2, 0xBC, sizeof(hasher2));
	memset(&hasher3, 0xBC, sizeof(hasher3));
	errno = 0;
	r = libhashsum_init_blake384_hasher(&hasher1, salt);
	if (r) {
		ASSERT(r == -1);
		ASSERT(errno == ENOSYS);
		errno = 0;
		ASSERT(libhashsum_init_blakeb_hasher(&hasher2, 384, salt) == -1);
		ASSERT(errno == ENOSYS);
		errno = 0;
		ASSERT(libhashsum_init_blake_hasher(&hasher3, 384, salt, 32) == -1);
		ASSERT(errno == ENOSYS);
	} else {
		ASSERT(r == 0);
		ASSERT(libhashsum_init_blakeb_hasher(&hasher2, 384, salt) == 0);
		ASSERT(libhashsum_init_blake_hasher(&hasher3, 384, salt, 32) == 0);
		ASSERT(eq(&hasher1, &hasher2));
		ASSERT(eq(&hasher1, &hasher3));
		if (salt) {
			errno = 0;
			ASSERT(libhashsum_init_blake_hasher(&hasher3, 384, salt, 0) == -1);
			ASSERT(errno == EINVAL);
			errno = 0;
			ASSERT(libhashsum_init_blake_hasher(&hasher3, 384, salt, 16) == -1);
			ASSERT(errno == EINVAL);
			errno = 0;
			ASSERT(libhashsum_init_blake_hasher(&hasher3, 384, salt, 33) == -1);
			ASSERT(errno == EINVAL);
		} else {
			memset(&hasher3, 0xBC, sizeof(hasher3));
			ASSERT(libhashsum_init_blake_hasher(&hasher3, 384, salt, 0) == 0);
			ASSERT(libhashsum_init_blake_hasher(&hasher3, 384, salt, 16) == 0);
			ASSERT(libhashsum_init_blake_hasher(&hasher3, 384, salt, 33) == 0);
			ASSERT(eq(&hasher1, &hasher3));
		}
	}

	memset(&hasher1, 0xBC, sizeof(hasher1));
	memset(&hasher2, 0xBC, sizeof(hasher2));
	memset(&hasher3, 0xBC, sizeof(hasher3));
	errno = 0;
	r = libhashsum_init_blake512_hasher(&hasher1, salt);
	if (r) {
		ASSERT(r == -1);
		ASSERT(errno == ENOSYS);
		errno = 0;
		ASSERT(libhashsum_init_blakeb_hasher(&hasher2, 512, salt) == -1);
		ASSERT(errno == ENOSYS);
		errno = 0;
		ASSERT(libhashsum_init_blake_hasher(&hasher3, 512, salt, 32) == -1);
		ASSERT(errno == ENOSYS);
	} else {
		ASSERT(r == 0);
		ASSERT(libhashsum_init_blakeb_hasher(&hasher2, 512, salt) == 0);
		ASSERT(libhashsum_init_blake_hasher(&hasher3, 512, salt, 32) == 0);
		ASSERT(eq(&hasher1, &hasher2));
		ASSERT(eq(&hasher1, &hasher3));
		if (salt) {
			errno = 0;
			ASSERT(libhashsum_init_blake_hasher(&hasher3, 512, salt, 0) == -1);
			ASSERT(errno == EINVAL);
			errno = 0;
			ASSERT(libhashsum_init_blake_hasher(&hasher3, 512, salt, 16) == -1);
			ASSERT(errno == EINVAL);
			errno = 0;
			ASSERT(libhashsum_init_blake_hasher(&hasher3, 512, salt, 33) == -1);
			ASSERT(errno == EINVAL);
		} else {
			memset(&hasher3, 0xBC, sizeof(hasher3));
			ASSERT(libhashsum_init_blake_hasher(&hasher3, 512, salt, 0) == 0);
			ASSERT(libhashsum_init_blake_hasher(&hasher3, 512, salt, 16) == 0);
			ASSERT(libhashsum_init_blake_hasher(&hasher3, 512, salt, 33) == 0);
			ASSERT(eq(&hasher1, &hasher3));
		}
	}

#ifdef SUPPORT_BLAKES
	errno = 0;
	ASSERT(libhashsum_init_blakes_hasher(&hasher2, 128, salt) == -1);
	ASSERT(errno == EINVAL);
	errno = 0;
	ASSERT(libhashsum_init_blakes_hasher(&hasher2, 384, salt) == -1);
	ASSERT(errno == EINVAL);
#else
	errno = 0;
	ASSERT(libhashsum_init_blakes_hasher(&hasher2, 128, salt) == -1);
	ASSERT(errno == EINVAL || errno == ENOSYS);
	errno = 0;
	ASSERT(libhashsum_init_blakes_hasher(&hasher2, 384, salt) == -1);
	ASSERT(errno == EINVAL || errno == ENOSYS);
#endif

#ifdef SUPPORT_BLAKEB
	errno = 0;
	ASSERT(libhashsum_init_blakeb_hasher(&hasher2, 128, salt) == -1);
	ASSERT(errno == EINVAL);
	errno = 0;
	ASSERT(libhashsum_init_blakeb_hasher(&hasher2, 256, salt) == -1);
	ASSERT(errno == EINVAL);
	errno = 0;
	ASSERT(libhashsum_init_blakeb_hasher(&hasher2, 1024, salt) == -1);
	ASSERT(errno == EINVAL);
#else
	errno = 0;
	ASSERT(libhashsum_init_blakeb_hasher(&hasher2, 128, salt) == -1);
	ASSERT(errno == EINVAL || errno == ENOSYS);
	errno = 0;
	ASSERT(libhashsum_init_blakeb_hasher(&hasher2, 256, salt) == -1);
	ASSERT(errno == EINVAL || errno == ENOSYS);
	errno = 0;
	ASSERT(libhashsum_init_blakeb_hasher(&hasher2, 1024, salt) == -1);
	ASSERT(errno == EINVAL || errno == ENOSYS);
#endif

#ifdef SUPPORT_BLAKE
	errno = 0;
	ASSERT(libhashsum_init_blake_hasher(&hasher2, 128, salt, 16) == -1);
	ASSERT(errno == EINVAL);
	errno = 0;
	ASSERT(libhashsum_init_blake_hasher(&hasher2, 400, salt, 32) == -1);
	ASSERT(errno == EINVAL);
	errno = 0;
	ASSERT(libhashsum_init_blake_hasher(&hasher2, 1024, salt, 32) == -1);
	ASSERT(errno == EINVAL);
#else
	errno = 0;
	ASSERT(libhashsum_init_blake_hasher(&hasher2, 128, salt, 16) == -1);
	ASSERT(errno == EINVAL || errno == ENOSYS);
	errno = 0;
	ASSERT(libhashsum_init_blake_hasher(&hasher2, 400, salt, 32) == -1);
	ASSERT(errno == EINVAL || errno == ENOSYS);
	errno = 0;
	ASSERT(libhashsum_init_blake_hasher(&hasher2, 1024, salt, 32) == -1);
	ASSERT(errno == EINVAL || errno == ENOSYS);
#endif
}


int
main(void)
{
	struct libhashsum_hasher hasher;
	enum libhashsum_algorithm algo;

	test_blake(NULL);
	test_blake("1234567890abcdefhijkABCDEFHIJK,.1234567890abcdefhijkABCDEFHIJK,.");

	errno = 0;
	ASSERT(libhashsum_init_hasher(&hasher, -1) == -1);
	ASSERT(errno == EINVAL);

	errno = 0;
	ASSERT(libhashsum_init_hasher(&hasher, 999) == -1);
	ASSERT(errno == EINVAL);

	errno = 0;
	ASSERT(libhashsum_init_hasher(&hasher, LIBHASHSUM_KECCAK) == -1);
	ASSERT(errno == EINVAL);

	ASSERT(libhashsum_get_algorithm_from_string(&algo, "") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "X") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "MD") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "MD55555") == 0);

	ASSERT(libhashsum_get_algorithm_from_string(&algo, "MD2") == 1 && algo == LIBHASHSUM_MD2);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "MD4") == 1 && algo == LIBHASHSUM_MD4);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "MD5") == 1 && algo == LIBHASHSUM_MD5);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "Keccak") == 1 && algo == LIBHASHSUM_KECCAK);

	ASSERT(libhashsum_get_algorithm_from_string(&algo, "md2") == 1 && algo == LIBHASHSUM_MD2);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "md4") == 1 && algo == LIBHASHSUM_MD4);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "md5") == 1 && algo == LIBHASHSUM_MD5);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "keccak") == 1 && algo == LIBHASHSUM_KECCAK);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "KECCAK") == 1 && algo == LIBHASHSUM_KECCAK);

	ASSERT(libhashsum_get_algorithm_from_string(&algo, "MD2[]") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "MD4[]") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "MD5[]") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "Keccak[]") == 1 && algo == LIBHASHSUM_KECCAK);

	ASSERT(libhashsum_get_algorithm_from_string(&algo, "RIPEMD-128") == 1 && algo == LIBHASHSUM_RIPEMD_128);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "RIPEMD-160") == 1 && algo == LIBHASHSUM_RIPEMD_160);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "RIPEMD-256") == 1 && algo == LIBHASHSUM_RIPEMD_256);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "RIPEMD-320") == 1 && algo == LIBHASHSUM_RIPEMD_320);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "RMD-128") == 1 && algo == LIBHASHSUM_RIPEMD_128);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "RMD-160") == 1 && algo == LIBHASHSUM_RIPEMD_160);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "RMD-256") == 1 && algo == LIBHASHSUM_RIPEMD_256);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "RMD-320") == 1 && algo == LIBHASHSUM_RIPEMD_320);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-0") == 1 && algo == LIBHASHSUM_SHA0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-1") == 1 && algo == LIBHASHSUM_SHA1);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-2-224") == 1 && algo == LIBHASHSUM_SHA_224);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-2-256") == 1 && algo == LIBHASHSUM_SHA_256);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-2-384") == 1 && algo == LIBHASHSUM_SHA_384);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-2-512") == 1 && algo == LIBHASHSUM_SHA_512);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-2-512/224") == 1 && algo == LIBHASHSUM_SHA_512_224);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-2-512/256") == 1 && algo == LIBHASHSUM_SHA_512_256);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-2-512-224") == 1 && algo == LIBHASHSUM_SHA_512_224);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-2-512-256") == 1 && algo == LIBHASHSUM_SHA_512_256);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-2-512_224") == 1 && algo == LIBHASHSUM_SHA_512_224);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-2-512_256") == 1 && algo == LIBHASHSUM_SHA_512_256);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-224") == 1 && algo == LIBHASHSUM_SHA_224);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-256") == 1 && algo == LIBHASHSUM_SHA_256);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-384") == 1 && algo == LIBHASHSUM_SHA_384);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-512") == 1 && algo == LIBHASHSUM_SHA_512);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-512/224") == 1 && algo == LIBHASHSUM_SHA_512_224);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-512/256") == 1 && algo == LIBHASHSUM_SHA_512_256);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-512-224") == 1 && algo == LIBHASHSUM_SHA_512_224);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-512-256") == 1 && algo == LIBHASHSUM_SHA_512_256);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-512_224") == 1 && algo == LIBHASHSUM_SHA_512_224);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-512_256") == 1 && algo == LIBHASHSUM_SHA_512_256);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "Keccak-224") == 1 && algo == LIBHASHSUM_KECCAK_224);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "Keccak-256") == 1 && algo == LIBHASHSUM_KECCAK_256);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "Keccak-384") == 1 && algo == LIBHASHSUM_KECCAK_384);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "Keccak-512") == 1 && algo == LIBHASHSUM_KECCAK_512);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-3-224") == 1 && algo == LIBHASHSUM_SHA3_224);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-3-256") == 1 && algo == LIBHASHSUM_SHA3_256);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-3-384") == 1 && algo == LIBHASHSUM_SHA3_384);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-3-512") == 1 && algo == LIBHASHSUM_SHA3_512);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHAKE-128") == 1 && algo == LIBHASHSUM_SHAKE128);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHAKE-256") == 1 && algo == LIBHASHSUM_SHAKE256);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHAKE-512") == 1 && algo == LIBHASHSUM_SHAKE512);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "RawSHAKE-128") == 1 && algo == LIBHASHSUM_RAWSHAKE128);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "RawSHAKE-256") == 1 && algo == LIBHASHSUM_RAWSHAKE256);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "RawSHAKE-512") == 1 && algo == LIBHASHSUM_RAWSHAKE512);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "BLAKE-224") == 1 && algo == LIBHASHSUM_BLAKE224);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "BLAKE-256") == 1 && algo == LIBHASHSUM_BLAKE256);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "BLAKE-384") == 1 && algo == LIBHASHSUM_BLAKE384);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "BLAKE-512") == 1 && algo == LIBHASHSUM_BLAKE512);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "B-224") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "B-256") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "B-384") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "B-512") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "BLAKE-2s") == 1 && algo == LIBHASHSUM_BLAKE2S);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "BLAKE-2b") == 1 && algo == LIBHASHSUM_BLAKE2B);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "B-2s") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "B-2b") == 0);

	ASSERT(libhashsum_get_algorithm_from_string(&algo, "RIPEMD128") == 1 && algo == LIBHASHSUM_RIPEMD_128);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "RIPEMD160") == 1 && algo == LIBHASHSUM_RIPEMD_160);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "RIPEMD256") == 1 && algo == LIBHASHSUM_RIPEMD_256);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "RIPEMD320") == 1 && algo == LIBHASHSUM_RIPEMD_320);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "RMD128") == 1 && algo == LIBHASHSUM_RIPEMD_128);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "RMD160") == 1 && algo == LIBHASHSUM_RIPEMD_160);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "RMD256") == 1 && algo == LIBHASHSUM_RIPEMD_256);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "RMD320") == 1 && algo == LIBHASHSUM_RIPEMD_320);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA0") == 1 && algo == LIBHASHSUM_SHA0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA1") == 1 && algo == LIBHASHSUM_SHA1);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA2-224") == 1 && algo == LIBHASHSUM_SHA_224);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA2-256") == 1 && algo == LIBHASHSUM_SHA_256);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA2-384") == 1 && algo == LIBHASHSUM_SHA_384);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA2-512") == 1 && algo == LIBHASHSUM_SHA_512);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA2-512/224") == 1 && algo == LIBHASHSUM_SHA_512_224);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA2-512/256") == 1 && algo == LIBHASHSUM_SHA_512_256);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA2-512-224") == 1 && algo == LIBHASHSUM_SHA_512_224);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA2-512-256") == 1 && algo == LIBHASHSUM_SHA_512_256);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA2-512_224") == 1 && algo == LIBHASHSUM_SHA_512_224);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA2-512_256") == 1 && algo == LIBHASHSUM_SHA_512_256);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA224") == 1 && algo == LIBHASHSUM_SHA_224);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA256") == 1 && algo == LIBHASHSUM_SHA_256);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA384") == 1 && algo == LIBHASHSUM_SHA_384);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA512") == 1 && algo == LIBHASHSUM_SHA_512);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA512/224") == 1 && algo == LIBHASHSUM_SHA_512_224);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA512/256") == 1 && algo == LIBHASHSUM_SHA_512_256);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA512-224") == 1 && algo == LIBHASHSUM_SHA_512_224);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA512-256") == 1 && algo == LIBHASHSUM_SHA_512_256);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA512_224") == 1 && algo == LIBHASHSUM_SHA_512_224);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA512_256") == 1 && algo == LIBHASHSUM_SHA_512_256);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "Keccak224") == 1 && algo == LIBHASHSUM_KECCAK_224);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "Keccak256") == 1 && algo == LIBHASHSUM_KECCAK_256);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "Keccak384") == 1 && algo == LIBHASHSUM_KECCAK_384);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "Keccak512") == 1 && algo == LIBHASHSUM_KECCAK_512);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA3-224") == 1 && algo == LIBHASHSUM_SHA3_224);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA3-256") == 1 && algo == LIBHASHSUM_SHA3_256);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA3-384") == 1 && algo == LIBHASHSUM_SHA3_384);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA3-512") == 1 && algo == LIBHASHSUM_SHA3_512);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHAKE128") == 1 && algo == LIBHASHSUM_SHAKE128);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHAKE256") == 1 && algo == LIBHASHSUM_SHAKE256);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHAKE512") == 1 && algo == LIBHASHSUM_SHAKE512);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "RawSHAKE128") == 1 && algo == LIBHASHSUM_RAWSHAKE128);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "RawSHAKE256") == 1 && algo == LIBHASHSUM_RAWSHAKE256);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "RawSHAKE512") == 1 && algo == LIBHASHSUM_RAWSHAKE512);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "BLAKE224") == 1 && algo == LIBHASHSUM_BLAKE224);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "BLAKE256") == 1 && algo == LIBHASHSUM_BLAKE256);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "BLAKE384") == 1 && algo == LIBHASHSUM_BLAKE384);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "BLAKE512") == 1 && algo == LIBHASHSUM_BLAKE512);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "B224") == 1 && algo == LIBHASHSUM_BLAKE224);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "B256") == 1 && algo == LIBHASHSUM_BLAKE256);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "B384") == 1 && algo == LIBHASHSUM_BLAKE384);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "B512") == 1 && algo == LIBHASHSUM_BLAKE512);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "BLAKE2s") == 1 && algo == LIBHASHSUM_BLAKE2S);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "BLAKE2b") == 1 && algo == LIBHASHSUM_BLAKE2B);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "B2s") == 1 && algo == LIBHASHSUM_BLAKE2S);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "B2b") == 1 && algo == LIBHASHSUM_BLAKE2B);

	ASSERT(libhashsum_get_algorithm_from_string(&algo, "RIPEMD-128[]") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "RIPEMD-160[]") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "RIPEMD-256[]") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "RIPEMD-320[]") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "RMD-128[]") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "RMD-160[]") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "RMD-256[]") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "RMD-320[]") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-0[]") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-1[]") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-2-224[]") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-2-256[]") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-2-384[]") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-2-512[]") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-2-512/224[]") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-2-512/256[]") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-2-512-224[]") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-2-512-256[]") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-2-512_224[]") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-2-512_256[]") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-224[]") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-256[]") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-384[]") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-512[]") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-512/224[]") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-512/256[]") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-512-224[]") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-512-256[]") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-512_224[]") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-512_256[]") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "Keccak-224[]") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "Keccak-256[]") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "Keccak-384[]") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "Keccak-512[]") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-3-224[]") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-3-256[]") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-3-384[]") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHA-3-512[]") == 0);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHAKE-128[]") == 1 && algo == LIBHASHSUM_SHAKE128);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHAKE-256[]") == 1 && algo == LIBHASHSUM_SHAKE256);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "SHAKE-512[]") == 1 && algo == LIBHASHSUM_SHAKE512);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "RawSHAKE-128[]") == 1 && algo == LIBHASHSUM_RAWSHAKE128);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "RawSHAKE-256[]") == 1 && algo == LIBHASHSUM_RAWSHAKE256);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "RawSHAKE-512[]") == 1 && algo == LIBHASHSUM_RAWSHAKE512);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "BLAKE-224[]") == 1 && algo == LIBHASHSUM_BLAKE224);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "BLAKE-256[]") == 1 && algo == LIBHASHSUM_BLAKE256);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "BLAKE-384[]") == 1 && algo == LIBHASHSUM_BLAKE384);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "BLAKE-512[]") == 1 && algo == LIBHASHSUM_BLAKE512);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "B224[]") == 1 && algo == LIBHASHSUM_BLAKE224);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "B256[]") == 1 && algo == LIBHASHSUM_BLAKE256);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "B384[]") == 1 && algo == LIBHASHSUM_BLAKE384);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "B512[]") == 1 && algo == LIBHASHSUM_BLAKE512);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "BLAKE2s[]") == 1 && algo == LIBHASHSUM_BLAKE2S);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "BLAKE2b[]") == 1 && algo == LIBHASHSUM_BLAKE2B);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "B2s[]") == 1 && algo == LIBHASHSUM_BLAKE2S);
	ASSERT(libhashsum_get_algorithm_from_string(&algo, "B2b[]") == 1 && algo == LIBHASHSUM_BLAKE2B);

#define CHECK(ALGO, CALL)\
	do {\
		struct libhashsum_hasher hasher2;\
		int r;\
		memset(&hasher, 0xBC, sizeof(hasher));\
		memset(&hasher2, 0xBC, sizeof(hasher2));\
		r = CALL;\
		if (r) {\
			ASSERT(r == -1);\
			ASSERT(errno == ENOSYS);\
			errno = 0;\
			ASSERT(libhashsum_init_hasher_from_string(&hasher2, ALGO) == -1);\
			ASSERT(errno == ENOSYS);\
			break;\
		}\
		ASSERT(libhashsum_init_hasher_from_string(&hasher2, ALGO) == 0);\
		ASSERT(eq(&hasher, &hasher2));\
		if (hasher.destroy) {\
			hasher.destroy(&hasher);\
			hasher2.destroy(&hasher2);\
		}\
	} while (0)

#define SALT "\x01\x23\x45\x67\x89\xAb\xcd\xef\x01\x23\x45\x67\x89\xab\xcd\xef"

	CHECK("MD2", libhashsum_init_md2_hasher(&hasher));
	CHECK("MD4", libhashsum_init_md4_hasher(&hasher));
	CHECK("MD5", libhashsum_init_md5_hasher(&hasher));
	CHECK("RIPEMD128", libhashsum_init_ripemd_128_hasher(&hasher));
	CHECK("RIPEMD160", libhashsum_init_ripemd_160_hasher(&hasher));
	CHECK("RIPEMD256", libhashsum_init_ripemd_256_hasher(&hasher));
	CHECK("RIPEMD320", libhashsum_init_ripemd_320_hasher(&hasher));
	CHECK("RMD128", libhashsum_init_ripemd_128_hasher(&hasher));
	CHECK("RMD160", libhashsum_init_ripemd_160_hasher(&hasher));
	CHECK("RMD256", libhashsum_init_ripemd_256_hasher(&hasher));
	CHECK("RMD320", libhashsum_init_ripemd_320_hasher(&hasher));
	CHECK("SHA0", libhashsum_init_sha0_hasher(&hasher));
	CHECK("SHA1", libhashsum_init_sha1_hasher(&hasher));
	CHECK("SHA2-224", libhashsum_init_sha_224_hasher(&hasher));
	CHECK("SHA2-256", libhashsum_init_sha_256_hasher(&hasher));
	CHECK("SHA2-384", libhashsum_init_sha_384_hasher(&hasher));
	CHECK("SHA2-512", libhashsum_init_sha_512_hasher(&hasher));
	CHECK("SHA2-512/224", libhashsum_init_sha_512_224_hasher(&hasher));
	CHECK("SHA2-512/256", libhashsum_init_sha_512_256_hasher(&hasher));
	CHECK("SHA2-512-224", libhashsum_init_sha_512_224_hasher(&hasher));
	CHECK("SHA2-512-256", libhashsum_init_sha_512_256_hasher(&hasher));
	CHECK("SHA2-512_224", libhashsum_init_sha_512_224_hasher(&hasher));
	CHECK("SHA2-512_256", libhashsum_init_sha_512_256_hasher(&hasher));
	CHECK("SHA224", libhashsum_init_sha_224_hasher(&hasher));
	CHECK("SHA256", libhashsum_init_sha_256_hasher(&hasher));
	CHECK("SHA384", libhashsum_init_sha_384_hasher(&hasher));
	CHECK("SHA512", libhashsum_init_sha_512_hasher(&hasher));
	CHECK("SHA512/224", libhashsum_init_sha_512_224_hasher(&hasher));
	CHECK("SHA512/256", libhashsum_init_sha_512_256_hasher(&hasher));
	CHECK("SHA512-224", libhashsum_init_sha_512_224_hasher(&hasher));
	CHECK("SHA512-256", libhashsum_init_sha_512_256_hasher(&hasher));
	CHECK("SHA512_224", libhashsum_init_sha_512_224_hasher(&hasher));
	CHECK("SHA512_256", libhashsum_init_sha_512_256_hasher(&hasher));
	CHECK("Keccak224", libhashsum_init_keccak_224_hasher(&hasher));
	CHECK("Keccak256", libhashsum_init_keccak_256_hasher(&hasher));
	CHECK("Keccak384", libhashsum_init_keccak_384_hasher(&hasher));
	CHECK("Keccak512", libhashsum_init_keccak_512_hasher(&hasher));
	CHECK("SHA3-224", libhashsum_init_sha3_224_hasher(&hasher));
	CHECK("SHA3-256", libhashsum_init_sha3_256_hasher(&hasher));
	CHECK("SHA3-384", libhashsum_init_sha3_384_hasher(&hasher));
	CHECK("SHA3-512", libhashsum_init_sha3_512_hasher(&hasher));
	CHECK("SHAKE128", libhashsum_init_shake128_hasher(&hasher, 0));
	CHECK("SHAKE256", libhashsum_init_shake256_hasher(&hasher, 0));
	CHECK("SHAKE512", libhashsum_init_shake512_hasher(&hasher, 0));
	CHECK("SHAKE128[]", libhashsum_init_shake128_hasher(&hasher, 0));
	CHECK("SHAKE256[]", libhashsum_init_shake256_hasher(&hasher, 0));
	CHECK("SHAKE512[]", libhashsum_init_shake512_hasher(&hasher, 0));
	CHECK("SHAKE128[n=10000]", libhashsum_init_shake128_hasher(&hasher, 10000));
	CHECK("SHAKE256[n=10000]", libhashsum_init_shake256_hasher(&hasher, 10000));
	CHECK("SHAKE512[N=10000]", libhashsum_init_shake512_hasher(&hasher, 10000));
	CHECK("RawSHAKE128", libhashsum_init_rawshake128_hasher(&hasher, 0));
	CHECK("RawSHAKE256", libhashsum_init_rawshake256_hasher(&hasher, 0));
	CHECK("RawSHAKE512", libhashsum_init_rawshake512_hasher(&hasher, 0));
	CHECK("RawSHAKE128[]", libhashsum_init_rawshake128_hasher(&hasher, 0));
	CHECK("RawSHAKE256[]", libhashsum_init_rawshake256_hasher(&hasher, 0));
	CHECK("RawSHAKE512[]", libhashsum_init_rawshake512_hasher(&hasher, 0));
	CHECK("RawSHAKE128[n=200]", libhashsum_init_rawshake128_hasher(&hasher, 200));
	CHECK("RawSHAKE256[N=200]", libhashsum_init_rawshake256_hasher(&hasher, 200));
	CHECK("RawSHAKE512[n=200]", libhashsum_init_rawshake512_hasher(&hasher, 200));
	CHECK("BLAKE224", libhashsum_init_blake224_hasher(&hasher, NULL));
	CHECK("BLAKE256", libhashsum_init_blake256_hasher(&hasher, NULL));
	CHECK("BLAKE384", libhashsum_init_blake384_hasher(&hasher, NULL));
	CHECK("BLAKE512", libhashsum_init_blake512_hasher(&hasher, NULL));
	CHECK("BLAKE224[]", libhashsum_init_blake224_hasher(&hasher, NULL));
	CHECK("BLAKE256[]", libhashsum_init_blake256_hasher(&hasher, NULL));
	CHECK("BLAKE384[]", libhashsum_init_blake384_hasher(&hasher, NULL));
	CHECK("BLAKE512[]", libhashsum_init_blake512_hasher(&hasher, NULL));
	CHECK("BLAKE224[salt=00000000000000000000000000000000]", libhashsum_init_blake224_hasher(&hasher, NULL));
	CHECK("BLAKE224[salt=0123456789abcdef0123456789ABCDEF]", libhashsum_init_blake224_hasher(&hasher, SALT));
	CHECK("BLAKE256[SALT=0123456789abcdef0123456789ABCDEF]", libhashsum_init_blake256_hasher(&hasher, SALT));
	CHECK("BLAKE384[Salt=0123456789abcdef0123456789abcdef0123456789ABCDEF0123456789ABCDEF]",
	      libhashsum_init_blake384_hasher(&hasher, SALT SALT));
	CHECK("BLAKE512[SaLt=0123456789abcdef0123456789abcdef0123456789ABCDEF0123456789ABCDEF]",
	      libhashsum_init_blake512_hasher(&hasher, SALT SALT));
	CHECK("BLAKE224[salt=0x0123456789Abcdef0123456789abcdef]", libhashsum_init_blake224_hasher(&hasher, SALT));
	CHECK("BLAKE256[SALT=0X0123456789aBcdef0123456789abcdef]", libhashsum_init_blake256_hasher(&hasher, SALT));
	CHECK("BLAKE384[Salt=0x0123456789abCdef0123456789abcdef0123456789abcdef0123456789abcdef]",
	      libhashsum_init_blake384_hasher(&hasher, SALT SALT));
	CHECK("BLAKE512[SaLt=0X0123456789abcDef0123456789abcdef0123456789abcdef0123456789abcdef]",
	      libhashsum_init_blake512_hasher(&hasher, SALT SALT));
	CHECK("Keccak", libhashsum_init_keccak_hasher(&hasher, 0, 0, 0, 0));
	CHECK("Keccak[]", libhashsum_init_keccak_hasher(&hasher, 0, 0, 0, 0));
	CHECK("Keccak[r=256]", libhashsum_init_keccak_hasher(&hasher, 256, 0, 0, 0));
	CHECK("Keccak[R=256]", libhashsum_init_keccak_hasher(&hasher, 256, 0, 0, 0));
	CHECK("Keccak[c=256]", libhashsum_init_keccak_hasher(&hasher, 0, 256, 0, 0));
	CHECK("Keccak[C=256]", libhashsum_init_keccak_hasher(&hasher, 0, 256, 0, 0));
	CHECK("Keccak[n=256]", libhashsum_init_keccak_hasher(&hasher, 0, 0, 256, 0));
	CHECK("Keccak[N=256]", libhashsum_init_keccak_hasher(&hasher, 0, 0, 256, 0));
	CHECK("Keccak[z=256]", libhashsum_init_keccak_hasher(&hasher, 0, 0, 0, 256));
	CHECK("Keccak[Z=256]", libhashsum_init_keccak_hasher(&hasher, 0, 0, 0, 256));
	CHECK("Keccak[r=1200,c=400,n=100,z=60]", libhashsum_init_keccak_hasher(&hasher, 1200, 400, 100, 60));
	CHECK("Keccak[z=60,r=1200,c=400,n=100]", libhashsum_init_keccak_hasher(&hasher, 1200, 400, 100, 60));
	CHECK("BLAKE2s", libhashsum_init_blake2s_hasher(&hasher, 0, NULL, NULL, NULL, 0));
	CHECK("BLAKE2s[]", libhashsum_init_blake2s_hasher(&hasher, 0, NULL, NULL, NULL, 0));
	CHECK("BLAKE2s[n=128]", libhashsum_init_blake2s_hasher(&hasher, 128, NULL, NULL, NULL, 0));
	CHECK("BLAKE2s[Salt=0000000000000000]", libhashsum_init_blake2s_hasher(&hasher, 0, NULL, NULL, NULL, 0));
	CHECK("BLAKE2s[pePPer=0000000000000000]", libhashsum_init_blake2s_hasher(&hasher, 0, NULL, NULL, NULL, 0));
	CHECK("BLAKE2s[key=]", libhashsum_init_blake2s_hasher(&hasher, 0, NULL, NULL, NULL, 0));
	CHECK("BLAKE2s[salt=0123456789abcDEF]", libhashsum_init_blake2s_hasher(&hasher, 0, SALT, NULL, NULL, 0));
	CHECK("BLAKE2s[pepper=0123456789abcDEF]", libhashsum_init_blake2s_hasher(&hasher, 0, NULL, SALT, NULL, 0));
	CHECK("BLAKE2s[key=0123456789abcDEF]", libhashsum_init_blake2s_hasher(&hasher, 0, NULL, NULL, SALT, 64));
	CHECK("BLAKE2s[KEY=0123456789abcdef0123456789ABCDEF]", libhashsum_init_blake2s_hasher(&hasher, 0, NULL, NULL, SALT, 128));
	CHECK("BLAKE2s[key=0123456789abcdef0123456789ABCDEF0123456789abcdef0123456789ABCDEF]",
	      libhashsum_init_blake2s_hasher(&hasher, 0, NULL, NULL, SALT SALT, 256));
	CHECK("BLAKE2b", libhashsum_init_blake2b_hasher(&hasher, 0, NULL, NULL, NULL, 0));
	CHECK("BLAKE2b[]", libhashsum_init_blake2b_hasher(&hasher, 0, NULL, NULL, NULL, 0));
	CHECK("BLAKE2b[n=64]", libhashsum_init_blake2b_hasher(&hasher, 64, NULL, NULL, NULL, 0));
	CHECK("BLAKE2b[N=128]", libhashsum_init_blake2b_hasher(&hasher, 128, NULL, NULL, NULL, 0));
	CHECK("BLAKE2b[salt=0123456789abcDEF0123456789abcDEF]",
	      libhashsum_init_blake2b_hasher(&hasher, 0, SALT, NULL, NULL, 0));
	CHECK("BLAKE2b[pepper=0123456789abcDEF0123456789abcDEF]",
	      libhashsum_init_blake2b_hasher(&hasher, 0, NULL, SALT, NULL, 0));
	CHECK("BLAKE2b[key=0123456789abcDEF]", libhashsum_init_blake2b_hasher(&hasher, 0, NULL, NULL, SALT, 64));
	CHECK("BLAKE2b[salt=00000000000000000000000000000000]",
	      libhashsum_init_blake2b_hasher(&hasher, 0, NULL, NULL, NULL, 0));
	CHECK("BLAKE2b[pepper=00000000000000000000000000000000]",
	      libhashsum_init_blake2b_hasher(&hasher, 0, NULL, NULL, NULL, 0));
	CHECK("BLAKE2b[key=]", libhashsum_init_blake2b_hasher(&hasher, 0, NULL, NULL, NULL, 0));
	CHECK("BLAKE2b[key=0123456789abcdef0123456789ABCDEF]", libhashsum_init_blake2b_hasher(&hasher, 0, NULL, NULL, SALT, 128));
	CHECK("BLAKE2b[key=0123456789abcdef0123456789ABCDEF0123456789abcdef0123456789ABCDEF]",
	      libhashsum_init_blake2b_hasher(&hasher, 0, NULL, NULL, SALT SALT, 256));
	CHECK("BLAKE2b[key=0123456789abcdef0123456789ABCDEF0123456789abcdef0123456789ABCDEF"
	                  "0123456789abcdef0123456789ABCDEF0123456789abcdef0123456789ABCDEF]",
	      libhashsum_init_blake2b_hasher(&hasher, 0, NULL, NULL, SALT SALT SALT SALT, 512));

#undef CHECK
#undef SALT

	ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE2b[]sum") == -1 && errno == EINVAL);
	ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE256[]sum") == -1 && errno == EINVAL);
	ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE256[salt=]") == -1 && errno == EINVAL);
	ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE256[salt=zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz") == -1);
	ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE256[salt=00zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz") == -1);
	ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE256[salt=000zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz") == -1);
	ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE256[salt=00z0zzzzzzzzzzzzzzzzzzzzzzzzzzzzz") == -1);
	ASSERT(errno == EINVAL);
	ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE256[salt=00000000]") == -1 && errno == EINVAL);
	ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE256[salt=1234567890abcdef1234567890abcdef"
	                                                                 "1234567890abcdef1234567890abcdef]"));
	ASSERT(errno == EINVAL);
	ASSERT(libhashsum_init_hasher_from_string(&hasher, "SHAKE128[n]") == -1 && errno == EINVAL);
	ASSERT(libhashsum_init_hasher_from_string(&hasher, "SHAKE128[n=]") == -1 && errno == EINVAL);
	ASSERT(libhashsum_init_hasher_from_string(&hasher, "SHAKE128[n=0]") == -1 && errno == EINVAL);
	ASSERT(libhashsum_init_hasher_from_string(&hasher, "SHAKE128[n=1000,]") == -1 && errno == EINVAL);
	ASSERT(libhashsum_init_hasher_from_string(&hasher, "SHAKE128[,n=1000]") == -1 && errno == EINVAL);
	ASSERT(libhashsum_init_hasher_from_string(&hasher, "shake128[]sum") == -1 && errno == EINVAL);
	ASSERT(libhashsum_init_hasher_from_string(&hasher, "") == -1 && errno == EINVAL);
	ASSERT(libhashsum_init_hasher_from_string(&hasher, "X") == -1 && errno == EINVAL);
	ASSERT(libhashsum_init_hasher_from_string(&hasher, "Keccak[") == -1 && errno == EINVAL);
	ASSERT(libhashsum_init_hasher_from_string(&hasher, "Keccak[]sum") == -1 && errno == EINVAL);
	ASSERT(libhashsum_init_hasher_from_string(&hasher, "Keccak[n=256]sum") == -1 && errno == EINVAL);
	ASSERT(libhashsum_init_hasher_from_string(&hasher, "Keccak[r=0]") == -1 && errno == EINVAL);
	ASSERT(libhashsum_init_hasher_from_string(&hasher, "Keccak[c=0]") == -1 && errno == EINVAL);
	ASSERT(libhashsum_init_hasher_from_string(&hasher, "Keccak[n=0]") == -1 && errno == EINVAL);
	ASSERT(libhashsum_init_hasher_from_string(&hasher, "Keccak[z=0]") == -1 && errno == EINVAL);
	ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE2s[n=0]") == -1 && errno == EINVAL);
	ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE2b[n=0]") == -1 && errno == EINVAL);
	ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE2s[salt=00000000000000]") == -1 && errno == EINVAL);
	ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE2b[salt=000000000000000000000000000000]") == -1);
	ASSERT(errno == EINVAL);
	ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE2s[salt=000000000000000000]") == -1 && errno == EINVAL);
	ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE2b[salt=0000000000000000000000000000000000]") == -1);
	ASSERT(errno == EINVAL);
	ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE2s[pepper=00000000000000]") == -1 && errno == EINVAL);
	ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE2b[pepper=000000000000000000000000000000]") == -1);
	ASSERT(errno == EINVAL);
	ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE2s[pepper=000000000000000000]") == -1 && errno == EINVAL);
	ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE2b[pepper=0000000000000000000000000000000000]") == -1);
	ASSERT(errno == EINVAL);
	ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE2s[salt=zzzzzzzzzzzzzzzz]") == -1 && errno == EINVAL);
	ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE2b[salt=zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz]") == -1);
	ASSERT(errno == EINVAL);
	ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE2s[salt=00zzzzzzzzzzzzzz]") == -1 && errno == EINVAL);
	ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE2b[salt=00zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz]") == -1);
	ASSERT(errno == EINVAL);
	ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE2s[salt=000zzzzzzzzzzzzz]") == -1 && errno == EINVAL);
	ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE2b[salt=000zzzzzzzzzzzzzzzzzzzzzzzzzzzzz]") == -1);
	ASSERT(errno == EINVAL);
	ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE2s[salt=00z0zzzzzzzzzzzz]") == -1 && errno == EINVAL);
	ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE2b[salt=00z0zzzzzzzzzzzzzzzzzzzzzzzzzzzz]") == -1);
	ASSERT(errno == EINVAL);
	ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE2s[key=00000000000000000000000000000000"
	                                                               "0000000000000000000000000000000000"
	                                                               "00000000000000000000000000000000"
	                                                               "00000000000000000000000000000000]") == -1);
	ASSERT(errno == EINVAL || errno == ENOSYS);
	ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE2b[key=00000000000000000000000000000000"
	                                                               "0000000000000000000000000000000000"
	                                                               "00000000000000000000000000000000"
	                                                               "00000000000000000000000000000000"
	                                                               "00000000000000000000000000000000"
	                                                               "00000000000000000000000000000000"
	                                                               "00000000000000000000000000000000"
	                                                               "00000000000000000000000000000000]") == -1);
	ASSERT(errno == EINVAL || errno == ENOSYS);

	return 0;
}