1 /* Declarations of functions and data types used for SHA512 and SHA384 sum
3 Copyright (C) 2005 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the
7 Free Software Foundation; either version 2, or (at your option) any
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software Foundation,
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
24 /* The following contortions are an attempt to use the C preprocessor
25 to determine an unsigned integral type that is 64 bits wide. An
26 alternative approach is to use autoconf's AC_CHECK_SIZEOF macro, but
27 doing that would require that the configure script compile and *run*
28 the resulting executable. Locally running cross-compiled executables
29 is usually not possible. */
32 # include <inttypes.h>
34 # if HAVE_STDINT_H || _LIBC
38 typedef uint64_t sha512_uint64;
41 /* Structure to save state of computation between the single steps. */
44 sha512_uint64 state[8];
46 sha512_uint64 total[2];
52 /* Initialize structure containing state of computation. */
53 extern void sha512_init_ctx (struct sha512_ctx *ctx);
54 extern void sha384_init_ctx (struct sha512_ctx *ctx);
56 /* Starting with the result of former calls of this function (or the
57 initialization function update the context for the next LEN bytes
59 It is necessary that LEN is a multiple of 128!!! */
60 extern void sha512_process_block (const void *buffer, size_t len,
61 struct sha512_ctx *ctx);
63 /* Starting with the result of former calls of this function (or the
64 initialization function update the context for the next LEN bytes
66 It is NOT required that LEN is a multiple of 128. */
67 extern void sha512_process_bytes (const void *buffer, size_t len,
68 struct sha512_ctx *ctx);
70 /* Process the remaining bytes in the buffer and put result from CTX
71 in first 64 (48) bytes following RESBUF. The result is always in little
72 endian byte order, so that a byte-wise output yields to the wanted
73 ASCII representation of the message digest.
75 IMPORTANT: On some systems it is required that RESBUF be correctly
76 aligned for a 64 bits value. */
77 extern void *sha512_finish_ctx (struct sha512_ctx *ctx, void *resbuf);
78 extern void *sha384_finish_ctx (struct sha512_ctx *ctx, void *resbuf);
81 /* Put result from CTX in first 64 (48) bytes following RESBUF. The result is
82 always in little endian byte order, so that a byte-wise output yields
83 to the wanted ASCII representation of the message digest.
85 IMPORTANT: On some systems it is required that RESBUF is correctly
86 aligned for a 32 bits value. */
87 extern void *sha512_read_ctx (const struct sha512_ctx *ctx, void *resbuf);
88 extern void *sha384_read_ctx (const struct sha512_ctx *ctx, void *resbuf);
91 /* Compute SHA512 (SHA384) message digest for bytes read from STREAM. The
92 resulting message digest number will be written into the 64 (48) bytes
93 beginning at RESBLOCK. */
94 extern int sha512_stream (FILE *stream, void *resblock);
95 extern int sha384_stream (FILE *stream, void *resblock);
97 /* Compute SHA512 (SHA384) message digest for LEN bytes beginning at BUFFER. The
98 result is always in little endian byte order, so that a byte-wise
99 output yields to the wanted ASCII representation of the message
101 extern void *sha512_buffer (const char *buffer, size_t len, void *resblock);
102 extern void *sha384_buffer (const char *buffer, size_t len, void *resblock);
104 # define rol64(x,n) ( ((x) << (n)) | ((x) >> (64-(n))) )