Ordo  0.3.4
Symmetric Cryptography Library
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Macros | Functions
alg.h File Reference

Internal, Utility More...

Go to the source code of this file.

Macros

#define bits(n)
 
#define bytes(n)
 
#define offset(ptr, len)
 

Functions

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)
 

Detailed Description

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.

Macro Definition Documentation

#define bits (   n)

Converts bits into bytes (rounded down to the nearest byte boundary).

Remarks
As an example, bits(256) returns 32 (bytes).
#define bytes (   n)

Converts bytes into bits (as a multiple of 8 bits).

Remarks
As an example, bytes(32) returns 256 (bits).
#define offset (   ptr,
  len 
)

Computes a byte-based offset.

Parameters
[in]ptrBase pointer.
[in]lenOffset (in bytes).
Returns
The pointer exactly len bytes after ptr.
Remarks
This is a dangerous macro, in the sense it can lead to accessing data at unaligned addresses, and so should be used carefully.

Function Documentation

ORDO_HIDDEN size_t pad_check ( const void *  buffer,
size_t  len 
)

Checks whether a buffer conforms to PKCS #7 padding.

Parameters
[in]bufferThe buffer to verify, starting at the first data byte (not at the first padding byte).
[in]lenThe 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.
Remarks
PKCS padding is defined as appending N bytes of padding data at the end of the message, each with binary value N, with N between 1 and the block size of the block cipher used such that the length of the message plus N is a multiple of the block cipher's block size.
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]dstThe destination buffer.
[in]srcThe source buffer.
[in]lenThe number of bytes to process.
Remarks
This is conceptually equivalent to dst ^= src.
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]bufferThe buffer to increment in-place.
[in]lenThe size, in bytes, of the buffer.
Remarks
Carry propagation is done left-to-right.