DSL
hmac.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_HMAC_H_
12 #define _DSL_HMAC_H_
13 
14 #include <drift/rwops.h>
15 
24 struct HMAC_PROVIDER;
25 struct HMAC_NATIVE;
26 struct HASH_HMAC_CTX {
27  size_t hashSize;
28 
29 #ifndef DOXYGEN_SKIP
30  const HMAC_PROVIDER * provider;
31  void *pptr1;
32  const HMAC_NATIVE * impl;
33 #endif
34 };
35 
46 DSL_API HASH_HMAC_CTX * DSL_CC hmac_init(const char * name, const uint8 *key, size_t length);
47 DSL_API void DSL_CC hmac_update(HASH_HMAC_CTX *ctx, const uint8 *input, size_t length);
48 DSL_API bool DSL_CC hmac_finish(HASH_HMAC_CTX *ctx, uint8 * out, size_t outlen);
49 
50 DSL_API bool DSL_CC hmacdata(const char * name, const uint8 *key, size_t keylen, const uint8 *data, size_t datalen, char * out, size_t outlen);
51 DSL_API bool DSL_CC hmacfile(const char * name, const uint8 *key, size_t keylen, const char * fn, char * out, size_t outlen);
52 DSL_API bool DSL_CC hmacfile_fp(const char * name, const uint8 *key, size_t keylen, FILE * fp, char * out, size_t outlen);
53 DSL_API bool DSL_CC hmacfile_rw(const char * name, const uint8 *key, size_t keylen, DSL_FILE * fp, char * out, size_t outlen);
54 
57 #ifndef DOXYGEN_SKIP
58 
59 struct HMAC_PROVIDER {
60  const char * const name;
61  HASH_HMAC_CTX * (*hmac_init)(const char * name, const uint8 *key, size_t length);
62  void(*hmac_update)(HASH_HMAC_CTX *ctx, const uint8 *input, size_t length);
63  bool(*hmac_finish)(HASH_HMAC_CTX *ctx, uint8 * out, size_t outlen);
64 };
65 
66 struct HMAC_NATIVE {
67  int hashSize;
68 
69  bool(*init)(HASH_HMAC_CTX * ctx, const uint8 *key, size_t length);
70  void(*update)(HASH_HMAC_CTX * ctx, const uint8 *input, size_t length);
71  bool(*finish)(HASH_HMAC_CTX * ctx, uint8 * out);
72 };
73 
74 DSL_API void DSL_CC dsl_add_hmac_provider(const HMAC_PROVIDER * p);
75 DSL_API void DSL_CC dsl_remove_hmac_provider(const HMAC_PROVIDER * p);
76 DSL_API void DSL_CC dsl_get_hmac_providers(vector<const HMAC_PROVIDER *>& p);
77 
78 DSL_API void DSL_CC dsl_add_native_hmac(const char * name, const HMAC_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. */
79 extern const HMAC_PROVIDER dsl_native_hmacers;
80 #endif // DOXYGEN_SKIP
81 
82 #endif // _DSL_HMAC_H_
DSL_API bool DSL_CC hmacfile_rw(const char *name, const uint8 *key, size_t keylen, DSL_FILE *fp, char *out, size_t outlen)
Wrapper around hmac_init()/hmac_update()/hmac_finish(). If raw_output == true out will contain binary...
Definition: hmac.cpp:116
DSL_API bool DSL_CC hmacfile(const char *name, const uint8 *key, size_t keylen, const char *fn, char *out, size_t outlen)
Wrapper around hmac_init()/hmac_update()/hmac_finish(). If raw_output == true out will contain binary...
Definition: hmac.cpp:94
DSL_API bool DSL_CC hmac_finish(HASH_HMAC_CTX *ctx, uint8 *out, size_t outlen)
Finalize HMAC and store in out. outlen should be >= hashSize in the HASH_CTX struct....
Definition: hmac.cpp:66
DSL_API HASH_HMAC_CTX *DSL_CC hmac_init(const char *name, const uint8 *key, size_t length)
Definition: hmac.cpp:47
DSL_API bool DSL_CC hmacdata(const char *name, const uint8 *key, size_t keylen, const uint8 *data, size_t datalen, char *out, size_t outlen)
Wrapper around hmac_init()/hmac_update()/hmac_finish(). If raw_output == true out will contain binary...
Definition: hmac.cpp:73
DSL_API bool DSL_CC hmacfile_fp(const char *name, const uint8 *key, size_t keylen, FILE *fp, char *out, size_t outlen)
Wrapper around hmac_init()/hmac_update()/hmac_finish(). If raw_output == true out will contain binary...
Definition: hmac.cpp:104
DSL_API void DSL_CC hmac_update(HASH_HMAC_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: hmac.cpp:59
Definition: rwops.h:24