我正在尝试使用libtomcrypt库为我的学校项目开发RSA公钥。但我无法使用Contiki OS在Cooja中加载库。
我尝试将我需要的文件编译到目标文件中并将其加载到.csc
文件中。
这是我收到的错误消息:
se.sics.cooja.GUI$SimulationCreationException: Mote type creation error: Error when creating corecomm instance: Lib1
at se.sics.cooja.GUI.loadSimulationConfig(GUI.java:3440)
at se.sics.cooja.GUI.loadSimulationConfig(GUI.java:3352)
at se.sics.cooja.GUI.doLoadConfig(GUI.java:2397)
at se.sics.cooja.GUI$4.run(GUI.java:636)
at java.lang.Thread.run(Thread.java:745)
Caused by: se.sics.cooja.MoteType$MoteTypeCreationException: Error when creating corecomm instance: Lib1
at se.sics.cooja.CoreComm.createCoreComm(CoreComm.java:343)
at se.sics.cooja.contikimote.ContikiMoteType.doInit(ContikiMoteType.java:385)
at se.sics.cooja.contikimote.ContikiMoteType.configureAndInit(ContikiMoteType.java:348)
at se.sics.cooja.contikimote.ContikiMoteType.setConfigXML(ContikiMoteType.java:1389)
at se.sics.cooja.Simulation.setConfigXML(Simulation.java:681)
at se.sics.cooja.GUI.loadSimulationConfig(GUI.java:3422)
... 4 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at se.sics.cooja.CoreComm.createCoreComm(CoreComm.java:334)
... 9 more
Caused by: java.lang.UnsatisfiedLinkError: /home/user/contiki/regression-tests/12-rpl/code/obj_cooja/mtype834.cooja: /home/user/contiki/regression-tests/12-rpl/code/obj_cooja/mtype834.cooja: undefined symbol: rsa_get_size
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary1(ClassLoader.java:1968)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1893)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1854)
at java.lang.Runtime.load0(Runtime.java:795)
at java.lang.System.load(System.java:1062)
at se.sics.cooja.corecomm.Lib1.<init>(Lib1.java:49)
... 14 more
se.sics.cooja.GUI$SimulationCreationException: Mote type creation error: Error when creating corecomm instance: Lib1
at se.sics.cooja.GUI.loadSimulationConfig(GUI.java:3440)
at se.sics.cooja.GUI.loadSimulationConfig(GUI.java:3352)
at se.sics.cooja.GUI.doLoadConfig(GUI.java:2397)
at se.sics.cooja.GUI$4.run(GUI.java:636)
at java.lang.Thread.run(Thread.java:745)
Caused by: se.sics.cooja.MoteType$MoteTypeCreationException: Error when creating corecomm instance: Lib1
at se.sics.cooja.CoreComm.createCoreComm(CoreComm.java:343)
at se.sics.cooja.contikimote.ContikiMoteType.doInit(ContikiMoteType.java:385)
at se.sics.cooja.contikimote.ContikiMoteType.configureAndInit(ContikiMoteType.java:348)
at se.sics.cooja.contikimote.ContikiMoteType.setConfigXML(ContikiMoteType.java:1389)
at se.sics.cooja.Simulation.setConfigXML(Simulation.java:681)
at se.sics.cooja.GUI.loadSimulationConfig(GUI.java:3422)
... 4 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at se.sics.cooja.CoreComm.createCoreComm(CoreComm.java:334)
... 9 more
Caused by: java.lang.UnsatisfiedLinkError: /home/user/contiki/regression-tests/12-rpl/code/obj_cooja/mtype834.cooja: /home/user/contiki/regression-tests/12-rpl/code/obj_cooja/mtype834.cooja: undefined symbol: rsa_get_size
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary1(ClassLoader.java:1968)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1893)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1854)
at java.lang.Runtime.load0(Runtime.java:795)
at java.lang.System.load(System.java:1062)
at se.sics.cooja.corecomm.Lib1.<init>(Lib1.java:49)
... 14 more
这是我尝试将目标文件(rsa_get_size.o)添加到Cooja模拟脚本的mote
部分中的代码。
<motetype>
se.sics.cooja.contikimote.ContikiMoteType
<identifier>mtype456</identifier>
<description>Sender</description>
<source>[CONFIG_DIR]/code/sender-node.c</source>
<commands>make TARGET=cooja clean
make sender-node.cooja rsa_get_size.o TARGET=cooja</commands>
<moteinterface>se.sics.cooja.interfaces.Position</moteinterface>
<moteinterface>se.sics.cooja.interfaces.Battery</moteinterface>
<moteinterface>se.sics.cooja.contikimote.interfaces.ContikiVib</moteinterface>
<moteinterface>se.sics.cooja.contikimote.interfaces.ContikiMoteID</moteinterface>
<moteinterface>se.sics.cooja.contikimote.interfaces.ContikiRS232</moteinterface>
<moteinterface>se.sics.cooja.contikimote.interfaces.ContikiBeeper</moteinterface>
<moteinterface>se.sics.cooja.interfaces.RimeAddress</moteinterface>
<moteinterface>se.sics.cooja.contikimote.interfaces.ContikiIPAddress</moteinterface>
<moteinterface>se.sics.cooja.contikimote.interfaces.ContikiRadio</moteinterface>
<moteinterface>se.sics.cooja.contikimote.interfaces.ContikiButton</moteinterface>
<moteinterface>se.sics.cooja.contikimote.interfaces.ContikiPIR</moteinterface>
<moteinterface>se.sics.cooja.contikimote.interfaces.ContikiClock</moteinterface>
<moteinterface>se.sics.cooja.contikimote.interfaces.ContikiLED</moteinterface>
<moteinterface>se.sics.cooja.contikimote.interfaces.ContikiCFS</moteinterface>
<moteinterface>se.sics.cooja.interfaces.Mote2MoteRelations</moteinterface>
<moteinterface>se.sics.cooja.interfaces.MoteAttributes</moteinterface>
<symbols>false</symbols>
</motetype>
<motetype>
这是我尝试实现RSA公钥生成的代码:
#include "contiki.h"
#include "lib/random.h"
#include "sys/ctimer.h"
#include "sys/etimer.h"
#include "net/uip.h"
#include "net/uip-ds6.h"
#include "net/uip-debug.h"
#include "simple-udp.h"
#include <stdio.h>
#include <string.h>
#include <tomcrypt.h>
#define UDP_PORT 1234
#define SEND_INTERVAL (60 * CLOCK_SECOND)
#define SEND_TIME (random_rand() % (SEND_INTERVAL))
static struct simple_udp_connection unicast_connection;
/*---------------------------------------------------------------------------*/
PROCESS(sender_node_process, "Sender node process");
AUTOSTART_PROCESSES(&sender_node_process);
/*---------------------------------------------------------------------------*/
static void
receiver(struct simple_udp_connection *c,
const uip_ipaddr_t *sender_addr,
uint16_t sender_port,
const uip_ipaddr_t *receiver_addr,
uint16_t receiver_port,
const uint8_t *data,
uint16_t datalen)
{
printf("Sender received data on port %d from port %d with length %d\n",
receiver_port, sender_port, datalen);
}
/*---------------------------------------------------------------------------*/
static void
set_global_address(void)
{
uip_ipaddr_t ipaddr;
int i;
uint8_t state;
uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
printf("IPv6 addresses: ");
for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
state = uip_ds6_if.addr_list[i].state;
if(uip_ds6_if.addr_list[i].isused &&
(state == ADDR_TENTATIVE || state == ADDR_PREFERRED)) {
uip_debug_ipaddr_print(&uip_ds6_if.addr_list[i].ipaddr);
printf("\n");
}
}
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(sender_node_process, ev, data)
{
static struct etimer periodic_timer;
static struct etimer send_timer;
uip_ipaddr_t addr;
prng_state* prng;
rsa_key* key;
// register_algs();
int size = rsa_get_size(key);
int result = rsa_make_key(
prng,
0,
size,
65537,
key);
printf("key %d\n",result);
PROCESS_BEGIN();
set_global_address();
simple_udp_register(&unicast_connection, UDP_PORT,
NULL, UDP_PORT, receiver);
etimer_set(&periodic_timer, SEND_INTERVAL);
while(1) {
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer));
etimer_reset(&periodic_timer);
etimer_set(&send_timer, SEND_TIME);
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&send_timer));
uip_ip6addr(&addr, 0xaaaa, 0, 0, 0, 0x0201, 0x001, 0x001, 0x001);
{
static unsigned int message_number;
char buf[20];
printf("Sending unicast to ");
uip_debug_ipaddr_print(&addr);
printf("\n");
sprintf(buf, "Message %d", message_number);
message_number++;
simple_udp_sendto(&unicast_connection, buf, strlen(buf) + 1, &addr);
}
}
PROCESS_END();
}
答案 0 :(得分:1)
Contiki使用基于GNU make的系统。每个应用程序都有Makefile
个。要向应用程序添加额外文件,请更改Makefile
。
如果只需要添加一个文件:
PROJECT_SOURCEFILES += rsa_get_size.c
如果它是.c
文件的整个目录,请在应用程序的文件夹中说tomcrypt
:
MODULES += ./tomcrypt