3#if !defined(ORG_FOSSIL_SCM_FSL_HASH_H_INCLUDED)
4#define ORG_FOSSIL_SCM_FSL_HASH_H_INCLUDED
19#if !defined(FSL_SHA1_HARDENED)
20# define FSL_SHA1_HARDENED 1
22#if defined(__cplusplus)
78#define FSL_MD5_INITIAL_HASH "d41d8cd98f00b204e9800998ecf8427e"
101 unsigned char in[64];
110#define fsl_md5_cx_empty_m { \
112 {0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476 }, \
114 {0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, \
115 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, \
116 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, \
229typedef void(*fsl_sha1h_collision_callback)(uint64_t,
const uint32_t*,
const uint32_t*,
const uint32_t*,
const uint32_t*);
261 int reduced_round_coll;
262 fsl_sha1h_collision_callback callback;
267 uint32_t states[80][5];
278#define fsl_sha1_cx_empty_m {0}
280#define fsl_sha1_cx_empty_m { \
281 {0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0 }, \
283 {0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, \
284 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0 \
451 unsigned char x[1600];
557 const char *zHash,
int nHash);
564 const char *zUnknown);
566#if defined(__cplusplus)
uint64_t fsl_size_t
fsl_size_t is an unsigned integer type used to denote absolute ranges and lengths.
int64_t fsl_int_t
fsl_int_t is a signed integer type used to denote "relative" ranges and lengths, or to tell a routine...
FSL_EXPORT const fsl_md5_cx fsl_md5_cx_empty
Equivalent to fsl_md5_cx_empty_m but suitable for non-const copy initialization.
FSL_EXPORT void fsl_sha3_digest_to_base16(unsigned char const *digest, char *zBuf)
SHA3-256 counterpart of fsl_sha1_digest_to_base16().
FSL_EXPORT void fsl_md5_update_buffer(fsl_md5_cx *cx, fsl_buffer const *b)
Equivalent to fsl_md5_update(cx, b->mem, b->used).
FSL_EXPORT int fsl_md5_update_stream(fsl_md5_cx *cx, fsl_input_f src, void *srcState)
Reads all input from src() and passes it through fsl_md5_update(cx,...).
FSL_EXPORT int fsl_sha1sum_buffer(fsl_buffer const *pIn, fsl_buffer *pCksum)
Computes the SHA1 checksum of pIn and stores the resulting checksum in the buffer pCksum.
FSL_EXPORT void fsl_md5_init(fsl_md5_cx *cx)
Initializes the given context pointer.
FSL_EXPORT char * fsl_md5sum_cstr(const char *zIn, fsl_int_t len)
The md5 counterpart of fsl_sha1sum_cstr(), identical in semantics except that its result is an MD5 ha...
FSL_EXPORT int fsl_md5sum_buffer(fsl_buffer const *pIn, fsl_buffer *pCksum)
The md5 counterpart of fsl_sha1sum_buffer(), identical in semantics except that its result is an MD5 ...
FSL_EXPORT int fsl_sha1sum_stream(fsl_input_f src, void *srcState, fsl_buffer *pCksum)
Consumes all input from src and calculates its SHA1 hash.
FSL_EXPORT int fsl_sha1sum_buffer2(fsl_buffer const *pIn, fsl_buffer *pCksum)
Works like fsl_sha1sum_buffer() except that it appends the hash to the target buffer,...
FSL_EXPORT int fsl_md5sum_stream(fsl_input_f src, void *srcState, fsl_buffer *pCksum)
The MD5 counter part to fsl_sha1sum_stream(), with identical semantics except that the generated hash...
FSL_EXPORT int fsl_md5_update_filename(fsl_md5_cx *cx, char const *fname)
A fsl_md5_update_stream() proxy which updates cx to include the contents of the given file.
FSL_EXPORT char * fsl_sha3sum_cstr(const char *zIn, fsl_int_t len)
SHA3 counter part of fsl_sha1sum_cstr().
FSL_EXPORT int fsl_sha1sum_filename(const char *zFilename, fsl_buffer *pCksum)
A fsl_sha1sum_stream() wrapper which calculates the SHA1 of given file.
FSL_EXPORT fsl_hash_types_e fsl_validate_hash(const char *zHash, fsl_size_t nHash)
Expects zHash to be a full-length hash value of one of the fsl_hash_types_t-specified types,...
FSL_EXPORT fsl_hash_types_e fsl_verify_blob_hash(fsl_buffer const *pIn, const char *zHash, int nHash)
Expects (zHash, nHash) to refer to a full hash (of a supported content hash type) of pIn's contents.
FSL_EXPORT int fsl_md5sum_filename(const char *zFilename, fsl_buffer *pCksum)
The MD5 counter part to fsl_sha1sum_filename(), with identical semantics except that the generated ha...
FSL_EXPORT void fsl_md5_digest_to_base16(unsigned char const *digest, char *zBuf)
Converts an md5 digest value (from fsl_md5_final()'s 2nd parameter) to a 32-byte (FSL_STRLEN_MD5) CRC...
FSL_EXPORT void fsl_sha1_update(fsl_sha1_cx *context, void const *data, fsl_size_t len)
Updates the given context to include the hash of the first len bytes of the given data.
FSL_EXPORT void fsl_sha3_update(fsl_sha3_cx *cx, void const *data, unsigned int len)
Updates cx's state to include the first len bytes of data.
FSL_EXPORT unsigned char const * fsl_sha3_end(fsl_sha3_cx *cx)
To be called when SHA3 hashing is complete: finishes the hash calculation and populates cx->hex with ...
FSL_EXPORT void fsl_sha1_init(fsl_sha1_cx *context)
Initializes the given context with the initial SHA1 state.
FSL_EXPORT int fsl_sha3sum_stream(fsl_input_f src, void *srcState, fsl_buffer *pCksum)
SHA3 counterpart of fsl_sha1sum_stream().
FSL_EXPORT void fsl_md5_final(fsl_md5_cx *cx, unsigned char *digest)
Finishes up the calculation of the md5 for the given context and writes a 16-byte digest value to the...
FSL_EXPORT int fsl_sha3sum_buffer(fsl_buffer const *pIn, fsl_buffer *pCksum)
SHA3 counter part of fsl_sha1sum_buffer().
fsl_sha3_hash_size
Legal values for SHA3 hash sizes, in bits: an increment of 32 bits in the inclusive range (128....
@ FSL_SHA3_INVALID
Sentinel value.
FSL_EXPORT enum fsl_sha3_hash_size fsl_sha3_hash_size_for_int(int)
If the given number is a valid fsl_sha3_hash_size value, its enum entry is returned,...
FSL_EXPORT void fsl_sha3_init2(fsl_sha3_cx *cx, enum fsl_sha3_hash_size sz)
Initialize a new hash.
FSL_EXPORT void fsl_sha3_init(fsl_sha3_cx *cx)
Equivalent to fsl_sha3_init2(cx, FSL_SHA3_DEFAULT).
FSL_EXPORT void fsl_md5_update_cstr(fsl_md5_cx *cx, char const *str, fsl_int_t len)
Passes the first len bytes of str to fsl_md5_update(cx).
FSL_EXPORT const char * fsl_sha1_final_hex(fsl_sha1_cx *context, char *zHex)
A convenience form of fsl_sha1_final() which writes FSL_STRLEN_SHA1+1 bytes (hash plus terminating NU...
FSL_EXPORT char * fsl_sha1sum_cstr(const char *zIn, fsl_int_t len)
Computes the SHA1 checksum of the first len bytes of the given string.
FSL_EXPORT void fsl_md5_update(fsl_md5_cx *cx, void const *buf, fsl_size_t len)
Updates cx's state to reflect the addition of the data specified by the range (buf,...
FSL_EXPORT void fsl_sha1_digest_to_base16(unsigned char const *digest, char *zBuf)
Convert a digest into base-16.
FSL_EXPORT const char * fsl_hash_type_name(fsl_hash_types_e h, const char *zUnknown)
Returns a human-readable name for the given hash type, or its second argument h is not a supported ha...
FSL_EXPORT const fsl_sha1_cx fsl_sha1_cx_empty
fsl_sha1_cx instance intended for copy initialization.
fsl_hash_constants
Various set-in-stone constants used by the API.
@ FSL_STRLEN_SHA1
The length, in bytes, of a hex-format SHA1 hash string.
@ FSL_STRLEN_MD5
The length, in bytes, of a hex-format MD5 hash string.
@ FSL_UUID_STRLEN_MIN
Minimum length of a full fossil UUID.
@ FSL_STRLEN_K256
The length, in bytes, of a hex-format SHA3-256 hash string.
@ FSL_UUID_STRLEN_MAX
Maximum length of a full fossil UUID.
fsl_hash_types_e
Unique IDs for hash types supported by fossil.
@ FSL_HTYPE_ERROR
Invalid hash type.
@ FSL_HTYPE_K256
SHA3-256.
FSL_EXPORT int fsl_sha1sum_update_stream(fsl_sha1_cx *ctx, fsl_input_f src, void *srcState)
Reads all input from src() and passes it through fsl_sha1_update(cx,...).
FSL_EXPORT int fsl_sha3sum_filename(const char *zFilename, fsl_buffer *pCksum)
SHA3 counterpart of fsl_sha1sum_filename().
FSL_EXPORT int fsl_sha1_final(fsl_sha1_cx *context, unsigned char *digest)
Add padding and finalizes the message digest.
A general-purpose buffer class, analog to Fossil's Blob class, but it is not called fsl_blob to avoid...
Holds state for MD5 calculations.
Holds state for SHA1 calculations.
Type for holding SHA3 processing state.
enum fsl_sha3_hash_size size
union fsl_sha3_cx::@110263043236320153224353116264214062327335250213 u
This file declares a number of utility classes and routines used by libfossil.
int(* fsl_input_f)(void *state, void *dest, fsl_size_t *n)
Generic interface for streaming in data.