This repository was archived by the owner on Nov 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathshake256.c
More file actions
96 lines (70 loc) · 1.94 KB
/
shake256.c
File metadata and controls
96 lines (70 loc) · 1.94 KB
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
/*
* Copyright (C) 2022 - This file is part of libdrbg project
*
* Author: Ryad BENADJILA <ryad.benadjila@ssi.gouv.fr>
* Contributor: 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 "libhash_config.h"
#ifdef WITH_HASH_SHAKE256
#include "shake256.h"
int shake256_init(shake256_context *ctx)
{
int ret;
ret = _shake_init(ctx, SHAKE256_DIGEST_SIZE, SHAKE256_BLOCK_SIZE); EG(ret, err);
/* Tell that we are initialized */
ctx->magic = SHAKE256_HASH_MAGIC;
err:
return ret;
}
int shake256_update(shake256_context *ctx, const uint8_t *input, uint32_t ilen)
{
int ret;
SHAKE256_HASH_CHECK_INITIALIZED(ctx, ret, err);
ret = _shake_update((shake_context *)ctx, input, ilen);
err:
return ret;
}
int shake256_final(shake256_context *ctx, uint8_t output[SHAKE256_DIGEST_SIZE])
{
int ret;
SHAKE256_HASH_CHECK_INITIALIZED(ctx, ret, err);
ret = _shake_finalize((shake_context *)ctx, output);
/* Tell that we are uninitialized */
ctx->magic = (uint64_t)0;
err:
return ret;
}
int shake256_scattered(const uint8_t **inputs, const uint32_t *ilens,
uint8_t output[SHAKE256_DIGEST_SIZE])
{
shake256_context ctx;
int pos = 0, ret;
MUST_HAVE((inputs != NULL) && (ilens != NULL) && (output != NULL), ret, err);
ret = shake256_init(&ctx); EG(ret, err);
while (inputs[pos] != NULL) {
ret = shake256_update(&ctx, inputs[pos], ilens[pos]); EG(ret, err);
pos += 1;
}
ret = shake256_final(&ctx, output);
err:
return ret;
}
int shake256(const uint8_t *input, uint32_t ilen, uint8_t output[SHAKE256_DIGEST_SIZE])
{
int ret;
shake256_context ctx;
ret = shake256_init(&ctx); EG(ret, err);
ret = shake256_update(&ctx, input, ilen); EG(ret, err);
ret = shake256_final(&ctx, output);
err:
return ret;
}
#else
/*
* Dummy definition to avoid the empty translation unit ISO C warning
*/
typedef int dummy;
#endif