Dibbler - a portable DHCPv6  1.0.2RC1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sha.h
Go to the documentation of this file.
1 /* sha.h
2  *
3  * The sha1 and sha256 hash functions.
4  */
5 
6 /* nettle, low-level cryptographics library
7  *
8  * Copyright (C) 2001 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.
14  *
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.
19  *
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., 59 Temple Place - Suite 330, Boston,
23  * MA 02111-1307, USA.
24  */
25 
26 #ifndef NETTLE_SHA_H_INCLUDED
27 #define NETTLE_SHA_H_INCLUDED
28 
29 #include "nettle-types.h"
30 
31 /* Name mangling */
32 #define sha1_init nettle_sha1_init
33 #define sha1_update nettle_sha1_update
34 #define sha1_digest nettle_sha1_digest
35 #define sha256_init nettle_sha256_init
36 #define sha256_update nettle_sha256_update
37 #define sha256_digest nettle_sha256_digest
38 
39 /* SHA1 */
40 
41 #define SHA1_DIGEST_SIZE 20
42 #define SHA1_DATA_SIZE 64
43 
44 /* Digest is kept internally as 5 32-bit words. */
45 #define _SHA1_DIGEST_LENGTH 5
46 
47 struct sha1_ctx
48 {
49  uint32_t digest[_SHA1_DIGEST_LENGTH]; /* Message digest */
50  uint32_t count_low, count_high; /* 64-bit block count */
51  uint8_t block[SHA1_DATA_SIZE]; /* SHA1 data buffer */
52  unsigned int index; /* index into buffer */
53 };
54 
55 void
56 sha1_init(struct sha1_ctx *ctx);
57 
58 void
59 sha1_update(struct sha1_ctx *ctx,
60  unsigned length,
61  const uint8_t *data);
62 
63 void
64 sha1_digest(struct sha1_ctx *ctx,
65  unsigned length,
66  uint8_t *digest);
67 
68 /* Internal compression function. STATE points to 5 uint32_t words,
69  and DATA points to 16 uint32_t words which are destroyed. */
70 void
72 
73 /* SHA256 */
74 
75 #define SHA256_DIGEST_SIZE 32
76 #define SHA256_DATA_SIZE 64
77 
78 /* Digest is kept internally as 8 32-bit words. */
79 #define _SHA256_DIGEST_LENGTH 8
80 
81 struct sha256_ctx
82 {
83  uint32_t state[_SHA256_DIGEST_LENGTH]; /* State variables */
84  uint32_t count_low, count_high; /* 64-bit block count */
85  uint8_t block[SHA256_DATA_SIZE]; /* SHA256 data buffer */
86  unsigned int index; /* index into buffer */
87 };
88 
89 void
90 sha256_init(struct sha256_ctx *ctx);
91 
92 void
93 sha256_update(struct sha256_ctx *ctx,
94  unsigned length,
95  const uint8_t *data);
96 
97 void
98 sha256_digest(struct sha256_ctx *ctx,
99  unsigned length,
100  uint8_t *digest);
101 
102 
103 #endif /* NETTLE_SHA_H_INCLUDED */
104