Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 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, |
Wolfgang Denk | 4ef218f | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 20 | * MA 02110-1301 USA |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 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 | /** |
Wolfgang Denk | 4ef218f | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 38 | * \brief SHA-1 context structure |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 39 | */ |
| 40 | typedef struct |
| 41 | { |
Wolfgang Denk | 4ef218f | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 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 */ |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 45 | } |
| 46 | sha1_context; |
| 47 | |
| 48 | /** |
Wolfgang Denk | 4ef218f | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 49 | * \brief SHA-1 context setup |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 50 | * |
Wolfgang Denk | 4ef218f | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 51 | * \param ctx SHA-1 context to be initialized |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 52 | */ |
| 53 | void sha1_starts( sha1_context *ctx ); |
| 54 | |
| 55 | /** |
Wolfgang Denk | 4ef218f | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 56 | * \brief SHA-1 process buffer |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 57 | * |
Wolfgang Denk | 4ef218f | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 58 | * \param ctx SHA-1 context |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 59 | * \param input buffer holding the data |
Wolfgang Denk | 4ef218f | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 60 | * \param ilen length of the input data |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 61 | */ |
Simon Glass | a7d1d76 | 2012-12-05 14:46:33 +0000 | [diff] [blame] | 62 | void sha1_update(sha1_context *ctx, const unsigned char *input, |
| 63 | unsigned int ilen); |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 64 | |
| 65 | /** |
Wolfgang Denk | 4ef218f | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 66 | * \brief SHA-1 final digest |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 67 | * |
Wolfgang Denk | 4ef218f | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 68 | * \param ctx SHA-1 context |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 69 | * \param output SHA-1 checksum result |
| 70 | */ |
| 71 | void sha1_finish( sha1_context *ctx, unsigned char output[20] ); |
| 72 | |
| 73 | /** |
Wolfgang Denk | 4ef218f | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 74 | * \brief Output = SHA-1( input buffer ) |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 75 | * |
| 76 | * \param input buffer holding the data |
Wolfgang Denk | 4ef218f | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 77 | * \param ilen length of the input data |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 78 | * \param output SHA-1 checksum result |
| 79 | */ |
Simon Glass | a7d1d76 | 2012-12-05 14:46:33 +0000 | [diff] [blame] | 80 | void sha1_csum(const unsigned char *input, unsigned int ilen, |
| 81 | unsigned char *output); |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 82 | |
| 83 | /** |
Bartlomiej Sieka | 215b01b | 2008-04-22 12:27:56 +0200 | [diff] [blame] | 84 | * \brief Output = SHA-1( input buffer ), with watchdog triggering |
| 85 | * |
| 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) |
| 90 | */ |
Simon Glass | a7d1d76 | 2012-12-05 14:46:33 +0000 | [diff] [blame] | 91 | void sha1_csum_wd(const unsigned char *input, unsigned int ilen, |
| 92 | unsigned char *output, unsigned int chunk_sz); |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 93 | |
| 94 | /** |
Wolfgang Denk | 4ef218f | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 95 | * \brief Output = HMAC-SHA-1( input buffer, hmac key ) |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 96 | * |
Wolfgang Denk | 4ef218f | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 97 | * \param key HMAC secret key |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 98 | * \param keylen length of the HMAC key |
| 99 | * \param input buffer holding the data |
Wolfgang Denk | 4ef218f | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 100 | * \param ilen length of the input data |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 101 | * \param output HMAC-SHA-1 result |
| 102 | */ |
Simon Glass | a7d1d76 | 2012-12-05 14:46:33 +0000 | [diff] [blame] | 103 | void sha1_hmac(const unsigned char *key, int keylen, |
| 104 | const unsigned char *input, unsigned int ilen, |
| 105 | unsigned char *output); |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 106 | |
| 107 | /** |
Wolfgang Denk | 4ef218f | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 108 | * \brief Checkup routine |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 109 | * |
Wolfgang Denk | 4ef218f | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 110 | * \return 0 if successful, or 1 if the test failed |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 111 | */ |
| 112 | int sha1_self_test( void ); |
| 113 | |
| 114 | #ifdef __cplusplus |
| 115 | } |
| 116 | #endif |
| 117 | |
| 118 | #endif /* sha1.h */ |