]> git.ipfire.org Git - thirdparty/nettle.git/blame - sm3.h
ci: Update .gitlab-ci.yml job tags.
[thirdparty/nettle.git] / sm3.h
CommitLineData
b72886e5
TZ
1/* sm3.h
2
3 The SM3 hash function.
4
5 Copyright (C) 2017 Jia Zhang
6 Copyright (C) 2021 Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
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#ifndef NETTLE_SM3_H_INCLUDED
36#define NETTLE_SM3_H_INCLUDED
37
38#include "nettle-types.h"
39
40#ifdef __cplusplus
41extern "C" {
42#endif
43
44/* Name mangling */
45#define sm3_init nettle_sm3_init
46#define sm3_update nettle_sm3_update
47#define sm3_digest nettle_sm3_digest
48
49#define SM3_DIGEST_SIZE 32
50#define SM3_BLOCK_SIZE 64
51
52/* Digest is kept internally as 8 32-bit words. */
53#define _SM3_DIGEST_LENGTH 8
54
55struct sm3_ctx
56{
57 uint32_t state[_SM3_DIGEST_LENGTH];
58 uint64_t count; /* Block count */
59 unsigned index; /* Into buffer */
60 uint8_t block[SM3_BLOCK_SIZE]; /* Block buffer */
61};
62
63void
64sm3_init(struct sm3_ctx *ctx);
65
66void
67sm3_update(struct sm3_ctx *ctx,
68 size_t length,
69 const uint8_t *data);
70
71void
72sm3_digest(struct sm3_ctx *ctx,
73 size_t length,
74 uint8_t *digest);
75
76#ifdef __cplusplus
77}
78#endif
79
80#endif /* NETTLE_SM3_H_INCLUDED */