//========================================================================
// ECrypt
//
// AUTHOR:  Gabor Nagy
// DATE:    2024-Jan-10 18:19:28
//
// Copyright (C) 1996-2026 by Gabor Nagy. All rights reserved.
//========================================================================
#ifndef _ECrypt_h
#define _ECrypt_h

#include <sys/stat.h>

#if defined (__cplusplus) && (!(defined (__CPLUSLIBS)))
extern "C" {
#endif

#define	ECrNONE          -1

#define ECrAlgorithm0       37
#define ECrVersion           1
#define	ECrMAX_MAGICLENGTH   9    // A magic number maximalis hossza
#define	ECrMagicLength       4    // A magic number hossza
#define	ECrVersionLength     2    // A verzioszam hossza
#define	ECrModeLength        4    // A file mode hossza
#define	ECrTimeLength        4    // A file mode hossza

#define	ECrMAX_PASSWORDLENGTH  16

enum { ECrCHECKWF_NONE = 0, ECrCHECKWF_FILE1, ECrCHECKWF_FILE2, ECrCHECKWF_FILE3, ECrCHECKWF_FILE4, ECrCHECKWF_FILE5 };

//--------------------------------------------------------------------------------
// Length of info-block's informative part: info-block length, algorythm
// alternators, magic numbers, version, file mode, ATime, MTime, CTime
//--------------------------------------------------------------------------------
#define	ECrMinInfoLength  (2 + ECrMAX_PASSWORDLENGTH + ECrMagicLength + ECrVersionLength + ECrModeLength + ECrTimeLength + ECrTimeLength + ECrTimeLength)


#define	ECrInfoOffset          87   // Az info blokk a file elejetol itt kezdodik

enum { ECrPASSWORD_REMOVED = 0, ECrPASSWORD_ON, ECrPASSWORD_OFF, ECrTIMER_RESET };

#ifdef _ECrypt0_c
#else
extern int     ECr_CCnt;
extern char    ECr_Jelszo[ECrMAX_PASSWORDLENGTH];

extern int     ECr_CheckPWWithFile;
extern char    ECr_CheckFile1[256];
extern char    ECr_CheckFile2[256];
extern char    ECr_CheckFile3[256];
extern char    ECr_CheckFile4[256];
extern char    ECr_CheckFile5[256];

extern EBool   ECr_RestoreTimeAfterEnc, ECr_RestoreTimeAfterDec;

extern EBool   ECr_IsEncrypted(const char* PPassword, FILE* PFile, const EIndex PFileLength, int* PInfoOffsetR, int* PInfoLengthR, int* PAlgorithmR, uint8_t* PAlternatorsR, uint8_t* PInfoBlockR);
extern EBool   ECr_SaveEncrypted(const char* PPassword, const char* PBuffer, const EIndex PBytes, const int PSalt,  FILE* PFile, const struct stat* PFStat);

#endif // _ECrypt0_c

extern void   ECr_Encrypt0(const char* PPassword, uint8_t* PBuffer, const EIndex PLength, const uint8_t* PAlternators);
extern EBool  ECr_Titkosits0(const char* PPassword, const char* PFileName, const int PSalt, const EBool PRecrypt);
extern int    ECr_DecryptToMemory(const char* PPassword, FILE* PInFile, char** PBuffer, EIndex* PLength, uint8_t* PInfoBlockPtr);

#if defined (__cplusplus) && (!(defined (__CPLUSLIBS)))
} // Close scope of 'extern "C"' declaration
#endif

#endif // _ECrypt_h
