xref: /freebsd/lib/libmd/sha.h (revision 55b130956d63f4aa283b24b0db3dc3d61f6c0ec0)
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
829d8b6686SThomas Quinot 
839d8b6686SThomas Quinot /* Ensure libmd symbols do not clash with libcrypto */
849d8b6686SThomas Quinot 
85*55b13095SThomas Quinot #ifndef SHA_Init
869d8b6686SThomas Quinot #define SHA_Init	_libmd_SHA_Init
87*55b13095SThomas Quinot #endif
88*55b13095SThomas Quinot #ifndef SHA_Update
899d8b6686SThomas Quinot #define SHA_Update	_libmd_SHA_Update
90*55b13095SThomas Quinot #endif
91*55b13095SThomas Quinot #ifndef SHA_Final
929d8b6686SThomas Quinot #define SHA_Final	_libmd_SHA_Final
93*55b13095SThomas Quinot #endif
94*55b13095SThomas Quinot #ifndef SHA_End
959d8b6686SThomas Quinot #define SHA_End		_libmd_SHA_End
96*55b13095SThomas Quinot #endif
97*55b13095SThomas Quinot #ifndef SHA_File
989d8b6686SThomas Quinot #define SHA_File	_libmd_SHA_File
99*55b13095SThomas Quinot #endif
100*55b13095SThomas Quinot #ifndef SHA_FileChunk
1019d8b6686SThomas Quinot #define SHA_FileChunk	_libmd_SHA_FileChunk
102*55b13095SThomas Quinot #endif
103*55b13095SThomas Quinot #ifndef SHA_Data
1049d8b6686SThomas Quinot #define SHA_Data	_libmd_SHA_Data
105*55b13095SThomas Quinot #endif
1069d8b6686SThomas Quinot 
107*55b13095SThomas Quinot #ifndef SHA_Transform
1089d8b6686SThomas Quinot #define SHA_Transform	_libmd_SHA_Transform
109*55b13095SThomas Quinot #endif
110*55b13095SThomas Quinot #ifndef SHA_version
1119d8b6686SThomas Quinot #define SHA_version	_libmd_SHA_version
112*55b13095SThomas Quinot #endif
113*55b13095SThomas Quinot #ifndef sha_block
1149d8b6686SThomas Quinot #define sha_block	_libmd_sha_block
115*55b13095SThomas Quinot #endif
1169d8b6686SThomas Quinot 
117*55b13095SThomas Quinot #ifndef SHA1_Init
1189d8b6686SThomas Quinot #define SHA1_Init	_libmd_SHA1_Init
119*55b13095SThomas Quinot #endif
120*55b13095SThomas Quinot #ifndef SHA1_Update
1219d8b6686SThomas Quinot #define SHA1_Update	_libmd_SHA1_Update
122*55b13095SThomas Quinot #endif
123*55b13095SThomas Quinot #ifndef SHA1_Final
1249d8b6686SThomas Quinot #define SHA1_Final	_libmd_SHA1_Final
125*55b13095SThomas Quinot #endif
126*55b13095SThomas Quinot #ifndef SHA1_End
1279d8b6686SThomas Quinot #define SHA1_End	_libmd_SHA1_End
128*55b13095SThomas Quinot #endif
129*55b13095SThomas Quinot #ifndef SHA1_File
1309d8b6686SThomas Quinot #define SHA1_File	_libmd_SHA1_File
131*55b13095SThomas Quinot #endif
132*55b13095SThomas Quinot #ifndef SHA1_FileChunk
1339d8b6686SThomas Quinot #define SHA1_FileChunk	_libmd_SHA1_FileChunk
134*55b13095SThomas Quinot #endif
135*55b13095SThomas Quinot #ifndef SHA1_Data
1369d8b6686SThomas Quinot #define SHA1_Data	_libmd_SHA1_Data
137*55b13095SThomas Quinot #endif
1389d8b6686SThomas Quinot 
139*55b13095SThomas Quinot #ifndef SHA1_Transform
1409d8b6686SThomas Quinot #define SHA1_Transform	_libmd_SHA1_Transform
141*55b13095SThomas Quinot #endif
142*55b13095SThomas Quinot #ifndef SHA1_version
1439d8b6686SThomas Quinot #define SHA1_version	_libmd_SHA1_version
144*55b13095SThomas Quinot #endif
145*55b13095SThomas Quinot #ifndef sha1_block
1469d8b6686SThomas Quinot #define sha1_block	_libmd_sha1_block
147*55b13095SThomas Quinot #endif
1489d8b6686SThomas Quinot 
149c177a86bSGarrett Wollman void	SHA_Init(SHA_CTX *c);
15025a14196SPoul-Henning Kamp void	SHA_Update(SHA_CTX *c, const void *data, size_t len);
151c177a86bSGarrett Wollman void	SHA_Final(unsigned char *md, SHA_CTX *c);
152c177a86bSGarrett Wollman char   *SHA_End(SHA_CTX *, char *);
153c177a86bSGarrett Wollman char   *SHA_File(const char *, char *);
1548a24546cSPoul-Henning Kamp char   *SHA_FileChunk(const char *, char *, off_t, off_t);
15525a14196SPoul-Henning Kamp char   *SHA_Data(const void *, unsigned int, char *);
1569d8b6686SThomas Quinot 
157c177a86bSGarrett Wollman void	SHA1_Init(SHA_CTX *c);
15825a14196SPoul-Henning Kamp void	SHA1_Update(SHA_CTX *c, const void *data, size_t len);
159c177a86bSGarrett Wollman void	SHA1_Final(unsigned char *md, SHA_CTX *c);
160c177a86bSGarrett Wollman char   *SHA1_End(SHA_CTX *, char *);
161c177a86bSGarrett Wollman char   *SHA1_File(const char *, char *);
1628a24546cSPoul-Henning Kamp char   *SHA1_FileChunk(const char *, char *, off_t, off_t);
16325a14196SPoul-Henning Kamp char   *SHA1_Data(const void *, unsigned int, char *);
164c177a86bSGarrett Wollman __END_DECLS
165c177a86bSGarrett Wollman 
166c177a86bSGarrett Wollman #endif /* !_SHA_H_ */
167