Commit 822a8287 authored by Jean Flavien Bussotti's avatar Jean Flavien Bussotti

The programs runs going through encryption and everything

parent 975d6baf
......@@ -315,7 +315,49 @@ if ((pdcp_p->security_activated != 0) &&
} else {
start_meas(&UE_pdcp_stats[ctxt_pP->module_id].apply_security);
}
*/ printf("apply sec fct\n");
*/
pdcp_p= (pdcp_t*)malloc(sizeof(pdcp_t*));
pdcp_p->next_pdcp_tx_sn = 0;
pdcp_p->next_pdcp_rx_sn = 0;
pdcp_p->tx_hfn = 0;
pdcp_p->rx_hfn = 0;
pdcp_p->last_submitted_pdcp_rx_sn = 4095;
pdcp_p->seq_num_size = 12;
pdcp_p->cipheringAlgorithm = EEA1_128_ALG_ID;//(resQ==1?EEA1_128_ALG_ID:EEA2_128_ALG_ID);
//tried to understand where to obtain the Kupenc key in code without success, only understood that it comes from kenb key and also that's it the one we need since our srb_flagP is 3
//Also we give it a value thanks to osa_stream_eea.c
/*
memcpy(K+3,stream_cipher->key+0,4); /*K[3] = key[0]; we assume
K[3]=key[0]||key[1]||...||key[31] , with key[0] the
* most important bit of key*//*
memcpy(K+2,stream_cipher->key+4,4); /*K[2] = key[1];*//*
memcpy(K+1,stream_cipher->key+8,4); /*K[1] = key[2];*//*
memcpy(K+0,stream_cipher->key+12,4); /*K[0] = key[3]; we assume
K[0]=key[96]||key[97]||...||key[127] , with key[127] the
* least important bit of key*//*
*/
/*
uint8_t *keyTest;
keyTest=(uint8_t*)malloc(128*sizeof(uint8_t));*/
uint8_t keyTest[128];
for( int i =0; i<128; i++)
{
keyTest[i]=2*i;
}
pdcp_p->kUPenc=keyTest;
printf("4\n");
pdcp_init_seq_numbers(pdcp_p);
printf("4bis\n");
printf("apply sec fct\n");
pdcp_apply_security(ctxt_pP,
pdcp_p,
srb_flagP,
......@@ -333,6 +375,8 @@ if ((pdcp_p->security_activated != 0) &&
}*/
//}
//We jump over everything next
return TRUE;
/* Print octets of outgoing data in hexadecimal form */
LOG_D(PDCP, "Following content with size %d will be sent over RLC (PDCP PDU header is the first two bytes)\n",
pdcp_pdu_size);
......
......@@ -147,7 +147,7 @@ pdcp_apply_security(
} else {
LOG_D(PDCP, "[OSA][RB %ld] %s Applying user-plane security\n",
rb_id, (pdcp_pP->is_ue != 0) ? "UE -> eNB" : "eNB -> UE");
printf("line 150 pdcp_security\n");
encrypt_params.key = pdcp_pP->kUPenc;// + 128;
}
......@@ -157,12 +157,13 @@ pdcp_apply_security(
buffer_encrypted = &pdcp_pdu_buffer[pdcp_header_len];
/* Apply ciphering if any requested */
printf("l160 pdcp_security.c\n");
stream_encrypt(pdcp_pP->cipheringAlgorithm,
&encrypt_params,
&buffer_encrypted);
printf("l163 pdcp_security.c\n");
VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_APPLY_SECURITY, VCD_FUNCTION_OUT);
printf("l165 before return pdcp_security.c\n");
return 0;
}
......
......@@ -77,14 +77,15 @@ int stream_encrypt_eea1(stream_cipher_t *stream_cipher, uint8_t **out)
DevAssert(stream_cipher->key != NULL);
DevAssert(stream_cipher->key_length == 16);
DevAssert(out != NULL);
printf("stream encrypt eea1 (osa stream eea l80\n");
n = ( stream_cipher->blength + 31 ) / 32;
zero_bit = stream_cipher->blength & 0x7;
printf("osa stream eea l82\n");
memset(&snow_3g_context, 0, sizeof(snow_3g_context));
/*Initialisation*/
/* Load the confidentiality key for SNOW 3G initialization as in section
3.4. */
printf("osa stream eea l88\n");
memcpy(K+3,stream_cipher->key+0,4); /*K[3] = key[0]; we assume
K[3]=key[0]||key[1]||...||key[31] , with key[0] the
* most important bit of key*/
......@@ -93,6 +94,7 @@ int stream_encrypt_eea1(stream_cipher_t *stream_cipher, uint8_t **out)
memcpy(K+0,stream_cipher->key+12,4); /*K[0] = key[3]; we assume
K[0]=key[96]||key[97]||...||key[127] , with key[127] the
* least important bit of key*/
printf("osa stream eea l97\n");
K[3] = hton_int32(K[3]);
K[2] = hton_int32(K[2]);
K[1] = hton_int32(K[1]);
......@@ -103,12 +105,12 @@ int stream_encrypt_eea1(stream_cipher_t *stream_cipher, uint8_t **out)
IV[2] = ((((uint32_t)stream_cipher->bearer) << 3) | ((((uint32_t)stream_cipher->direction) & 0x1) << 2)) << 24;
IV[1] = IV[3];
IV[0] = IV[2];
printf("osa stream eea l106\n");
/* Run SNOW 3G algorithm to generate sequence of key stream bits KS*/
osa_snow3g_initialize(K, IV, &snow_3g_context);
KS = (uint32_t *)malloc(4*n);
osa_snow3g_generate_key_stream(n,(uint32_t*)KS, &snow_3g_context);
printf("osa stream eea l113\n");
if (zero_bit > 0) {
KS[n - 1] = KS[n - 1] & (uint32_t)(0xFFFFFFFF << (8 - zero_bit));
......@@ -117,7 +119,7 @@ int stream_encrypt_eea1(stream_cipher_t *stream_cipher, uint8_t **out)
for (i=0; i<n; i++) {
KS[i] = hton_int32(KS[i]);
}
printf("osa stream eea l122\n");
/* Exclusive-OR the input data with keystream to generate the output bit
stream */
for (i=0; i<n*4; i++) {
......@@ -128,9 +130,12 @@ int stream_encrypt_eea1(stream_cipher_t *stream_cipher, uint8_t **out)
int ceil_index = (stream_cipher->blength+7) >> 3;
stream_cipher->message[ceil_index - 1] = stream_cipher->message[ceil_index - 1] & (uint8_t)(0xFF << (8 - zero_bit));
}
printf("osa stream eea l133\n");
free(KS);
*out = stream_cipher->message;
*out = stream_cipher->message;
printf("osa stream eea l136\n");
return 0;
}
......@@ -147,7 +152,7 @@ int stream_encrypt_eea2(stream_cipher_t *stream_cipher, uint8_t **out)
DevAssert(stream_cipher != NULL);
DevAssert(out != NULL);
printf("stream encrypt eea2 (osa stream eea l150\n");
LOG_D(OSA, "Entering stream_encrypt_eea2, bits length %u, bearer %u, "
"count %u, direction %s\n", stream_cipher->blength,
stream_cipher->bearer, stream_cipher->count, stream_cipher->direction == SECU_DIRECTION_DOWNLINK ?
......@@ -226,10 +231,16 @@ int stream_encrypt_eea2(stream_cipher_t *stream_cipher, uint8_t **out)
int stream_encrypt(uint8_t algorithm, stream_cipher_t *stream_cipher, uint8_t **out)
{
printf("l232 eea file\n");
if (algorithm == EEA0_ALG_ID) {
return stream_encrypt_eea0(stream_cipher, out);
} else if (algorithm == EEA1_128_ALG_ID) {
return stream_encrypt_eea1(stream_cipher, out);
printf("before stream encrypt\n");
int res= stream_encrypt_eea1(stream_cipher, out);
printf("after stream encrypt res=%d \n",res);
return res;
} else if (algorithm == EEA2_128_ALG_ID) {
return stream_encrypt_eea2(stream_cipher, out);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment