An implementation of SPARX block cipher targeting microcontrollers
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.
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.
See the test for an example.
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);
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);
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.
Just clone the repository with submodules and make run
.
Currently only supporting little-endian CPU, if someone happen to use it on a big-endian one, feel free to send a pull request.
The author of this library also authored Embeddable Speck library, implementing an NSA-designed-algorithm, with the exact same API as this one.
Embeddable SPARX is released under the BSD 3-Clause License.