DSL
hash.h
1 //@AUTOHEADER@BEGIN@
2 /***********************************************************************\
3 | Drift Standard Libraries v1.01 |
4 | Copyright 2010-2023 Drift Solutions / Indy Sams |
5 | Docs and more information available at https://www.driftsolutions.dev |
6 | This file released under the 3-clause BSD license, |
7 | see included DSL.LICENSE.TXT file for details. |
8 \***********************************************************************/
9 //@AUTOHEADER@END@
10 
11 #ifndef _DSL_HASH_H_
12 #define _DSL_HASH_H_
13 
14 #include <drift/rwops.h>
15 
24 struct HASH_NATIVE;
25 struct HASH_PROVIDER;
26 struct HASH_CTX {
27  size_t hashSize;
28  size_t blockSize;
29 
30 #ifndef DOXYGEN_SKIP
31  const HASH_PROVIDER * provider;
32  void *pptr1;
33  const HASH_NATIVE * impl;
34 #endif
35 };
36 
46 DSL_API HASH_CTX * DSL_CC hash_init(const char * name);
47 DSL_API void DSL_CC hash_update(HASH_CTX *ctx, const uint8 *input, size_t length);
48 DSL_API bool DSL_CC hash_finish(HASH_CTX *ctx, uint8 * out, size_t outlen);
49 
50 DSL_API bool DSL_CC hashdata(const char * name, const uint8 *data, size_t datalen, char * out, size_t outlen, bool raw_output = false);
51 DSL_API bool DSL_CC hashfile(const char * name, const char * fn, char * out, size_t outlen, bool raw_output = false);
52 DSL_API bool DSL_CC hashfile_fp(const char * name, FILE * fp, char * out, size_t outlen, bool raw_output = false);
53 DSL_API bool DSL_CC hashfile_rw(const char * name, DSL_FILE * fp, char * out, size_t outlen, bool raw_output = false);
54 
57 #ifndef DOXYGEN_SKIP
58 /* The rest are for internal use only */
59 
60 struct HASH_PROVIDER {
61  const char * const name;
62  HASH_CTX * (*hash_init)(const char * name);
63  void(*hash_update)(HASH_CTX *ctx, const uint8 *input, size_t length);
64  bool(*hash_finish)(HASH_CTX *ctx, uint8 * out, size_t outlen);
65 };
66 
67 struct HASH_NATIVE {
68  int hashSize;
69  int blockSize;
70 
71  bool(*init)(HASH_CTX * ctx);
72  void(*update)(HASH_CTX * ctx, const uint8 *input, size_t length);
73  bool(*finish)(HASH_CTX * ctx, uint8 * out);
74 };
75 
76 DSL_API void DSL_CC dsl_add_hash_provider(const HASH_PROVIDER * p);
77 DSL_API void DSL_CC dsl_remove_hash_provider(const HASH_PROVIDER * p);
78 DSL_API void DSL_CC dsl_get_hash_providers(vector<const HASH_PROVIDER *>& p);
79 
80 DSL_API void DSL_CC dsl_add_native_hash(const char * name, const HASH_NATIVE * p); /* This should be called directly after dsl_init() and before any other DSL functions. The pointer must remain valid until after dsl_cleanup() is called. */
81 extern const HASH_PROVIDER dsl_native_hashers;
82 #endif // DOXYGEN_SKIP
83 
84 #endif // _DSL_HASH_H_
DSL_API bool DSL_CC hashdata(const char *name, const uint8 *data, size_t datalen, char *out, size_t outlen, bool raw_output=false)
Wrapper around hash_init()/hash_update()/hash_finish(). If raw_output == true out will contain binary...
Definition: hash.cpp:83
DSL_API bool DSL_CC hashfile_rw(const char *name, DSL_FILE *fp, char *out, size_t outlen, bool raw_output=false)
Wrapper around hash_init()/hash_update()/hash_finish(). If raw_output == true out will contain binary...
Definition: hash.cpp:133
DSL_API void DSL_CC hash_update(HASH_CTX *ctx, const uint8 *input, size_t length)
Call with the data you want to hash, can be called multiple times to hash a large file in chunks for ...
Definition: hash.cpp:62
DSL_API bool DSL_CC hashfile(const char *name, const char *fn, char *out, size_t outlen, bool raw_output=false)
Wrapper around hash_init()/hash_update()/hash_finish(). If raw_output == true out will contain binary...
Definition: hash.cpp:111
DSL_API HASH_CTX *DSL_CC hash_init(const char *name)
Definition: hash.cpp:49
DSL_API bool DSL_CC hashfile_fp(const char *name, FILE *fp, char *out, size_t outlen, bool raw_output=false)
Wrapper around hash_init()/hash_update()/hash_finish(). If raw_output == true out will contain binary...
Definition: hash.cpp:121
DSL_API bool DSL_CC hash_finish(HASH_CTX *ctx, uint8 *out, size_t outlen)
Finalize hash and store in out. outlen should be >= hashSize in the HASH_CTX struct....
Definition: hash.cpp:68
Definition: rwops.h:22
Definition: hash.h:26
Definition: hash.h:67
Definition: hash.h:60