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