/*1* Copyright (C) 2022 - This file is part of libecc project2*3* Authors:4* Ryad BENADJILA <[email protected]>5* Arnaud EBALARD <[email protected]>6*7* This software is licensed under a dual BSD and GPL v2 license.8* See LICENSE file at the root folder of the project.9*/10#include <libecc/lib_ecc_config.h>11#ifdef WITH_HASH_BASH2241213#include <libecc/hash/bash224.h>1415/* Init hash function. Returns 0 on success, -1 on error. */16int bash224_init(bash224_context *ctx)17{18int ret;1920ret = _bash_init(ctx, BASH224_DIGEST_SIZE); EG(ret, err);2122/* Tell that we are initialized */23ctx->magic = BASH224_HASH_MAGIC;2425err:26return ret;27}2829/* Update hash function. Returns 0 on success, -1 on error. */30int bash224_update(bash224_context *ctx, const u8 *input, u32 ilen)31{32int ret;3334BASH224_HASH_CHECK_INITIALIZED(ctx, ret, err);3536ret = _bash_update((bash_context *)ctx, input, ilen);3738err:39return ret;40}4142/* Finalize hash function. Returns 0 on success, -1 on error. */43int bash224_final(bash224_context *ctx, u8 output[BASH224_DIGEST_SIZE])44{45int ret;4647BASH224_HASH_CHECK_INITIALIZED(ctx, ret, err);4849ret = _bash_finalize((bash_context *)ctx, output); EG(ret, err);5051/* Tell that we are uninitialized */52ctx->magic = WORD(0);53ret = 0;5455err:56return ret;57}5859/*60* Scattered version performing init/update/finalize on a vector of buffers61* 'inputs' with the length of each buffer passed via 'ilens'. The function62* loops on pointers in 'inputs' until it finds a NULL pointer. The function63* returns 0 on success, -1 on error.64*/65int bash224_scattered(const u8 **inputs, const u32 *ilens,66u8 output[BASH224_DIGEST_SIZE])67{68bash224_context ctx;69int ret, pos = 0;7071MUST_HAVE((inputs != NULL) && (ilens != NULL) && (output != NULL), ret, err);7273ret = bash224_init(&ctx); EG(ret, err);7475while (inputs[pos] != NULL) {76ret = bash224_update(&ctx, inputs[pos], ilens[pos]); EG(ret, err);77pos += 1;78}7980ret = bash224_final(&ctx, output);8182err:83return ret;84}8586/*87* Single call version performing init/update/final on given input.88* Returns 0 on success, -1 on error.89*/90int bash224(const u8 *input, u32 ilen, u8 output[BASH224_DIGEST_SIZE])91{92bash224_context ctx;93int ret;9495ret = bash224_init(&ctx); EG(ret, err);96ret = bash224_update(&ctx, input, ilen); EG(ret, err);97ret = bash224_final(&ctx, output);9899err:100return ret;101}102103#else /* WITH_HASH_BASH224 */104105/*106* Dummy definition to avoid the empty translation unit ISO C warning107*/108typedef int dummy;109#endif /* WITH_HASH_BASH224 */110111112