1 /* Declaration of functions and data types used for SHA1 sum computing
3 Copyright (C) 2008 Red Hat, Inc.
4 This file is part of elfutils.
5 Written by Ulrich Drepper <drepper@redhat.com>, 2008.
7 This file is free software; you can redistribute it and/or modify
8 it under the terms of either
10 * the GNU Lesser General Public License as published by the Free
11 Software Foundation; either version 3 of the License, or (at
12 your option) any later version
16 * the GNU General Public License as published by the Free
17 Software Foundation; either version 2 of the License, or (at
18 your option) any later version
20 or both in parallel, as here.
22 elfutils is distributed in the hope that it will be useful, but
23 WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 General Public License for more details.
27 You should have received copies of the GNU General Public License and
28 the GNU Lesser General Public License along with this program. If
29 not, see <http://www.gnu.org/licenses/>. */
38 #define SHA1_DIGEST_SIZE 20
39 #define SHA1_BLOCK_SIZE 64
41 typedef uint32_t sha1_uint32;
42 typedef uintptr_t sha1_uintptr;
44 /* Structure to save state of computation between the single steps. */
55 char buffer[128] __attribute__ ((__aligned__ (__alignof__ (sha1_uint32))));
58 /* Initialize structure containing state of computation. */
59 extern void sha1_init_ctx (struct sha1_ctx *ctx);
61 /* Starting with the result of former calls of this function (or the
62 initialization function update the context for the next LEN bytes
64 It is necessary that LEN is a multiple of 64!!! */
65 extern void sha1_process_block (const void *buffer, size_t len,
66 struct sha1_ctx *ctx);
68 /* Starting with the result of former calls of this function (or the
69 initialization function update the context for the next LEN bytes
71 It is NOT required that LEN is a multiple of 64. */
72 extern void sha1_process_bytes (const void *buffer, size_t len,
73 struct sha1_ctx *ctx);
75 /* Process the remaining bytes in the buffer and put result from CTX
76 in first 20 bytes following RESBUF. The result is always in little
77 endian byte order, so that a byte-wise output yields to the wanted
78 ASCII representation of the message digest.
80 IMPORTANT: On some systems it is required that RESBUF is correctly
81 aligned for a 32 bits value. */
82 extern void *sha1_finish_ctx (struct sha1_ctx *ctx, void *resbuf);
85 /* Put result from CTX in first 20 bytes following RESBUF. The result is
86 always in little endian byte order, so that a byte-wise output yields
87 to the wanted ASCII representation of the message digest.
89 IMPORTANT: On some systems it is required that RESBUF is correctly
90 aligned for a 32 bits value. */
91 extern void *sha1_read_ctx (const struct sha1_ctx *ctx, void *resbuf);