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
17 #include <linux/types.h>
23 #define SHA1_SUM_POS -0x20
24 #define SHA1_SUM_LEN 20
25 #define SHA1_DER_LEN 15
27 extern const uint8_t sha1_der_prefix[];
30 * \brief SHA-1 context structure
34 unsigned long total[2]; /*!< number of bytes processed */
35 uint32_t state[5]; /*!< intermediate digest state */
36 unsigned char buffer[64]; /*!< data block being processed */
41 * \brief SHA-1 context setup
43 * \param ctx SHA-1 context to be initialized
45 void sha1_starts( sha1_context *ctx );
48 * \brief SHA-1 process buffer
50 * \param ctx SHA-1 context
51 * \param input buffer holding the data
52 * \param ilen length of the input data
54 void sha1_update(sha1_context *ctx, const unsigned char *input,
58 * \brief SHA-1 final digest
60 * \param ctx SHA-1 context
61 * \param output SHA-1 checksum result
63 void sha1_finish( sha1_context *ctx, unsigned char output[20] );
66 * \brief Output = SHA-1( input buffer )
68 * \param input buffer holding the data
69 * \param ilen length of the input data
70 * \param output SHA-1 checksum result
72 void sha1_csum(const unsigned char *input, unsigned int ilen,
73 unsigned char *output);
76 * \brief Output = SHA-1( input buffer ), with watchdog triggering
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)
83 void sha1_csum_wd(const unsigned char *input, unsigned int ilen,
84 unsigned char *output, unsigned int chunk_sz);
87 * \brief Output = HMAC-SHA-1( input buffer, hmac key )
89 * \param key HMAC secret key
90 * \param keylen length of the HMAC key
91 * \param input buffer holding the data
92 * \param ilen length of the input data
93 * \param output HMAC-SHA-1 result
95 void sha1_hmac(const unsigned char *key, int keylen,
96 const unsigned char *input, unsigned int ilen,
97 unsigned char *output);
100 * \brief Checkup routine
102 * \return 0 if successful, or 1 if the test failed
104 int sha1_self_test( void );