maint.mk: import changes to syntax-check macros from coreutils
[gnulib.git] / lib / sha512.h
1 /* Declarations of functions and data types used for SHA512 and SHA384 sum
2    library functions.
3    Copyright (C) 2005, 2006, 2008 Free Software Foundation, Inc.
4
5    This program is free software: you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation, either version 3 of the License, or
8    (at your option) any later version.
9
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.
14
15    You should have received a copy of the GNU General Public License
16    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
17
18 #ifndef SHA512_H
19 # define SHA512_H 1
20
21 # include <stdio.h>
22
23 # include "u64.h"
24
25 /* Structure to save state of computation between the single steps.  */
26 struct sha512_ctx
27 {
28   u64 state[8];
29
30   u64 total[2];
31   size_t buflen;
32   u64 buffer[32];
33 };
34
35 enum { SHA384_DIGEST_SIZE = 384 / 8 };
36 enum { SHA512_DIGEST_SIZE = 512 / 8 };
37
38 /* Initialize structure containing state of computation. */
39 extern void sha512_init_ctx (struct sha512_ctx *ctx);
40 extern void sha384_init_ctx (struct sha512_ctx *ctx);
41
42 /* Starting with the result of former calls of this function (or the
43    initialization function update the context for the next LEN bytes
44    starting at BUFFER.
45    It is necessary that LEN is a multiple of 128!!! */
46 extern void sha512_process_block (const void *buffer, size_t len,
47                                   struct sha512_ctx *ctx);
48
49 /* Starting with the result of former calls of this function (or the
50    initialization function update the context for the next LEN bytes
51    starting at BUFFER.
52    It is NOT required that LEN is a multiple of 128.  */
53 extern void sha512_process_bytes (const void *buffer, size_t len,
54                                   struct sha512_ctx *ctx);
55
56 /* Process the remaining bytes in the buffer and put result from CTX
57    in first 64 (48) bytes following RESBUF.  The result is always in little
58    endian byte order, so that a byte-wise output yields to the wanted
59    ASCII representation of the message digest.  */
60 extern void *sha512_finish_ctx (struct sha512_ctx *ctx, void *resbuf);
61 extern void *sha384_finish_ctx (struct sha512_ctx *ctx, void *resbuf);
62
63
64 /* Put result from CTX in first 64 (48) bytes following RESBUF.  The result is
65    always in little endian byte order, so that a byte-wise output yields
66    to the wanted ASCII representation of the message digest.
67
68    IMPORTANT: On some systems it is required that RESBUF is correctly
69    aligned for a 32 bits value.  */
70 extern void *sha512_read_ctx (const struct sha512_ctx *ctx, void *resbuf);
71 extern void *sha384_read_ctx (const struct sha512_ctx *ctx, void *resbuf);
72
73
74 /* Compute SHA512 (SHA384) message digest for bytes read from STREAM.  The
75    resulting message digest number will be written into the 64 (48) bytes
76    beginning at RESBLOCK.  */
77 extern int sha512_stream (FILE *stream, void *resblock);
78 extern int sha384_stream (FILE *stream, void *resblock);
79
80 /* Compute SHA512 (SHA384) message digest for LEN bytes beginning at BUFFER.  The
81    result is always in little endian byte order, so that a byte-wise
82    output yields to the wanted ASCII representation of the message
83    digest.  */
84 extern void *sha512_buffer (const char *buffer, size_t len, void *resblock);
85 extern void *sha384_buffer (const char *buffer, size_t len, void *resblock);
86
87 #endif