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-2024, 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/cryptohash.h"
18 #include "common/sha2.h"
19 #include "port/pg_crc32c.h"
20 
21 /*
22  * Supported checksum types. It's not necessarily the case that code using
23  * these functions needs a cryptographically strong checksum; it may only
24  * need to detect accidental modification. That's why we include CRC-32C: it's
25  * much faster than any of the other algorithms. On the other hand, we omit
26  * MD5 here because any new that does need a cryptographically strong checksum
27  * should use something better.
28  */
29 typedef enum pg_checksum_type
30 {
38 
39 /*
40  * This is just a union of all applicable context types.
41  */
43 {
47 
48 /*
49  * This structure provides a convenient way to pass the checksum type and the
50  * checksum context around together.
51  */
52 typedef struct pg_checksum_context
53 {
57 
58 /*
59  * This is the longest possible output for any checksum algorithm supported
60  * by this file.
61  */
62 #define PG_CHECKSUM_MAX_LENGTH PG_SHA512_DIGEST_LENGTH
63 
64 extern bool pg_checksum_parse_type(char *name, pg_checksum_type *);
66 
69  size_t len);
71 
72 #endif
uint8_t uint8
Definition: c.h:483
struct pg_checksum_context pg_checksum_context
int pg_checksum_final(pg_checksum_context *, uint8 *output)
int pg_checksum_update(pg_checksum_context *, const uint8 *input, size_t len)
char * pg_checksum_type_name(pg_checksum_type)
pg_checksum_type
@ CHECKSUM_TYPE_SHA384
@ CHECKSUM_TYPE_SHA256
@ CHECKSUM_TYPE_SHA224
@ CHECKSUM_TYPE_NONE
@ CHECKSUM_TYPE_CRC32C
@ CHECKSUM_TYPE_SHA512
int pg_checksum_init(pg_checksum_context *, pg_checksum_type)
bool pg_checksum_parse_type(char *name, pg_checksum_type *)
union pg_checksum_raw_context pg_checksum_raw_context
FILE * input
FILE * output
uint32 pg_crc32c
Definition: pg_crc32c.h:38
const void size_t len
pg_checksum_type type
pg_checksum_raw_context raw_context
pg_cryptohash_ctx * c_sha2
const char * name