Commit | Line | Data |
---|---|---|
e6e0e332 MW |
1 | /* -*-c-*- |
2 | * | |
3 | * $Id: sha.h,v 1.1 2000/05/21 11:28:30 mdw Exp $ | |
4 | * | |
5 | * Implementation of the SHA-1 hash function | |
6 | * | |
7 | * (c) 1999 Straylight/Edgeware | |
8 | * (c) 2000 Mark Wooding | |
9 | */ | |
10 | ||
11 | /*----- Licensing notice --------------------------------------------------* | |
12 | * | |
13 | * Copyright (c) 2000 Mark Wooding | |
14 | * All rights reserved. | |
15 | * | |
16 | * Redistribution and use in source and binary forms, with or without | |
17 | * modification, are permitted provided that the following conditions are | |
18 | * met: | |
19 | * | |
20 | * 1. Redistributions of source code must retain the above copyright | |
21 | * notice, this list of conditions and the following disclaimer. | |
22 | * | |
23 | * 2, Redistributions in binary form must reproduce the above copyright | |
24 | * notice, this list of conditions and the following disclaimer in the | |
25 | * documentation and/or other materials provided with the distribution. | |
26 | * | |
27 | * 3. The name of the authors may not be used to endorse or promote | |
28 | * products derived from this software without specific prior written | |
29 | * permission. | |
30 | * | |
31 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED | |
32 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
33 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN | |
34 | * NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | |
35 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
36 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
37 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
39 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | |
40 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
41 | * POSSIBILITY OF SUCH DAMAGE. | |
42 | * | |
43 | * Instead of accepting the above terms, you may redistribute and/or modify | |
44 | * this software under the terms of either the GNU General Public License, | |
45 | * or the GNU Library General Public License, published by the Free | |
46 | * Software Foundation; either version 2 of the License, or (at your | |
47 | * option) any later version. | |
48 | */ | |
49 | ||
50 | #ifndef SHA_H | |
51 | #define SHA_H | |
52 | ||
53 | #ifdef __cplusplus | |
54 | extern "C" { | |
55 | #endif | |
56 | ||
57 | /*----- Magic numbers -----------------------------------------------------*/ | |
58 | ||
59 | #define SHA_BUFSZ 64 | |
60 | #define SHA_HASHSZ 20 | |
61 | ||
62 | /*----- Data structures ---------------------------------------------------*/ | |
63 | ||
64 | typedef struct sha_ctx { | |
65 | uint32 a, b, c, d, e; /* Chaining variables */ | |
66 | uint32 nl, nh; /* Byte count so far */ | |
67 | int off; /* Offset into buffer */ | |
68 | octet buf[SHA_BUFSZ]; /* Accumulation buffer */ | |
69 | } sha_ctx; | |
70 | ||
71 | /*----- Functions provided ------------------------------------------------*/ | |
72 | ||
73 | /* --- @sha_compress@ --- * | |
74 | * | |
75 | * Arguments: @sha_ctx *ctx@ = pointer to context block | |
76 | * @const void *sbuf@ = pointer to buffer of appropriate size | |
77 | * | |
78 | * Returns: --- | |
79 | * | |
80 | * Use: SHA compression function. | |
81 | */ | |
82 | ||
83 | extern void sha_compress(sha_ctx */*ctx*/, const void */*sbuf*/); | |
84 | ||
85 | /* --- @sha_init@ --- * | |
86 | * | |
87 | * Arguments: @sha_ctx *ctx@ = pointer to context block to initialize | |
88 | * | |
89 | * Returns: --- | |
90 | * | |
91 | * Use: Initializes a context block ready for hashing. | |
92 | */ | |
93 | ||
94 | extern void sha_init(sha_ctx *ctx); | |
95 | ||
96 | /* --- @sha_hash@ --- * | |
97 | * | |
98 | * Arguments: @sha_ctx *ctx@ = pointer to context block | |
99 | * @const void *buf@ = buffer of data to hash | |
100 | * @size_t sz@ = size of buffer to hash | |
101 | * | |
102 | * Returns: --- | |
103 | * | |
104 | * Use: Hashes a buffer of data. The buffer may be of any size and | |
105 | * alignment. | |
106 | */ | |
107 | ||
108 | extern void sha_hash(sha_ctx */*ctx*/, const void */*buf*/, size_t /*sz*/); | |
109 | ||
110 | /* --- @sha_done@ --- * | |
111 | * | |
112 | * Arguments: @sha_ctx *ctx@ = pointer to context block | |
113 | * @void *hash@ = pointer to output buffer | |
114 | * | |
115 | * Returns: --- | |
116 | * | |
117 | * Use: Returns the hash of the data read so far. | |
118 | */ | |
119 | ||
120 | extern void sha_done(sha_ctx */*ctx*/, void */*hash*/); | |
121 | ||
122 | /*----- That's all, folks -------------------------------------------------*/ | |
123 | ||
124 | #ifdef __cplusplus | |
125 | } | |
126 | #endif | |
127 | ||
128 | #endif |