1 /******************************************************************************/
2 /* SlunkCrypt, by LoRd_MuldeR <MuldeR2@GMX.de> */
3 /* This work has been released under the CC0 1.0 Universal license! */
4 /******************************************************************************/
6 #ifndef INC_SLUNKCRYPT_H
7 #define INC_SLUNKCRYPT_H
12 #if defined(__cplusplus) && (__cplusplus < 201103L) && (!defined(_MSVC_LANG) || (_MSVC_LANG < 201103L))
13 #error This file requires compiler and library support for the ISO C++11 standard.
14 #elif !defined(__cplusplus) && (!defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L)) && (!defined(_MSC_VER) || (_MSC_VER < 1600))
15 #error This file requires compiler and library support for the ISO C99 standard.
21 #ifndef SLUNKCRYPT_SHARED
22 #define SLUNKCRYPT_SHARED 0
24 #ifndef SLUNKCRYPT_EXPORT
25 #define SLUNKCRYPT_EXPORT 0
31 #if defined(_MSC_VER) && SLUNKCRYPT_SHARED
33 #define SLUNKCRYPT_API __declspec(dllexport)
35 #define SLUNKCRYPT_API __declspec(dllimport)
38 #define SLUNKCRYPT_API
54 * Opaque handle to internal state
56 typedef uintptr_t slunkcrypt_t;
57 #define SLUNKCRYPT_NULL ((slunkcrypt_t)NULL)
62 static const int SLUNKCRYPT_ENCRYPT = 0;
63 static const int SLUNKCRYPT_DECRYPT = 1;
68 static const int SLUNKCRYPT_SUCCESS = 0;
69 static const int SLUNKCRYPT_FAILURE = -1;
70 static const int SLUNKCRYPT_ABORTED = -2;
75 static const size_t SLUNKCRYPT_PWDLEN_MIN = 8U;
76 static const size_t SLUNKCRYPT_PWDLEN_MAX = 256U;
81 static const uint16_t SLUNKCRYPT_PARAM_VERSION = 1U;
84 uint16_t version; /* Must set to SLUNKCRYPT_PARAM_VERSION */
85 size_t thread_count; /* Number of threads, set to 0 for auto-detection */
92 SLUNKCRYPT_API extern const uint16_t SLUNKCRYPT_VERSION_MAJOR;
93 SLUNKCRYPT_API extern const uint16_t SLUNKCRYPT_VERSION_MINOR;
94 SLUNKCRYPT_API extern const uint16_t SLUNKCRYPT_VERSION_PATCH;
99 SLUNKCRYPT_API extern const char *const SLUNKCRYPT_BUILD;
104 SLUNKCRYPT_API extern volatile int g_slunkcrypt_abort_flag;
109 SLUNKCRYPT_API int slunkcrypt_generate_nonce(uint64_t *const nonce);
112 * Allocate, reset or free state
114 SLUNKCRYPT_API slunkcrypt_t slunkcrypt_alloc(const uint64_t nonce, const uint8_t *const passwd, const size_t passwd_len, const int mode);
115 SLUNKCRYPT_API slunkcrypt_t slunkcrypt_alloc_ext(const uint64_t nonce, const uint8_t *const passwd, const size_t passwd_len, const int mode, const slunkparam_t *const param);
116 SLUNKCRYPT_API int slunkcrypt_reset(const slunkcrypt_t context, const uint64_t nonce, const uint8_t *const passwd, const size_t passwd_len, const int mode);
117 SLUNKCRYPT_API void slunkcrypt_free(const slunkcrypt_t context);
120 * Encryption routines
122 SLUNKCRYPT_API int slunkcrypt_process(const slunkcrypt_t context, const uint8_t *const input, uint8_t *const output, size_t length);
123 SLUNKCRYPT_API int slunkcrypt_inplace(const slunkcrypt_t context, uint8_t *const buffer, size_t length);
126 * Auxiliary functions
128 SLUNKCRYPT_API size_t slunkcrypt_random_bytes(uint8_t *const buffer, const size_t length);
129 SLUNKCRYPT_API void slunkcrypt_bzero(void *const buffer, const size_t length);
134 #define SLUNKCRYPT_SAFE_FREE(X) do { if((X) != SLUNKCRYPT_NULL) { slunkcrypt_free((X)); X = SLUNKCRYPT_NULL; } } while(0)