CC2420 Security Tutorial

From TinyOS Wiki
Revision as of 13:12, 11 September 2009 by Jgko (talk | contribs)
Jump to: navigation, search

This tutorial explains how the CC2420 in-line security features can be enabled in an application. Using the security features require modifications to the Makefile, configuration file, and the implementation file.

Note: CC2420 Security Features are part of TinyOS 2.1.1.

Introduction

The CC2420 radio chip supports three types of in-line security modes [1], leveraging the same underlying 128-bit AES encryption: Counter Mode Encryption, CBC-MAC (Cipher Block Chaining Message Authentication Code) and CCM (Counter with CBC-MAC). The CC2420 in-line security implementations add two new interfaces to the CC2420 radio stack in TinyOS 2.x: CC2420SecurityMode and CC2420Keys. The design of the security implementation is based on the CC2420 specifications [1] and the IEEE 802.15.4 standards [2].

Makefile

Users intending to enable the security features MUST add the CC2420_HW_SECURITY flag in the Makefile.

  CFLAGS+=-CC2420_HW_SECURITY

Another point to note is the possible need for modifying the value of TOSH_DATA_LENGTH. Using different security options will add different amounts of additional overhead in the packet. For example, using the CBC-MAC authentication with a 16 byte MIC will require an additional 16 bytes in the payload portion of the message_t. While the security header is located in the cc2420_header_t, it takes up 6 additional bytes in the packet as well.

Wiring (configuration file)

  components new SecAMSenderC(AM_RADIO_COUNT_MSG) as AMSenderC;
  components new AMReceiverC(AM_RADIO_COUNT_MSG);
  components CC2420KeysC;
  App.Receive -> AMReceiverC;
  App.AMSend -> AMSenderC;
  App.Packet -> AMSenderC;
  App.CC2420SecurityMode -> AMSenderC;
  App.CC2420Keys -> CC2420KeysC;

The AMSender interface MUST be wired to the SecAMSenderC component. The Packet interface is also provided by the SecAMSenderC and all packets that use the CC2420 in-line security features MUST be wired to this component. Note that the CC2420SecurityMode interface explained in the previous section is also provided by the SecAMSenderC component. The CC2420Key interface is provided by the CC2420KeyC component. The Receive interface can be wired as the case when no security is used because decryption happens transparently for the secured packets at the lower layers (below AM stack).

Implementation File

An array of 16 bytes SHOULD be set to store the desired key values. An example is shown below.

  uint8_t key[16] = {0x98,0x67,0x7F,0xAF,0xD6,0xAD,0xB7,0x0C,0x59,0xE8,0xD9,0x47,0xC9,0x71,0x15,0x0F};

After the radio starts (SplitControl.startDone()), the following commands SHOULD be called to set the key values to a desired key register as explained above.

  call CC2420Keys.setKey(1, key);

This call to the setKey command signals an event indicating the end of the key setting process.

  event void CC2420Keys.setKeyDone(uint8_t keyNo, uint8_t* skey){}

This event is important for both the transmitting and receiving nodes. For the receiver, this event indicates that the radio is now ready to decrypt packets with the user-defined key values. At the transmitting node, when this event is signaled, the following commands provided by the CC2420SecurityMode interface can be called for each packet transmission, with respect to the user-defined key values.

  call CC2420SecurityMode.setCtr(msg, 1, 0);
  call CC2420SecurityMode.setCbcMac(msg, 1, 0, 16);
  call CC2420SecurityMode.setCcm(msg, 1, 0, 16);

Once the above steps are done (at the transmitter), call AMSend.send(msg, len) can be called to send a packet. A sample implementation with the CC2420 in-line security features (RadioCountToLeds and BaseStation) can be found in /apps/tests/cc2420/TestSecurity/.