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