aboutsummaryrefslogblamecommitdiffstats
path: root/libhashsum_init_sha3_hasher.c
blob: c9d6ac76cd8c624125a37060e5b5c843dfd8be3e (plain) (tree)









































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


int
libhashsum_init_sha3_hasher(struct libhashsum_hasher *this, size_t hashbits)
{
	struct libkeccak_spec spec;

	if (hashbits == 224U) {
		this->algorithm = LIBHASHSUM_SHA3_224;
		this->algorithm_string = "SHA3-224";
	} else if (hashbits == 256U) {
		this->algorithm = LIBHASHSUM_SHA3_256;
		this->algorithm_string = "SHA3-256";
	} else if (hashbits == 384U) {
		this->algorithm = LIBHASHSUM_SHA3_384;
		this->algorithm_string = "SHA3-384";
	} else if (hashbits == 512U) {
		this->algorithm = LIBHASHSUM_SHA3_512;
		this->algorithm_string = "SHA3-512";
	} else {
		errno = EINVAL;
		return -1;
	}

	libkeccak_spec_sha3(&spec, (long int)hashbits);
	return libhashsum_init_keccak__(this, hashbits, &spec, LIBKECCAK_SHA3_SUFFIX);
}


#else
int
libhashsum_init_sha3_hasher(struct libhashsum_hasher *this, size_t hashbits)
{
	(void) this;
	(void) hashbits;
	errno = ENOSYS;
	return -1;
}
#endif