seq no longer mishandles cases like "seq 0 0.000001 0.000003",
[coreutils/ericb.git] / lib / sha512.h
blob995511e91ebfe9e24e9404fdce0d41600358d317
1 /* Declarations of functions and data types used for SHA512 and SHA384 sum
2 library functions.
3 Copyright (C) 2005, 2006 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
8 later version.
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. */
19 #ifndef SHA512_H
20 # define SHA512_H 1
22 # include <stdio.h>
24 # include "u64.h"
26 /* Structure to save state of computation between the single steps. */
27 struct sha512_ctx
29 u64 state[8];
31 u64 total[2];
32 size_t buflen;
33 u64 buffer[32];
37 /* Initialize structure containing state of computation. */
38 extern void sha512_init_ctx (struct sha512_ctx *ctx);
39 extern void sha384_init_ctx (struct sha512_ctx *ctx);
41 /* Starting with the result of former calls of this function (or the
42 initialization function update the context for the next LEN bytes
43 starting at BUFFER.
44 It is necessary that LEN is a multiple of 128!!! */
45 extern void sha512_process_block (const void *buffer, size_t len,
46 struct sha512_ctx *ctx);
48 /* Starting with the result of former calls of this function (or the
49 initialization function update the context for the next LEN bytes
50 starting at BUFFER.
51 It is NOT required that LEN is a multiple of 128. */
52 extern void sha512_process_bytes (const void *buffer, size_t len,
53 struct sha512_ctx *ctx);
55 /* Process the remaining bytes in the buffer and put result from CTX
56 in first 64 (48) bytes following RESBUF. The result is always in little
57 endian byte order, so that a byte-wise output yields to the wanted
58 ASCII representation of the message digest.
60 IMPORTANT: On some systems it is required that RESBUF be correctly
61 aligned for a 64 bits value. */
62 extern void *sha512_finish_ctx (struct sha512_ctx *ctx, void *resbuf);
63 extern void *sha384_finish_ctx (struct sha512_ctx *ctx, void *resbuf);
66 /* Put result from CTX in first 64 (48) bytes following RESBUF. The result is
67 always in little endian byte order, so that a byte-wise output yields
68 to the wanted ASCII representation of the message digest.
70 IMPORTANT: On some systems it is required that RESBUF is correctly
71 aligned for a 32 bits value. */
72 extern void *sha512_read_ctx (const struct sha512_ctx *ctx, void *resbuf);
73 extern void *sha384_read_ctx (const struct sha512_ctx *ctx, void *resbuf);
76 /* Compute SHA512 (SHA384) message digest for bytes read from STREAM. The
77 resulting message digest number will be written into the 64 (48) bytes
78 beginning at RESBLOCK. */
79 extern int sha512_stream (FILE *stream, void *resblock);
80 extern int sha384_stream (FILE *stream, void *resblock);
82 /* Compute SHA512 (SHA384) message digest for LEN bytes beginning at BUFFER. The
83 result is always in little endian byte order, so that a byte-wise
84 output yields to the wanted ASCII representation of the message
85 digest. */
86 extern void *sha512_buffer (const char *buffer, size_t len, void *resblock);
87 extern void *sha384_buffer (const char *buffer, size_t len, void *resblock);
89 #endif