475 |
andreas |
1 |
/*
|
|
|
2 |
* Copyright (C) 2024 by Andreas Theofilu <andreas@theosys.at>
|
|
|
3 |
*
|
|
|
4 |
* This program is free software; you can redistribute it and/or modify
|
|
|
5 |
* it under the terms of the GNU General Public License as published by
|
|
|
6 |
* the Free Software Foundation; either version 3 of the License, or
|
|
|
7 |
* (at your option) any later version.
|
|
|
8 |
*
|
|
|
9 |
* This program is distributed in the hope that it will be useful,
|
|
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
* GNU General Public License for more details.
|
|
|
13 |
*
|
|
|
14 |
* You should have received a copy of the GNU General Public License
|
|
|
15 |
* along with this program; if not, write to the Free Software Foundation,
|
|
|
16 |
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
17 |
*/
|
|
|
18 |
|
|
|
19 |
#ifndef TSCRAMBLE_H
|
|
|
20 |
#define TSCRAMBLE_H
|
|
|
21 |
|
|
|
22 |
#include <string>
|
|
|
23 |
#include <openssl/core.h>
|
|
|
24 |
|
|
|
25 |
#define AES128_KEY_SIZE 16
|
|
|
26 |
#define AES128_SALT_SIZE 8
|
|
|
27 |
|
|
|
28 |
class TScramble
|
|
|
29 |
{
|
|
|
30 |
public:
|
|
|
31 |
TScramble();
|
|
|
32 |
~TScramble();
|
|
|
33 |
|
476 |
andreas |
34 |
bool aesInit(const std::string& key, const std::string& salt);
|
475 |
andreas |
35 |
bool aesDecodeFile(std::ifstream& is);
|
|
|
36 |
bool aesDecodeFile(const std::string& fname);
|
|
|
37 |
unsigned char *getAesKey(size_t& len) { len = AES128_KEY_SIZE; return mAesKey; }
|
|
|
38 |
unsigned char *getAesSalt(size_t& len) { len = AES128_SALT_SIZE; return mAesSalt; }
|
|
|
39 |
unsigned char *getAesIV(size_t& len) { len = AES128_KEY_SIZE; return mAesIV; }
|
|
|
40 |
std::string& getDecrypted() { return mDecrypted; }
|
|
|
41 |
void aesReset() { mAesInitialized = false; }
|
|
|
42 |
|
|
|
43 |
private:
|
|
|
44 |
unsigned char mAesKey[AES128_KEY_SIZE]; // Key used for decryption/encryption
|
|
|
45 |
unsigned char mAesSalt[AES128_SALT_SIZE]; // Salt for decryption/encryption
|
|
|
46 |
unsigned char mAesIV[AES128_KEY_SIZE]; // Initialization Vector
|
|
|
47 |
EVP_CIPHER_CTX *mCtx{nullptr}; // Context
|
|
|
48 |
std::string mDecrypted; // Buffer for clear (decrypted) text
|
|
|
49 |
bool mAesInitialized{false}; // TRUE if initialized
|
|
|
50 |
};
|
|
|
51 |
|
|
|
52 |
#endif // TSCRAMBLE_H
|