3 * $Id: sha.h,v 1.2 2000/07/02 15:21:20 mdw Exp $
5 * Implementation of the SHA-1 hash function
7 * (c) 1999 Straylight/Edgeware
8 * (c) 2000 Mark Wooding
11 /*----- Licensing notice --------------------------------------------------*
13 * Copyright (c) 2000 Mark Wooding
14 * All rights reserved.
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions are
20 * 1. Redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer.
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.
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
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 AUTHORS 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.
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.
57 /*----- Magic numbers -----------------------------------------------------*/
62 /*----- Data structures ---------------------------------------------------*/
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 */
71 /*----- Functions provided ------------------------------------------------*/
73 /* --- @sha_compress@ --- *
75 * Arguments: @sha_ctx *ctx@ = pointer to context block
76 * @const void *sbuf@ = pointer to buffer of appropriate size
80 * Use: SHA compression function.
83 extern void sha_compress(sha_ctx */
*ctx*/
, const void */
*sbuf*/
);
85 /* --- @sha_init@ --- *
87 * Arguments: @sha_ctx *ctx@ = pointer to context block to initialize
91 * Use: Initializes a context block ready for hashing.
94 extern void sha_init(sha_ctx
*ctx
);
96 /* --- @sha_hash@ --- *
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
104 * Use: Hashes a buffer of data. The buffer may be of any size and
108 extern void sha_hash(sha_ctx */
*ctx*/
, const void */
*buf*/
, size_t /*sz*/);
110 /* --- @sha_done@ --- *
112 * Arguments: @sha_ctx *ctx@ = pointer to context block
113 * @void *hash@ = pointer to output buffer
117 * Use: Returns the hash of the data read so far.
120 extern void sha_done(sha_ctx */
*ctx*/
, void */
*hash*/
);
122 /*----- That's all, folks -------------------------------------------------*/