1 #ifndef LDNS_SHA1_H 2 #define LDNS_SHA1_H 3 4 #include <stdint.h> /* uint32_t and friends */ 5 #include <stddef.h> /* size_t and NULL */ 6 7 #if LDNS_BUILD_CONFIG_HAVE_INTTYPES_H 8 # include <inttypes.h> 9 #endif 10 11 #ifdef __cplusplus 12 extern "C" { 13 #endif 14 15 #define LDNS_SHA1_BLOCK_LENGTH 64 16 #define LDNS_SHA1_DIGEST_LENGTH 20 17 18 typedef struct { 19 uint32_t state[5]; 20 uint64_t count; 21 unsigned char buffer[LDNS_SHA1_BLOCK_LENGTH]; 22 } ldns_sha1_ctx; 23 24 void ldns_sha1_init(ldns_sha1_ctx * context); 25 void ldns_sha1_transform(uint32_t state[5], const unsigned char buffer[LDNS_SHA1_BLOCK_LENGTH]); 26 void ldns_sha1_update(ldns_sha1_ctx *context, const unsigned char *data, unsigned int len); 27 void ldns_sha1_final(unsigned char digest[LDNS_SHA1_DIGEST_LENGTH], ldns_sha1_ctx *context); 28 29 /** 30 * Convenience function to digest a fixed block of data at once. 31 * 32 * \param[in] data the data to digest 33 * \param[in] data_len the length of data in bytes 34 * \param[out] digest the length of data in bytes 35 * This pointer MUST have LDNS_SHA1_DIGEST_LENGTH bytes 36 * available 37 * \return the SHA1 digest of the given data 38 */ 39 unsigned char *ldns_sha1(const unsigned char *data, unsigned int data_len, unsigned char *digest); 40 41 #ifdef __cplusplus 42 } 43 #endif 44 45 #endif /* LDNS_SHA1_H */ 46