1/* Declaration of functions and data types used for SHA1 sum computing
2   library functions.
3   Copyright (C) 2008 Red Hat, Inc.
4   This file is part of Red Hat elfutils.
5   Written by Ulrich Drepper <drepper@redhat.com>, 2008.
6
7   Red Hat elfutils is free software; you can redistribute it and/or modify
8   it under the terms of the GNU General Public License as published by the
9   Free Software Foundation; version 2 of the License.
10
11   Red Hat elfutils is distributed in the hope that it will be useful, but
12   WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   General Public License for more details.
15
16   You should have received a copy of the GNU General Public License along
17   with Red Hat elfutils; if not, write to the Free Software Foundation,
18   Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
19
20   Red Hat elfutils is an included package of the Open Invention Network.
21   An included package of the Open Invention Network is a package for which
22   Open Invention Network licensees cross-license their patents.  No patent
23   license is granted, either expressly or impliedly, by designation as an
24   included package.  Should you wish to participate in the Open Invention
25   Network licensing program, please visit www.openinventionnetwork.com
26   <http://www.openinventionnetwork.com>.  */
27
28#ifndef _SHA1_H
29#define _SHA1_H 1
30
31#include <limits.h>
32#include <stdint.h>
33#include <stdio.h>
34
35#define SHA1_DIGEST_SIZE 20
36#define SHA1_BLOCK_SIZE 64
37
38typedef uint32_t sha1_uint32;
39typedef uintptr_t sha1_uintptr;
40
41/* Structure to save state of computation between the single steps.  */
42struct sha1_ctx
43{
44  sha1_uint32 A;
45  sha1_uint32 B;
46  sha1_uint32 C;
47  sha1_uint32 D;
48  sha1_uint32 E;
49
50  sha1_uint32 total[2];
51  sha1_uint32 buflen;
52  char buffer[128] __attribute__ ((__aligned__ (__alignof__ (sha1_uint32))));
53};
54
55/* Initialize structure containing state of computation.  */
56extern void sha1_init_ctx (struct sha1_ctx *ctx);
57
58/* Starting with the result of former calls of this function (or the
59   initialization function update the context for the next LEN bytes
60   starting at BUFFER.
61   It is necessary that LEN is a multiple of 64!!! */
62extern void sha1_process_block (const void *buffer, size_t len,
63				struct sha1_ctx *ctx);
64
65/* Starting with the result of former calls of this function (or the
66   initialization function update the context for the next LEN bytes
67   starting at BUFFER.
68   It is NOT required that LEN is a multiple of 64.  */
69extern void sha1_process_bytes (const void *buffer, size_t len,
70				struct sha1_ctx *ctx);
71
72/* Process the remaining bytes in the buffer and put result from CTX
73   in first 20 bytes following RESBUF.  The result is always in little
74   endian byte order, so that a byte-wise output yields to the wanted
75   ASCII representation of the message digest.
76
77   IMPORTANT: On some systems it is required that RESBUF is correctly
78   aligned for a 32 bits value.  */
79extern void *sha1_finish_ctx (struct sha1_ctx *ctx, void *resbuf);
80
81
82/* Put result from CTX in first 20 bytes following RESBUF.  The result is
83   always in little endian byte order, so that a byte-wise output yields
84   to the wanted ASCII representation of the message digest.
85
86   IMPORTANT: On some systems it is required that RESBUF is correctly
87   aligned for a 32 bits value.  */
88extern void *sha1_read_ctx (const struct sha1_ctx *ctx, void *resbuf);
89
90#endif /* sha1.h */
91