This repository has been archived by the owner on Jan 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 86
/
bash512.c
110 lines (85 loc) · 2.46 KB
/
bash512.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
* Copyright (C) 2022 - This file is part of libecc project
*
* Authors:
* Ryad BENADJILA <ryadbenadjila@gmail.com>
* Arnaud EBALARD <arnaud.ebalard@ssi.gouv.fr>
*
* This software is licensed under a dual BSD and GPL v2 license.
* See LICENSE file at the root folder of the project.
*/
#include "../lib_ecc_config.h"
#ifdef WITH_HASH_BASH512
#include "bash512.h"
/* Init hash function. Returns 0 on success, -1 on error. */
int bash512_init(bash512_context *ctx)
{
int ret;
ret = _bash_init(ctx, BASH512_DIGEST_SIZE); EG(ret, err);
/* Tell that we are initialized */
ctx->magic = BASH512_HASH_MAGIC;
err:
return ret;
}
/* Update hash function. Returns 0 on success, -1 on error. */
int bash512_update(bash512_context *ctx, const u8 *input, u32 ilen)
{
int ret;
BASH512_HASH_CHECK_INITIALIZED(ctx, ret, err);
ret = _bash_update((bash_context *)ctx, input, ilen);
err:
return ret;
}
/* Finalize hash function. Returns 0 on success, -1 on error. */
int bash512_final(bash512_context *ctx, u8 output[BASH512_DIGEST_SIZE])
{
int ret;
BASH512_HASH_CHECK_INITIALIZED(ctx, ret, err);
ret = _bash_finalize((bash_context *)ctx, output); EG(ret, err);
/* Tell that we are uninitialized */
ctx->magic = WORD(0);
ret = 0;
err:
return ret;
}
/*
* Scattered version performing init/update/finalize on a vector of buffers
* 'inputs' with the length of each buffer passed via 'ilens'. The function
* loops on pointers in 'inputs' until it finds a NULL pointer. The function
* returns 0 on success, -1 on error.
*/
int bash512_scattered(const u8 **inputs, const u32 *ilens,
u8 output[BASH512_DIGEST_SIZE])
{
bash512_context ctx;
int ret, pos = 0;
MUST_HAVE((inputs != NULL) && (ilens != NULL) && (output != NULL), ret, err);
ret = bash512_init(&ctx); EG(ret, err);
while (inputs[pos] != NULL) {
ret = bash512_update(&ctx, inputs[pos], ilens[pos]); EG(ret, err);
pos += 1;
}
ret = bash512_final(&ctx, output);
err:
return ret;
}
/*
* Single call version performing init/update/final on given input.
* Returns 0 on success, -1 on error.
*/
int bash512(const u8 *input, u32 ilen, u8 output[BASH512_DIGEST_SIZE])
{
bash512_context ctx;
int ret;
ret = bash512_init(&ctx); EG(ret, err);
ret = bash512_update(&ctx, input, ilen); EG(ret, err);
ret = bash512_final(&ctx, output);
err:
return ret;
}
#else /* WITH_HASH_BASH512 */
/*
* Dummy definition to avoid the empty translation unit ISO C warning
*/
typedef int dummy;
#endif /* WITH_HASH_BASH512 */