Coverage Report

Created: 2025-03-18 06:55

/src/nettle/shake128.c
Line
Count
Source (jump to first uncovered line)
1
/* shake128.c
2
3
   The SHAKE128 hash function, arbitrary length output.
4
5
   Copyright (C) 2017 Daiki Ueno
6
   Copyright (C) 2017 Red Hat, Inc.
7
8
   This file is part of GNU Nettle.
9
10
   GNU Nettle is free software: you can redistribute it and/or
11
   modify it under the terms of either:
12
13
     * the GNU Lesser General Public License as published by the Free
14
       Software Foundation; either version 3 of the License, or (at your
15
       option) any later version.
16
17
   or
18
19
     * the GNU General Public License as published by the Free
20
       Software Foundation; either version 2 of the License, or (at your
21
       option) any later version.
22
23
   or both in parallel, as here.
24
25
   GNU Nettle is distributed in the hope that it will be useful,
26
   but WITHOUT ANY WARRANTY; without even the implied warranty of
27
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
28
   General Public License for more details.
29
30
   You should have received copies of the GNU General Public License and
31
   the GNU Lesser General Public License along with this program.  If
32
   not, see http://www.gnu.org/licenses/.
33
*/
34
35
#if HAVE_CONFIG_H
36
# include "config.h"
37
#endif
38
39
#include <string.h>
40
41
#include "sha3.h"
42
#include "sha3-internal.h"
43
44
void
45
sha3_128_init (struct sha3_128_ctx *ctx)
46
0
{
47
0
  memset (ctx, 0, offsetof (struct sha3_128_ctx, block));
48
0
}
49
50
void
51
sha3_128_update (struct sha3_128_ctx *ctx,
52
     size_t length,
53
     const uint8_t *data)
54
0
{
55
0
  ctx->index = _nettle_sha3_update (&ctx->state,
56
0
            SHA3_128_BLOCK_SIZE, ctx->block,
57
0
            ctx->index, length, data);
58
0
}
59
60
void
61
sha3_128_shake (struct sha3_128_ctx *ctx,
62
    size_t length, uint8_t *dst)
63
0
{
64
0
  _nettle_sha3_shake (&ctx->state, sizeof (ctx->block), ctx->block, ctx->index, length, dst);
65
0
  sha3_128_init (ctx);
66
0
}
67
68
void
69
sha3_128_shake_output (struct sha3_128_ctx *ctx,
70
           size_t length, uint8_t *digest)
71
0
{
72
0
  ctx->index =
73
0
    _nettle_sha3_shake_output (&ctx->state,
74
0
             sizeof (ctx->block), ctx->block, ctx->index,
75
0
             length, digest);
76
0
}