3 * based from http://xyssl.org/code/source/sha1/
4 * FIPS-180-1 compliant SHA-1 implementation
6 * Copyright (C) 2003-2006 Christophe Devine
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.
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.
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,
23 * The SHA-1 standard was published by NIST in 1993.
25 * http://www.itl.nist.gov/fipspubs/fip180-1.htm
34 #define SHA1_SUM_POS -0x20
35 #define SHA1_SUM_LEN 20
38 * \brief SHA-1 context structure
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 */
49 * \brief SHA-1 context setup
51 * \param ctx SHA-1 context to be initialized
53 void sha1_starts( sha1_context *ctx );
56 * \brief SHA-1 process buffer
58 * \param ctx SHA-1 context
59 * \param input buffer holding the data
60 * \param ilen length of the input data
62 void sha1_update(sha1_context *ctx, const unsigned char *input,
66 * \brief SHA-1 final digest
68 * \param ctx SHA-1 context
69 * \param output SHA-1 checksum result
71 void sha1_finish( sha1_context *ctx, unsigned char output[20] );
74 * \brief Output = SHA-1( input buffer )
76 * \param input buffer holding the data
77 * \param ilen length of the input data
78 * \param output SHA-1 checksum result
80 void sha1_csum(const unsigned char *input, unsigned int ilen,
81 unsigned char *output);
84 * \brief Output = SHA-1( input buffer ), with watchdog triggering
86 * \param input buffer holding the data
87 * \param ilen length of the input data
88 * \param output SHA-1 checksum result
89 * \param chunk_sz watchdog triggering period (in bytes of input processed)
91 void sha1_csum_wd(const unsigned char *input, unsigned int ilen,
92 unsigned char *output, unsigned int chunk_sz);
95 * \brief Output = HMAC-SHA-1( input buffer, hmac key )
97 * \param key HMAC secret key
98 * \param keylen length of the HMAC key
99 * \param input buffer holding the data
100 * \param ilen length of the input data
101 * \param output HMAC-SHA-1 result
103 void sha1_hmac(const unsigned char *key, int keylen,
104 const unsigned char *input, unsigned int ilen,
105 unsigned char *output);
108 * \brief Checkup routine
110 * \return 0 if successful, or 1 if the test failed
112 int sha1_self_test( void );