Skip to content

Commit

Permalink
placing AES key to PROGMEM when available
Browse files Browse the repository at this point in the history
  • Loading branch information
divanchykhin committed Jun 12, 2015
1 parent 82abf59 commit 2814ef6
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 15 deletions.
3 changes: 2 additions & 1 deletion firmware/src/common/sa-aes-128.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Copyright (C) 2015 OLogN Technologies AG
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*******************************************************************************/

#include "sa-common.h"
#include "sa-aes-128.h"
const uint8_t rijndael_sbox[256] ZEPTO_PROG_CONSTANT_LOCATION =
{
Expand Down Expand Up @@ -107,7 +108,7 @@ void sa_aes_128_encrypt_block( const uint8_t* key, const uint8_t* _block, uint8_
{
uint8_t block[16], ksc[16];
memcpy( block, _block, 16 );
memcpy( ksc, key, 16 );
ZEPTO_MEMCPY_FROM_PROGMEM( ksc, key, 16 );
uint8_t rcon = 1;

uint8_t i;
Expand Down
12 changes: 7 additions & 5 deletions firmware/src/common/saccp_protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,16 @@ uint8_t handler_saccp_receive( MEMORY_HANDLE mem_h )

#else // USED_AS_MASTER

#include "../plugins/smart-echo/smart-echo.h"
//#include "../plugins/smart-echo/smart-echo.h"
#include "../sa_bodypart_list.h"

SmartEchoPluginConfig pl_conf;
SmartEchoPluginState pl_state;
//SmartEchoPluginConfig pl_conf;
//SmartEchoPluginState pl_state;

void zepto_vm_init()
{
smart_echo_plugin_handler_init( (void*)(&pl_conf), (void*)(&pl_state) );
// smart_echo_plugin_handler_init( (void*)(&pl_conf), (void*)(&pl_state) );
smart_echo_plugin_handler_init( (void*)(bodyparts[0].ph_config), (void*)(bodyparts[0].ph_state) );
}


Expand Down Expand Up @@ -229,7 +231,7 @@ void handler_zepto_vm( MEMORY_HANDLE mem_h, uint8_t first_byte )
// handler_zepto_test_plugin( MEMORY_HANDLE_DEFAULT_PLUGIN );
parser_obj po3;
zepto_parser_init( &po3, MEMORY_HANDLE_DEFAULT_PLUGIN );
smart_echo_plugin_handler( &pl_conf, &pl_state, &po3, MEMORY_HANDLE_DEFAULT_PLUGIN/*, WaitingFor* waiting_for*/, first_byte );
smart_echo_plugin_handler( (void*)(bodyparts[0].ph_config), (void*)(bodyparts[0].ph_state), &po3, MEMORY_HANDLE_DEFAULT_PLUGIN/*, WaitingFor* waiting_for*/, first_byte );
// now we have raw data from plugin; form a frame
// TODO: here is a place to form optional headers, if any
uint16_t ret_data_sz = zepto_writer_get_response_size( MEMORY_HANDLE_DEFAULT_PLUGIN );
Expand Down
10 changes: 6 additions & 4 deletions firmware/src/sa-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ Copyright (C) 2015 OLogN Technologies AG
#endif
// #include "test-generator.h"
#include <stdio.h>
#include "zepto_config.h"



// TODO: actual key loading, etc
uint8_t sasp_key[16];
//uint8_t AES_ENCRYPTION_KEY[16];
DECLARE_AES_ENCRYPTION_KEY

// tester_initTestSystem();

Expand Down Expand Up @@ -71,7 +73,7 @@ bool sa_main_init()
wait_for.wait_packet = 1;
TIME_MILLISECONDS16_TO_TIMEVAL( 1000, wait_for.wait_time ); //+++TODO: actual processing throughout the code

memset( sasp_key, 0xab, 16 );
// memset( AES_ENCRYPTION_KEY, 0xab, 16 );
// SASP_initAtLifeStart( &sasp_data ); // TODO: replace by more extensive restore-from-backup-etc
SASP_initAtLifeStart(); // TODO: replace by more extensive restore-from-backup-etc
// sagdp_init( &sagdp_data );
Expand Down Expand Up @@ -308,7 +310,7 @@ ZEPTO_DEBUG_PRINTF_1( "Processing continued...\n" );


// 2.2. Pass to SASP
ret_code = handler_sasp_receive( sasp_key, pid, MEMORY_HANDLE_MAIN_LOOP/*, &sasp_data*/ );
ret_code = handler_sasp_receive( AES_ENCRYPTION_KEY, pid, MEMORY_HANDLE_MAIN_LOOP/*, &sasp_data*/ );
zepto_response_to_request( MEMORY_HANDLE_MAIN_LOOP );
ZEPTO_DEBUG_PRINTF_4( "SASP1: ret: %d; rq_size: %d, rsp_size: %d\n", ret_code, ugly_hook_get_request_size( MEMORY_HANDLE_MAIN_LOOP ), ugly_hook_get_response_size( MEMORY_HANDLE_MAIN_LOOP ) );

Expand Down Expand Up @@ -633,7 +635,7 @@ ZEPTO_DEBUG_PRINTF_3( "Processing in progress... (period = %d, time = %d)\n", wa

// SASP
saspsend:
ret_code = handler_sasp_send( sasp_key, nonce, MEMORY_HANDLE_MAIN_LOOP/*, &sasp_data*/ );
ret_code = handler_sasp_send( AES_ENCRYPTION_KEY, nonce, MEMORY_HANDLE_MAIN_LOOP/*, &sasp_data*/ );
zepto_response_to_request( MEMORY_HANDLE_MAIN_LOOP );
ZEPTO_DEBUG_PRINTF_4( "SASP2: ret: %d; rq_size: %d, rsp_size: %d\n", ret_code, ugly_hook_get_request_size( MEMORY_HANDLE_MAIN_LOOP ), ugly_hook_get_response_size( MEMORY_HANDLE_MAIN_LOOP ) );

Expand Down
49 changes: 49 additions & 0 deletions firmware/src/zepto_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*******************************************************************************
Copyright (C) 2015 OLogN Technologies AG
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*******************************************************************************/

/*******************************************************************************
THIS FILE IS MANUALLY OR AUTOMATICALLY GENERATED BASED ON DESIRED PLUGIN LIST
*******************************************************************************/



#if !defined __ZEPTO_CONFIG_H__
#define __ZEPTO_CONFIG_H__

#define DECLARE_AES_ENCRYPTION_KEY \
const uint8_t AES_ENCRYPTION_KEY[16] ZEPTO_PROG_CONSTANT_LOCATION = \
{ \
0x00, \
0x01, \
0x02, \
0x03, \
0x04, \
0x05, \
0x06, \
0x07, \
0x08, \
0x09, \
0x0a, \
0x0b, \
0x0c, \
0x0d, \
0x0e, \
0x0f, \
}; \


#endif // __ZEPTO_CONFIG_H__
13 changes: 8 additions & 5 deletions tests/emulator/sa_client_comm_stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ Copyright (C) 2015 OLogN Technologies AG
#include "../../firmware/src/common/saccp_protocol.h"
#include "test-generator.h"
#include <stdio.h>
#include "../../firmware/src/zepto_config.h"

DECLARE_AES_ENCRYPTION_KEY


int main_loop()
Expand All @@ -43,9 +46,9 @@ int main_loop()
tester_initTestSystem();

// TODO: actual key loading, etc
uint8_t sasp_key[16];
// memcpy( sasp_key, "16-byte fake key", 16 );
memset( sasp_key, 0xab, 16 );
// uint8_t AES_ENCRYPTION_KEY[16];
// memcpy( AES_ENCRYPTION_KEY, "16-byte fake key", 16 );
// memset( AES_ENCRYPTION_KEY, 0xab, 16 );

// timeout_action tact;
// tact.action = 0;
Expand Down Expand Up @@ -210,7 +213,7 @@ int main_loop()
}

// 2.2. Pass to SASP
ret_code = handler_sasp_receive( sasp_key, pid, MEMORY_HANDLE_MAIN_LOOP/*, &sasp_data*/ );
ret_code = handler_sasp_receive( AES_ENCRYPTION_KEY, pid, MEMORY_HANDLE_MAIN_LOOP/*, &sasp_data*/ );
zepto_response_to_request( MEMORY_HANDLE_MAIN_LOOP );
ZEPTO_DEBUG_PRINTF_4( "SASP1: ret: %d; rq_size: %d, rsp_size: %d\n", ret_code, ugly_hook_get_request_size( MEMORY_HANDLE_MAIN_LOOP ), ugly_hook_get_response_size( MEMORY_HANDLE_MAIN_LOOP ) );

Expand Down Expand Up @@ -407,7 +410,7 @@ int main_loop()

// SASP
saspsend:
ret_code = handler_sasp_send( sasp_key, nonce, MEMORY_HANDLE_MAIN_LOOP/*, &sasp_data*/ );
ret_code = handler_sasp_send( AES_ENCRYPTION_KEY, nonce, MEMORY_HANDLE_MAIN_LOOP/*, &sasp_data*/ );
zepto_response_to_request( MEMORY_HANDLE_MAIN_LOOP );
ZEPTO_DEBUG_PRINTF_4( "SASP2: ret: %d; rq_size: %d, rsp_size: %d\n", ret_code, ugly_hook_get_request_size( MEMORY_HANDLE_MAIN_LOOP ), ugly_hook_get_response_size( MEMORY_HANDLE_MAIN_LOOP ) );

Expand Down

0 comments on commit 2814ef6

Please sign in to comment.