Internal, Utility
More...
Go to the source code of this file.
|
ORDO_HIDDEN size_t | pad_check (const void *buffer, size_t len) |
|
ORDO_HIDDEN void | xor_buffer (void *RESTRICT dst, const void *RESTRICT src, size_t len) |
|
ORDO_HIDDEN void | inc_buffer (unsigned char *buffer, size_t len) |
|
Internal, Utility
This header provides various utility functions which are used by some library modules and a few convenience macros. It is not to be used outside the library, and this is enforced by an include guard. If you really must access it, define the ORDO_INTERNAL_ACCESS
token before including it.
Converts bits into bytes (rounded down to the nearest byte boundary).
Converts bytes into bits (as a multiple of 8 bits).
#define offset |
( |
|
ptr, |
|
|
|
len |
|
) |
| |
Computes a byte-based offset.
- Parameters
-
[in] | ptr | Base pointer. |
[in] | len | Offset (in bytes). |
- Returns
- The pointer exactly
len
bytes after ptr
.
ORDO_HIDDEN size_t pad_check |
( |
const void * |
buffer, |
|
|
size_t |
len |
|
) |
| |
Checks whether a buffer conforms to PKCS #7 padding.
- Parameters
-
[in] | buffer | The buffer to verify, starting at the first data byte (not at the first padding byte). |
[in] | len | The length in bytes of the buffer. |
- Returns
- The message length if the buffer is valid, or
0
otherwise. The message can therefore be recovered as the first N bytes.
- Warning
- This implies the buffer must be at least
padding
bytes long.
ORDO_HIDDEN void xor_buffer |
( |
void *RESTRICT |
dst, |
|
|
const void *RESTRICT |
src, |
|
|
size_t |
len |
|
) |
| |
Performs a bitwise exclusive-or of one buffer onto another.
- Parameters
-
[in,out] | dst | The destination buffer. |
[in] | src | The source buffer. |
[in] | len | The number of bytes to process. |
- Warning
- The source and destination buffers may not overlap.
ORDO_HIDDEN void inc_buffer |
( |
unsigned char * |
buffer, |
|
|
size_t |
len |
|
) |
| |
Increments a buffer of arbitrary length, as though it were a len
byte integer stored as a byte array.
- Parameters
-
[in,out] | buffer | The buffer to increment in-place. |
[in] | len | The size, in bytes, of the buffer. |