Difference between revisions of "CC2420 Security Tutorial"

From TinyOS Wiki
Jump to: navigation, search
m
m
Line 93: Line 93:
  
 
Sample implementations of applications that enable the CC2420 in-line security features (RadioCountToLeds and BaseStation) can be found in [http://tinyos.cvs.sourceforge.net/viewvc/tinyos/tinyos-2.x/apps/tests/cc2420/TestSecurity/ apps/tests/cc2420/TestSecurity/].
 
Sample implementations of applications that enable the CC2420 in-line security features (RadioCountToLeds and BaseStation) can be found in [http://tinyos.cvs.sourceforge.net/viewvc/tinyos/tinyos-2.x/apps/tests/cc2420/TestSecurity/ apps/tests/cc2420/TestSecurity/].
 +
 +
 +
== See also ==
 +
*[[TinySec]]
  
 
[[Category:CC2420]]
 
[[Category:CC2420]]
 
[[Category:Security]]
 
[[Category:Security]]
 
[[Category:Tutorials]]
 
[[Category:Tutorials]]

Revision as of 09:47, 17 November 2009

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, 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.1: CC2420SecurityMode and CC2420Keys. The implementations are located in tos/chips/cc2420/security/ and the interfaces are located in tos/chips/cc2420/interfaces/. The design of the security implementation is based on the CC2420 specifications and the IEEE 802.15.4-2006 standards.

Transmitter Configuration

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. The format of the security header can be found in tos/chips/cc2420/CC2420.h

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. The example below sets register 1 of the key registers (CC2420 offers registers 0 and 1) to a user specified key value shown 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 node. When this event is signaled, one of 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,

  call AMSend.send(msg, len); 

can be called to send a packet just like any other packet transmissions.

Receiver Configuration

A receiver node that intends to enable the CC2420 Security features MUST add the CC2420_HW_SECURITY flag in the Makefile as well as the transmitter.

  CFLAGS+=-CC2420_HW_SECURITY

This enables all the decryption processes in the CC2420ReceiveP.nc file. Also, the receiver must have knowledge about the key values that a transmitter is using and SHOULD set the key registers with the user-desired keys before packets are exchanged. The example below sets register 1 of the key registers (CC2420 offers registers 0 and 1) to a user specified key value.

  uint8_t key[16] = {0x98,0x67,0x7F,0xAF,0xD6,0xAD,0xB7,0x0C,0x59,0xE8,0xD9,0x47,0xC9,0x71,0x15,0x0F};
  call CC2420Keys.setKey(1, key);

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

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

To use the CC2420Keys interface above, the following wiring MUST be done in the configuration file.

  components CC2420KeysC;
  App.CC2420Keys -> CC2420KeysC;

For the receiver, this event indicates that the radio is now ready to decrypt packets with the user-defined key values.

Examples

Sample implementations of applications that enable the CC2420 in-line security features (RadioCountToLeds and BaseStation) can be found in apps/tests/cc2420/TestSecurity/.


See also