freezer/deezcryptor/src/deezcryptor.c

46 lines
1.1 KiB
C

#include "deezcryptor.h"
#include "blowfish/blowfish.h"
#define CHUNK_SIZE 2048
#define BLOCK_SIZE 8
FFI_PLUGIN_EXPORT int decryptChunk(unsigned char *buffer, unsigned char *encrypted, BLOWFISH_CTX *ctx)
{
BF_KEY _key;
BF_set_key(&_key, 16, key);
unsigned char IV = {0, 1, 2, 3, 4, 5, 6, 7};
BF_cbc_encrypt(encrypted, buffer, CHUNK_SIZE, &_key, IV, BF_DECRYPT);
return CHUNK_SIZE;
}
void bfCbcDecrypt(BLOWFISH_CTX *ctx, unsigned char *iv, const uint8_t *cipher, uint8_t *decrypted, size_t length)
{
size_t i;
uint8_t t[BLOCK_SIZE];
//CBC mode operates in a block-by-block fashion
while(length >= BLOCK_SIZE)
{
//Save input block
memcpy(t, c, BLOCK_SIZE);
//Decrypt the current block
Blowfish_Decrypt(ctx, , p);
//XOR output block with IV contents
for(i = 0; i < cipher->blockSize; i++)
{
p[i] ^= iv[i];
}
//Update IV with input block contents
memcpy(iv, t, cipher->blockSize);
//Next block
c += BLOCK_SIZE;
p = BLOCK_SIZE;
length -= BLOCK_SIZE;
}
}