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