Loading...
Searching...
No Matches
ciphers.h File Reference

Headers for the packet encryption class. 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 "modules.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   16
 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.
 
#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 algorithm 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.
 
typedef const cipher_interface_tcipher_id_t
 Pointer type to BlockCipher-Interface for the Cipher-Algorithms.
 
const cipher_id_t CIPHER_AES
 AES cipher id.
 
int cipher_init (cipher_t *cipher, cipher_id_t cipher_id, const uint8_t *key, uint8_t key_size)
 Initialize new cipher state.
 
int cipher_encrypt (const cipher_t *cipher, const uint8_t *input, uint8_t *output)
 Encrypt data of BLOCK_SIZE length *.
 
int cipher_decrypt (const cipher_t *cipher, const uint8_t *input, uint8_t *output)
 Decrypt data of BLOCK_SIZE length *.
 
int cipher_get_block_size (const cipher_t *cipher)
 Get block size of cipher *.
 

Macro Definition Documentation

◆ CIPHER_ERR_BAD_CONTEXT_SIZE

#define CIPHER_ERR_BAD_CONTEXT_SIZE   0

Is returned by the cipher_init functions, if the corresponding algorithm has not been included in the build.

Definition at line 71 of file ciphers.h.

◆ CIPHER_ERR_DEC_FAILED

#define CIPHER_ERR_DEC_FAILED   -6

Definition at line 68 of file ciphers.h.

◆ CIPHER_ERR_ENC_FAILED

#define CIPHER_ERR_ENC_FAILED   -5

Definition at line 67 of file ciphers.h.

◆ CIPHER_ERR_INVALID_KEY_SIZE

#define CIPHER_ERR_INVALID_KEY_SIZE   -3

Definition at line 65 of file ciphers.h.

◆ CIPHER_ERR_INVALID_LENGTH

#define CIPHER_ERR_INVALID_LENGTH   -4

Definition at line 66 of file ciphers.h.

◆ CIPHER_INIT_SUCCESS

#define CIPHER_INIT_SUCCESS   1

Returned by cipher_init upon successful initialization of a cipher.

Definition at line 73 of file ciphers.h.

◆ CIPHER_MAX_BLOCK_SIZE

#define CIPHER_MAX_BLOCK_SIZE   16

Definition at line 47 of file ciphers.h.

◆ CIPHER_MAX_CONTEXT_SIZE

#define CIPHER_MAX_CONTEXT_SIZE   1

Context sizes needed for the different ciphers.

Always order by number of bytes descending!!!

aes needs CIPHERS_MAX_KEY_SIZE bytes

Definition at line 60 of file ciphers.h.

◆ CIPHERS_MAX_KEY_SIZE

#define CIPHERS_MAX_KEY_SIZE   16

the length of keys in bytes

As of now AES is the only cipher which supports different key sizes. Here we optimize the CIPHERS_MAX_KEY_SIZE to always have the smallest possible value based on which AES key sizes are used.

Definition at line 45 of file ciphers.h.

Typedef Documentation

◆ cipher_id_t

Pointer type to BlockCipher-Interface for the Cipher-Algorithms.

Definition at line 108 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.