1 /* Declarations of functions and data types used for SHA1 sum library
3 * part of Cumulus: Smart Filesystem Backup to Dumb Servers
5 * Copyright (C) 2000, 2001, 2003, 2005 Free Software Foundation, Inc.
6 * Copyright (C) 2006-2007 The Regents of the University of California
8 * Original code (in C) is taken from GNU coreutils (Debian package 5.97-5).
9 * Modifications by Michael Vrable <mvrable@cs.ucsd.edu> to integrate into
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
35 typedef uint32_t md5_uint32;
37 /* Structure to save state of computation between the single steps. */
48 char buffer[128] __attribute__ ((__aligned__ (__alignof__ (md5_uint32))));
52 /* Initialize structure containing state of computation. */
53 extern void sha1_init_ctx (struct sha1_ctx *ctx);
55 /* Starting with the result of former calls of this function (or the
56 initialization function update the context for the next LEN bytes
58 It is necessary that LEN is a multiple of 64!!! */
59 extern void sha1_process_block (const void *buffer, size_t len,
60 struct sha1_ctx *ctx);
62 /* Starting with the result of former calls of this function (or the
63 initialization function update the context for the next LEN bytes
65 It is NOT required that LEN is a multiple of 64. */
66 extern void sha1_process_bytes (const void *buffer, size_t len,
67 struct sha1_ctx *ctx);
69 /* Process the remaining bytes in the buffer and put result from CTX
70 in first 20 bytes following RESBUF. The result is always in little
71 endian byte order, so that a byte-wise output yields to the wanted
72 ASCII representation of the message digest.
74 IMPORTANT: On some systems it is required that RESBUF be correctly
75 aligned for a 32 bits value. */
76 extern void *sha1_finish_ctx (struct sha1_ctx *ctx, void *resbuf);
79 /* Put result from CTX in first 20 bytes following RESBUF. The result is
80 always in little endian byte order, so that a byte-wise output yields
81 to the wanted ASCII representation of the message digest.
83 IMPORTANT: On some systems it is required that RESBUF is correctly
84 aligned for a 32 bits value. */
85 extern void *sha1_read_ctx (const struct sha1_ctx *ctx, void *resbuf);
87 /* An object-oriented wrapper around checksumming functionality. */
91 char resbuf[20] __attribute__ ((__aligned__ (__alignof__ (md5_uint32))));
97 void process(const void *data, size_t len);
98 bool process_file(const char *filename);
99 const uint8_t *checksum();
100 size_t checksum_size() const { return 20; }
101 std::string checksum_str();