Announcements‎ > ‎

Securing SWAP networks

posted Jun 11, 2012, 3:31 AM by Daniel Berenguer
Wireless security is one of the trending topics nowadays. Depending on the type of application, it can get even more relevance than the rest of technical aspects. In order to provide the necessary security for most projects, panStamps now include a dual mechanism consisting of an anti-playback system and a basic smart encryption engine run from firmware.

panStamp, dual security mechanism

Anti-playback relies on the nonce field, included in every SWAP packet. This nonce byte continuously evolves on each status transmission whilst commands have to match the current nonce for each mote. Otherwise, they are discarded my the mote. This mechanism protects the wireless network against anyone sitting in front of your house and recording the command used to open your garage door.

Smart encryption is implemented from firmware and, as such, it has been designed to be efficient and effective. Instead of using heavier algorithms, panStamps (optionally) run a simple XOR-based encryption using a 12-byte password and the evolutive nonce as the encryption operands. Our new smart algorithm overcomes the typical vulnerabilities of other basic XOR encryptions thanks to the following strategies:

  • SWAP packets are typically short so the bytes from the 12-byte password don't need to be extensively reused.
  • Function code is the only byte from the SWAP packet that can be easily guessed. This field uses its own password byte, not reusable for the rest of the packet.
  • Thanks to the nonce byte, identical packets result in total different contents after encryption.

Security is now available from the panStamp Arduino library and has to be configured from the user application as follows:

void setup()
  // Init panstamp

  // Smart encryption
  byte password[] = {1,2,3,4,5,6,7,8,9,10,11,12};

  // Anti-playback

And finally, this is the piece of code used to encrypt and decrypt wireless packets:

 * smartEncrypt
 * Apply Smart Encryption to the SWAP packet passed as argument
 * 'decrypt': if true, Decrypt packet. Encrypt otherwise
void SWPACKET::smartEncrypt(bool decrypt) 
  byte i, j = 0;
  static byte newData[CC1101_DATA_LEN];

  if (decrypt)
    nonce ^= panstamp.encryptPwd[9];

  function ^= panstamp.encryptPwd[11] ^ nonce;
  srcAddr ^= panstamp.encryptPwd[10] ^ nonce;
  regAddr ^= panstamp.encryptPwd[8] ^ nonce;
  regId ^= panstamp.encryptPwd[7] ^ nonce;

  for(i=0 ; i<value.length ; i++)
    newData[i] =[i] ^ panstamp.encryptPwd[j] ^ nonce;
    if (j == 11)  // Don't re-use last byte from password
      j = 0;
  if (value.length > 0) = newData;

  if (!decrypt)
    nonce ^= panstamp.encryptPwd[9];