ciphers.h File Reference

Headers for the packet encryption class. They are used to encrypt single packets. More...

Detailed Description

Headers for the packet encryption class. They are used to encrypt single packets.

Author
Freie Universitaet Berlin, Computer Systems & Telematics
Nicolai Schmittberger nicol.nosp@m.ai.s.nosp@m.chmit.nosp@m.tber.nosp@m.ger@f.nosp@m.u-be.nosp@m.rlin..nosp@m.de
Zakaria Kasmi zkasm.nosp@m.i@in.nosp@m.f.fu-.nosp@m.berl.nosp@m.in.de
Mark Essien marke.nosp@m.ssie.nosp@m.n@gma.nosp@m.il.c.nosp@m.om

Definition in file ciphers.h.

#include <stdint.h>
+ Include dependency graph for ciphers.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  cipher_context_t
 the context for cipher-operations More...
 
struct  cipher_interface_st
 BlockCipher-Interface for the Cipher-Algorithms. More...
 
struct  cipher_t
 basic struct for using block ciphers contains the cipher interface and the context More...
 
#define CIPHERS_MAX_KEY_SIZE   20
 the length of keys in bytes
 
#define CIPHER_MAX_BLOCK_SIZE   16
 
#define CIPHER_MAX_CONTEXT_SIZE   1
 Context sizes needed for the different ciphers. More...
 
#define CIPHER_ERR_INVALID_KEY_SIZE   -3
 
#define CIPHER_ERR_INVALID_LENGTH   -4
 
#define CIPHER_ERR_ENC_FAILED   -5
 
#define CIPHER_ERR_DEC_FAILED   -6
 
#define CIPHER_ERR_BAD_CONTEXT_SIZE   0
 Is returned by the cipher_init functions, if the corresponding alogirithm has not been included in the build.
 
#define CIPHER_INIT_SUCCESS   1
 Returned by cipher_init upon successful initialization of a cipher.
 
typedef struct cipher_interface_st cipher_interface_t
 BlockCipher-Interface for the Cipher-Algorithms.
 
const typedef cipher_interface_tcipher_id_t
 
const cipher_id_t CIPHER_AES_128
 
int cipher_init (cipher_t *cipher, cipher_id_t cipher_id, const uint8_t *key, uint8_t key_size)
 Initialize new cipher state. More...
 
int cipher_encrypt (const cipher_t *cipher, const uint8_t *input, uint8_t *output)
 Encrypt data of BLOCK_SIZE length *. More...
 
int cipher_decrypt (const cipher_t *cipher, const uint8_t *input, uint8_t *output)
 Decrypt data of BLOCK_SIZE length *. More...
 
int cipher_get_block_size (const cipher_t *cipher)
 Get block size of cipher *. More...
 

Macro Definition Documentation

◆ CIPHER_MAX_CONTEXT_SIZE

#define CIPHER_MAX_CONTEXT_SIZE   1

Context sizes needed for the different ciphers.

Always order by number of bytes descending!!!

threedes needs 24 bytes
aes needs CIPHERS_MAX_KEY_SIZE bytes

Definition at line 50 of file ciphers.h.

Function Documentation

◆ cipher_decrypt()

int cipher_decrypt ( const cipher_t cipher,
const uint8_t *  input,
uint8_t *  output 
)

Decrypt data of BLOCK_SIZE length *.

Parameters
cipherAlready initialized cipher struct
inputpointer to input data (of size BLOCKS_SIZE) to decrypt
outputpointer to allocated memory for decrypted data. It has to be of size BLOCK_SIZE
Returns
The result of the decrypt operation of the underlying cipher, which is always 1 in case of success
A negative value for an error

◆ cipher_encrypt()

int cipher_encrypt ( const cipher_t cipher,
const uint8_t *  input,
uint8_t *  output 
)

Encrypt data of BLOCK_SIZE length *.

Parameters
cipherAlready initialized cipher struct
inputpointer to input data to encrypt
outputpointer to allocated memory for encrypted data. It has to be of size BLOCK_SIZE
Returns
The result of the encrypt operation of the underlying cipher, which is always 1 in case of success
A negative value for an error

◆ cipher_get_block_size()

int cipher_get_block_size ( const cipher_t cipher)

Get block size of cipher *.

Parameters
cipherAlready initialized cipher struct
Returns
The cipher's block size (in bytes)

◆ cipher_init()

int cipher_init ( cipher_t cipher,
cipher_id_t  cipher_id,
const uint8_t *  key,
uint8_t  key_size 
)

Initialize new cipher state.

Parameters
ciphercipher struct to init (already allocated memory)
cipher_idcipher algorithm id
keyencryption key to use
key_sizelength of the encryption key
Returns
CIPHER_INIT_SUCCESS if the initialization was successful.
CIPHER_ERR_BAD_CONTEXT_SIZE if CIPHER_MAX_CONTEXT_SIZE has not been defined (which means that the cipher has not been included in the build)
The command may return CIPHER_ERR_INVALID_KEY_SIZE if the key size is not valid.