我正在尝试使用Cooja仿真环境实现的Contiki OS,在Ipsec协议中测试IKEv.2的一些方法(主要是会话恢复)。
我需要你的帮助来帮助我在C中合并会话恢复协议代码,以便我可以恢复我的模拟。
我尽力开发代码,但每次尝试运行代码时,它总会给我同样的错误"阅读内存不足"
我跟踪了我从https://github.com/vjutvik/Contiki-IPsec
下载的IPsec和IKEv.2协议代码中的错误并且在调用 hmac_sha1(prf_data); 函数时发现错误。错误信息是"读取外部存储器:0xfa8b6"。
此函数的文件路径为:contiki-ipsec \ core \ net \ ipsec \ ike \ prf.c
/**
* PRF as defined in the RFC
*/
void prf(sa_prf_transform_type_t prf_type, prf_data_t *prf_data)
{
switch (prf_type) {
case SA_PRF_HMAC_SHA1: // MUST
hmac_sha1(prf_data);
break;
case SA_PRF_AES128_CBC: // SHOULD+
PRINTF(IPSEC "Error: Not implemented\n");
break;
default:
PRINTF(IPSEC "Error: Unknown PRF request\n");
}
}
代码函数hmac_sha1(prf_data);
此函数的文件路径为:contiki-ipsec \ core \ lib \ hmac-sha1 \ hmac-sha1.c
/**
* Performs HMAC-SHA1-96. Call this function from your program.
*
* @param out Output from HMAC-SHA1-96 (must be at least 96/8=12 bytes)
* @param key The key to use
* @param keylen The length of the key
* @param data The data to hash
* @param datalen The length of the data
*/
//void hmac_sha1_96( uint16_t datalen, uint8_t * out, uint8_t * key, uint8_t keylen, uint8_t * data )
void hmac_sha1( hmac_data_t *hmac_data )
{
uint8_t * out=hmac_data->out;
uint8_t * key= (uint8_t *) hmac_data->key;
uint8_t keylen=hmac_data->keylen;
uint8_t * data=hmac_data->data;
uint16_t datalen=hmac_data->datalen;
dy_printf( "Data after %d %d %d %d %d\n", (int)out, (int)key,(int)keylen,(int)data, (int)datalen );
// Variables
uint8_t padded_key[ SHA1_B ];
uint8_t padded_key_xor_ipad[ SHA1_B ];
uint8_t sentence_a[ SHA1_B + datalen ];
uint8_t hash_output_a[ SHA1_L ];
uint8_t padded_key_xor_opad[ SHA1_B ];
uint8_t sentence_b[ SHA1_B + SHA1_L ];
uint8_t hash_output_b[ SHA1_L ];
init();
// Hash overlength keys
if( keylen > SHA1_B ){
hash_sha1( padded_key, key, keylen ); // Assumes SHA1_L <= SHA_B
create_padded_key( padded_key, padded_key, SHA1_L ); // Adds the zeros
}
else{
create_padded_key( padded_key, key, keylen );
}
dy_printf("datelen:%d\n",(int)datalen);
PRINT_BUF("padded_key",padded_key,SHA1_B);
xor_array( padded_key_xor_ipad, padded_key, ipad, SHA1_B );
PRINT_BUF("padded_key_xor_ipad",padded_key_xor_ipad,SHA1_B);
merge_arrays( sentence_a, padded_key_xor_ipad, SHA1_B, data, datalen );
PRINT_BUF("sentence_a",sentence_a,SHA1_B+datalen);
hash_sha1( hash_output_a, sentence_a, SHA1_B + datalen );
PRINT_BUF("hash_output_a",hash_output_a,SHA1_L);
xor_array( padded_key_xor_opad, padded_key, opad, SHA1_B );
PRINT_BUF("padded_key_xor_opad",padded_key_xor_opad,SHA1_B);
merge_arrays( sentence_b, padded_key_xor_opad, SHA1_B, hash_output_a, SHA1_L );
hash_sha1(hmac_data->out, sentence_b, SHA1_B + SHA1_L );
// Old truncate code
//hash_sha1( hash_output_b, sentence_b, SHA1_B + SHA1_L );
//truncate( out, hash_output_b, 96/8 );
}
我使用Ubuntu 14.04 LTS 32位
gcc(Ubuntu 4.8.4-2ubuntu1~14.04)4.8.4
版权所有(C)2013 Free Software Foundation,Inc。
msp430-gcc(GCC)4.7.2 20120920(mspgcc dev 20120911)
版权所有(C)2012 Free Software Foundation,Inc。
我使用Contiki-IPsec 2.7操作系统,我也在Cooja模拟中使用Wismote
修改:
上面函数中指针定义的类型是
typedef struct {
uint8_t *out;
const uint8_t *key;
uint8_t keylen;
uint8_t *data;
uint16_t datalen;
} hmac_data_t;
和另一种类型定义
typedef hmac_data_t prf_data_t;
高度赞赏任何克服此问题的想法。
高级感谢你。