peerplays-fc/include/fc/crypto/aes.hpp

61 lines
2 KiB
C++
Raw Normal View History

#pragma once
2013-08-13 17:57:16 +00:00
#include <fc/crypto/sha512.hpp>
2013-08-25 05:24:07 +00:00
#include <fc/crypto/sha256.hpp>
#include <fc/uint128.hpp>
#include <fc/fwd.hpp>
2013-08-13 17:57:16 +00:00
#include <vector>
namespace fc {
2013-08-31 17:12:55 +00:00
class path;
2013-08-25 05:24:07 +00:00
class aes_encoder
{
public:
2013-09-05 23:02:10 +00:00
aes_encoder();
2013-08-25 05:24:07 +00:00
~aes_encoder();
2013-09-05 23:02:10 +00:00
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 );
2013-08-25 05:24:07 +00:00
private:
struct impl;
fc::fwd<impl,96> my;
};
2013-09-05 22:49:55 +00:00
class aes_decoder
{
public:
2013-09-05 23:02:10 +00:00
aes_decoder();
2013-09-05 22:49:55 +00:00
~aes_decoder();
2013-09-05 23:02:10 +00:00
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 );
2013-09-05 22:49:55 +00:00
private:
struct impl;
fc::fwd<impl,96> my;
};
2013-08-25 05:24:07 +00:00
int aes_encrypt(unsigned char *plaintext, int plaintext_len, unsigned char *key,
unsigned char *iv, unsigned char *ciphertext);
2014-01-20 14:17:39 +00:00
int aes_decrypt(unsigned char *ciphertext, int ciphertext_len, unsigned char *key,
unsigned char *iv, unsigned char *plaintext);
2014-02-13 20:53:20 +00:00
int aes_cfb_decrypt(unsigned char *ciphertext, int ciphertext_len, unsigned char *key,
unsigned char *iv, unsigned char *plaintext);
2013-08-25 05:24:07 +00:00
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 );
2013-08-31 17:12:55 +00:00
/** 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