Rename FILESYSTEM_PREFIX_LEN.
[gnulib.git] / lib / sha.h
1 /* sha.h - Declaration of functions and datatypes for SHA1 sum computing
2    library functions.
3
4    Copyright (C) 1999, Scott G. Miller
5 */
6
7 #ifndef _SHA_H
8 # define _SHA_H 1
9
10 # include <stdio.h>
11 # include "md5.h"
12
13 /* Structure to save state of computation between the single steps.  */
14 struct sha_ctx
15 {
16   md5_uint32 A;
17   md5_uint32 B;
18   md5_uint32 C;
19   md5_uint32 D;
20   md5_uint32 E;
21
22   md5_uint32 total[2];
23   md5_uint32 buflen;
24   char buffer[128];
25 };
26
27
28 /* Starting with the result of former calls of this function (or the
29    initialization function update the context for the next LEN bytes
30    starting at BUFFER.
31    It is necessary that LEN is a multiple of 64!!! */
32 extern void sha_process_block (const void *buffer, size_t len,
33                                struct sha_ctx *ctx);
34
35 /* Starting with the result of former calls of this function (or the
36    initialization function update the context for the next LEN bytes
37    starting at BUFFER.
38    It is NOT required that LEN is a multiple of 64.  */
39 extern void sha_process_bytes (const void *buffer, size_t len,
40                                struct sha_ctx *ctx);
41
42 /* Initialize structure containing state of computation. */
43 extern void sha_init_ctx (struct sha_ctx *ctx);
44
45 /* Process the remaining bytes in the buffer and put result from CTX
46    in first 16 bytes following RESBUF.  The result is always in little
47    endian byte order, so that a byte-wise output yields to the wanted
48    ASCII representation of the message digest.
49
50    IMPORTANT: On some systems it is required that RESBUF is correctly
51    aligned for a 32 bits value.  */
52 extern void *sha_finish_ctx (struct sha_ctx *ctx, void *resbuf);
53
54
55 /* Put result from CTX in first 16 bytes following RESBUF.  The result is
56    always in little endian byte order, so that a byte-wise output yields
57    to the wanted ASCII representation of the message digest.
58
59    IMPORTANT: On some systems it is required that RESBUF is correctly
60    aligned for a 32 bits value.  */
61 extern void *sha_read_ctx (const struct sha_ctx *ctx, void *resbuf);
62
63
64 /* Compute MD5 message digest for bytes read from STREAM.  The
65    resulting message digest number will be written into the 16 bytes
66    beginning at RESBLOCK.  */
67 extern int sha_stream (FILE *stream, void *resblock);
68
69 /* Compute MD5 message digest for LEN bytes beginning at BUFFER.  The
70    result is always in little endian byte order, so that a byte-wise
71    output yields to the wanted ASCII representation of the message
72    digest.  */
73 extern void *sha_buffer (const char *buffer, size_t len, void *resblock);
74
75 #endif