1 /* SPDX-License-Identifier: LGPL-2.1 */
4 * based from http://xyssl.org/code/source/sha1/
5 * FIPS-180-1 compliant SHA-1 implementation
7 * Copyright (C) 2003-2006 Christophe Devine
10 * The SHA-1 standard was published by NIST in 1993.
12 * http://www.itl.nist.gov/fipspubs/fip180-1.htm
21 #define SHA1_SUM_POS -0x20
22 #define SHA1_SUM_LEN 20
23 #define SHA1_DER_LEN 15
25 extern const uint8_t sha1_der_prefix[];
28 * \brief SHA-1 context structure
32 unsigned long total[2]; /*!< number of bytes processed */
33 unsigned long state[5]; /*!< intermediate digest state */
34 unsigned char buffer[64]; /*!< data block being processed */
39 * \brief SHA-1 context setup
41 * \param ctx SHA-1 context to be initialized
43 void sha1_starts( sha1_context *ctx );
46 * \brief SHA-1 process buffer
48 * \param ctx SHA-1 context
49 * \param input buffer holding the data
50 * \param ilen length of the input data
52 void sha1_update(sha1_context *ctx, const unsigned char *input,
56 * \brief SHA-1 final digest
58 * \param ctx SHA-1 context
59 * \param output SHA-1 checksum result
61 void sha1_finish( sha1_context *ctx, unsigned char output[20] );
64 * \brief Output = SHA-1( input buffer )
66 * \param input buffer holding the data
67 * \param ilen length of the input data
68 * \param output SHA-1 checksum result
70 void sha1_csum(const unsigned char *input, unsigned int ilen,
71 unsigned char *output);
74 * \brief Output = SHA-1( input buffer ), with watchdog triggering
76 * \param input buffer holding the data
77 * \param ilen length of the input data
78 * \param output SHA-1 checksum result
79 * \param chunk_sz watchdog triggering period (in bytes of input processed)
81 void sha1_csum_wd(const unsigned char *input, unsigned int ilen,
82 unsigned char *output, unsigned int chunk_sz);
85 * \brief Output = HMAC-SHA-1( input buffer, hmac key )
87 * \param key HMAC secret key
88 * \param keylen length of the HMAC key
89 * \param input buffer holding the data
90 * \param ilen length of the input data
91 * \param output HMAC-SHA-1 result
93 void sha1_hmac(const unsigned char *key, int keylen,
94 const unsigned char *input, unsigned int ilen,
95 unsigned char *output);
98 * \brief Checkup routine
100 * \return 0 if successful, or 1 if the test failed
102 int sha1_self_test( void );