1 /* calc_sums.h */
2 #ifndef CALC_SUMS_H
3 #define CALC_SUMS_H
4 
5 #include "common_func.h"
6 #include "file.h"
7 #include "hash_check.h"
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 /**
14  * Information about a file to calculate/verify message digests for.
15  */
16 struct file_info {
17 	uint64_t size;          /* the size of the hashed file */
18 	uint64_t msg_offset;    /* rctx->msg_size before hashing this file */
19 	double time;            /* file processing time in seconds */
20 	file_t* file;           /* the file being processed */
21 	struct rhash_context* rctx; /* state of hash algorithms */
22 	struct hash_parser* hp;  /* parsed line of a hash file */
23 	unsigned sums_flags;    /* mask of ids of calculated hash functions */
24 	int processing_result;  /* -1/-2 for i/o error, 0 on success, 1 on a hash mismatch */
25 };
26 
27 int calc_sums(struct file_info* info);
28 int calculate_and_print_sums(FILE* out, file_t* out_file, file_t* file);
29 int find_embedded_crc32(file_t* file, unsigned* crc32);
30 int rename_file_by_embeding_crc32(struct file_info* info);
31 int save_torrent_to(file_t* torrent_file, struct rhash_context* rctx);
32 
33 /* Benchmarking */
34 
35 /** Benchmarking flag: measure the CPU "clocks per byte" speed */
36 #define BENCHMARK_CPB 1
37 /** Benchmarking flag: print benchmark result in tab-delimited format */
38 #define BENCHMARK_RAW 2
39 
40 /**
41  * Benchmark a hash algorithm.
42  *
43  * @param hash_id hash algorithm identifier
44  * @param flags benchmark flags, can contain BENCHMARK_CPB, BENCHMARK_RAW
45  */
46 void run_benchmark(unsigned hash_id, unsigned flags);
47 
48 #ifdef __cplusplus
49 } /* extern "C" */
50 #endif /* __cplusplus */
51 
52 #endif /* CALC_SUMS_H */
53