2020-10-19 21:56:12 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
/* SlunkCrypt, by LoRd_MuldeR <MuldeR2@GMX.de> */
|
|
|
|
/* This work has been released under the CC0 1.0 Universal license! */
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
#ifndef INC_SLUNKCRYPT_H
|
|
|
|
#define INC_SLUNKCRYPT_H
|
|
|
|
|
2021-03-24 20:21:59 +01:00
|
|
|
/*
|
|
|
|
* Compiler check
|
|
|
|
*/
|
|
|
|
#if defined(__cplusplus) && (__cplusplus < 201103L) && (!defined(_MSVC_LANG) || (_MSVC_LANG < 201103L))
|
|
|
|
#error This file requires compiler and library support for the ISO C++11 standard.
|
|
|
|
#elif !defined(__cplusplus) && (!defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L)) && (!defined(_MSC_VER) || (_MSC_VER < 1600))
|
|
|
|
#error This file requires compiler and library support for the ISO C99 standard.
|
|
|
|
#endif
|
|
|
|
|
2020-10-19 21:56:12 +02:00
|
|
|
/*
|
2020-10-24 15:06:12 +02:00
|
|
|
* Build options
|
2020-10-19 21:56:12 +02:00
|
|
|
*/
|
2020-10-24 15:06:12 +02:00
|
|
|
#ifndef SLUNKCRYPT_SHARED
|
|
|
|
#define SLUNKCRYPT_SHARED 0
|
|
|
|
#endif
|
|
|
|
#ifndef SLUNKCRYPT_EXPORT
|
|
|
|
#define SLUNKCRYPT_EXPORT 0
|
|
|
|
#endif
|
2020-10-20 15:21:00 +02:00
|
|
|
|
2020-10-24 15:51:13 +02:00
|
|
|
/*
|
|
|
|
* DLL support
|
|
|
|
*/
|
2020-10-24 15:06:12 +02:00
|
|
|
#if defined(_MSC_VER) && SLUNKCRYPT_SHARED
|
|
|
|
#if SLUNKCRYPT_EXPORT
|
|
|
|
#define SLUNKCRYPT_API __declspec(dllexport)
|
|
|
|
#else
|
|
|
|
#define SLUNKCRYPT_API __declspec(dllimport)
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#define SLUNKCRYPT_API
|
|
|
|
#endif
|
2020-10-24 15:51:13 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* C++ support
|
|
|
|
*/
|
|
|
|
#ifndef __cplusplus
|
2020-10-24 15:06:12 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdint.h>
|
2020-10-24 15:51:13 +02:00
|
|
|
#else
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstdint>
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
2020-10-19 21:56:12 +02:00
|
|
|
|
2020-10-24 15:51:13 +02:00
|
|
|
/*
|
|
|
|
* Opaque handle to internal state
|
|
|
|
*/
|
2020-10-19 21:56:12 +02:00
|
|
|
typedef uintptr_t slunkcrypt_t;
|
2020-10-20 15:21:00 +02:00
|
|
|
#define SLUNKCRYPT_NULL ((slunkcrypt_t)NULL)
|
2020-10-19 21:56:12 +02:00
|
|
|
|
2021-04-01 01:58:39 +02:00
|
|
|
/*
|
|
|
|
* Mode of operation
|
|
|
|
*/
|
|
|
|
static const int SLUNKCRYPT_ENCRYPT = 0;
|
|
|
|
static const int SLUNKCRYPT_DECRYPT = 1;
|
|
|
|
|
2020-10-19 21:56:12 +02:00
|
|
|
/*
|
2020-10-20 15:21:00 +02:00
|
|
|
* Error codes
|
2020-10-19 21:56:12 +02:00
|
|
|
*/
|
2020-10-24 15:51:13 +02:00
|
|
|
static const int SLUNKCRYPT_SUCCESS = 0;
|
2020-10-20 15:21:00 +02:00
|
|
|
static const int SLUNKCRYPT_FAILURE = -1;
|
|
|
|
static const int SLUNKCRYPT_ABORTED = -2;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Limits
|
|
|
|
*/
|
2021-03-26 01:14:33 +01:00
|
|
|
static const size_t SLUNKCRYPT_PWDLEN_MIN = 8U;
|
|
|
|
static const size_t SLUNKCRYPT_PWDLEN_MAX = 256U;
|
2020-10-19 21:56:12 +02:00
|
|
|
|
2020-10-24 15:06:12 +02:00
|
|
|
/*
|
|
|
|
* Version info
|
|
|
|
*/
|
|
|
|
SLUNKCRYPT_API extern const uint16_t SLUNKCRYPT_VERSION_MAJOR;
|
|
|
|
SLUNKCRYPT_API extern const uint16_t SLUNKCRYPT_VERSION_MINOR;
|
|
|
|
SLUNKCRYPT_API extern const uint16_t SLUNKCRYPT_VERSION_PATCH;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Build date and time
|
|
|
|
*/
|
|
|
|
SLUNKCRYPT_API extern const char *const SLUNKCRYPT_BUILD;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Abort flag
|
|
|
|
*/
|
|
|
|
SLUNKCRYPT_API extern volatile int g_slunkcrypt_abort_flag;
|
|
|
|
|
2020-10-22 18:01:59 +02:00
|
|
|
/*
|
2020-10-28 14:40:13 +01:00
|
|
|
* Nonce generator
|
2020-10-19 21:56:12 +02:00
|
|
|
*/
|
2021-04-01 23:37:37 +02:00
|
|
|
SLUNKCRYPT_API int slunkcrypt_generate_nonce(uint64_t *const nonce);
|
2020-10-19 21:56:12 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate, reset or free state
|
|
|
|
*/
|
2021-04-01 01:58:39 +02:00
|
|
|
SLUNKCRYPT_API slunkcrypt_t slunkcrypt_alloc(const uint64_t nonce, const uint8_t *const passwd, const size_t passwd_len, const int mode);
|
|
|
|
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);
|
2020-10-24 15:06:12 +02:00
|
|
|
SLUNKCRYPT_API void slunkcrypt_free(const slunkcrypt_t context);
|
2020-10-19 21:56:12 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Encryption routines
|
|
|
|
*/
|
2021-04-01 23:37:37 +02:00
|
|
|
SLUNKCRYPT_API int slunkcrypt_process(const slunkcrypt_t context, const uint8_t *const input, uint8_t *const output, size_t length);
|
2021-04-02 16:37:19 +02:00
|
|
|
SLUNKCRYPT_API int slunkcrypt_inplace(const slunkcrypt_t context, uint8_t *const buffer, size_t length);
|
2020-10-19 21:56:12 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Auxiliary functions
|
|
|
|
*/
|
2021-04-01 23:37:37 +02:00
|
|
|
SLUNKCRYPT_API size_t slunkcrypt_random_bytes(uint8_t *const buffer, const size_t length);
|
|
|
|
SLUNKCRYPT_API void slunkcrypt_bzero(void *const buffer, const size_t length);
|
2020-10-19 21:56:12 +02:00
|
|
|
|
2020-10-24 15:51:13 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
2020-10-19 21:56:12 +02:00
|
|
|
#endif
|