summaryrefslogtreecommitdiff
path: root/src/libstrongswan/plugins/xcbc/xcbc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstrongswan/plugins/xcbc/xcbc.c')
-rw-r--r--src/libstrongswan/plugins/xcbc/xcbc.c54
1 files changed, 27 insertions, 27 deletions
diff --git a/src/libstrongswan/plugins/xcbc/xcbc.c b/src/libstrongswan/plugins/xcbc/xcbc.c
index dd63af005..b9f03eeac 100644
--- a/src/libstrongswan/plugins/xcbc/xcbc.c
+++ b/src/libstrongswan/plugins/xcbc/xcbc.c
@@ -23,7 +23,7 @@ typedef struct private_xcbc_t private_xcbc_t;
/**
* Private data of a xcbc_t object.
- *
+ *
* The variable names are the same as in the RFC.
*/
struct private_xcbc_t {
@@ -31,42 +31,42 @@ struct private_xcbc_t {
* Public xcbc_t interface.
*/
xcbc_t xcbc;
-
+
/**
* Block size, in bytes
*/
u_int8_t b;
-
+
/**
* crypter using k1
*/
crypter_t *k1;
-
+
/**
* k2
*/
u_int8_t *k2;
-
+
/**
* k3
*/
u_int8_t *k3;
-
+
/**
* E
*/
u_int8_t *e;
-
+
/**
* remaining, unprocessed bytes in append mode
*/
u_int8_t *remaining;
-
+
/**
* number of bytes in remaining
*/
int remaining_bytes;
-
+
/**
* TRUE if we have zero bytes to xcbc in final()
*/
@@ -79,34 +79,34 @@ struct private_xcbc_t {
static void update(private_xcbc_t *this, chunk_t data)
{
chunk_t iv;
-
+
if (data.len)
{
this->zero = FALSE;
}
-
+
if (this->remaining_bytes + data.len <= this->b)
{ /* no complete block, just copy into remaining */
memcpy(this->remaining + this->remaining_bytes, data.ptr, data.len);
this->remaining_bytes += data.len;
return;
}
-
+
iv = chunk_alloca(this->b);
memset(iv.ptr, 0, iv.len);
-
+
/* (3) For each block M[i], where i = 1 ... n-1:
* XOR M[i] with E[i-1], then encrypt the result with Key K1,
* yielding E[i].
*/
-
+
/* append data to remaining bytes, process block M[1] */
memcpy(this->remaining + this->remaining_bytes, data.ptr,
this->b - this->remaining_bytes);
data = chunk_skip(data, this->b - this->remaining_bytes);
memxor(this->e, this->remaining, this->b);
this->k1->encrypt(this->k1, chunk_create(this->e, this->b), iv, NULL);
-
+
/* process blocks M[2] ... M[n-1] */
while (data.len > this->b)
{
@@ -115,7 +115,7 @@ static void update(private_xcbc_t *this, chunk_t data)
memxor(this->e, this->remaining, this->b);
this->k1->encrypt(this->k1, chunk_create(this->e, this->b), iv, NULL);
}
-
+
/* store remaining bytes of block M[n] */
memcpy(this->remaining, data.ptr, data.len);
this->remaining_bytes = data.len;
@@ -127,10 +127,10 @@ static void update(private_xcbc_t *this, chunk_t data)
static void final(private_xcbc_t *this, u_int8_t *out)
{
chunk_t iv;
-
+
iv = chunk_alloca(this->b);
memset(iv.ptr, 0, iv.len);
-
+
/* (4) For block M[n]: */
if (this->remaining_bytes == this->b && !this->zero)
{
@@ -165,9 +165,9 @@ static void final(private_xcbc_t *this, u_int8_t *out)
memxor(this->e, this->k3, this->b);
this->k1->encrypt(this->k1, chunk_create(this->e, this->b), iv, NULL);
}
-
+
memcpy(out, this->e, this->b);
-
+
/* (2) Define E[0] = 0x00000000000000000000000000000000 */
memset(this->e, 0, this->b);
this->remaining_bytes = 0;
@@ -181,13 +181,13 @@ static void get_mac(private_xcbc_t *this, chunk_t data, u_int8_t *out)
{
/* update E, do not process last block */
update(this, data);
-
+
if (out)
{ /* if not in append mode, process last block and output result */
final(this, out);
}
}
-
+
/**
* Implementation of xcbc_t.get_block_size.
*/
@@ -225,8 +225,8 @@ static void set_key(private_xcbc_t *this, chunk_t key)
k1 = chunk_alloca(this->b);
iv = chunk_alloca(this->b);
memset(iv.ptr, 0, iv.len);
-
- /*
+
+ /*
* (1) Derive 3 128-bit keys (K1, K2 and K3) from the 128-bit secret
* key K, as follows:
* K1 = 0x01010101010101010101010101010101 encrypted with Key K
@@ -263,7 +263,7 @@ xcbc_t *xcbc_create(encryption_algorithm_t algo, size_t key_size)
{
private_xcbc_t *this;
crypter_t *crypter;
-
+
crypter = lib->crypto->create_crypter(lib->crypto, algo, key_size);
if (!crypter)
{
@@ -275,13 +275,13 @@ xcbc_t *xcbc_create(encryption_algorithm_t algo, size_t key_size)
crypter->destroy(crypter);
return NULL;
}
-
+
this = malloc_thing(private_xcbc_t);
this->xcbc.get_mac = (void (*)(xcbc_t *,chunk_t,u_int8_t*))get_mac;
this->xcbc.get_block_size = (size_t (*)(xcbc_t *))get_block_size;
this->xcbc.set_key = (void (*)(xcbc_t *,chunk_t))set_key;
this->xcbc.destroy = (void (*)(xcbc_t *))destroy;
-
+
this->b = crypter->get_block_size(crypter);
this->k1 = crypter;
this->k2 = malloc(this->b);