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