- code cleaned up

This commit is contained in:
Jan Hutter
2005-12-06 15:21:26 +00:00
parent 1e7d52a611
commit 62abe4a37d
4 changed files with 49 additions and 27 deletions
@@ -75,12 +75,12 @@ struct private_aes_cbc_crypter_t {
u_int32_t aes_d_key[AES_KS_LENGTH]; u_int32_t aes_d_key[AES_KS_LENGTH];
/** /**
* the number of columns in the cipher state * The number of columns in the cipher state.
*/ */
u_int32_t aes_Ncol; u_int32_t aes_Ncol;
/** /**
* Blocksize of this AES cypher object * Blocksize of this AES cypher object.
*/ */
u_int32_t blocksize; u_int32_t blocksize;
@@ -90,7 +90,7 @@ struct private_aes_cbc_crypter_t {
* No memory gets allocated. * No memory gets allocated.
* *
* @param this calling object * @param this calling object
* @param[in] in_blk block to decrypt * @param[in] in_blk block to decrypt
* @param[out] out_blk decrypted data are written to this location * @param[out] out_blk decrypted data are written to this location
*/ */
void (*decrypt_block) (const private_aes_cbc_crypter_t *this, const unsigned char in_blk[], unsigned char out_blk[]); void (*decrypt_block) (const private_aes_cbc_crypter_t *this, const unsigned char in_blk[], unsigned char out_blk[]);
@@ -101,7 +101,7 @@ struct private_aes_cbc_crypter_t {
* No memory gets allocated. * No memory gets allocated.
* *
* @param this calling object * @param this calling object
* @param[in] in_blk block to encrypt * @param[in] in_blk block to encrypt
* @param[out] out_blk encrypted data are written to this location * @param[out] out_blk encrypted data are written to this location
*/ */
void (*encrypt_block) (const private_aes_cbc_crypter_t *this, const unsigned char in_blk[], unsigned char out_blk[]); void (*encrypt_block) (const private_aes_cbc_crypter_t *this, const unsigned char in_blk[], unsigned char out_blk[]);
@@ -32,12 +32,15 @@ typedef struct aes_cbc_crypter_t aes_cbc_crypter_t;
/** /**
* @brief Class implementing the AES symmetric encryption algorithm. * @brief Class implementing the AES symmetric encryption algorithm.
* *
* @b Constructors:
* - aes_cbc_crypter_create()
*
* @ingroup crypters * @ingroup crypters
*/ */
struct aes_cbc_crypter_t { struct aes_cbc_crypter_t {
/** /**
* crypter_t interface. * The crypter_t interface.
*/ */
crypter_t crypter_interface; crypter_t crypter_interface;
}; };
@@ -45,10 +48,12 @@ struct aes_cbc_crypter_t {
/** /**
* @brief Constructor to create aes_cbc_crypter_t objects. * @brief Constructor to create aes_cbc_crypter_t objects.
* *
* If an unvalid blocksize is specified, 16 is selected.
*
* @param blocksize block size of AES crypter * @param blocksize block size of AES crypter
* (16, 24 or 32 are supported) * (16, 24 or 32 are supported)
* Default size is set to 16. * Default size is set to 16.
* @return aes_cbc_crypter_t if successfully * @return aes_cbc_crypter_t object
*/ */
aes_cbc_crypter_t *aes_cbc_crypter_create(size_t blocksize); aes_cbc_crypter_t *aes_cbc_crypter_create(size_t blocksize);
+1 -1
View File
@@ -27,7 +27,7 @@
/** /**
* string mappings for encryption_algorithm_t * String mappings for encryption_algorithm_t.
*/ */
mapping_t encryption_algorithm_m[] = { mapping_t encryption_algorithm_m[] = {
{ENCR_UNDEFINED, "ENCR_UNDEFINED"}, {ENCR_UNDEFINED, "ENCR_UNDEFINED"},
+37 -20
View File
@@ -28,7 +28,18 @@
typedef enum encryption_algorithm_t encryption_algorithm_t; typedef enum encryption_algorithm_t encryption_algorithm_t;
/** /**
* @brief Encryption algorithm, as in IKEv2 draft 3.3.2 * @brief Encryption algorithm, as in IKEv2 draft 3.3.2.
*
* Currently only the following algorithms are implemented and therefore supported:
* - ENCR_AES_CBC
*
* @b Constructors:
* - crypter_create()
* - aes_cbc_crypter_create()
*
* @todo Implement more enryption algorithm, especially 3DES
*
* @ingroup crypters
*/ */
enum encryption_algorithm_t { enum encryption_algorithm_t {
ENCR_UNDEFINED = 1024, ENCR_UNDEFINED = 1024,
@@ -41,17 +52,20 @@ enum encryption_algorithm_t {
ENCR_BLOWFISH = 7, ENCR_BLOWFISH = 7,
ENCR_3IDEA = 8, ENCR_3IDEA = 8,
ENCR_DES_IV32 = 9, ENCR_DES_IV32 = 9,
RESERVED = 10,
ENCR_NULL = 11, ENCR_NULL = 11,
/**
* Implemented in class aes_cbc_crypter_t.
*/
ENCR_AES_CBC = 12, ENCR_AES_CBC = 12,
ENCR_AES_CTR = 13 ENCR_AES_CTR = 13
}; };
/** /**
* string mappings for encryption_algorithm_t * String mappings for encryption_algorithm_t.
*/ */
extern mapping_t encryption_algorithm_m[]; extern mapping_t encryption_algorithm_m[];
typedef struct crypter_t crypter_t; typedef struct crypter_t crypter_t;
/** /**
@@ -67,13 +81,13 @@ struct crypter_t {
* @brief Encrypt a chunk of data and allocate space for * @brief Encrypt a chunk of data and allocate space for
* the encrypted value. * the encrypted value.
* *
* @param this calling crypter * @param this calling object
* @param data data to encrypt * @param data data to encrypt
* @param iv iv * @param iv initializing vector
* @param [out]encrypted pointer where the encrypted bytes will be written * @param [out]encrypted pointer where the encrypted bytes will be written
* @return * @return
* - SUCCESS, or * - SUCCESS
* - INVALID_ARG if data size not a multiple of block size * - INVALID_ARG if data size not a multiple of block size
*/ */
status_t (*encrypt) (crypter_t *this, chunk_t data, chunk_t iv, chunk_t *encrypted); status_t (*encrypt) (crypter_t *this, chunk_t data, chunk_t iv, chunk_t *encrypted);
@@ -81,31 +95,31 @@ struct crypter_t {
* @brief Decrypt a chunk of data and allocate space for * @brief Decrypt a chunk of data and allocate space for
* the decrypted value. * the decrypted value.
* *
* @param this calling crypter * @param this calling object
* @param data data to decrypt * @param data data to decrypt
* @param iv iv * @param iv initializing vector
* @param [out]encrypted pointer where the decrypted bytes will be written * @param [out]encrypted pointer where the decrypted bytes will be written
* @return * @return
* - SUCCESS, or * - SUCCESS
* - INVALID_ARG if data size not a multiple of block size * - INVALID_ARG if data size not a multiple of block size
*/ */
status_t (*decrypt) (crypter_t *this, chunk_t data, chunk_t iv, chunk_t *decrypted); status_t (*decrypt) (crypter_t *this, chunk_t data, chunk_t iv, chunk_t *decrypted);
/** /**
* @brief get the block size of this crypter * @brief Get the block size of this crypter_t object.
* *
* @param this calling crypter * @param this calling object
* @return block size in bytes * @return block size in bytes
*/ */
size_t (*get_block_size) (crypter_t *this); size_t (*get_block_size) (crypter_t *this);
/** /**
* @brief Set the key for this crypter * @brief Set the key for this crypter_t object.
* *
* @param this calling crypter * @param this calling object
* @param key key to set * @param key key to set
* @return * @return
* - SUCCESS, or * - SUCCESS
* - INVALID_ARG if key size != block size * - INVALID_ARG if key size != block size
*/ */
status_t (*set_key) (crypter_t *this, chunk_t key); status_t (*set_key) (crypter_t *this, chunk_t key);
@@ -113,7 +127,7 @@ struct crypter_t {
/** /**
* @brief Destroys a crypter_t object. * @brief Destroys a crypter_t object.
* *
* @param this crypter_t object to destroy * @param this calling object
*/ */
void (*destroy) (crypter_t *this); void (*destroy) (crypter_t *this);
}; };
@@ -121,11 +135,14 @@ struct crypter_t {
/** /**
* @brief Generic constructor for crypter_t objects. * @brief Generic constructor for crypter_t objects.
* *
* Currently only the following algorithms are implemented and therefore supported:
* - ENCR_AES_CBC
*
* @param encryption_algorithm Algorithm to use for crypter * @param encryption_algorithm Algorithm to use for crypter
* @param blocksize block size in bytes * @param blocksize block size in bytes
* @return * @return
* - crypter_t if successfully * - crypter_t object
* - NULL if crypter not supported * - NULL if encryption algorithm or blocksize is not supported
*/ */
crypter_t *crypter_create(encryption_algorithm_t encryption_algorithm, size_t blocksize); crypter_t *crypter_create(encryption_algorithm_t encryption_algorithm, size_t blocksize);