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
{
31
CHECKSUM_TYPE_NONE
,
32
CHECKSUM_TYPE_CRC32C
,
33
CHECKSUM_TYPE_SHA224
,
34
CHECKSUM_TYPE_SHA256
,
35
CHECKSUM_TYPE_SHA384
,
36
CHECKSUM_TYPE_SHA512
,
37
}
pg_checksum_type
;
38
39
/*
40
* This is just a union of all applicable context types.
41
*/
42
typedef
union
pg_checksum_raw_context
43
{
44
pg_crc32c
c_crc32c
;
45
pg_cryptohash_ctx
*
c_sha2
;
46
}
pg_checksum_raw_context
;
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
{
54
pg_checksum_type
type
;
55
pg_checksum_raw_context
raw_context
;
56
}
pg_checksum_context
;
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
*);
65
extern
char
*
pg_checksum_type_name
(
pg_checksum_type
);
66
67
extern
int
pg_checksum_init
(
pg_checksum_context
*,
pg_checksum_type
);
68
extern
int
pg_checksum_update
(
pg_checksum_context
*,
const
uint8
*
input
,
69
size_t
len
);
70
extern
int
pg_checksum_final
(
pg_checksum_context
*,
uint8
*
output
);
71
72
#endif
uint8
uint8_t uint8
Definition:
c.h:483
pg_checksum_context
struct pg_checksum_context pg_checksum_context
pg_checksum_final
int pg_checksum_final(pg_checksum_context *, uint8 *output)
Definition:
checksum_helper.c:176
pg_checksum_update
int pg_checksum_update(pg_checksum_context *, const uint8 *input, size_t len)
Definition:
checksum_helper.c:145
pg_checksum_type_name
char * pg_checksum_type_name(pg_checksum_type)
Definition:
checksum_helper.c:56
pg_checksum_type
pg_checksum_type
Definition:
checksum_helper.h:30
CHECKSUM_TYPE_SHA384
@ CHECKSUM_TYPE_SHA384
Definition:
checksum_helper.h:35
CHECKSUM_TYPE_SHA256
@ CHECKSUM_TYPE_SHA256
Definition:
checksum_helper.h:34
CHECKSUM_TYPE_SHA224
@ CHECKSUM_TYPE_SHA224
Definition:
checksum_helper.h:33
CHECKSUM_TYPE_NONE
@ CHECKSUM_TYPE_NONE
Definition:
checksum_helper.h:31
CHECKSUM_TYPE_CRC32C
@ CHECKSUM_TYPE_CRC32C
Definition:
checksum_helper.h:32
CHECKSUM_TYPE_SHA512
@ CHECKSUM_TYPE_SHA512
Definition:
checksum_helper.h:36
pg_checksum_init
int pg_checksum_init(pg_checksum_context *, pg_checksum_type)
Definition:
checksum_helper.c:83
pg_checksum_parse_type
bool pg_checksum_parse_type(char *name, pg_checksum_type *)
Definition:
checksum_helper.c:28
pg_checksum_raw_context
union pg_checksum_raw_context pg_checksum_raw_context
cryptohash.h
input
FILE * input
output
FILE * output
Definition:
pg_test_timing.c:182
pg_crc32c.h
pg_crc32c
uint32 pg_crc32c
Definition:
pg_crc32c.h:38
len
const void size_t len
Definition:
pg_crc32c_sse42.c:25
sha2.h
pg_checksum_context
Definition:
checksum_helper.h:53
pg_checksum_context::type
pg_checksum_type type
Definition:
checksum_helper.h:54
pg_checksum_context::raw_context
pg_checksum_raw_context raw_context
Definition:
checksum_helper.h:55
pg_cryptohash_ctx
Definition:
cryptohash.c:52
pg_checksum_raw_context
Definition:
checksum_helper.h:43
pg_checksum_raw_context::c_sha2
pg_cryptohash_ctx * c_sha2
Definition:
checksum_helper.h:45
pg_checksum_raw_context::c_crc32c
pg_crc32c c_crc32c
Definition:
checksum_helper.h:44
name
const char * name
Definition:
wait_event_funcs.c:28
src
include
common
checksum_helper.h
Generated on Sat Dec 14 2024 12:13:24 for PostgreSQL Source Code by
1.9.1