- wrote test for aes_cbc but encryption does not seem to work :-(

This commit is contained in:
Jan Hutter
2005-11-28 09:12:49 +00:00
parent 363a7dab5e
commit 7b0dafeb52
9 changed files with 234 additions and 39 deletions
@@ -18,6 +18,6 @@ OBJS+= $(BUILD_DIR)crypter.o
$(BUILD_DIR)crypter.o : $(CRYPTERS_DIR)crypter.c $(CRYPTERS_DIR)crypter.h
$(CC) $(CFLAGS) -c -o $@ $<
OBJS+= $(BUILD_DIR)aes_crypter.o
$(BUILD_DIR)aes_crypter.o : $(CRYPTERS_DIR)aes_crypter.c $(CRYPTERS_DIR)aes_crypter.h
OBJS+= $(BUILD_DIR)aes_cbc_crypter.o
$(BUILD_DIR)aes_cbc_crypter.o : $(CRYPTERS_DIR)aes_cbc_crypter.c $(CRYPTERS_DIR)aes_cbc_crypter.h
$(CC) $(CFLAGS) -c -o $@ $<
@@ -1,7 +1,7 @@
/**
* @file aes_crypter.c
* @file aes_cbc_crypter.c
*
* @brief Implementation of aes_crypter_t
* @brief Implementation of aes_cbc_crypter_t
*
*/
@@ -21,7 +21,7 @@
* for more details.
*/
#include "aes_crypter.h"
#include "aes_cbc_crypter.h"
#include <utils/allocator.h>
@@ -41,19 +41,19 @@
#define AES_KS_LENGTH 120
#define AES_RC_LENGTH 29
typedef struct private_aes_crypter_t private_aes_crypter_t;
typedef struct private_aes_cbc_crypter_t private_aes_cbc_crypter_t;
/**
* @brief Class implementing the AES symmetric encryption algorithm.
*
* @ingroup crypters
*/
struct private_aes_crypter_t {
struct private_aes_cbc_crypter_t {
/**
* Public part of this class.
*/
aes_crypter_t public;
aes_cbc_crypter_t public;
/**
* Number of words in the key input block.
@@ -96,7 +96,7 @@ struct private_aes_crypter_t {
* @return
* - SUCCESS in any case
*/
status_t (*encrypt_block) (private_aes_crypter_t *this, u_int8_t *data, u_int8_t *encrypted);
status_t (*encrypt_block) (private_aes_cbc_crypter_t *this, u_int8_t *data, u_int8_t *encrypted);
/**
* @brief Decrypt a chunk of data with blocksize length.
@@ -109,7 +109,7 @@ struct private_aes_crypter_t {
* @return
* - SUCCESS in any case
*/
status_t (*decrypt_block) (private_aes_crypter_t *this, u_int8_t *data, u_int8_t *decrypted);
status_t (*decrypt_block) (private_aes_cbc_crypter_t *this, u_int8_t *data, u_int8_t *decrypted);
};
@@ -1263,9 +1263,9 @@ switch(this->aes_Ncol) \
/**
* Implementation of private_aes_crypter_t.encrypt_block.
* Implementation of private_aes_cbc_crypter_t.encrypt_block.
*/
static status_t encrypt_block (private_aes_crypter_t *this, u_int8_t *data, u_int8_t *encrypted)
static status_t encrypt_block (private_aes_cbc_crypter_t *this, u_int8_t *data, u_int8_t *encrypted)
{
u_int32_t locals(b0, b1);
const u_int32_t *kp = this->aes_e_key;
@@ -1338,9 +1338,9 @@ static status_t encrypt_block (private_aes_crypter_t *this, u_int8_t *data, u_in
}
/**
* Implementation of private_aes_crypter_t.decrypt_block.
* Implementation of private_aes_cbc_crypter_t.decrypt_block.
*/
static status_t decrypt_block (private_aes_crypter_t *this, u_int8_t *data, u_int8_t *decrypted)
static status_t decrypt_block (private_aes_cbc_crypter_t *this, u_int8_t *data, u_int8_t *decrypted)
{
u_int32_t locals(b0, b1);
const u_int32_t *kp = this->aes_d_key;
@@ -1417,7 +1417,7 @@ static status_t decrypt_block (private_aes_crypter_t *this, u_int8_t *data, u_in
/**
* Implementation of crypter_t.decrypt.
*/
static status_t decrypt (private_aes_crypter_t *this, chunk_t data, chunk_t iv, chunk_t *decrypted)
static status_t decrypt (private_aes_cbc_crypter_t *this, chunk_t data, chunk_t iv, chunk_t *decrypted)
{
int ret, pos;
const u_int32_t *iv_i;
@@ -1465,7 +1465,7 @@ static status_t decrypt (private_aes_crypter_t *this, chunk_t data, chunk_t iv,
/**
* Implementation of crypter_t.decrypt.
*/
static status_t encrypt (private_aes_crypter_t *this, chunk_t data, chunk_t iv, chunk_t *encrypted)
static status_t encrypt (private_aes_cbc_crypter_t *this, chunk_t data, chunk_t iv, chunk_t *encrypted)
{
int ret, pos;
const u_int32_t *iv_i;
@@ -1510,7 +1510,7 @@ static status_t encrypt (private_aes_crypter_t *this, chunk_t data, chunk_t iv,
/**
* Implementation of crypter_t.get_block_size.
*/
static size_t get_block_size (private_aes_crypter_t *this)
static size_t get_block_size (private_aes_cbc_crypter_t *this)
{
return this->blocksize;
}
@@ -1518,7 +1518,7 @@ static size_t get_block_size (private_aes_crypter_t *this)
/**
* Implementation of crypter_t.set_key.
*/
static status_t set_key (private_aes_crypter_t *this, chunk_t key)
static status_t set_key (private_aes_cbc_crypter_t *this, chunk_t key)
{
u_int32_t *kf, *kt, rci, f = 0;
@@ -1612,18 +1612,18 @@ static status_t set_key (private_aes_crypter_t *this, chunk_t key)
}
/**
* Implementation of crypter_t.destroy and aes_crypter_t.destroy.
* Implementation of crypter_t.destroy and aes_cbc_crypter_t.destroy.
*/
static status_t destroy (private_aes_crypter_t *this)
static status_t destroy (private_aes_cbc_crypter_t *this)
{
allocator_free(this);
return SUCCESS;
}
aes_crypter_t *aes_crypter_create(size_t blocksize)
aes_cbc_crypter_t *aes_cbc_crypter_create(size_t blocksize)
{
private_aes_crypter_t *this = allocator_alloc_thing(private_aes_crypter_t);
private_aes_cbc_crypter_t *this = allocator_alloc_thing(private_aes_cbc_crypter_t);
if (this == NULL)
{
return NULL;
@@ -1657,7 +1657,7 @@ aes_crypter_t *aes_crypter_create(size_t blocksize)
this->public.crypter_interface.destroy = (status_t (*) (crypter_t *)) destroy;
/* public functions */
this->public.destroy = (status_t (*) (aes_crypter_t *)) destroy;
this->public.destroy = (status_t (*) (aes_cbc_crypter_t *)) destroy;
/* private functions */
this->encrypt_block = encrypt_block;
@@ -1,7 +1,7 @@
/**
* @file aes_crypter.h
* @file aes_cbc_crypter.h
*
* @brief Interface of aes_crypter_t
* @brief Interface of aes_cbc_crypter_t
*
*/
@@ -27,14 +27,14 @@
#include <transforms/crypters/crypter.h>
typedef struct aes_crypter_t aes_crypter_t;
typedef struct aes_cbc_crypter_t aes_cbc_crypter_t;
/**
* @brief Class implementing the AES symmetric encryption algorithm.
*
* @ingroup crypters
*/
struct aes_crypter_t {
struct aes_cbc_crypter_t {
/**
* crypter_t interface.
@@ -42,26 +42,26 @@ struct aes_crypter_t {
crypter_t crypter_interface;
/**
* @brief Destroys a aes_crypter_t object.
* @brief Destroys a aes_cbc_crypter_t object.
*
* @param this crypter_t object to destroy
* @return
* - SUCCESS in any case
*/
status_t (*destroy) (aes_crypter_t *this);
status_t (*destroy) (aes_cbc_crypter_t *this);
};
/**
* @brief Constructor to create aes_crypter_t objects.
* @brief Constructor to create aes_cbc_crypter_t objects.
*
* @param blocksize block size of AES crypter
* (16, 24 or 32 are supported)
* Default size is set to 16.
* @return
* - aes_crypter_t if successfully
* - aes_cbc_crypter_t if successfully
* - NULL if out of ressources
*/
aes_crypter_t *aes_crypter_create(size_t blocksize);
aes_cbc_crypter_t *aes_cbc_crypter_create(size_t blocksize);
#endif //_AES_CRYPTER_H_