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