aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Hutter <jhutter@hsr.ch>2005-11-09 15:12:48 +0000
committerJan Hutter <jhutter@hsr.ch>2005-11-09 15:12:48 +0000
commit74683cbdac0c7f73c7f7f58038c53170f8fa93d8 (patch)
treecaf2c7596d224fb11dcd1f3d2aba67ea646c565e
parentae4abe3546ad5338878f5d3a2996e12172e6fa8e (diff)
downloadstrongswan-74683cbdac0c7f73c7f7f58038c53170f8fa93d8.tar.bz2
strongswan-74683cbdac0c7f73c7f7f58038c53170f8fa93d8.tar.xz
- u int values can be generated: Not fully tested !
-rw-r--r--Source/charon/encodings/ike_header.c2
-rw-r--r--Source/charon/encodings/ike_header.h4
-rw-r--r--Source/charon/generator.c113
-rw-r--r--Source/charon/tests/generator_test.c9
4 files changed, 107 insertions, 21 deletions
diff --git a/Source/charon/encodings/ike_header.c b/Source/charon/encodings/ike_header.c
index d5cca3c85..df0613953 100644
--- a/Source/charon/encodings/ike_header.c
+++ b/Source/charon/encodings/ike_header.c
@@ -45,6 +45,8 @@ encoding_rule_t ike_header_encodings[] = {
{ U_INT_4, offsetof(ike_header_t, maj_version) },
/* 4 Bit minor version, stored in the field min_version */
{ U_INT_4, offsetof(ike_header_t, min_version) },
+ /* 8 Bit for the exchange type */
+ { U_INT_8, offsetof(ike_header_t, exchange_type) },
/* 2 Bit reserved bits, nowhere stored */
{ RESERVED_BIT, 0 },
{ RESERVED_BIT, 0 },
diff --git a/Source/charon/encodings/ike_header.h b/Source/charon/encodings/ike_header.h
index 29106d497..58b4348f6 100644
--- a/Source/charon/encodings/ike_header.h
+++ b/Source/charon/encodings/ike_header.h
@@ -43,11 +43,11 @@ struct ike_header_s{
/**
* SPI of the initiator
*/
- u_int32_t initiator_spi;
+ u_int64_t initiator_spi;
/**
* SPI of the responder
*/
- u_int32_t responder_spi;
+ u_int64_t responder_spi;
/**
* next payload type
*/
diff --git a/Source/charon/generator.c b/Source/charon/generator.c
index 04f164a67..d5d1be383 100644
--- a/Source/charon/generator.c
+++ b/Source/charon/generator.c
@@ -81,6 +81,8 @@ struct generator_infos_s {
*/
status_t (*make_space_available) (generator_infos_t *this,size_t bits);
+ status_t (*write_bytes_to_buffer) (generator_infos_t *this,void * bytes,size_t number_of_bytes);
+
status_t (*write_chunk) (generator_infos_t *this,chunk_t *data);
};
@@ -113,6 +115,28 @@ static status_t generator_info_make_space_available (generator_infos_t *this, si
return SUCCESS;
}
+static status_t generator_info_write_bytes_to_buffer (generator_infos_t *this,void * bytes,size_t number_of_bytes)
+{
+ u_int8_t *read_position = (u_int8_t *) bytes;
+ int i;
+ status_t status;
+
+ status = this->make_space_available(this,number_of_bytes * 8);
+
+ if (status != SUCCESS)
+ {
+ return status;
+ }
+
+ for (i = 0; i < number_of_bytes; i++)
+ {
+ *(this->out_position) = *(read_position);
+ read_position++;
+ this->out_position++;
+ }
+ return status;
+}
+
static status_t generator_infos_write_chunk (generator_infos_t *this,chunk_t *data)
{
size_t data_length = this->out_position - this->buffer;
@@ -160,6 +184,7 @@ generator_infos_t * generator_infos_create(void *data_struct)
this->destroy = generator_infos_destroy;
this->make_space_available = generator_info_make_space_available;
this->write_chunk = generator_infos_write_chunk;
+ this->write_bytes_to_buffer = generator_info_write_bytes_to_buffer;
/* allocate memory for buffer */
this->buffer = allocator_alloc(GENERATOR_DATA_BUFFER_SIZE);
@@ -226,7 +251,6 @@ struct private_generator_s {
static status_t generate_u_int_type (private_generator_t *this,encoding_type_t int_type,u_int32_t offset,generator_infos_t *generator_infos)
{
size_t number_of_bits = 0;
-
status_t status;
@@ -250,6 +274,11 @@ static status_t generate_u_int_type (private_generator_t *this,encoding_type_t i
default:
return FAILED;
}
+ if (((number_of_bits % 8) == 0) && (generator_infos->current_bit != 0))
+ {
+ /* current bit has to be zero for values greater then 4 bits */
+ return FAILED;
+ }
status = generator_infos->make_space_available(generator_infos,number_of_bits);
@@ -257,27 +286,74 @@ static status_t generate_u_int_type (private_generator_t *this,encoding_type_t i
{
return status;
}
-
- /* process 4 byte integer special */
- if (number_of_bits == 4)
+
+ switch (int_type)
{
- if (generator_infos->current_bit == 0)
- {
- *(generator_infos->out_position) = *((u_int8_t *)(generator_infos->data_struct + offset)) << 4;
- generator_infos->current_bit = 4;
- }
- else if (generator_infos->current_bit == 4)
- {
- generator_infos->out_position++;
- generator_infos->current_bit = 0;
+ case U_INT_4:
+ {
+ if (generator_infos->current_bit == 0)
+ {
+ u_int8_t high_val = *((u_int8_t *)(generator_infos->data_struct + offset)) << 4;
+ u_int8_t low_val = *(generator_infos->out_position) & 0x0F;
+
+ *(generator_infos->out_position) = high_val | low_val;
+ /* write position is not changed, just bit position is moved */
+ generator_infos->current_bit = 4;
+ }
+ else if (generator_infos->current_bit == 4)
+ {
+ u_int high_val = *(generator_infos->out_position) & 0xF0;
+ u_int low_val = *((u_int8_t *)(generator_infos->data_struct + offset)) & 0x0F;
+ *(generator_infos->out_position) = high_val | low_val;
+ generator_infos->out_position++;
+ generator_infos->current_bit = 0;
+
+ }
+ else
+ {
+ /* 4 Bit integers must have a 4 bit alignment */
+ return FAILED;
+ };
+ break;
+ }
- }
- else
- {
- /* 4 Bit integers must have a 4 bit alignment */
+ case U_INT_8:
+ {
+ *generator_infos->out_position = *((u_int8_t *)(generator_infos->data_struct + offset));
+ generator_infos->out_position++;
+ break;
+
+ }
+ case U_INT_16:
+ {
+ u_int16_t int16_val = htons(*((u_int16_t*)(generator_infos->data_struct + offset)));
+ generator_infos->write_bytes_to_buffer(generator_infos,&int16_val,sizeof(u_int16_t));
+
+ break;
+ }
+ case U_INT_32:
+ {
+ u_int32_t int32_val = htonl(*((u_int32_t*)(generator_infos->data_struct + offset)));
+ generator_infos->write_bytes_to_buffer(generator_infos,&int32_val,sizeof(u_int32_t));
+ break;
+ }
+ case U_INT_64:
+ {
+ u_int32_t int32_val_low = htonl(*((u_int32_t*)(generator_infos->data_struct + offset)));
+ u_int32_t int32_val_high = htonl(*((u_int32_t*)(generator_infos->data_struct + offset) + 1));
+ generator_infos->write_bytes_to_buffer(generator_infos,&int32_val_high,sizeof(u_int32_t));
+ generator_infos->write_bytes_to_buffer(generator_infos,&int32_val_low,sizeof(u_int32_t));
+ break;
+ }
+
+ default:
return FAILED;
- }
+
}
+
+
+
+
return SUCCESS;
}
@@ -297,6 +373,7 @@ static status_t generate (private_generator_t *this,void * data_struct,encoding_
return OUT_OF_RES;
}
+
for (i = 0; i < encoding_rules_count;i++)
{
status = SUCCESS;
diff --git a/Source/charon/tests/generator_test.c b/Source/charon/tests/generator_test.c
index f254992c0..49ffb0829 100644
--- a/Source/charon/tests/generator_test.c
+++ b/Source/charon/tests/generator_test.c
@@ -68,7 +68,14 @@ void test_generator_with_header_payload(tester_t *tester)
tester->assert_true(tester,(generator != NULL), "generator create check");
tester->assert_true(tester,(generator->generate_payload(generator,HEADER,&header_data,&generated_data) == SUCCESS),"generate_payload call check");
- DBG_dump("test:",generated_data.ptr,generated_data.len);
+ int i;
+ u_int8_t *data = generated_data.ptr;
+
+ for (i = 0; i < generated_data.len;i++)
+ {
+ fprintf(stderr,"%x\n",data[i]);
+ }
+
allocator_free_chunk(generated_data);