]>
Commit | Line | Data |
---|---|---|
566a494f HS |
1 | /** |
2 | * \file sha1.h | |
3 | * based from http://xyssl.org/code/source/sha1/ | |
4 | * FIPS-180-1 compliant SHA-1 implementation | |
5 | * | |
6 | * Copyright (C) 2003-2006 Christophe Devine | |
7 | * | |
8 | * This library is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU Lesser General Public | |
10 | * License, version 2.1 as published by the Free Software Foundation. | |
11 | * | |
12 | * This library is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * Lesser General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU Lesser General Public | |
18 | * License along with this library; if not, write to the Free Software | |
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | |
4ef218f6 | 20 | * MA 02110-1301 USA |
566a494f HS |
21 | */ |
22 | /* | |
23 | * The SHA-1 standard was published by NIST in 1993. | |
24 | * | |
25 | * http://www.itl.nist.gov/fipspubs/fip180-1.htm | |
26 | */ | |
27 | #ifndef _SHA1_H | |
28 | #define _SHA1_H | |
29 | ||
30 | #ifdef __cplusplus | |
31 | extern "C" { | |
32 | #endif | |
33 | ||
34 | #define SHA1_SUM_POS -0x20 | |
35 | #define SHA1_SUM_LEN 20 | |
36 | ||
37 | /** | |
4ef218f6 | 38 | * \brief SHA-1 context structure |
566a494f HS |
39 | */ |
40 | typedef struct | |
41 | { | |
4ef218f6 WD |
42 | unsigned long total[2]; /*!< number of bytes processed */ |
43 | unsigned long state[5]; /*!< intermediate digest state */ | |
44 | unsigned char buffer[64]; /*!< data block being processed */ | |
566a494f HS |
45 | } |
46 | sha1_context; | |
47 | ||
48 | /** | |
4ef218f6 | 49 | * \brief SHA-1 context setup |
566a494f | 50 | * |
4ef218f6 | 51 | * \param ctx SHA-1 context to be initialized |
566a494f HS |
52 | */ |
53 | void sha1_starts( sha1_context *ctx ); | |
54 | ||
55 | /** | |
4ef218f6 | 56 | * \brief SHA-1 process buffer |
566a494f | 57 | * |
4ef218f6 | 58 | * \param ctx SHA-1 context |
566a494f | 59 | * \param input buffer holding the data |
4ef218f6 | 60 | * \param ilen length of the input data |
566a494f HS |
61 | */ |
62 | void sha1_update( sha1_context *ctx, unsigned char *input, int ilen ); | |
63 | ||
64 | /** | |
4ef218f6 | 65 | * \brief SHA-1 final digest |
566a494f | 66 | * |
4ef218f6 | 67 | * \param ctx SHA-1 context |
566a494f HS |
68 | * \param output SHA-1 checksum result |
69 | */ | |
70 | void sha1_finish( sha1_context *ctx, unsigned char output[20] ); | |
71 | ||
72 | /** | |
4ef218f6 | 73 | * \brief Output = SHA-1( input buffer ) |
566a494f HS |
74 | * |
75 | * \param input buffer holding the data | |
4ef218f6 | 76 | * \param ilen length of the input data |
566a494f HS |
77 | * \param output SHA-1 checksum result |
78 | */ | |
79 | void sha1_csum( unsigned char *input, int ilen, | |
4ef218f6 | 80 | unsigned char output[20] ); |
566a494f | 81 | |
215b01bb BS |
82 | /** |
83 | * \brief Output = SHA-1( input buffer ), with watchdog triggering | |
84 | * | |
85 | * \param input buffer holding the data | |
86 | * \param ilen length of the input data | |
87 | * \param output SHA-1 checksum result | |
88 | * \param chunk_sz watchdog triggering period (in bytes of input processed) | |
89 | */ | |
90 | void sha1_csum_wd (unsigned char *input, int ilen, | |
91 | unsigned char output[20], unsigned int chunk_sz); | |
92 | ||
566a494f | 93 | /** |
4ef218f6 | 94 | * \brief Output = SHA-1( file contents ) |
566a494f | 95 | * |
4ef218f6 | 96 | * \param path input file name |
566a494f | 97 | * \param output SHA-1 checksum result |
4ef218f6 | 98 | * \return 0 if successful, or 1 if fopen failed |
566a494f HS |
99 | */ |
100 | int sha1_file( char *path, unsigned char output[20] ); | |
101 | ||
102 | /** | |
4ef218f6 | 103 | * \brief Output = HMAC-SHA-1( input buffer, hmac key ) |
566a494f | 104 | * |
4ef218f6 | 105 | * \param key HMAC secret key |
566a494f HS |
106 | * \param keylen length of the HMAC key |
107 | * \param input buffer holding the data | |
4ef218f6 | 108 | * \param ilen length of the input data |
566a494f HS |
109 | * \param output HMAC-SHA-1 result |
110 | */ | |
111 | void sha1_hmac( unsigned char *key, int keylen, | |
4ef218f6 WD |
112 | unsigned char *input, int ilen, |
113 | unsigned char output[20] ); | |
566a494f HS |
114 | |
115 | /** | |
4ef218f6 | 116 | * \brief Checkup routine |
566a494f | 117 | * |
4ef218f6 | 118 | * \return 0 if successful, or 1 if the test failed |
566a494f HS |
119 | */ |
120 | int sha1_self_test( void ); | |
121 | ||
122 | #ifdef __cplusplus | |
123 | } | |
124 | #endif | |
125 | ||
126 | #endif /* sha1.h */ |