Rev 5191 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5191 | Rev 6324 | ||
---|---|---|---|
1 | /* Declarations of functions and data types used for SHA1 sum |
1 | /* Declarations of functions and data types used for SHA1 sum |
2 | library functions. |
2 | library functions. |
3 | Copyright (C) 2000, 2001, 2003, 2005, 2006, 2008, 2010 |
- | |
4 | Free Software Foundation, Inc. |
3 | Copyright (C) 2000-2015 Free Software Foundation, Inc. |
5 | 4 | ||
6 | This program is free software; you can redistribute it and/or modify it |
5 | This program is free software; you can redistribute it and/or modify it |
7 | under the terms of the GNU General Public License as published by the |
6 | under the terms of the GNU General Public License as published by the |
8 | Free Software Foundation; either version 3, or (at your option) any |
7 | Free Software Foundation; either version 3, or (at your option) any |
9 | later version. |
8 | later version. |
10 | 9 | ||
11 | This program is distributed in the hope that it will be useful, |
10 | This program is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | GNU General Public License for more details. |
13 | GNU General Public License for more details. |
15 | 14 | ||
16 | You should have received a copy of the GNU General Public License |
15 | You should have received a copy of the GNU General Public License |
17 | along with this program; if not, write to the Free Software Foundation, |
16 | along with this program; if not, write to the Free Software Foundation, |
18 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ |
17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ |
19 | 18 | ||
20 | #ifndef SHA1_H |
19 | #ifndef SHA1_H |
21 | # define SHA1_H 1 |
20 | # define SHA1_H 1 |
22 | 21 | ||
23 | #include |
22 | #include |
24 | 23 | ||
25 | #if defined HAVE_LIMITS_H || _LIBC |
24 | #if defined HAVE_LIMITS_H || _LIBC |
26 | # include |
25 | # include |
27 | #endif |
26 | #endif |
28 | 27 | ||
29 | #include "ansidecl.h" |
28 | #include "ansidecl.h" |
30 | 29 | ||
31 | /* The following contortions are an attempt to use the C preprocessor |
30 | /* The following contortions are an attempt to use the C preprocessor |
32 | to determine an unsigned integral type that is 32 bits wide. An |
31 | to determine an unsigned integral type that is 32 bits wide. An |
33 | alternative approach is to use autoconf's AC_CHECK_SIZEOF macro, but |
32 | alternative approach is to use autoconf's AC_CHECK_SIZEOF macro, but |
34 | doing that would require that the configure script compile and *run* |
33 | doing that would require that the configure script compile and *run* |
35 | the resulting executable. Locally running cross-compiled executables |
34 | the resulting executable. Locally running cross-compiled executables |
36 | is usually not possible. */ |
35 | is usually not possible. */ |
37 | 36 | ||
38 | #ifdef _LIBC |
37 | #ifdef _LIBC |
39 | # include |
38 | # include |
40 | typedef u_int32_t sha1_uint32; |
39 | typedef u_int32_t sha1_uint32; |
41 | typedef uintptr_t sha1_uintptr; |
40 | typedef uintptr_t sha1_uintptr; |
42 | #elif defined (HAVE_SYS_TYPES_H) && defined (HAVE_STDINT_H) |
41 | #elif defined (HAVE_SYS_TYPES_H) && defined (HAVE_STDINT_H) |
43 | #include |
42 | #include |
44 | #include |
43 | #include |
45 | typedef uint32_t sha1_uint32; |
44 | typedef uint32_t sha1_uint32; |
46 | typedef uintptr_t sha1_uintptr; |
45 | typedef uintptr_t sha1_uintptr; |
47 | #else |
46 | #else |
48 | # define INT_MAX_32_BITS 2147483647 |
47 | # define INT_MAX_32_BITS 2147483647 |
49 | 48 | ||
50 | /* If UINT_MAX isn't defined, assume it's a 32-bit type. |
49 | /* If UINT_MAX isn't defined, assume it's a 32-bit type. |
51 | This should be valid for all systems GNU cares about because |
50 | This should be valid for all systems GNU cares about because |
52 | that doesn't include 16-bit systems, and only modern systems |
51 | that doesn't include 16-bit systems, and only modern systems |
53 | (that certainly have |
52 | (that certainly have |
54 | 53 | ||
55 | # ifndef INT_MAX |
54 | # ifndef INT_MAX |
56 | # define INT_MAX INT_MAX_32_BITS |
55 | # define INT_MAX INT_MAX_32_BITS |
57 | # endif |
56 | # endif |
58 | 57 | ||
59 | # if INT_MAX == INT_MAX_32_BITS |
58 | # if INT_MAX == INT_MAX_32_BITS |
60 | typedef unsigned int sha1_uint32; |
59 | typedef unsigned int sha1_uint32; |
61 | # else |
60 | # else |
62 | # if SHRT_MAX == INT_MAX_32_BITS |
61 | # if SHRT_MAX == INT_MAX_32_BITS |
63 | typedef unsigned short sha1_uint32; |
62 | typedef unsigned short sha1_uint32; |
64 | # else |
63 | # else |
65 | # if LONG_MAX == INT_MAX_32_BITS |
64 | # if LONG_MAX == INT_MAX_32_BITS |
66 | typedef unsigned long sha1_uint32; |
65 | typedef unsigned long sha1_uint32; |
67 | # else |
66 | # else |
68 | /* The following line is intended to evoke an error. |
67 | /* The following line is intended to evoke an error. |
69 | Using #error is not portable enough. */ |
68 | Using #error is not portable enough. */ |
70 | "Cannot determine unsigned 32-bit data type." |
69 | "Cannot determine unsigned 32-bit data type." |
71 | # endif |
70 | # endif |
72 | # endif |
71 | # endif |
73 | # endif |
72 | # endif |
74 | #endif |
73 | #endif |
75 | 74 | ||
76 | #ifdef __cplusplus |
75 | #ifdef __cplusplus |
77 | extern "C" { |
76 | extern "C" { |
78 | #endif |
77 | #endif |
79 | 78 | ||
80 | /* Structure to save state of computation between the single steps. */ |
79 | /* Structure to save state of computation between the single steps. */ |
81 | struct sha1_ctx |
80 | struct sha1_ctx |
82 | { |
81 | { |
83 | sha1_uint32 A; |
82 | sha1_uint32 A; |
84 | sha1_uint32 B; |
83 | sha1_uint32 B; |
85 | sha1_uint32 C; |
84 | sha1_uint32 C; |
86 | sha1_uint32 D; |
85 | sha1_uint32 D; |
87 | sha1_uint32 E; |
86 | sha1_uint32 E; |
88 | 87 | ||
89 | sha1_uint32 total[2]; |
88 | sha1_uint32 total[2]; |
90 | sha1_uint32 buflen; |
89 | sha1_uint32 buflen; |
91 | sha1_uint32 buffer[32]; |
90 | sha1_uint32 buffer[32]; |
92 | }; |
91 | }; |
93 | 92 | ||
94 | 93 | ||
95 | /* Initialize structure containing state of computation. */ |
94 | /* Initialize structure containing state of computation. */ |
96 | extern void sha1_init_ctx (struct sha1_ctx *ctx); |
95 | extern void sha1_init_ctx (struct sha1_ctx *ctx); |
97 | 96 | ||
98 | /* Starting with the result of former calls of this function (or the |
97 | /* Starting with the result of former calls of this function (or the |
99 | initialization function update the context for the next LEN bytes |
98 | initialization function update the context for the next LEN bytes |
100 | starting at BUFFER. |
99 | starting at BUFFER. |
101 | It is necessary that LEN is a multiple of 64!!! */ |
100 | It is necessary that LEN is a multiple of 64!!! */ |
102 | extern void sha1_process_block (const void *buffer, size_t len, |
101 | extern void sha1_process_block (const void *buffer, size_t len, |
103 | struct sha1_ctx *ctx); |
102 | struct sha1_ctx *ctx); |
104 | 103 | ||
105 | /* Starting with the result of former calls of this function (or the |
104 | /* Starting with the result of former calls of this function (or the |
106 | initialization function update the context for the next LEN bytes |
105 | initialization function update the context for the next LEN bytes |
107 | starting at BUFFER. |
106 | starting at BUFFER. |
108 | It is NOT required that LEN is a multiple of 64. */ |
107 | It is NOT required that LEN is a multiple of 64. */ |
109 | extern void sha1_process_bytes (const void *buffer, size_t len, |
108 | extern void sha1_process_bytes (const void *buffer, size_t len, |
110 | struct sha1_ctx *ctx); |
109 | struct sha1_ctx *ctx); |
111 | 110 | ||
112 | /* Process the remaining bytes in the buffer and put result from CTX |
111 | /* Process the remaining bytes in the buffer and put result from CTX |
113 | in first 20 bytes following RESBUF. The result is always in little |
112 | in first 20 bytes following RESBUF. The result is always in little |
114 | endian byte order, so that a byte-wise output yields to the wanted |
113 | endian byte order, so that a byte-wise output yields to the wanted |
115 | ASCII representation of the message digest. |
114 | ASCII representation of the message digest. |
116 | 115 | ||
117 | IMPORTANT: On some systems it is required that RESBUF be correctly |
116 | IMPORTANT: On some systems it is required that RESBUF be correctly |
118 | aligned for a 32 bits value. */ |
117 | aligned for a 32 bits value. */ |
119 | extern void *sha1_finish_ctx (struct sha1_ctx *ctx, void *resbuf); |
118 | extern void *sha1_finish_ctx (struct sha1_ctx *ctx, void *resbuf); |
120 | 119 | ||
121 | 120 | ||
122 | /* Put result from CTX in first 20 bytes following RESBUF. The result is |
121 | /* Put result from CTX in first 20 bytes following RESBUF. The result is |
123 | always in little endian byte order, so that a byte-wise output yields |
122 | always in little endian byte order, so that a byte-wise output yields |
124 | to the wanted ASCII representation of the message digest. |
123 | to the wanted ASCII representation of the message digest. |
125 | 124 | ||
126 | IMPORTANT: On some systems it is required that RESBUF is correctly |
125 | IMPORTANT: On some systems it is required that RESBUF is correctly |
127 | aligned for a 32 bits value. */ |
126 | aligned for a 32 bits value. */ |
128 | extern void *sha1_read_ctx (const struct sha1_ctx *ctx, void *resbuf); |
127 | extern void *sha1_read_ctx (const struct sha1_ctx *ctx, void *resbuf); |
129 | 128 | ||
130 | 129 | ||
131 | /* Compute SHA1 message digest for bytes read from STREAM. The |
130 | /* Compute SHA1 message digest for bytes read from STREAM. The |
132 | resulting message digest number will be written into the 20 bytes |
131 | resulting message digest number will be written into the 20 bytes |
133 | beginning at RESBLOCK. */ |
132 | beginning at RESBLOCK. */ |
134 | extern int sha1_stream (FILE *stream, void *resblock); |
133 | extern int sha1_stream (FILE *stream, void *resblock); |
135 | 134 | ||
136 | /* Compute SHA1 message digest for LEN bytes beginning at BUFFER. The |
135 | /* Compute SHA1 message digest for LEN bytes beginning at BUFFER. The |
137 | result is always in little endian byte order, so that a byte-wise |
136 | result is always in little endian byte order, so that a byte-wise |
138 | output yields to the wanted ASCII representation of the message |
137 | output yields to the wanted ASCII representation of the message |
139 | digest. */ |
138 | digest. */ |
140 | extern void *sha1_buffer (const char *buffer, size_t len, void *resblock); |
139 | extern void *sha1_buffer (const char *buffer, size_t len, void *resblock); |
141 | 140 | ||
142 | #ifdef __cplusplus |
141 | #ifdef __cplusplus |
143 | } |
142 | } |
144 | #endif |
143 | #endif |
145 | 144 | ||
146 | #endif |
145 | #endif |