![]() |
![]() |
A collection of utility functions for cryptographic purposes.
============================================================================
#include <stdint.h>#include <stdbool.h>#include <string.h>
Go to the source code of this file.
Functions | |
| bool | CryptoUtils_buffersMatch (const void *buffer0, const void *buffer1, size_t bufferByteLength) |
| Compares two buffers for equality without branching. More... | |
| bool | CryptoUtils_buffersMatchWordAligned (const uint32_t *buffer0, const uint32_t *buffer1, size_t bufferByteLength) |
| Compares two buffers for equality word-by-word without branching. More... | |
| bool CryptoUtils_buffersMatch | ( | const void * | buffer0, |
| const void * | buffer1, | ||
| size_t | bufferByteLength | ||
| ) |
Compares two buffers for equality without branching.
Most memcmp implementations break out of their comparison loop immediately once a mismatch is detected to save execution time. For cryptographic purposes, this is a flaw.
This function compares two buffers without branching thus requiring a an amount of time that does not vary with the content of buffer0 and buffer1.
| buffer0 | Buffer to compare against buffer1. |
| buffer1 | Buffer tp compare against buffer0 |
| bufferByteLength | Length in bytes of buffer0 and buffer1. |
| true | The contents of the buffers match. |
| false | The contents of the buffers do not match. |
| bool CryptoUtils_buffersMatchWordAligned | ( | const uint32_t * | buffer0, |
| const uint32_t * | buffer1, | ||
| size_t | bufferByteLength | ||
| ) |
Compares two buffers for equality word-by-word without branching.
Most memcmp implementations break out of their comparison loop immediately once a mismatch is detected to save execution time. For cryptographic purposes, this is a flaw.
This function compares two buffers without branching thus requiring a an amount of time that does not vary with the content of buffer0 and buffer1.
Unlike CryptoUtils_buffersMatch(), this function expects buffer0 and buffer1 to be 32-bit aligned. It will only perform 32-bit aligned accesses to memory. This is needed to access the registers of certain peripherals.
| buffer0 | Buffer to compare against buffer1. |
| buffer1 | Buffer tp compare against buffer0 |
| bufferByteLength | Length in bytes of buffer0 and buffer1. Must be evenly divisible by sizeof(uint32_t). This function will return false if bufferByteLength is not evenly divisible by sizeof(uin32_t). |
| true | The contents of the buffers match. |
| false | The contents of the buffers do not match. |