nettle  3.7.3
About: Nettle is a low-level cryptographic library.
  Fossies Dox: nettle-3.7.3.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

sha2.h
Go to the documentation of this file.
1 /* sha2.h
2 
3  The sha2 family of hash functions.
4 
5  Copyright (C) 2001, 2012 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 #ifndef NETTLE_SHA2_H_INCLUDED
35 #define NETTLE_SHA2_H_INCLUDED
36 
37 #include "nettle-types.h"
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 /* Name mangling */
44 #define sha224_init nettle_sha224_init
45 #define sha224_digest nettle_sha224_digest
46 #define sha256_init nettle_sha256_init
47 #define sha256_update nettle_sha256_update
48 #define sha256_digest nettle_sha256_digest
49 #define sha384_init nettle_sha384_init
50 #define sha384_digest nettle_sha384_digest
51 #define sha512_init nettle_sha512_init
52 #define sha512_update nettle_sha512_update
53 #define sha512_digest nettle_sha512_digest
54 #define sha512_224_init nettle_sha512_224_init
55 #define sha512_224_digest nettle_sha512_224_digest
56 #define sha512_256_init nettle_sha512_256_init
57 #define sha512_256_digest nettle_sha512_256_digest
58 
59 /* For backwards compatibility */
60 #define SHA224_DATA_SIZE SHA256_BLOCK_SIZE
61 #define SHA256_DATA_SIZE SHA256_BLOCK_SIZE
62 #define SHA512_DATA_SIZE SHA512_BLOCK_SIZE
63 #define SHA384_DATA_SIZE SHA512_BLOCK_SIZE
64 
65 /* SHA256 */
66 
67 #define SHA256_DIGEST_SIZE 32
68 #define SHA256_BLOCK_SIZE 64
69 
70 /* Digest is kept internally as 8 32-bit words. */
71 #define _SHA256_DIGEST_LENGTH 8
72 
73 struct sha256_ctx
74 {
75  uint32_t state[_SHA256_DIGEST_LENGTH]; /* State variables */
76  uint64_t count; /* 64-bit block count */
77  unsigned int index; /* index into buffer */
78  uint8_t block[SHA256_BLOCK_SIZE]; /* SHA256 data buffer */
79 };
80 
81 void
82 sha256_init(struct sha256_ctx *ctx);
83 
84 void
85 sha256_update(struct sha256_ctx *ctx,
86  size_t length,
87  const uint8_t *data);
88 
89 void
90 sha256_digest(struct sha256_ctx *ctx,
91  size_t length,
92  uint8_t *digest);
93 
94 
95 /* SHA224, a truncated SHA256 with different initial state. */
96 
97 #define SHA224_DIGEST_SIZE 28
98 #define SHA224_BLOCK_SIZE SHA256_BLOCK_SIZE
99 #define sha224_ctx sha256_ctx
100 
101 void
102 sha224_init(struct sha256_ctx *ctx);
103 
104 #define sha224_update nettle_sha256_update
105 
106 void
107 sha224_digest(struct sha256_ctx *ctx,
108  size_t length,
109  uint8_t *digest);
110 
111 
112 /* SHA512 */
113 
114 #define SHA512_DIGEST_SIZE 64
115 #define SHA512_BLOCK_SIZE 128
116 
117 /* Digest is kept internally as 8 64-bit words. */
118 #define _SHA512_DIGEST_LENGTH 8
119 
121 {
122  uint64_t state[_SHA512_DIGEST_LENGTH]; /* State variables */
123  uint64_t count_low, count_high; /* 128-bit block count */
124  unsigned int index; /* index into buffer */
125  uint8_t block[SHA512_BLOCK_SIZE]; /* SHA512 data buffer */
126 };
127 
128 void
129 sha512_init(struct sha512_ctx *ctx);
130 
131 void
132 sha512_update(struct sha512_ctx *ctx,
133  size_t length,
134  const uint8_t *data);
135 
136 void
137 sha512_digest(struct sha512_ctx *ctx,
138  size_t length,
139  uint8_t *digest);
140 
141 
142 /* SHA384, a truncated SHA512 with different initial state. */
143 
144 #define SHA384_DIGEST_SIZE 48
145 #define SHA384_BLOCK_SIZE SHA512_BLOCK_SIZE
146 #define sha384_ctx sha512_ctx
147 
148 void
149 sha384_init(struct sha512_ctx *ctx);
150 
151 #define sha384_update nettle_sha512_update
152 
153 void
154 sha384_digest(struct sha512_ctx *ctx,
155  size_t length,
156  uint8_t *digest);
157 
158 
159 /* SHA512_224 and SHA512_256, two truncated versions of SHA512
160  with different initial states. */
161 
162 #define SHA512_224_DIGEST_SIZE 28
163 #define SHA512_224_BLOCK_SIZE SHA512_BLOCK_SIZE
164 #define sha512_224_ctx sha512_ctx
165 
166 void
167 sha512_224_init(struct sha512_224_ctx *ctx);
168 
169 #define sha512_224_update nettle_sha512_update
170 
171 void
173  size_t length,
174  uint8_t *digest);
175 
176 #define SHA512_256_DIGEST_SIZE 32
177 #define SHA512_256_BLOCK_SIZE SHA512_BLOCK_SIZE
178 #define sha512_256_ctx sha512_ctx
179 
180 void
181 sha512_256_init(struct sha512_256_ctx *ctx);
182 
183 #define sha512_256_update nettle_sha512_update
184 
185 void
187  size_t length,
188  uint8_t *digest);
189 
190 #ifdef __cplusplus
191 }
192 #endif
193 
194 #endif /* NETTLE_SHA2_H_INCLUDED */
#define sha512_224_ctx
Definition: sha2.h:164
#define sha512_update
Definition: sha2.h:52
#define sha512_init
Definition: sha2.h:51
#define sha256_update
Definition: sha2.h:47
#define sha512_224_init
Definition: sha2.h:54
#define _SHA512_DIGEST_LENGTH
Definition: sha2.h:118
#define sha256_digest
Definition: sha2.h:48
#define sha256_init
Definition: sha2.h:46
#define sha384_init
Definition: sha2.h:49
#define sha512_digest
Definition: sha2.h:53
#define _SHA256_DIGEST_LENGTH
Definition: sha2.h:71
#define sha512_256_init
Definition: sha2.h:56
#define sha512_256_digest
Definition: sha2.h:57
#define sha224_digest
Definition: sha2.h:45
#define sha384_digest
Definition: sha2.h:50
#define sha512_224_digest
Definition: sha2.h:55
#define SHA256_BLOCK_SIZE
Definition: sha2.h:68
#define sha224_init
Definition: sha2.h:44
#define SHA512_BLOCK_SIZE
Definition: sha2.h:115
#define sha512_256_ctx
Definition: sha2.h:178
unsigned int index
Definition: sha2.h:77
uint64_t count
Definition: sha2.h:76
uint8_t block[64]
Definition: sha2.h:78
uint32_t state[8]
Definition: sha2.h:75
uint64_t state[8]
Definition: sha2.h:122
unsigned int index
Definition: sha2.h:124
uint64_t count_high
Definition: sha2.h:123
uint8_t block[128]
Definition: sha2.h:125
uint64_t count_low
Definition: sha2.h:123