尝试使用libtomcrypt库时出现Contiki微粒类型创建错误(RSA公钥生成) [英] Contiki mote type creation error when trying to use libtomcrypt library (rsa public key generation)

查看:111
本文介绍了尝试使用libtomcrypt库时出现Contiki微粒类型创建错误(RSA公钥生成)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的学校项目使用libtomcrypt库进行RSA公钥生成.但是我无法使用Contiki OS在Cooja中加载库.

I am trying to work on RSA public key generation using libtomcrypt library for my school project. But I am unable to load the library in Cooja using Contiki OS.

我试图将所需的文件编译为目标文件,并将其加载到 .csc 文件中.

I tried to compile the file I need into an object file and load it in .csc file.

这是我收到的错误消息:

This is the error message I got:

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 部分中的代码.

This is the code I tried to use to add the object file (rsa_get_size.o) into the mote section in the Cooja simulation script.

 <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公钥生成的代码:

This is the code where I tried to implement RSA public key generation:

#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();
}

推荐答案

Contiki使用基于GNU make的系统.每个应用程序都有一个 Makefile .要将其他文件添加到您的应用程序,请更改 Makefile .

Contiki uses GNU make based system. There is a Makefile for each application. To add extra files to your application, change the Makefile.

如果只是一个文件,则需要添加:

If it's just one file you need to add:

PROJECT_SOURCEFILES += rsa_get_size.c

如果它是 .c 文件的整个目录,则假设应用程序文件夹中的 tomcrypt :

If it's a whole directory of .c files, let's say tomcrypt in the application's folder:

MODULES += ./tomcrypt

这篇关于尝试使用libtomcrypt库时出现Contiki微粒类型创建错误(RSA公钥生成)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆