Loading...
Searching...
No Matches
aes.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2013 Freie Universität Berlin, Computer Systems & Telematics
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
6#pragma once
7
31
32#include <stdint.h>
33
34#include "compiler_hints.h"
35#include "crypto/ciphers.h"
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
41typedef uint32_t u32;
42typedef uint16_t u16;
43typedef uint8_t u8;
44
45#define GETU32(pt) (((u32)(pt)[0] << 24) ^ ((u32)(pt)[1] << 16) ^ \
46 ((u32)(pt)[2] << 8) ^ ((u32)(pt)[3]))
47#define PUTU32(ct, st) { (ct)[0] = (u8)((st) >> 24); \
48 (ct)[1] = (u8)((st) >> 16); \
49 (ct)[2] = (u8)((st) >> 8); \
50 (ct)[3] = (u8)(st); }
51
52#define AES_MAXNR 14
53#define AES_BLOCK_SIZE 16
54
59#define AES_KEY_SIZE_128 16
60#define AES_KEY_SIZE_192 24
61#define AES_KEY_SIZE_256 32
63
67typedef struct {
69 uint32_t context[(4 * (AES_MAXNR + 1)) + 1];
71
88ACCESS(read_only, 2, 3)
89int aes_init(cipher_context_t *context, const uint8_t *key, uint8_t keySize);
90
109int aes_encrypt(const cipher_context_t *context, const uint8_t *plain_block,
110 uint8_t *cipher_block);
111
130int aes_decrypt(const cipher_context_t *context, const uint8_t *cipher_block,
131 uint8_t *plain_block);
132
133#ifdef __cplusplus
134}
135#endif
136
int aes_init(cipher_context_t *context, const uint8_t *key, uint8_t keySize)
initializes the AES Cipher-algorithm with the passed parameters
int aes_decrypt(const cipher_context_t *context, const uint8_t *cipher_block, uint8_t *plain_block)
Decrypts one cipher-block and saves the plain-block in plain_block.
int aes_encrypt(const cipher_context_t *context, const uint8_t *plain_block, uint8_t *cipher_block)
encrypts one plainBlock-block and saves the result in cipherblock.
Headers for the packet encryption class.
Common macros and compiler attributes/pragmas configuration.
#define ACCESS(mode, ptr_idx, size_idx)
Emit an attribute (if supported by the compiler) that declares how a function will access its paramet...
the cipher_context_t-struct adapted for AES
Definition aes.h:67
uint32_t context[(4 *(AES_MAXNR+1))+1]
context data buffer
Definition aes.h:69
the context for cipher-operations
Definition ciphers.h:77