PostgreSQL Source Code  git master
checksum_helper.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * checksum_helper.h
4  * Compute a checksum of any of various types using common routines
5  *
6  * Portions Copyright (c) 2016-2020, PostgreSQL Global Development Group
7  *
8  * IDENTIFICATION
9  * src/include/common/checksum_helper.h
10  *
11  *-------------------------------------------------------------------------
12  */
13 
14 #ifndef CHECKSUM_HELPER_H
15 #define CHECKSUM_HELPER_H
16 
17 #include "common/sha2.h"
18 #include "port/pg_crc32c.h"
19 
20 /*
21  * Supported checksum types. It's not necessarily the case that code using
22  * these functions needs a cryptographically strong checksum; it may only
23  * need to detect accidental modification. That's why we include CRC-32C: it's
24  * much faster than any of the other algorithms. On the other hand, we omit
25  * MD5 here because any new that does need a cryptographically strong checksum
26  * should use something better.
27  */
28 typedef enum pg_checksum_type
29 {
37 
38 /*
39  * This is just a union of all applicable context types.
40  */
42 {
49 
50 /*
51  * This structure provides a convenient way to pass the checksum type and the
52  * checksum context around together.
53  */
54 typedef struct pg_checksum_context
55 {
59 
60 /*
61  * This is the longest possible output for any checksum algorithm supported
62  * by this file.
63  */
64 #define PG_CHECKSUM_MAX_LENGTH PG_SHA512_DIGEST_LENGTH
65 
66 extern bool pg_checksum_parse_type(char *name, pg_checksum_type *);
68 
70 extern void pg_checksum_update(pg_checksum_context *, const uint8 *input,
71  size_t len);
73 
74 #endif
char * pg_checksum_type_name(pg_checksum_type)
static void output(uint64 loop_count)
uint32 pg_crc32c
Definition: pg_crc32c.h:38
pg_checksum_raw_context raw_context
unsigned char uint8
Definition: c.h:373
struct pg_checksum_context pg_checksum_context
union pg_checksum_raw_context pg_checksum_raw_context
pg_checksum_type
void pg_checksum_init(pg_checksum_context *, pg_checksum_type)
bool pg_checksum_parse_type(char *name, pg_checksum_type *)
int pg_checksum_final(pg_checksum_context *, uint8 *output)
const char * name
Definition: encode.c:561
pg_checksum_type type
void pg_checksum_update(pg_checksum_context *, const uint8 *input, size_t len)