8e9d49fefb1bdf65ccae726555b499ab4a8927d7
[platform/upstream/nettle.git] / gosthash94.h
1 /* gosthash94.h
2
3    The GOST R 34.11-94 hash function, described in RFC 5831.
4
5    Copyright (C) 2012 Nikos Mavrogiannopoulos, Niels Möller
6
7    This file is part of GNU Nettle.
8
9    GNU Nettle is free software: you can redistribute it and/or
10    modify it under the terms of either:
11
12      * the GNU Lesser General Public License as published by the Free
13        Software Foundation; either version 3 of the License, or (at your
14        option) any later version.
15
16    or
17
18      * the GNU General Public License as published by the Free
19        Software Foundation; either version 2 of the License, or (at your
20        option) any later version.
21
22    or both in parallel, as here.
23
24    GNU Nettle is distributed in the hope that it will be useful,
25    but WITHOUT ANY WARRANTY; without even the implied warranty of
26    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
27    General Public License for more details.
28
29    You should have received copies of the GNU General Public License and
30    the GNU Lesser General Public License along with this program.  If
31    not, see http://www.gnu.org/licenses/.
32 */
33
34 /* Based on rhash gost.h. */
35
36 /* Copyright: 2009-2012 Aleksey Kravchenko <rhash.admin@gmail.com>
37  *
38  * Permission is hereby granted, free of charge, to any person obtaining a
39  * copy of this software and associated documentation files (the
40  * "Software"), to deal in the Software without restriction, including
41  * without limitation the rights to use, copy, modify, merge, publish,
42  * distribute, sublicense, and/or sell copies of the Software, and to
43  * permit persons to whom the Software is furnished to do so, subject to
44  * the following conditions:
45  *
46  * The above copyright notice and this permission notice shall be included
47  * in all copies or substantial portions of the Software.
48  *
49  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
50  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
51  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
52  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
53  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
54  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
55  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
56  */
57
58 /*
59  * Ported to nettle by Nikos Mavrogiannopoulos.
60  */
61
62 #ifndef NETTLE_GOSTHASH94_H_INCLUDED
63 #define NETTLE_GOSTHASH94_H_INCLUDED
64
65 #include "nettle-types.h"
66
67 #ifdef __cplusplus
68 extern "C" {
69 #endif
70
71 #define gosthash94_init nettle_gosthash94_init
72 #define gosthash94_update nettle_gosthash94_update
73 #define gosthash94_digest nettle_gosthash94_digest
74
75 #define GOSTHASH94_BLOCK_SIZE 32
76 #define GOSTHASH94_DIGEST_SIZE 32
77 /* For backwards compatibility */
78 #define GOSTHASH94_DATA_SIZE GOSTHASH94_BLOCK_SIZE
79
80 struct gosthash94_ctx
81 {
82   uint32_t hash[8]; /* algorithm 256-bit state */
83   uint32_t sum[8];  /* sum of processed message blocks */
84   uint8_t message[GOSTHASH94_BLOCK_SIZE]; /* 256-bit buffer for leftovers */
85   uint64_t length;  /* number of processed bytes */
86 };
87
88 void gosthash94_init(struct gosthash94_ctx *ctx);
89 void gosthash94_update(struct gosthash94_ctx *ctx,
90                        size_t length, const uint8_t *msg);
91 void gosthash94_digest(struct gosthash94_ctx *ctx,
92                        size_t length, uint8_t *result);
93
94 #ifdef __cplusplus
95 }
96 #endif
97
98 #endif /* NETTLE_GOSTHASH94_H_INCLUDED */