1

嗨,我一直在尝试在 contiki os 和 cooja 上使用 libtomcrypt 库

我将 rsa 所需的文件编译为像 rsa_get_size.c 一样工作的目标文件,并在尝试将其加载到模拟器网络中时添加到 csc 文件中。

但我一直收到下面的错误。抱歉,我对 contiki os 和 libtomcrypt 库还很陌生,在此先感谢您的帮助和指导。

 > make TARGET=cooja clean 
    rm -f *~ *core core *.srec \
        *.lst *.map \
        *.cprg *.bin *.data contiki*.a *.firmware core-labels.S *.ihex *.ini \
        *.ce *.co
    rm -rf 
    rm -rf obj_cooja

    > make sender-node.cooja rsa_get_size.o TARGET=cooja 
      CC        sender-node.c
    sender-node.c: In function 'process_thread_sender_node_process':
    sender-node.c:165:3: warning: implicit declaration of function 'rsa_get_size' [-Wimplicit-function-declaration]
    sender-node.c:165:7: warning: 'key' is used uninitialized in this function [-Wuninitialized]
    sender-node.c:166:7: warning: 'prng' is used uninitialized in this function [-Wuninitialized]
    mkdir obj_cooja
      CC        ../../../platform/cooja/./contiki-cooja-main.c
    ../../../platform/cooja/./contiki-cooja-main.c: In function 'contiki_init':
    ../../../platform/cooja/./contiki-cooja-main.c:230:14: warning: variable 'shortaddr' set but not used [-Wunused-but-set-variable]
    ../../../platform/cooja/./contiki-cooja-main.c:288:5: warning: passing argument 1 of 'rimeaddr_copy' from incompatible pointer type [enabled by default]
    ../../../core/./net/rime/rimeaddr.h:79:6: note: expected 'union rimeaddr_t *' but argument is of type 'uint8_t *'
    mv contiki-cooja-main.o obj_cooja/mtype739.o
      CC        ../../../core/net/rime/rimeaddr.c
      CC        ../../../core/net/rime/timesynch.c
      CC        ../../../core/net/rime/rimestats.c
      CC        ../../../core/net/mac/cxmac.c
      CC        ../../../core/net/mac/xmac.c
    ../../../core/net/mac/xmac.c: In function 'send_packet':
    ../../../core/net/mac/xmac.c:457:7: warning: variable 'ret' set but not used [-Wunused-but-set-variable]
      CC        ../../../core/net/mac/nullmac.c
      CC        ../../../core/net/mac/lpp.c
    ../../../core/net/mac/lpp.c: In function 'input_packet':
    ../../../core/net/mac/lpp.c:783:7: warning: variable 'ret' set but not used [-Wunused-but-set-variable]
      CC        ../../../core/net/mac/frame802154.c
      CC        ../../../core/net/mac/sicslowmac.c
      CC        ../../../core/net/mac/nullrdc.c
    ../../../core/net/mac/nullrdc.c: In function 'send_one_packet':
    ../../../core/net/mac/nullrdc.c:182:13: warning: implicit declaration of function 'cooja_mt_yield' [-Wimplicit-function-declaration]
      CC        ../../../core/net/mac/nullrdc-noframer.c
      CC        ../../../core/net/mac/mac.c
      CC        ../../../core/net/mac/framer-nullmac.c
      CC        ../../../core/net/mac/framer-802154.c
      CC        ../../../core/net/mac/csma.c
      CC        ../../../core/net/mac/contikimac.c
    ../../../core/net/mac/contikimac.c: In function 'powercycle':
    ../../../core/net/mac/contikimac.c:386:27: warning: variable 't0' set but not used [-Wunused-but-set-variable]
    ../../../core/net/mac/contikimac.c: In function 'send_packet':
    ../../../core/net/mac/contikimac.c:766:11: warning: variable 'ret' set but not used [-Wunused-but-set-variable]
    ../../../core/net/mac/contikimac.c:544:11: warning: variable 'is_reliable' set but not used [-Wunused-but-set-variable]
      CC        ../../../core/net/mac/phase.c
      CC        ../../../core/net/rpl/rpl.c
      CC        ../../../core/net/rpl/rpl-dag.c
      CC        ../../../core/net/rpl/rpl-icmp6.c
      CC        ../../../core/net/rpl/rpl-timers.c
      CC        ../../../core/net/rpl/rpl-mrhof.c
      CC        ../../../core/net/rpl/rpl-ext-header.c
      CC        ../../../core/sys/process.c
      CC        ../../../core/sys/procinit.c
      CC        ../../../core/sys/autostart.c
      CC        ../../../core/loader/elfloader.c
      CC        ../../../core/sys/profile.c
      CC        ../../../core/sys/timetable.c
      CC        ../../../core/sys/timetable-aggregate.c
      CC        ../../../core/sys/compower.c
      CC        ../../../core/dev/serial-line.c
      CC        ../../../core/lib/memb.c
      CC        ../../../core/lib/mmem.c
      CC        ../../../core/sys/timer.c
      CC        ../../../core/lib/list.c
      CC        ../../../core/sys/etimer.c
      CC        ../../../core/sys/ctimer.c
      CC        ../../../core/sys/energest.c
      CC        ../../../core/sys/rtimer.c
      CC        ../../../core/sys/stimer.c
      CC        ../../../core/lib/trickle-timer.c
      CC        ../../../core/lib/print-stats.c
      CC        ../../../core/lib/ifft.c
      CC        ../../../core/lib/crc16.c
      CC        ../../../core/lib/random.c
      CC        ../../../core/lib/checkpoint.c
      CC        ../../../core/lib/ringbuf.c
      CC        ../../../core/lib/settings.c
      CC        ../../../core/net/dhcpc.c
      CC        ../../../core/net/hc.c
      CC        ../../../core/net/nbr-table.c
      CC        ../../../core/net/netstack.c
      CC        ../../../core/net/packetbuf.c
      CC        ../../../core/net/packetqueue.c
      CC        ../../../core/net/psock.c
      CC        ../../../core/net/queuebuf.c
      CC        ../../../core/net/resolv.c
    ../../../core/net/resolv.c: In function 'mdns_write_announce_records':
    ../../../core/net/resolv.c:509:22: warning: variable 'ans' set but not used [-Wunused-but-set-variable]
    ../../../core/net/resolv.c: In function 'mdns_prep_host_announce_packet':
    ../../../core/net/resolv.c:606:22: warning: unused variable 'ans' [-Wunused-variable]
      CC        ../../../core/net/sicslowpan.c
      CC        ../../../core/net/simple-udp.c
      CC        ../../../core/net/tcpdump.c
      CC        ../../../core/net/tcpip.c
      CC        ../../../core/net/uaodv-rt.c
    ../../../core/net/uaodv-rt.c: In function 'uaodv_rt_lookup_any':
    ../../../core/net/uaodv-rt.c:98:5: warning: implicit declaration of function 'memcmp' [-Wimplicit-function-declaration]
      CC        ../../../core/net/uaodv.c
    ../../../core/net/uaodv.c: In function 'fwc_lookup':
    ../../../core/net/uaodv.c:91:3: warning: implicit declaration of function 'memcmp' [-Wimplicit-function-declaration]
      CC        ../../../core/net/uip-debug.c
      CC        ../../../core/net/uip-ds6-route.c
      CC        ../../../core/net/uip-ds6-nbr.c
      CC        ../../../core/net/uip-ds6.c
      CC        ../../../core/net/uip-fw-drv.c
      CC        ../../../core/net/uip-fw.c
      CC        ../../../core/net/uip-icmp6.c
      CC        ../../../core/net/uip-nd6.c
      CC        ../../../core/net/uip-neighbor.c
      CC        ../../../core/net/uip-over-mesh.c
      CC        ../../../core/net/uip-packetqueue.c
      CC        ../../../core/net/uip-split.c
      CC        ../../../core/net/uip-udp-packet.c
      CC        ../../../core/net/uip.c
      CC        ../../../core/net/uip6.c
      CC        ../../../core/net/uip_arp.c
      CC        ../../../core/net/uiplib.c
      CC        ../../../core/sys/mt.c
      CC        ../../../core/dev/nullradio.c
      CC        ../../../platform/cooja/lib/simEnvChange.c
      CC        ../../../platform/cooja/sys/cooja_mt.c
      CC        ../../../platform/cooja/sys/cooja_mtarch.c
      CC        ../../../platform/cooja/./rtimer-arch.c
      CC        ../../../core/dev/slip.c
      CC        ../../../platform/cooja/dev/watchdog.c
      CC        ../../../platform/cooja/dev/beep.c
      CC        ../../../platform/cooja/dev/button-sensor.c
      CC        ../../../platform/cooja/dev/ip.c
      CC        ../../../platform/cooja/dev/leds-arch.c
      CC        ../../../platform/cooja/dev/moteid.c
      CC        ../../../platform/cooja/dev/pir-sensor.c
      CC        ../../../platform/cooja/dev/rs232.c
    ../../../platform/cooja/dev/rs232.c: In function 'slip_arch_writeb':
    ../../../platform/cooja/dev/rs232.c:73:3: warning: implicit declaration of function 'simlog_char' [-Wimplicit-function-declaration]
      CC        ../../../platform/cooja/dev/vib-sensor.c
      CC        ../../../platform/cooja/sys/clock.c
      CC        ../../../platform/cooja/sys/log.c
      CC        ../../../platform/cooja/cfs/cfs-cooja.c
    ../../../platform/cooja/cfs/cfs-cooja.c: In function 'cfs_write':
    ../../../platform/cooja/cfs/cfs-cooja.c:104:25: warning: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
      CC        ../../../platform/cooja/dev/cooja-radio.c
      CC        ../../../core/lib/sensors.c
      CC        ../../../core/dev/leds.c
      CC        symbols.c
      CC        ../../../platform/cooja/net/uip-driver.c
    ../../../platform/cooja/net/uip-driver.c: In function 'init':
    ../../../platform/cooja/net/uip-driver.c:66:3: warning: passing argument 1 of 'tcpip_set_outputfunc' from incompatible pointer type [enabled by default]
    ../../../core/./net/tcpip.h:344:6: note: expected 'uint8_t (*)(struct uip_lladdr_t *)' but argument is of type 'uint8_t (*)(void)'
    ar rcf obj_cooja/mtype739.a obj_cooja/rimeaddr.o obj_cooja/timesynch.o obj_cooja/rimestats.o obj_cooja/cxmac.o obj_cooja/xmac.o obj_cooja/nullmac.o obj_cooja/lpp.o obj_cooja/frame802154.o obj_cooja/sicslowmac.o obj_cooja/nullrdc.o obj_cooja/nullrdc-noframer.o obj_cooja/mac.o obj_cooja/framer-nullmac.o obj_cooja/framer-802154.o obj_cooja/csma.o obj_cooja/contikimac.o obj_cooja/phase.o obj_cooja/rpl.o obj_cooja/rpl-dag.o obj_cooja/rpl-icmp6.o obj_cooja/rpl-timers.o obj_cooja/rpl-mrhof.o obj_cooja/rpl-ext-header.o obj_cooja/process.o obj_cooja/procinit.o obj_cooja/autostart.o obj_cooja/elfloader.o obj_cooja/profile.o obj_cooja/timetable.o obj_cooja/timetable-aggregate.o obj_cooja/compower.o obj_cooja/serial-line.o obj_cooja/memb.o obj_cooja/mmem.o obj_cooja/timer.o obj_cooja/list.o obj_cooja/etimer.o obj_cooja/ctimer.o obj_cooja/energest.o obj_cooja/rtimer.o obj_cooja/stimer.o obj_cooja/trickle-timer.o obj_cooja/print-stats.o obj_cooja/ifft.o obj_cooja/crc16.o obj_cooja/random.o obj_cooja/checkpoint.o obj_cooja/ringbuf.o obj_cooja/settings.o obj_cooja/dhcpc.o obj_cooja/hc.o obj_cooja/nbr-table.o obj_cooja/netstack.o obj_cooja/packetbuf.o obj_cooja/packetqueue.o obj_cooja/psock.o obj_cooja/queuebuf.o obj_cooja/resolv.o obj_cooja/sicslowpan.o obj_cooja/simple-udp.o obj_cooja/tcpdump.o obj_cooja/tcpip.o obj_cooja/uaodv-rt.o obj_cooja/uaodv.o obj_cooja/uip-debug.o obj_cooja/uip-ds6-route.o obj_cooja/uip-ds6-nbr.o obj_cooja/uip-ds6.o obj_cooja/uip-fw-drv.o obj_cooja/uip-fw.o obj_cooja/uip-icmp6.o obj_cooja/uip-nd6.o obj_cooja/uip-neighbor.o obj_cooja/uip-over-mesh.o obj_cooja/uip-packetqueue.o obj_cooja/uip-split.o obj_cooja/uip-udp-packet.o obj_cooja/uip.o obj_cooja/uip6.o obj_cooja/uip_arp.o obj_cooja/uiplib.o obj_cooja/mt.o obj_cooja/nullradio.o obj_cooja/simEnvChange.o obj_cooja/cooja_mt.o obj_cooja/cooja_mtarch.o obj_cooja/rtimer-arch.o obj_cooja/slip.o obj_cooja/watchdog.o obj_cooja/beep.o obj_cooja/button-sensor.o obj_cooja/ip.o obj_cooja/leds-arch.o obj_cooja/moteid.o obj_cooja/pir-sensor.o obj_cooja/rs232.o obj_cooja/vib-sensor.o obj_cooja/clock.o obj_cooja/log.o obj_cooja/cfs-cooja.o obj_cooja/cooja-radio.o obj_cooja/sensors.o obj_cooja/leds.o obj_cooja/symbols.o obj_cooja/uip-driver.o 
    Redefining printf
    objcopy --redefine-sym printf=log_printf sender-node.co;   objcopy --redefine-sym printf=log_printf obj_cooja/mtype739.o;   objcopy --redefine-sym printf=log_printf obj_cooja/mtype739.a; 
    objcopy --redefine-sym puts=log_puts sender-node.co;   objcopy --redefine-sym puts=log_puts obj_cooja/mtype739.o;   objcopy --redefine-sym puts=log_puts obj_cooja/mtype739.a; 
    objcopy --redefine-sym putchar=log_putchar sender-node.co;   objcopy --redefine-sym putchar=log_putchar obj_cooja/mtype739.o;   objcopy --redefine-sym putchar=log_putchar obj_cooja/mtype739.a; 
    gcc -I'/usr/lib/jvm/java-7-openjdk-i386/include' -I'/usr/lib/jvm/java-7-openjdk-i386/include/linux' -shared -Wl,-Map=obj_cooja/mtype739.map -o obj_cooja/mtype739.cooja sender-node.co obj_cooja/mtype739.o obj_cooja/mtype739.a 
    cp obj_cooja/mtype739.cooja sender-node.cooja
    rm sender-node.co
    make: *** No rule to make target `rsa_get_size.o'.  Stop.
    Process returned error code 2

我认为问题在于我在调用 rsa_get_size 方法之前没有初始化 prng_state* prng 和 rsa_key* 键。

但我不确定我应该怎么做,也找不到任何关于它们的文档或教程

下面的源代码是我累调用函数的地方

#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");
    }
  }
}
void register_algs(void)
{
#ifdef LTC_RIJNDAEL
  register_cipher (&aes_desc);
#endif
#ifdef LTC_BLOWFISH
  register_cipher (&blowfish_desc);
#endif
#ifdef LTC_XTEA
  register_cipher (&xtea_desc);
#endif
#ifdef LTC_RC5
  register_cipher (&rc5_desc);
#endif
#ifdef LTC_RC6
  register_cipher (&rc6_desc);
#endif
#ifdef LTC_SAFERP
  register_cipher (&saferp_desc);
#endif
#ifdef LTC_TWOFISH
  register_cipher (&twofish_desc);
#endif
#ifdef LTC_SAFER
  register_cipher (&safer_k64_desc);
  register_cipher (&safer_sk64_desc);
  register_cipher (&safer_k128_desc);
  register_cipher (&safer_sk128_desc);
#endif
#ifdef LTC_RC2
  register_cipher (&rc2_desc);
#endif
#ifdef LTC_DES
  register_cipher (&des_desc);
  register_cipher (&des3_desc);
#endif
#ifdef LTC_CAST5
  register_cipher (&cast5_desc);
#endif
#ifdef LTC_NOEKEON
  register_cipher (&noekeon_desc);
#endif
#ifdef LTC_SKIPJACK
  register_cipher (&skipjack_desc);
#endif
#ifdef LTC_KHAZAD
  register_cipher (&khazad_desc);
#endif
#ifdef LTC_ANUBIS
  register_cipher (&anubis_desc);
#endif

   if (register_hash(&sha256_desc) == -1) {
      printf("Error registering LTC_SHA256\n");
      exit(-1);
   }

   if (register_prng(&yarrow_desc) == -1) {
      printf("Error registering yarrow PRNG\n");
      exit(-1);
   }

   if (register_prng(&sprng_desc) == -1) {
      printf("Error registering sprng PRNG\n");
      exit(-1);
   }
}
/*---------------------------------------------------------------------------*/
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();
}
4

0 回答 0