xref: /freebsd/lib/libmd/sha.h (revision 25a14196dd8e3f2483a0911237e5567986afae31)
1c177a86bSGarrett Wollman /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
2c177a86bSGarrett Wollman  * All rights reserved.
3c177a86bSGarrett Wollman  *
4c177a86bSGarrett Wollman  * This package is an SSL implementation written
5c177a86bSGarrett Wollman  * by Eric Young (eay@cryptsoft.com).
6c177a86bSGarrett Wollman  * The implementation was written so as to conform with Netscapes SSL.
7c177a86bSGarrett Wollman  *
8c177a86bSGarrett Wollman  * This library is free for commercial and non-commercial use as long as
9c177a86bSGarrett Wollman  * the following conditions are aheared to.  The following conditions
10c177a86bSGarrett Wollman  * apply to all code found in this distribution, be it the RC4, RSA,
11c177a86bSGarrett Wollman  * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
12c177a86bSGarrett Wollman  * included with this distribution is covered by the same copyright terms
13c177a86bSGarrett Wollman  * except that the holder is Tim Hudson (tjh@cryptsoft.com).
14c177a86bSGarrett Wollman  *
15c177a86bSGarrett Wollman  * Copyright remains Eric Young's, and as such any Copyright notices in
16c177a86bSGarrett Wollman  * the code are not to be removed.
17c177a86bSGarrett Wollman  * If this package is used in a product, Eric Young should be given attribution
18c177a86bSGarrett Wollman  * as the author of the parts of the library used.
19c177a86bSGarrett Wollman  * This can be in the form of a textual message at program startup or
20c177a86bSGarrett Wollman  * in documentation (online or textual) provided with the package.
21c177a86bSGarrett Wollman  *
22c177a86bSGarrett Wollman  * Redistribution and use in source and binary forms, with or without
23c177a86bSGarrett Wollman  * modification, are permitted provided that the following conditions
24c177a86bSGarrett Wollman  * are met:
25c177a86bSGarrett Wollman  * 1. Redistributions of source code must retain the copyright
26c177a86bSGarrett Wollman  *    notice, this list of conditions and the following disclaimer.
27c177a86bSGarrett Wollman  * 2. Redistributions in binary form must reproduce the above copyright
28c177a86bSGarrett Wollman  *    notice, this list of conditions and the following disclaimer in the
29c177a86bSGarrett Wollman  *    documentation and/or other materials provided with the distribution.
30c177a86bSGarrett Wollman  * 3. All advertising materials mentioning features or use of this software
31c177a86bSGarrett Wollman  *    must display the following acknowledgement:
32c177a86bSGarrett Wollman  *    "This product includes cryptographic software written by
33c177a86bSGarrett Wollman  *     Eric Young (eay@cryptsoft.com)"
34c177a86bSGarrett Wollman  *    The word 'cryptographic' can be left out if the rouines from the library
35c177a86bSGarrett Wollman  *    being used are not cryptographic related :-).
36c177a86bSGarrett Wollman  * 4. If you include any Windows specific code (or a derivative thereof) from
37c177a86bSGarrett Wollman  *    the apps directory (application code) you must include an acknowledgement:
38c177a86bSGarrett Wollman  *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
39c177a86bSGarrett Wollman  *
40c177a86bSGarrett Wollman  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
41c177a86bSGarrett Wollman  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42c177a86bSGarrett Wollman  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43c177a86bSGarrett Wollman  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
44c177a86bSGarrett Wollman  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45c177a86bSGarrett Wollman  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46c177a86bSGarrett Wollman  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47c177a86bSGarrett Wollman  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48c177a86bSGarrett Wollman  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49c177a86bSGarrett Wollman  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50c177a86bSGarrett Wollman  * SUCH DAMAGE.
51c177a86bSGarrett Wollman  *
52c177a86bSGarrett Wollman  * The licence and distribution terms for any publically available version or
53c177a86bSGarrett Wollman  * derivative of this code cannot be changed.  i.e. this code cannot simply be
54c177a86bSGarrett Wollman  * copied and put under another distribution licence
55c177a86bSGarrett Wollman  * [including the GNU Public Licence.]
56c177a86bSGarrett Wollman  *
577f3dea24SPeter Wemm  * $FreeBSD$
58c177a86bSGarrett Wollman  */
59c177a86bSGarrett Wollman 
60c177a86bSGarrett Wollman #ifndef _SHA_H_
61c177a86bSGarrett Wollman #define _SHA_H_		1
62c177a86bSGarrett Wollman 
63c177a86bSGarrett Wollman #include <sys/cdefs.h>
64c177a86bSGarrett Wollman #include <sys/types.h>		/* XXX switch to machine/ansi.h and __ types */
65c177a86bSGarrett Wollman 
66c177a86bSGarrett Wollman #define	SHA_CBLOCK	64
67c177a86bSGarrett Wollman #define	SHA_LBLOCK	16
68c177a86bSGarrett Wollman #define	SHA_BLOCK	16
69c177a86bSGarrett Wollman #define	SHA_LAST_BLOCK  56
70c177a86bSGarrett Wollman #define	SHA_LENGTH_BLOCK 8
71c177a86bSGarrett Wollman #define	SHA_DIGEST_LENGTH 20
72c177a86bSGarrett Wollman 
73c177a86bSGarrett Wollman typedef struct SHAstate_st {
74c177a86bSGarrett Wollman 	u_int32_t h0, h1, h2, h3, h4;
75c177a86bSGarrett Wollman 	u_int32_t Nl, Nh;
76c177a86bSGarrett Wollman 	u_int32_t data[SHA_LBLOCK];
77c177a86bSGarrett Wollman 	int num;
78c177a86bSGarrett Wollman } SHA_CTX;
79c177a86bSGarrett Wollman #define	SHA1_CTX	SHA_CTX
80c177a86bSGarrett Wollman 
81c177a86bSGarrett Wollman __BEGIN_DECLS
82c177a86bSGarrett Wollman void	SHA_Init(SHA_CTX *c);
8325a14196SPoul-Henning Kamp void	SHA_Update(SHA_CTX *c, const void *data, size_t len);
84c177a86bSGarrett Wollman void	SHA_Final(unsigned char *md, SHA_CTX *c);
85c177a86bSGarrett Wollman char   *SHA_End(SHA_CTX *, char *);
86c177a86bSGarrett Wollman char   *SHA_File(const char *, char *);
878a24546cSPoul-Henning Kamp char   *SHA_FileChunk(const char *, char *, off_t, off_t);
8825a14196SPoul-Henning Kamp char   *SHA_Data(const void *, unsigned int, char *);
89c177a86bSGarrett Wollman void	SHA1_Init(SHA_CTX *c);
9025a14196SPoul-Henning Kamp void	SHA1_Update(SHA_CTX *c, const void *data, size_t len);
91c177a86bSGarrett Wollman void	SHA1_Final(unsigned char *md, SHA_CTX *c);
92c177a86bSGarrett Wollman char   *SHA1_End(SHA_CTX *, char *);
93c177a86bSGarrett Wollman char   *SHA1_File(const char *, char *);
948a24546cSPoul-Henning Kamp char   *SHA1_FileChunk(const char *, char *, off_t, off_t);
9525a14196SPoul-Henning Kamp char   *SHA1_Data(const void *, unsigned int, char *);
96c177a86bSGarrett Wollman __END_DECLS
97c177a86bSGarrett Wollman 
98c177a86bSGarrett Wollman #endif /* !_SHA_H_ */
99