Skip to content

An implementation of SPARX block cipher targeting microcontrollers

License

Notifications You must be signed in to change notification settings

the-cave/embeddable-sparx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Embeddable SPARX

What is it?

Embeddable SPARX is an implementation of a block cipher SPARX. The goal of Embeddable SPARX is to make the cipher more suitble for PSK scheme adaptation for embedded systems.

What's special? and tradeoffs

  • The key scheduler is not included in the runtime environment, resulting in a lighter-weight code size and less heap memory usage
  • Asynchronous execution with callback interfaces
  • Hightly cooperative polling, non-blocking encryption and decryption
  • Optional concurrency with multiple instances
  • No CPU hogging
  • 128-bit block with 128-bit key mode only
  • Static (and precomputed) key schedule matrix must be present

Porting?

No need, the code is hardware and platform agnostic. It will run everywhere as long as C language works. You can even run the test on your PC.

However, at the very least, 32-bit processor like Arm Cortex-M0 is recommended.

Usages

See the test for an example.

Commons

Declare the key schedule matrix

static const uint32_t key_schedule[EMBEDDABLE_SPARX__ROUND] = ...;

Declare the configuration of an instance including the callback function

static void encrypted_handler(uint8_t *result);
static const EmbeddableSparx_Config encryption_config = {
    .key_schedule = (uint32_t *)key_schedule,
    .finished = &encrypted_handler,
};

Declare state in RAM and reset the memory on application start

static EmbeddableSparx_State encryption_state;
embeddable_sparx__init(&encryption_state);

Encryption

Start by feeding the input data to an instance

embeddable_sparx__start(&encryption_state, plain_text);

And keep polling for the encryption

embeddable_sparx__encryption_poll(&encryption_config, &encryption_state);

Decryption

The only difference from the encryption part is the polling function operate on an instance.
Keeping everything else the same.

embeddable_sparx__decryption_poll(&decryption_config, &decryption_state);

If the explanation is not clear you can always see an actual usage in the test.

Both embeddable_sparx__encryption_poll and embeddable_sparx__decryption_poll operations are safe to be called periodically. Just make sure each of them does not operate on the same instance.
If there is nothing to be done the function would return right away; costing only about a couple of address jump on the hardware running the program.

Prerequisites

Testing

Just clone the repository with submodules and make run.

Limitations

Currently only supporting little-endian CPU, if someone happen to use it on a big-endian one, feel free to send a pull request.

More controversy one

The author of this library also authored Embeddable Speck library, implementing an NSA-designed-algorithm, with the exact same API as this one.

License

Embeddable SPARX is released under the BSD 3-Clause License. 🎉