Loading...
Searching...
No Matches
Crypto

RIOT provides a collection of block cipher ciphers, different operation modes and cryptographic hash algorithms. More...

Detailed Description

RIOT provides a collection of block cipher ciphers, different operation modes and cryptographic hash algorithms.

Ciphers

RIOT supports the following block ciphers:

You can use them directly by adding crypto_aes_128, crypto_aes_192 or crypto_aes_256 to your USEMODULE-List. While you can use the ciphers functions directly, you should resort to the generic API for block ciphers whenever possible.

Depending on the selected block ciphers, a sufficient large buffer size of the cipher_context_t is used for en-/de-cryption operations.

Example:

#include "crypto/ciphers.h"
cipher_t cipher;
uint8_t key[AES_KEY_SIZE] = {0},
plain_text[AES_BLOCK_SIZE] = {0},
cipher_text[AES_BLOCK_SIZE] = {0};
if (cipher_init(&cipher, CIPHER_AES, key, AES_KEY_SIZE) < 0)
printf("Cipher init failed!\n");
if (cipher_encrypt(&cipher, plain_text, cipher_text) < 0)
printf("Cipher encryption failed!\n");
else
od_hex_dump(cipher_text, AES_BLOCK_SIZE, 0);
Headers for the packet encryption class.
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 *.
const cipher_id_t CIPHER_AES
AES cipher id.
#define printf(...)
A wrapper for the printf() function that passes arguments through unmodified, but fails to compile if...
Definition stdio.h:60
static void od_hex_dump(const void *data, size_t data_len, uint8_t width)
Dumps memory stored at data byte-wise up to data_len in hexadecimal representation to stdout.
Definition od.h:65
basic struct for using block ciphers contains the cipher interface and the context
Definition ciphers.h:119

Some aspects of the AES implementation can be fine tuned by pseudo-modules:

If you need to encrypt data of arbitrary size take a look at the different operation modes like: CBC, CTR or CCM.

Additional examples can be found in the test suite.

Modules

 HACL* High Assurance Cryptographic Library
 Support for HACL* (High Assurance Cryptographic Library)
 
 Lightweight ASN.1 decoding/encoding library
 Lightweight ASN.1 decoding/encoding library.
 
 Micro-ECC for RIOT
 Micro-ECC for RIOT.
 
 Relic toolkit for RIOT
 Provides the Relic cryptographic toolkit to RIOT.
 
 chacha20poly1305 AEAD cipher
 Provides RFC 8439 style chacha20poly1305.
 
 poly1305
 Poly1305 one-time message authentication code.
 

Files

file  aes.h
 Headers for the implementation of the AES cipher-algorithm.
 
file  chacha.h
 ChaCha stream cipher.
 
file  ciphers.h
 Headers for the packet encryption class.
 
file  helper.h
 helper functions for sys_crypto_modes
 
file  cbc.h
 Cipher block chaining mode of operation for block ciphers.
 
file  ccm.h
 Counter with CBC-MAC mode of operation for block ciphers.
 
file  ctr.h
 Counter mode of operation for block ciphers.
 
file  ecb.h
 Electronic code book mode of operation for block ciphers.
 
file  ocb.h
 Offset Codebook (OCB3) AEAD mode as specified in RFC 7253.