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

Primitive. More...

#include "ordo/primitives/block_modes.h"
Include dependency graph for ctr.h:

Go to the source code of this file.

Functions

ORDO_PUBLIC int ctr_init (struct CTR_STATE *state, struct BLOCK_STATE *cipher_state, const void *iv, size_t iv_len, int dir, const void *params)
 
ORDO_PUBLIC void ctr_update (struct CTR_STATE *state, struct BLOCK_STATE *cipher_state, const void *in, size_t in_len, void *out, size_t *out_len)
 
ORDO_PUBLIC int ctr_final (struct CTR_STATE *state, struct BLOCK_STATE *cipher_state, void *out, size_t *out_len)
 
ORDO_PUBLIC size_t ctr_query (prim_t cipher, int query, size_t value)
 
ORDO_PUBLIC size_t ctr_bsize (void)
 

Detailed Description

Primitive.

The CTR mode generates a keystream by repeatedly encrypting a counter starting from some initialization vector, effectively turning a block cipher into a stream cipher. As such, CTR mode requires no padding, and outlen will always be equal to inlen.

Note that the CTR keystream is independent of the plaintext, and is also spatially coherent (using a given initialization vector on a len-byte message will "use up" len bytes of the keystream) so care must be taken to avoid reusing the initialization vector in an insecure way. This also means the block cipher's inverse permutation is never used.

ctr_final() accepts 0 as an argument for out_len since by design the CTR mode of operation does not produce any final data. However, if a valid pointer is passed, its value will be set to zero as expected.

Function Documentation

ORDO_PUBLIC int ctr_init ( struct CTR_STATE *  state,
struct BLOCK_STATE *  cipher_state,
const void *  iv,
size_t  iv_len,
int  dir,
const void *  params 
)
ORDO_PUBLIC void ctr_update ( struct CTR_STATE *  state,
struct BLOCK_STATE *  cipher_state,
const void *  in,
size_t  in_len,
void *  out,
size_t *  out_len 
)
ORDO_PUBLIC int ctr_final ( struct CTR_STATE *  state,
struct BLOCK_STATE *  cipher_state,
void *  out,
size_t *  out_len 
)
ORDO_PUBLIC size_t ctr_query ( prim_t  cipher,
int  query,
size_t  value 
)
ORDO_PUBLIC size_t ctr_bsize ( void  )

Gets the size in bytes of a CTR_STATE.

Returns
The size in bytes of the structure.
Remarks
Binary compatibility layer.