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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
#include <string>
#include <vector>
#include <string.h>
#include <stdio.h>
#include "encrypt_stream.h"
#include "encrypt_stream_blowfish.h"
#include "utils.h"
encrypt_stream_blowfish::encrypt_stream_blowfish()
{
enc = NULL;
dec = NULL;
}
encrypt_stream_blowfish::~encrypt_stream_blowfish()
{
delete enc;
delete dec;
}
int encrypt_stream_blowfish::get_ivec_size()
{
return CryptoPP::Blowfish::BLOCKSIZE;
}
int encrypt_stream_blowfish::get_key_size()
{
return CryptoPP::Blowfish::DEFAULT_KEYLENGTH;
}
bool encrypt_stream_blowfish::init(unsigned char *key_in, int key_len, unsigned char *ivec_in, bool force)
{
my_assert(key_len > 0);
#ifdef CRYPTO_DEBUG
printf("KEY: "); hexdump(key_in, key_len);
#endif
if (enc)
delete enc;
if (dec)
delete dec;
enc = new CryptoPP::CFB_Mode<CryptoPP::Blowfish>::Encryption(key_in, key_len, ivec_in);
dec = new CryptoPP::CFB_Mode<CryptoPP::Blowfish>::Decryption(key_in, key_len, ivec_in);
return true;
}
std::string encrypt_stream_blowfish::get_name()
{
return "blowfish";
}
void encrypt_stream_blowfish::encrypt(unsigned char *p, int len, unsigned char *p_out)
{
my_assert(len > 0);
#ifdef CRYPTO_DEBUG
printf("ORG: "); hexdump(p, len);
printf("EIV %d before: ", ivec_offset); hexdump(ivec, 8);
#endif
enc -> ProcessData(p_out, p, len);
#ifdef CRYPTO_DEBUG
printf("EIV %d after: ", ivec_offset); hexdump(ivec, 8);
printf("ENC: "); hexdump(p_out, len);
#endif
}
void encrypt_stream_blowfish::decrypt(unsigned char *p, int len, unsigned char *p_out)
{
my_assert(len > 0);
#ifdef CRYPTO_DEBUG
printf("DEC: "); hexdump(p, len);
printf("EIV %d before: ", ivec_offset); hexdump(ivec, 8);
#endif
dec -> ProcessData(p_out, p, len);
#ifdef CRYPTO_DEBUG
printf("EIV %d after: ", ivec_offset); hexdump(ivec, 8);
printf("ORG: "); hexdump(p_out, len);
#endif
}
|