Heiko Schocher | 633e03a | 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 | * |
Tom Rini | e237880 | 2016-01-14 22:05:13 -0500 | [diff] [blame] | 8 | * SPDX-License-Identifier: LGPL-2.1 |
Heiko Schocher | 633e03a | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 9 | */ |
| 10 | /* |
| 11 | * The SHA-1 standard was published by NIST in 1993. |
| 12 | * |
| 13 | * http://www.itl.nist.gov/fipspubs/fip180-1.htm |
| 14 | */ |
| 15 | #ifndef _SHA1_H |
| 16 | #define _SHA1_H |
| 17 | |
| 18 | #ifdef __cplusplus |
| 19 | extern "C" { |
| 20 | #endif |
| 21 | |
| 22 | #define SHA1_SUM_POS -0x20 |
| 23 | #define SHA1_SUM_LEN 20 |
| 24 | |
| 25 | /** |
Wolfgang Denk | a0453aa | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 26 | * \brief SHA-1 context structure |
Heiko Schocher | 633e03a | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 27 | */ |
| 28 | typedef struct |
| 29 | { |
Wolfgang Denk | a0453aa | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 30 | unsigned long total[2]; /*!< number of bytes processed */ |
| 31 | unsigned long state[5]; /*!< intermediate digest state */ |
| 32 | unsigned char buffer[64]; /*!< data block being processed */ |
Heiko Schocher | 633e03a | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 33 | } |
| 34 | sha1_context; |
| 35 | |
| 36 | /** |
Wolfgang Denk | a0453aa | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 37 | * \brief SHA-1 context setup |
Heiko Schocher | 633e03a | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 38 | * |
Wolfgang Denk | a0453aa | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 39 | * \param ctx SHA-1 context to be initialized |
Heiko Schocher | 633e03a | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 40 | */ |
| 41 | void sha1_starts( sha1_context *ctx ); |
| 42 | |
| 43 | /** |
Wolfgang Denk | a0453aa | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 44 | * \brief SHA-1 process buffer |
Heiko Schocher | 633e03a | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 45 | * |
Wolfgang Denk | a0453aa | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 46 | * \param ctx SHA-1 context |
Heiko Schocher | 633e03a | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 47 | * \param input buffer holding the data |
Wolfgang Denk | a0453aa | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 48 | * \param ilen length of the input data |
Heiko Schocher | 633e03a | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 49 | */ |
Simon Glass | 5f60fa2 | 2012-12-05 14:46:33 +0000 | [diff] [blame] | 50 | void sha1_update(sha1_context *ctx, const unsigned char *input, |
| 51 | unsigned int ilen); |
Heiko Schocher | 633e03a | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 52 | |
| 53 | /** |
Wolfgang Denk | a0453aa | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 54 | * \brief SHA-1 final digest |
Heiko Schocher | 633e03a | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 55 | * |
Wolfgang Denk | a0453aa | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 56 | * \param ctx SHA-1 context |
Heiko Schocher | 633e03a | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 57 | * \param output SHA-1 checksum result |
| 58 | */ |
| 59 | void sha1_finish( sha1_context *ctx, unsigned char output[20] ); |
| 60 | |
| 61 | /** |
Wolfgang Denk | a0453aa | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 62 | * \brief Output = SHA-1( input buffer ) |
Heiko Schocher | 633e03a | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 63 | * |
| 64 | * \param input buffer holding the data |
Wolfgang Denk | a0453aa | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 65 | * \param ilen length of the input data |
Heiko Schocher | 633e03a | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 66 | * \param output SHA-1 checksum result |
| 67 | */ |
Simon Glass | 5f60fa2 | 2012-12-05 14:46:33 +0000 | [diff] [blame] | 68 | void sha1_csum(const unsigned char *input, unsigned int ilen, |
| 69 | unsigned char *output); |
Heiko Schocher | 633e03a | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 70 | |
| 71 | /** |
Bartlomiej Sieka | da5045d | 2008-04-22 12:27:56 +0200 | [diff] [blame] | 72 | * \brief Output = SHA-1( input buffer ), with watchdog triggering |
| 73 | * |
| 74 | * \param input buffer holding the data |
| 75 | * \param ilen length of the input data |
| 76 | * \param output SHA-1 checksum result |
| 77 | * \param chunk_sz watchdog triggering period (in bytes of input processed) |
| 78 | */ |
Simon Glass | 5f60fa2 | 2012-12-05 14:46:33 +0000 | [diff] [blame] | 79 | void sha1_csum_wd(const unsigned char *input, unsigned int ilen, |
| 80 | unsigned char *output, unsigned int chunk_sz); |
Bartlomiej Sieka | da5045d | 2008-04-22 12:27:56 +0200 | [diff] [blame] | 81 | |
| 82 | /** |
Wolfgang Denk | a0453aa | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 83 | * \brief Output = HMAC-SHA-1( input buffer, hmac key ) |
Heiko Schocher | 633e03a | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 84 | * |
Wolfgang Denk | a0453aa | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 85 | * \param key HMAC secret key |
Heiko Schocher | 633e03a | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 86 | * \param keylen length of the HMAC key |
| 87 | * \param input buffer holding the data |
Wolfgang Denk | a0453aa | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 88 | * \param ilen length of the input data |
Heiko Schocher | 633e03a | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 89 | * \param output HMAC-SHA-1 result |
| 90 | */ |
Simon Glass | 5f60fa2 | 2012-12-05 14:46:33 +0000 | [diff] [blame] | 91 | void sha1_hmac(const unsigned char *key, int keylen, |
| 92 | const unsigned char *input, unsigned int ilen, |
| 93 | unsigned char *output); |
Heiko Schocher | 633e03a | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 94 | |
| 95 | /** |
Wolfgang Denk | a0453aa | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 96 | * \brief Checkup routine |
Heiko Schocher | 633e03a | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 97 | * |
Wolfgang Denk | a0453aa | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 98 | * \return 0 if successful, or 1 if the test failed |
Heiko Schocher | 633e03a | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 99 | */ |
| 100 | int sha1_self_test( void ); |
| 101 | |
| 102 | #ifdef __cplusplus |
| 103 | } |
| 104 | #endif |
| 105 | |
| 106 | #endif /* sha1.h */ |