3 * based from http://xyssl.org/code/source/sha1/
4 * FIPS-180-1 compliant SHA-1 implementation
6 * Copyright (C) 2003-2006 Christophe Devine
8 * SPDX-License-Identifier: LGPL-2.1
11 * The SHA-1 standard was published by NIST in 1993.
13 * http://www.itl.nist.gov/fipspubs/fip180-1.htm
22 #define SHA1_SUM_POS -0x20
23 #define SHA1_SUM_LEN 20
24 #define SHA1_DER_LEN 15
26 extern const uint8_t sha1_der_prefix[];
29 * \brief SHA-1 context structure
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 */
40 * \brief SHA-1 context setup
42 * \param ctx SHA-1 context to be initialized
44 void sha1_starts( sha1_context *ctx );
47 * \brief SHA-1 process buffer
49 * \param ctx SHA-1 context
50 * \param input buffer holding the data
51 * \param ilen length of the input data
53 void sha1_update(sha1_context *ctx, const unsigned char *input,
57 * \brief SHA-1 final digest
59 * \param ctx SHA-1 context
60 * \param output SHA-1 checksum result
62 void sha1_finish( sha1_context *ctx, unsigned char output[20] );
65 * \brief Output = SHA-1( input buffer )
67 * \param input buffer holding the data
68 * \param ilen length of the input data
69 * \param output SHA-1 checksum result
71 void sha1_csum(const unsigned char *input, unsigned int ilen,
72 unsigned char *output);
75 * \brief Output = SHA-1( input buffer ), with watchdog triggering
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)
82 void sha1_csum_wd(const unsigned char *input, unsigned int ilen,
83 unsigned char *output, unsigned int chunk_sz);
86 * \brief Output = HMAC-SHA-1( input buffer, hmac key )
88 * \param key HMAC secret key
89 * \param keylen length of the HMAC key
90 * \param input buffer holding the data
91 * \param ilen length of the input data
92 * \param output HMAC-SHA-1 result
94 void sha1_hmac(const unsigned char *key, int keylen,
95 const unsigned char *input, unsigned int ilen,
96 unsigned char *output);
99 * \brief Checkup routine
101 * \return 0 if successful, or 1 if the test failed
103 int sha1_self_test( void );