xref: /OK3568_Linux_fs/u-boot/tools/rockchip/sha.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* sha.h
2*4882a593Smuzhiyun **
3*4882a593Smuzhiyun ** Copyright 2008, The Android Open Source Project
4*4882a593Smuzhiyun **
5*4882a593Smuzhiyun ** Redistribution and use in source and binary forms, with or without
6*4882a593Smuzhiyun ** modification, are permitted provided that the following conditions are met:
7*4882a593Smuzhiyun **     * Redistributions of source code must retain the above copyright
8*4882a593Smuzhiyun **       notice, this list of conditions and the following disclaimer.
9*4882a593Smuzhiyun **     * Redistributions in binary form must reproduce the above copyright
10*4882a593Smuzhiyun **       notice, this list of conditions and the following disclaimer in the
11*4882a593Smuzhiyun **       documentation and/or other materials provided with the distribution.
12*4882a593Smuzhiyun **     * Neither the name of Google Inc. nor the names of its contributors may
13*4882a593Smuzhiyun **       be used to endorse or promote products derived from this software
14*4882a593Smuzhiyun **       without specific prior written permission.
15*4882a593Smuzhiyun **
16*4882a593Smuzhiyun ** THIS SOFTWARE IS PROVIDED BY Google Inc. ``AS IS'' AND ANY EXPRESS OR
17*4882a593Smuzhiyun ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18*4882a593Smuzhiyun ** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19*4882a593Smuzhiyun ** EVENT SHALL Google Inc. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20*4882a593Smuzhiyun ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21*4882a593Smuzhiyun ** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22*4882a593Smuzhiyun ** OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23*4882a593Smuzhiyun ** WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24*4882a593Smuzhiyun ** OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25*4882a593Smuzhiyun ** ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*4882a593Smuzhiyun */
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun #ifndef _EMBEDDED_SHA_H_
29*4882a593Smuzhiyun #define _EMBEDDED_SHA_H_
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun #include <inttypes.h>
32*4882a593Smuzhiyun 
33*4882a593Smuzhiyun #ifdef __cplusplus
34*4882a593Smuzhiyun extern "C" {
35*4882a593Smuzhiyun #endif
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun 	typedef struct SHA_CTX {
38*4882a593Smuzhiyun 		uint64_t count;
39*4882a593Smuzhiyun 		uint32_t state[5];
40*4882a593Smuzhiyun #if defined(HAVE_ENDIAN_H) && defined(HAVE_LITTLE_ENDIAN)
41*4882a593Smuzhiyun 		union {
42*4882a593Smuzhiyun 			uint8_t b[64];
43*4882a593Smuzhiyun 			uint32_t w[16];
44*4882a593Smuzhiyun 		} buf;
45*4882a593Smuzhiyun #else
46*4882a593Smuzhiyun 		uint8_t buf[64];
47*4882a593Smuzhiyun #endif
48*4882a593Smuzhiyun 	} SHA_CTX;
49*4882a593Smuzhiyun 
50*4882a593Smuzhiyun 	void SHA_init(SHA_CTX* ctx);
51*4882a593Smuzhiyun 	void SHA_update(SHA_CTX* ctx, const void* data, int len);
52*4882a593Smuzhiyun 	const uint8_t* SHA_final(SHA_CTX* ctx);
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun 	/* Convenience method. Returns digest parameter value. */
55*4882a593Smuzhiyun 	const uint8_t* SHA(const void* data, int len, uint8_t* digest);
56*4882a593Smuzhiyun 
57*4882a593Smuzhiyun #define SHA_DIGEST_SIZE 20
58*4882a593Smuzhiyun 
59*4882a593Smuzhiyun #ifdef __cplusplus
60*4882a593Smuzhiyun }
61*4882a593Smuzhiyun #endif
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun #endif
64