forked from bytemaster/fc
-
Notifications
You must be signed in to change notification settings - Fork 53
/
aes.hpp
58 lines (47 loc) · 1.85 KB
/
aes.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#pragma once
#include <fc/crypto/sha512.hpp>
#include <fc/crypto/sha256.hpp>
#include <fc/uint128.hpp>
#include <fc/fwd.hpp>
#include <vector>
namespace fc {
class path;
class aes_encoder
{
public:
aes_encoder();
~aes_encoder();
void init( const fc::sha256& key, const fc::uint128& init_value );
uint32_t encode( const char* plaintxt, uint32_t len, char* ciphertxt );
// uint32_t final_encode( char* ciphertxt );
private:
struct impl;
fc::fwd<impl,96> my;
};
class aes_decoder
{
public:
aes_decoder();
~aes_decoder();
void init( const fc::sha256& key, const fc::uint128& init_value );
uint32_t decode( const char* ciphertxt, uint32_t len, char* plaintext );
// uint32_t final_decode( char* plaintext );
private:
struct impl;
fc::fwd<impl,96> my;
};
int aes_encrypt(unsigned char *plaintext, int plaintext_len, unsigned char *key,
unsigned char *iv, unsigned char *ciphertext);
int aes_decrypt(unsigned char *ciphertext, int ciphertext_len, unsigned char *key,
unsigned char *iv, unsigned char *plaintext);
std::vector<char> aes_encrypt( const fc::sha512& key, const std::vector<char>& plain_text );
std::vector<char> aes_decrypt( const fc::sha512& key, const std::vector<char>& cipher_text );
/** encrypts plain_text and then includes a checksum that enables us to verify the integrety of
* the file / key prior to decryption.
*/
void aes_save( const fc::path& file, const fc::sha512& key, std::vector<char> plain_text );
/**
* recovers the plain_text saved via aes_save()
*/
std::vector<char> aes_load( const fc::path& file, const fc::sha512& key );
} // namespace fc