"Fossies" - the Fresh Open Source Software Archive

Member "xorriso-1.5.4/libjte/checksum.h" (30 Jan 2021, 3456 Bytes) of package /linux/misc/xorriso-1.5.4.pl02.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "checksum.h" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 1.5.2_vs_1.5.4.

    1 /*
    2  * checksum.h
    3  *
    4  * Copyright (c) 2008-2019 Steve McIntyre <steve@einval.com>
    5  *
    6  * Definitions and prototypes for a generic checksum interface, used
    7  * in JTE. Inspired heavily by the interface to the MD5 code we're
    8  * using already.
    9  *
   10  * GNU GPL v2
   11  */
   12 
   13 #ifndef _JTE_CHECKSUM_H_
   14 #define _JTE_CHECKSUM_H_
   15 
   16 enum checksum_types
   17 {
   18     CHECK_MD5 = 0,
   19     CHECK_SHA1,
   20     CHECK_SHA256,
   21     CHECK_SHA512,
   22     NUM_CHECKSUMS
   23 };
   24 
   25 #define CHECK_MD5_USED     (1 << CHECK_MD5)
   26 #define CHECK_SHA1_USED    (1 << CHECK_SHA1)
   27 #define CHECK_SHA256_USED  (1 << CHECK_SHA256)
   28 #define CHECK_SHA512_USED  (1 << CHECK_SHA512)
   29 #define CHECK_ALL_USED     0xFFFFFFFF
   30 
   31 typedef void checksum_context_t;
   32 
   33 struct checksum_info
   34 {
   35     char          *name;
   36     char          *prog;
   37     int            digest_size;
   38 };
   39 
   40 /* Ask the library for information about a particular checksum
   41  * algorithm. Returns a pointer to internal memory - DO NOT
   42  * MODIFY/FREE! */
   43 struct checksum_info *checksum_information(enum checksum_types which);
   44 
   45 /* Allocate / initialise a context for the chosen checksums. OR
   46  * together the desired checksums as the parameter */
   47 checksum_context_t   *checksum_init_context(int checksums, const char *owner);
   48 
   49 /* Cleanup and free a context when it's finished with */
   50 void                  checksum_free_context(checksum_context_t *context);
   51 
   52 /* Pass a new buffer full of data through the checksum code */
   53 void                  checksum_update(checksum_context_t *context,
   54                                       unsigned char const *buf,
   55                                       unsigned int len);
   56 
   57 /* Finish the current set of checksums */
   58 void                  checksum_final(checksum_context_t *context);
   59 
   60 /* Extract a particular algorithm's checksum once checksum_final() has
   61  * been called. Use the details in checksum_information() above first
   62  * to see how big the digest will be. Only valid once checksum_final()
   63  * has been called, otherwise the digest returned will be all
   64  * zeroes. */
   65 void                  checksum_copy(checksum_context_t *context,
   66                                     enum checksum_types which,
   67                                     unsigned char *digest);
   68 
   69 /* Helper function: return a pointer to a string containing the ASCII
   70  * hexadecimal dump of a checksum. Only valid once checksum_final()
   71  * has been called, otherwise will return NULL */
   72 const char *          checksum_hex(checksum_context_t *context,
   73                                    enum checksum_types which);
   74 
   75 
   76 extern int            parse_checksum_algo(char *arg,
   77                                           int *algo);
   78 
   79 /* Helper function: Simply calculate the checksum of the first "size"
   80  * bytes of a file using the specified algorithm. If size == -1,
   81  * calculate the checksum for the whole of the file. The caller is
   82  * responsible for passing in a large enough buffer as "digest", based
   83  * on their choice of algorithm. */
   84 extern int            checksum_calculate(char *filename,
   85                                          int64_t size,
   86                                          unsigned char *digest,
   87                                          enum checksum_types which);
   88 
   89 
   90 /* Helper function: Parse a hexadecimal string "in" of length "size"
   91    characters (must be even) and convert to a raw checksum in
   92    "out". out must be allocated of a large-enough size by the
   93    caller */
   94 int checksum_parse_hex(char *in, unsigned char *out, int size);
   95 
   96 #endif
   97 /* _JTE_CHECKSUM_H_ */