BeRTOS
Functions
cipher.h File Reference

Generic interface for symmetric block ciphers. More...

#include <cfg/compiler.h>
#include <cfg/debug.h>

Go to the source code of this file.

Functions

size_t cipher_key_len (BlockCipher *c)
 Return the key length (in bytes).
size_t cipher_block_len (BlockCipher *c)
 Return the block length (in bytes)
void cipher_set_key (BlockCipher *c, const void *key)
 Set the current key used by the cipher.
void cipher_set_vkey (BlockCipher *c, const void *key, size_t len)
 Set the current key (of variable size) used by the cipher.
void cipher_ecb_encrypt (BlockCipher *c, void *block)
 Encrypt a block (in-place) using the current key in ECB mode.
void cipher_ecb_decrypt (BlockCipher *c, void *block)
 Decrypt a block (in-place) using the current key in ECB mode.
void cipher_cbc_begin (BlockCipher *c, void *iv)
 Initialize CBC by setting the IV.
void cipher_cbc_encrypt (BlockCipher *c, void *block)
 Encrypt a block (in-place) using the current key in CBC mode.
void cipher_cbc_decrypt (BlockCipher *c, void *block)
 Decrypt a block (in-place) using the current key in CBC mode.
void cipher_ctr_begin (BlockCipher *c, void *counter)
 Initialize CTR by setting the counter.
void cipher_ctr_encrypt (BlockCipher *c, void *block)
 Encrypt a block (in-place) using the current key in CTR mode.
void cipher_ctr_decrypt (BlockCipher *c, void *block)
 Decrypt a block (in-place) using the current key in CTR mode.
void cipher_ctr_step (BlockCipher *c, void *block)
 Generate the crypted stream block in CTR mode for the current counter, and then bump it.
void cipher_ofb_begin (BlockCipher *c, void *iv)
 Initialize OFB by setting the IV.
void cipher_ofb_encrypt (BlockCipher *c, void *block)
 Encrypt a block (in-place) using the current key in OFB mode.
void cipher_ofb_decrypt (BlockCipher *c, void *block)
 Decrypt a block (in-place) using the current key in OFB mode.

Detailed Description

Generic interface for symmetric block ciphers.

Author:
Giovanni Bajo <rasky@develer.com>

Definition in file cipher.h.


Function Documentation

void cipher_cbc_begin ( BlockCipher *  c,
void *  iv 
) [inline]

Initialize CBC by setting the IV.

Note:
the memory pointed by iv will be used and modified by the CBC functions. It is caller's responsibility to keep it available until there is no more CBC work to do.

Definition at line 138 of file cipher.h.

void cipher_ctr_begin ( BlockCipher *  c,
void *  counter 
) [inline]

Initialize CTR by setting the counter.

Note:
the memory pointed by counter will be used and modified (incremented) by the CTR functions. It is caller's responsibility to keep it available until there is no more CTR work to do.

Definition at line 166 of file cipher.h.

void cipher_ctr_step ( BlockCipher *  c,
void *  block 
)

Generate the crypted stream block in CTR mode for the current counter, and then bump it.

This function is basically the core CTR operation, without the final XOR pass with the plaintext or ciphertext. For normal CTR usage, you never need to call it.

Definition at line 67 of file cipher.c.

size_t cipher_key_len ( BlockCipher *  c) [inline]

Return the key length (in bytes).

In case of ciphers that allow a variabile key size with a fixed state (eg: Blowfish), this returns the preferred key length.

Definition at line 62 of file cipher.h.

void cipher_ofb_begin ( BlockCipher *  c,
void *  iv 
) [inline]

Initialize OFB by setting the IV.

Note:
the memory pointed by iv will be used and modified by the CBC functions. It is caller's responsibility to keep it available until there is no more OFB work to do.

Definition at line 203 of file cipher.h.

void cipher_set_key ( BlockCipher *  c,
const void *  key 
) [inline]

Set the current key used by the cipher.

Note:
the buffer pointed by key is not modified and it is not needed anymore after this call returns. Its lenght must match the value returned by cipher_key_len().

Definition at line 82 of file cipher.h.

void cipher_set_vkey ( BlockCipher *  c,
const void *  key,
size_t  len 
) [inline]

Set the current key (of variable size) used by the cipher.

This function is useful for ciphers that allow a variable size for the key (even with a fixed state). For all the other ciphers, the length must match the value returned by cipher_key_len().

Note:
the buffer pointed by key is not modified and it is not needed anymore after this call returns.

Definition at line 98 of file cipher.h.