/*1* Copyright (C) 2017 - This file is part of libecc project2*3* Authors:4* Ryad BENADJILA <[email protected]>5* Arnaud EBALARD <[email protected]>6* Jean-Pierre FLORI <[email protected]>7*8* Contributors:9* Nicolas VIVET <[email protected]>10* Karim KHALFALLAH <[email protected]>11*12* This software is licensed under a dual BSD and GPL v2 license.13* See LICENSE file at the root folder of the project.14*/15#include <libecc/lib_ecc_config.h>16#ifdef WITH_HASH_SHA3_2241718#include <libecc/hash/sha3-224.h>1920/* Init hash function. Returns 0 on success, -1 on error. */21int sha3_224_init(sha3_224_context *ctx)22{23int ret;2425ret = _sha3_init(ctx, SHA3_224_DIGEST_SIZE); EG(ret, err);2627/* Tell that we are initialized */28ctx->magic = SHA3_224_HASH_MAGIC;2930err:31return ret;32}3334/* Update hash function. Returns 0 on success, -1 on error. */35int sha3_224_update(sha3_224_context *ctx, const u8 *input, u32 ilen)36{37int ret;3839SHA3_224_HASH_CHECK_INITIALIZED(ctx, ret, err);4041ret = _sha3_update((sha3_context *)ctx, input, ilen);4243err:44return ret;45}4647/* Finalize hash function. Returns 0 on success, -1 on error. */48int sha3_224_final(sha3_224_context *ctx, u8 output[SHA3_224_DIGEST_SIZE])49{50int ret;5152SHA3_224_HASH_CHECK_INITIALIZED(ctx, ret, err);5354ret = _sha3_finalize((sha3_context *)ctx, output); EG(ret, err);5556/* Tell that we are uninitialized */57ctx->magic = WORD(0);58ret = 0;5960err:61return ret;62}6364/*65* Scattered version performing init/update/finalize on a vector of buffers66* 'inputs' with the length of each buffer passed via 'ilens'. The function67* loops on pointers in 'inputs' until it finds a NULL pointer. The function68* returns 0 on success, -1 on error.69*/70int sha3_224_scattered(const u8 **inputs, const u32 *ilens,71u8 output[SHA3_224_DIGEST_SIZE])72{73sha3_224_context ctx;74int ret, pos = 0;7576MUST_HAVE((inputs != NULL) && (ilens != NULL) && (output != NULL), ret, err);7778ret = sha3_224_init(&ctx); EG(ret, err);7980while (inputs[pos] != NULL) {81ret = sha3_224_update(&ctx, inputs[pos], ilens[pos]); EG(ret, err);82pos += 1;83}8485ret = sha3_224_final(&ctx, output);8687err:88return ret;89}9091/*92* Single call version performing init/update/final on given input.93* Returns 0 on success, -1 on error.94*/95int sha3_224(const u8 *input, u32 ilen, u8 output[SHA3_224_DIGEST_SIZE])96{97sha3_224_context ctx;98int ret;99100ret = sha3_224_init(&ctx); EG(ret, err);101ret = sha3_224_update(&ctx, input, ilen); EG(ret, err);102ret = sha3_224_final(&ctx, output);103104err:105return ret;106}107108#else /* WITH_HASH_SHA3_224 */109110/*111* Dummy definition to avoid the empty translation unit ISO C warning112*/113typedef int dummy;114#endif /* WITH_HASH_SHA3_224 */115116117