xref: /freebsd/lib/libmd/sha.h (revision 9d8b66868add17ed4d51feda862c6a782ca8d6ca)
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
82*9d8b6686SThomas Quinot 
83*9d8b6686SThomas Quinot /* Ensure libmd symbols do not clash with libcrypto */
84*9d8b6686SThomas Quinot 
85*9d8b6686SThomas Quinot #define SHA_Init	_libmd_SHA_Init
86*9d8b6686SThomas Quinot #define SHA_Update	_libmd_SHA_Update
87*9d8b6686SThomas Quinot #define SHA_Final	_libmd_SHA_Final
88*9d8b6686SThomas Quinot #define SHA_End		_libmd_SHA_End
89*9d8b6686SThomas Quinot #define SHA_File	_libmd_SHA_File
90*9d8b6686SThomas Quinot #define SHA_FileChunk	_libmd_SHA_FileChunk
91*9d8b6686SThomas Quinot #define SHA_Data	_libmd_SHA_Data
92*9d8b6686SThomas Quinot 
93*9d8b6686SThomas Quinot #define SHA_Transform	_libmd_SHA_Transform
94*9d8b6686SThomas Quinot #define SHA_version	_libmd_SHA_version
95*9d8b6686SThomas Quinot #define sha_block	_libmd_sha_block
96*9d8b6686SThomas Quinot 
97*9d8b6686SThomas Quinot #define SHA1_Init	_libmd_SHA1_Init
98*9d8b6686SThomas Quinot #define SHA1_Update	_libmd_SHA1_Update
99*9d8b6686SThomas Quinot #define SHA1_Final	_libmd_SHA1_Final
100*9d8b6686SThomas Quinot #define SHA1_End	_libmd_SHA1_End
101*9d8b6686SThomas Quinot #define SHA1_File	_libmd_SHA1_File
102*9d8b6686SThomas Quinot #define SHA1_FileChunk	_libmd_SHA1_FileChunk
103*9d8b6686SThomas Quinot #define SHA1_Data	_libmd_SHA1_Data
104*9d8b6686SThomas Quinot 
105*9d8b6686SThomas Quinot #define SHA1_Transform	_libmd_SHA1_Transform
106*9d8b6686SThomas Quinot #define SHA1_version	_libmd_SHA1_version
107*9d8b6686SThomas Quinot #define sha1_block	_libmd_sha1_block
108*9d8b6686SThomas Quinot 
109c177a86bSGarrett Wollman void	SHA_Init(SHA_CTX *c);
11025a14196SPoul-Henning Kamp void	SHA_Update(SHA_CTX *c, const void *data, size_t len);
111c177a86bSGarrett Wollman void	SHA_Final(unsigned char *md, SHA_CTX *c);
112c177a86bSGarrett Wollman char   *SHA_End(SHA_CTX *, char *);
113c177a86bSGarrett Wollman char   *SHA_File(const char *, char *);
1148a24546cSPoul-Henning Kamp char   *SHA_FileChunk(const char *, char *, off_t, off_t);
11525a14196SPoul-Henning Kamp char   *SHA_Data(const void *, unsigned int, char *);
116*9d8b6686SThomas Quinot 
117c177a86bSGarrett Wollman void	SHA1_Init(SHA_CTX *c);
11825a14196SPoul-Henning Kamp void	SHA1_Update(SHA_CTX *c, const void *data, size_t len);
119c177a86bSGarrett Wollman void	SHA1_Final(unsigned char *md, SHA_CTX *c);
120c177a86bSGarrett Wollman char   *SHA1_End(SHA_CTX *, char *);
121c177a86bSGarrett Wollman char   *SHA1_File(const char *, char *);
1228a24546cSPoul-Henning Kamp char   *SHA1_FileChunk(const char *, char *, off_t, off_t);
12325a14196SPoul-Henning Kamp char   *SHA1_Data(const void *, unsigned int, char *);
124c177a86bSGarrett Wollman __END_DECLS
125c177a86bSGarrett Wollman 
126c177a86bSGarrett Wollman #endif /* !_SHA_H_ */
127