4 * Copyright (c) 2008- Steve McIntyre <steve@einval.com>
6 * Definitions and prototypes for a generic checksum interface, used
7 * in JTE. Inspired heavily by the interface to the MD5 code we're
22 #define CHECK_MD5_USED (1 << CHECK_MD5)
23 #define CHECK_SHA1_USED (1 << CHECK_SHA1)
24 #define CHECK_SHA256_USED (1 << CHECK_SHA256)
25 #define CHECK_SHA512_USED (1 << CHECK_SHA512)
26 #define CHECK_ALL_USED 0xFFFFFFFF
28 typedef void checksum_context_t;
37 /* Ask the library for information about a particular checksum
38 * algorithm. Returns a pointer to internal memory - DO NOT
40 struct checksum_info *checksum_information(enum checksum_types which);
42 /* Allocate / initialise a context for the chosen checksums. OR
43 * together the desired checksums as the parameter */
44 checksum_context_t *checksum_init_context(int checksums, const char *owner);
46 /* Cleanup and free a context when it's finished with */
47 void checksum_free_context(checksum_context_t *context);
49 /* Pass a new buffer full of data through the checksum code */
50 void checksum_update(checksum_context_t *context,
51 unsigned char const *buf,
54 /* Finish the current set of checksums */
55 void checksum_final(checksum_context_t *context);
57 /* Extract a particular algorithm's checksum once checksum_final() has
58 * been called. Use the details in checksum_information() above first
59 * to see how big the digest will be. Only valid once checksum_final()
60 * has been called, otherwise the digest returned will be all
62 void checksum_copy(checksum_context_t *context,
63 enum checksum_types which,
64 unsigned char *digest);
66 /* Helper function: return a pointer to a string containing the ASCII
67 * hexadecimal dump of a checksum. Only valid once checksum_final()
68 * has been called, otherwise will return NULL */
69 const char * checksum_hex(checksum_context_t *context,
70 enum checksum_types which);
73 extern int parse_checksum_algo(char *arg,