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 * 8 * SPDX-License-Identifier: LGPL-2.1 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 19extern "C" { 20#endif 21 22#define SHA1_SUM_POS -0x20 23#define SHA1_SUM_LEN 20 24 25/** 26 * \brief SHA-1 context structure 27 */ 28typedef struct 29{ 30 unsigned long total[2]; /*!< number of bytes processed */ 31 unsigned long state[5]; /*!< intermediate digest state */ 32 unsigned char buffer[64]; /*!< data block being processed */ 33} 34sha1_context; 35 36/** 37 * \brief SHA-1 context setup 38 * 39 * \param ctx SHA-1 context to be initialized 40 */ 41void sha1_starts( sha1_context *ctx ); 42 43/** 44 * \brief SHA-1 process buffer 45 * 46 * \param ctx SHA-1 context 47 * \param input buffer holding the data 48 * \param ilen length of the input data 49 */ 50void sha1_update(sha1_context *ctx, const unsigned char *input, 51 unsigned int ilen); 52 53/** 54 * \brief SHA-1 final digest 55 * 56 * \param ctx SHA-1 context 57 * \param output SHA-1 checksum result 58 */ 59void sha1_finish( sha1_context *ctx, unsigned char output[20] ); 60 61/** 62 * \brief Output = SHA-1( input buffer ) 63 * 64 * \param input buffer holding the data 65 * \param ilen length of the input data 66 * \param output SHA-1 checksum result 67 */ 68void sha1_csum(const unsigned char *input, unsigned int ilen, 69 unsigned char *output); 70 71/** 72 * \brief Output = SHA-1( input buffer ), with watchdog triggering 73 * 74 * \param input buffer holding the data 75 * \param ilen length of the input data 76 * \param output SHA-1 checksum result 77 * \param chunk_sz watchdog triggering period (in bytes of input processed) 78 */ 79void sha1_csum_wd(const unsigned char *input, unsigned int ilen, 80 unsigned char *output, unsigned int chunk_sz); 81 82/** 83 * \brief Output = HMAC-SHA-1( input buffer, hmac key ) 84 * 85 * \param key HMAC secret key 86 * \param keylen length of the HMAC key 87 * \param input buffer holding the data 88 * \param ilen length of the input data 89 * \param output HMAC-SHA-1 result 90 */ 91void sha1_hmac(const unsigned char *key, int keylen, 92 const unsigned char *input, unsigned int ilen, 93 unsigned char *output); 94 95/** 96 * \brief Checkup routine 97 * 98 * \return 0 if successful, or 1 if the test failed 99 */ 100int sha1_self_test( void ); 101 102#ifdef __cplusplus 103} 104#endif 105 106#endif /* sha1.h */ 107