blob: 05301c809fd2720fd9439c0b74c50059de3ac389 [file] [log] [blame]
Ben Cheng25b3c042013-11-20 14:45:36 -08001/* Declaration of functions and data types used for SHA1 sum computing
2 library functions.
3 Copyright (C) 2008 Red Hat, Inc.
Elliott Hughes03333822015-02-18 22:19:45 -08004 This file is part of elfutils.
Ben Cheng25b3c042013-11-20 14:45:36 -08005 Written by Ulrich Drepper <drepper@redhat.com>, 2008.
6
Elliott Hughes03333822015-02-18 22:19:45 -08007 This file is free software; you can redistribute it and/or modify
8 it under the terms of either
Ben Cheng25b3c042013-11-20 14:45:36 -08009
Elliott Hughes03333822015-02-18 22:19:45 -080010 * 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
13
14 or
15
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
19
20 or both in parallel, as here.
21
22 elfutils is distributed in the hope that it will be useful, but
Ben Cheng25b3c042013-11-20 14:45:36 -080023 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.
26
Elliott Hughes03333822015-02-18 22:19:45 -080027 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/>. */
Ben Cheng25b3c042013-11-20 14:45:36 -080030
31#ifndef _SHA1_H
32#define _SHA1_H 1
33
34#include <limits.h>
35#include <stdint.h>
36#include <stdio.h>
37
38#define SHA1_DIGEST_SIZE 20
39#define SHA1_BLOCK_SIZE 64
40
41typedef uint32_t sha1_uint32;
42typedef uintptr_t sha1_uintptr;
43
44/* Structure to save state of computation between the single steps. */
45struct sha1_ctx
46{
47 sha1_uint32 A;
48 sha1_uint32 B;
49 sha1_uint32 C;
50 sha1_uint32 D;
51 sha1_uint32 E;
52
53 sha1_uint32 total[2];
54 sha1_uint32 buflen;
55 char buffer[128] __attribute__ ((__aligned__ (__alignof__ (sha1_uint32))));
56};
57
58/* Initialize structure containing state of computation. */
59extern void sha1_init_ctx (struct sha1_ctx *ctx);
60
61/* Starting with the result of former calls of this function (or the
62 initialization function update the context for the next LEN bytes
63 starting at BUFFER.
64 It is necessary that LEN is a multiple of 64!!! */
65extern void sha1_process_block (const void *buffer, size_t len,
66 struct sha1_ctx *ctx);
67
68/* Starting with the result of former calls of this function (or the
69 initialization function update the context for the next LEN bytes
70 starting at BUFFER.
71 It is NOT required that LEN is a multiple of 64. */
72extern void sha1_process_bytes (const void *buffer, size_t len,
73 struct sha1_ctx *ctx);
74
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.
79
80 IMPORTANT: On some systems it is required that RESBUF is correctly
81 aligned for a 32 bits value. */
82extern void *sha1_finish_ctx (struct sha1_ctx *ctx, void *resbuf);
83
84
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.
88
89 IMPORTANT: On some systems it is required that RESBUF is correctly
90 aligned for a 32 bits value. */
91extern void *sha1_read_ctx (const struct sha1_ctx *ctx, void *resbuf);
92
93#endif /* sha1.h */