I'm making an adapter to convert a wired keyboard I have into a wireless keyboard. I am going to use nRF2401 modules for wireless with some STM32 microcontrollers. I'm trying to come up with a method that will prevent playback attacks and prevent my data from being read. I don't have any formal training in cryptography, just what I've picked up as a hobbyist. Here's what I have so far:

The Keyboard and receiver will both have a CR2032 for RAM persistence when detached from power. The Keyboard will have a rechargeable battery for main power, receiver will be powered by USB from the host.

When a pairing button is pressed on the keyboard adapter it will start broadcasting an initialization message for a Diffie Hellman exchange, the keyboard will share it's randomly generated mod, base, and public key. I'll use the longest key length that the microcontrollers I'm using will allow, I'll benchmark it once they get in. This message will be broadcast once a second until it receives a valid ack from the receiver.

The receiver will not start listening for a pairing request from the keyboard until it's pairing button has also been pressed. The receiver will respond with it's random public key and an "OK" message. The keyboard will respond with an encrypted OK and both will be paired. If pairing does not finish within 5 seconds of starting it will be cancelled and they will both clear keys/have to be repaired. Both items having a random value within the DH exchange should prevent playback messages during this stage, I believe.

After pairing all messages will be encrypted with AES with messages padded to the same length with random data, and will include at least 8 bytes of random data in the stream before encryption. This should prevent any two packets from being identical to prevent heuristic attacks.

All packets will also have an incrementing number, starting at 0. The receiver and keyboard will both only accept an encrypted packet with a counter above the current counter. Both devices will keep track of the current packet counter. This counter will prevent playback attacks after pairing.

Every time the packet counter is incremented a checksum of the private key + packet counter will be stored in the persistent RAM. This checksum will be checked at main power power-up to verify the packet counter, if it doesn't match the keys will be cleared and communication won't occur until the devices are re-paired. This is to prevent a temporary power loss that may potentially reset the packet counter but not the key.

  • What is your use case for this? Is this just a one-off hobbyist project, or are you looking for something to be used in a production environment? Providing this information will help guide answers. – Dan Landberg Dec 28 '20 at 16:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.