Samba Patch - Denial of service - CPU loop and memory allocation.
[tomato.git] / release / src / router / nettle / sha2.h
blob738261e2e5e3dd11de36f85a4e192916bf591972
1 /* sha2.h
3 * The sha2 family of hash functions.
4 */
6 /* nettle, low-level cryptographics library
8 * Copyright (C) 2001, 2012 Niels Möller
9 *
10 * The nettle library is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation; either version 2.1 of the License, or (at your
13 * option) any later version.
15 * The nettle library is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with the nettle library; see the file COPYING.LIB. If not, write to
22 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
23 * MA 02111-1301, USA.
26 #ifndef NETTLE_SHA2_H_INCLUDED
27 #define NETTLE_SHA2_H_INCLUDED
29 #include "nettle-types.h"
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
35 /* Name mangling */
36 #define sha224_init nettle_sha224_init
37 #define sha224_digest nettle_sha224_digest
38 #define sha256_init nettle_sha256_init
39 #define sha256_update nettle_sha256_update
40 #define sha256_digest nettle_sha256_digest
41 #define sha384_init nettle_sha384_init
42 #define sha384_digest nettle_sha384_digest
43 #define sha512_init nettle_sha512_init
44 #define sha512_update nettle_sha512_update
45 #define sha512_digest nettle_sha512_digest
47 /* SHA256 */
49 #define SHA256_DIGEST_SIZE 32
50 #define SHA256_DATA_SIZE 64
52 /* Digest is kept internally as 8 32-bit words. */
53 #define _SHA256_DIGEST_LENGTH 8
55 struct sha256_ctx
57 uint32_t state[_SHA256_DIGEST_LENGTH]; /* State variables */
58 uint32_t count_low, count_high; /* 64-bit block count */
59 uint8_t block[SHA256_DATA_SIZE]; /* SHA256 data buffer */
60 unsigned int index; /* index into buffer */
63 void
64 sha256_init(struct sha256_ctx *ctx);
66 void
67 sha256_update(struct sha256_ctx *ctx,
68 unsigned length,
69 const uint8_t *data);
71 void
72 sha256_digest(struct sha256_ctx *ctx,
73 unsigned length,
74 uint8_t *digest);
76 /* Internal compression function. STATE points to 8 uint32_t words,
77 DATA points to 64 bytes of input data, possibly unaligned, and K
78 points to the table of constants. */
79 void
80 _nettle_sha256_compress(uint32_t *state, const uint8_t *data, const uint32_t *k);
83 /* SHA224, a truncated SHA256 with different initial state. */
85 #define SHA224_DIGEST_SIZE 28
86 #define SHA224_DATA_SIZE SHA256_DATA_SIZE
87 #define sha224_ctx sha256_ctx
89 void
90 sha224_init(struct sha256_ctx *ctx);
92 #define sha224_update nettle_sha256_update
94 void
95 sha224_digest(struct sha256_ctx *ctx,
96 unsigned length,
97 uint8_t *digest);
100 /* SHA512 */
102 #define SHA512_DIGEST_SIZE 64
103 #define SHA512_DATA_SIZE 128
105 /* Digest is kept internally as 8 64-bit words. */
106 #define _SHA512_DIGEST_LENGTH 8
108 struct sha512_ctx
110 uint64_t state[_SHA512_DIGEST_LENGTH]; /* State variables */
111 uint64_t count_low, count_high; /* 128-bit block count */
112 uint8_t block[SHA512_DATA_SIZE]; /* SHA512 data buffer */
113 unsigned int index; /* index into buffer */
116 void
117 sha512_init(struct sha512_ctx *ctx);
119 void
120 sha512_update(struct sha512_ctx *ctx,
121 unsigned length,
122 const uint8_t *data);
124 void
125 sha512_digest(struct sha512_ctx *ctx,
126 unsigned length,
127 uint8_t *digest);
129 /* Internal compression function. STATE points to 8 uint64_t words,
130 DATA points to 128 bytes of input data, possibly unaligned, and K
131 points to the table of constants. */
132 void
133 _nettle_sha512_compress(uint64_t *state, const uint8_t *data, const uint64_t *k);
136 /* SHA384, a truncated SHA512 with different initial state. */
138 #define SHA384_DIGEST_SIZE 48
139 #define SHA384_DATA_SIZE SHA512_DATA_SIZE
140 #define sha384_ctx sha512_ctx
142 void
143 sha384_init(struct sha512_ctx *ctx);
145 #define sha384_update nettle_sha512_update
147 void
148 sha384_digest(struct sha512_ctx *ctx,
149 unsigned length,
150 uint8_t *digest);
152 #ifdef __cplusplus
154 #endif
156 #endif /* NETTLE_SHA2_H_INCLUDED */