packages: clean up the package folder
[openwrt.git] / package / utils / px5g / src / polarssl / sha1.h
1 /**
2  * \file sha1.h
3  *
4  *  Based on XySSL: Copyright (C) 2006-2008  Christophe Devine
5  *
6  *  Copyright (C) 2009  Paul Bakker <polarssl_maintainer at polarssl dot org>
7  *
8  *  All rights reserved.
9  *
10  *  Redistribution and use in source and binary forms, with or without
11  *  modification, are permitted provided that the following conditions
12  *  are met:
13  *  
14  *    * Redistributions of source code must retain the above copyright
15  *      notice, this list of conditions and the following disclaimer.
16  *    * Redistributions in binary form must reproduce the above copyright
17  *      notice, this list of conditions and the following disclaimer in the
18  *      documentation and/or other materials provided with the distribution.
19  *    * Neither the names of PolarSSL or XySSL nor the names of its contributors
20  *      may be used to endorse or promote products derived from this software
21  *      without specific prior written permission.
22  *  
23  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29  *  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30  *  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31  *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32  *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 #ifndef POLARSSL_SHA1_H
36 #define POLARSSL_SHA1_H
37
38 /**
39  * \brief          SHA-1 context structure
40  */
41 typedef struct
42 {
43     unsigned long total[2];     /*!< number of bytes processed  */
44     unsigned long state[5];     /*!< intermediate digest state  */
45     unsigned char buffer[64];   /*!< data block being processed */
46
47     unsigned char ipad[64];     /*!< HMAC: inner padding        */
48     unsigned char opad[64];     /*!< HMAC: outer padding        */
49 }
50 sha1_context;
51
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55
56 /**
57  * \brief          SHA-1 context setup
58  *
59  * \param ctx      context to be initialized
60  */
61 void sha1_starts( sha1_context *ctx );
62
63 /**
64  * \brief          SHA-1 process buffer
65  *
66  * \param ctx      SHA-1 context
67  * \param input    buffer holding the  data
68  * \param ilen     length of the input data
69  */
70 void sha1_update( sha1_context *ctx, unsigned char *input, int ilen );
71
72 /**
73  * \brief          SHA-1 final digest
74  *
75  * \param ctx      SHA-1 context
76  * \param output   SHA-1 checksum result
77  */
78 void sha1_finish( sha1_context *ctx, unsigned char output[20] );
79
80 /**
81  * \brief          Output = SHA-1( input buffer )
82  *
83  * \param input    buffer holding the  data
84  * \param ilen     length of the input data
85  * \param output   SHA-1 checksum result
86  */
87 void sha1( unsigned char *input, int ilen, unsigned char output[20] );
88
89 /**
90  * \brief          Output = SHA-1( file contents )
91  *
92  * \param path     input file name
93  * \param output   SHA-1 checksum result
94  *
95  * \return         0 if successful, 1 if fopen failed,
96  *                 or 2 if fread failed
97  */
98 int sha1_file( char *path, unsigned char output[20] );
99
100 /**
101  * \brief          SHA-1 HMAC context setup
102  *
103  * \param ctx      HMAC context to be initialized
104  * \param key      HMAC secret key
105  * \param keylen   length of the HMAC key
106  */
107 void sha1_hmac_starts( sha1_context *ctx, unsigned char *key, int keylen );
108
109 /**
110  * \brief          SHA-1 HMAC process buffer
111  *
112  * \param ctx      HMAC context
113  * \param input    buffer holding the  data
114  * \param ilen     length of the input data
115  */
116 void sha1_hmac_update( sha1_context *ctx, unsigned char *input, int ilen );
117
118 /**
119  * \brief          SHA-1 HMAC final digest
120  *
121  * \param ctx      HMAC context
122  * \param output   SHA-1 HMAC checksum result
123  */
124 void sha1_hmac_finish( sha1_context *ctx, unsigned char output[20] );
125
126 /**
127  * \brief          Output = HMAC-SHA-1( hmac key, input buffer )
128  *
129  * \param key      HMAC secret key
130  * \param keylen   length of the HMAC key
131  * \param input    buffer holding the  data
132  * \param ilen     length of the input data
133  * \param output   HMAC-SHA-1 result
134  */
135 void sha1_hmac( unsigned char *key, int keylen,
136                 unsigned char *input, int ilen,
137                 unsigned char output[20] );
138
139 /**
140  * \brief          Checkup routine
141  *
142  * \return         0 if successful, or 1 if the test failed
143  */
144 int sha1_self_test( int verbose );
145
146 #ifdef __cplusplus
147 }
148 #endif
149
150 #endif /* sha1.h */