chiark / gitweb /
Static buffers: Replace references to bufs[b]
[secnet] / sha512.h
CommitLineData
b4a26b17
IJ
1/* Declarations of functions and data types used for SHA512 and SHA384 sum
2 library functions.
3 Copyright (C) 2005, 2006, 2008, 2009, 2010 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# ifdef __cplusplus
26extern "C" {
27# endif
28
29/* Structure to save state of computation between the single steps. */
30struct sha512_ctx
31{
32 u64 state[8];
33
34 u64 total[2];
35 size_t buflen;
36 u64 buffer[32];
37};
38
39enum { SHA384_DIGEST_SIZE = 384 / 8 };
40enum { SHA512_DIGEST_SIZE = 512 / 8 };
41
42/* Initialize structure containing state of computation. */
43extern void sha512_init_ctx (struct sha512_ctx *ctx);
44extern void sha384_init_ctx (struct sha512_ctx *ctx);
45
46/* Starting with the result of former calls of this function (or the
47 initialization function update the context for the next LEN bytes
48 starting at BUFFER.
49 It is necessary that LEN is a multiple of 128!!! */
50extern void sha512_process_block (const void *buffer, size_t len,
51 struct sha512_ctx *ctx);
52
53/* Starting with the result of former calls of this function (or the
54 initialization function update the context for the next LEN bytes
55 starting at BUFFER.
56 It is NOT required that LEN is a multiple of 128. */
57extern void sha512_process_bytes (const void *buffer, size_t len,
58 struct sha512_ctx *ctx);
59
60/* Process the remaining bytes in the buffer and put result from CTX
61 in first 64 (48) bytes following RESBUF. The result is always in little
62 endian byte order, so that a byte-wise output yields to the wanted
63 ASCII representation of the message digest. */
64extern void *sha512_finish_ctx (struct sha512_ctx *ctx, void *resbuf);
65extern void *sha384_finish_ctx (struct sha512_ctx *ctx, void *resbuf);
66
67
68/* Put result from CTX in first 64 (48) bytes following RESBUF. The result is
69 always in little endian byte order, so that a byte-wise output yields
70 to the wanted ASCII representation of the message digest.
71
72 IMPORTANT: On some systems it is required that RESBUF is correctly
73 aligned for a 32 bits value. */
74extern void *sha512_read_ctx (const struct sha512_ctx *ctx, void *resbuf);
75extern void *sha384_read_ctx (const struct sha512_ctx *ctx, void *resbuf);
76
77
78/* Compute SHA512 (SHA384) message digest for bytes read from STREAM. The
79 resulting message digest number will be written into the 64 (48) bytes
80 beginning at RESBLOCK. */
81extern int sha512_stream (FILE *stream, void *resblock);
82extern int sha384_stream (FILE *stream, void *resblock);
83
84/* Compute SHA512 (SHA384) message digest for LEN bytes beginning at BUFFER. The
85 result is always in little endian byte order, so that a byte-wise
86 output yields to the wanted ASCII representation of the message
87 digest. */
88extern void *sha512_buffer (const char *buffer, size_t len, void *resblock);
89extern void *sha384_buffer (const char *buffer, size_t len, void *resblock);
90
91# ifdef __cplusplus
92}
93# endif
94
95#endif