Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
checksum_helper.h73 linesDownload Raw Back to common
1/*-------------------------------------------------------------------------2 *3 * checksum_helper.h4 *	  Compute a checksum of any of various types using common routines5 *6 * Portions Copyright (c) 2016-2023, PostgreSQL Global Development Group7 *8 * IDENTIFICATION9 *		  src/include/common/checksum_helper.h10 *11 *-------------------------------------------------------------------------12 */13 14#ifndef CHECKSUM_HELPER_H15#define CHECKSUM_HELPER_H16 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 using23 * these functions needs a cryptographically strong checksum; it may only24 * need to detect accidental modification. That's why we include CRC-32C: it's25 * much faster than any of the other algorithms. On the other hand, we omit26 * MD5 here because any new that does need a cryptographically strong checksum27 * should use something better.28 */29typedef enum pg_checksum_type30{31	CHECKSUM_TYPE_NONE,32	CHECKSUM_TYPE_CRC32C,33	CHECKSUM_TYPE_SHA224,34	CHECKSUM_TYPE_SHA256,35	CHECKSUM_TYPE_SHA384,36	CHECKSUM_TYPE_SHA51237} pg_checksum_type;38 39/*40 * This is just a union of all applicable context types.41 */42typedef union pg_checksum_raw_context43{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 the50 * checksum context around together.51 */52typedef struct pg_checksum_context53{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 supported60 * by this file.61 */62#define PG_CHECKSUM_MAX_LENGTH		PG_SHA512_DIGEST_LENGTH63 64extern bool pg_checksum_parse_type(char *name, pg_checksum_type *);65extern char *pg_checksum_type_name(pg_checksum_type);66 67extern int	pg_checksum_init(pg_checksum_context *, pg_checksum_type);68extern int	pg_checksum_update(pg_checksum_context *, const uint8 *input,69							   size_t len);70extern int	pg_checksum_final(pg_checksum_context *, uint8 *output);71 72#endif73 
codekingpro/portable-devtools · Team Ai