RadioShuttle Lib for the STM32 L4 Heltec Board

Dependents:   Turtle_RadioShuttle

Committer:
Helmut Tschemernjak
Date:
Mon Mar 04 09:41:41 2019 +0100
Revision:
11:91bc7ef20f21
Parent:
0:0c31756924a2
Updated lib

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Helmut64 0:0c31756924a2 1 #ifndef _AES128_H_
Helmut64 0:0c31756924a2 2 #define _AES128_H_
Helmut64 0:0c31756924a2 3
Helmut64 0:0c31756924a2 4 #include <stdint.h>
Helmut64 0:0c31756924a2 5
Helmut64 0:0c31756924a2 6 #ifdef __cplusplus
Helmut64 0:0c31756924a2 7 extern "C" {
Helmut64 0:0c31756924a2 8 #endif
Helmut64 0:0c31756924a2 9
Helmut64 0:0c31756924a2 10 // #define the macros below to 1/0 to enable/disable the mode of operation.
Helmut64 0:0c31756924a2 11 //
Helmut64 0:0c31756924a2 12 // CBC enables AES128 encryption in CBC-mode of operation and handles 0-padding.
Helmut64 0:0c31756924a2 13 // ECB enables the basic ECB 16-byte block algorithm. Both can be enabled simultaneously.
Helmut64 0:0c31756924a2 14
Helmut64 0:0c31756924a2 15 // The #ifndef-guard allows it to be configured before #include'ing or at compile time.
Helmut64 0:0c31756924a2 16 #ifndef DISABLE_CBC_MODE
Helmut64 0:0c31756924a2 17 #define CBC_MODE
Helmut64 0:0c31756924a2 18 #endif
Helmut64 0:0c31756924a2 19
Helmut64 0:0c31756924a2 20 #ifndef DISABLE_ECB_MODE
Helmut64 0:0c31756924a2 21 #define ECB_MODE
Helmut64 0:0c31756924a2 22 #endif
Helmut64 0:0c31756924a2 23
Helmut64 0:0c31756924a2 24 /*****************************************************************************/
Helmut64 0:0c31756924a2 25 /* Private variables: */
Helmut64 0:0c31756924a2 26 /*****************************************************************************/
Helmut64 0:0c31756924a2 27 // state - array holding the intermediate results during decryption.
Helmut64 0:0c31756924a2 28 typedef uint8_t state_t[4][4];
Helmut64 0:0c31756924a2 29
Helmut64 0:0c31756924a2 30 // Key length in bytes [128 bit]
Helmut64 0:0c31756924a2 31 #define AES128_KEYLEN 16
Helmut64 0:0c31756924a2 32 // The number of rounds in AES Cipher.
Helmut64 0:0c31756924a2 33 #define Nr 10
Helmut64 0:0c31756924a2 34
Helmut64 0:0c31756924a2 35
Helmut64 0:0c31756924a2 36 typedef struct {
Helmut64 0:0c31756924a2 37 state_t* state;
Helmut64 0:0c31756924a2 38 uint8_t RoundKey[176]; // The array that stores the round keys
Helmut64 0:0c31756924a2 39 #ifdef CBC_MODE
Helmut64 0:0c31756924a2 40 // uint8_t* Iv;
Helmut64 0:0c31756924a2 41 uint8_t InitialVector[AES128_KEYLEN]; // Initial Vector used only for CBC mode
Helmut64 0:0c31756924a2 42 #endif
Helmut64 0:0c31756924a2 43 } AES_CTX;
Helmut64 0:0c31756924a2 44
Helmut64 0:0c31756924a2 45 void AES128_InitContext(AES_CTX *ctx, const uint8_t* key, const uint8_t* initialVector);
Helmut64 0:0c31756924a2 46
Helmut64 0:0c31756924a2 47 #ifdef ECB_MODE
Helmut64 0:0c31756924a2 48
Helmut64 0:0c31756924a2 49 void AES128_ECB_encrypt(AES_CTX *ctx, const uint8_t* input, uint8_t *output);
Helmut64 0:0c31756924a2 50 void AES128_ECB_decrypt(AES_CTX *ctx, const uint8_t* input, uint8_t *output);
Helmut64 0:0c31756924a2 51
Helmut64 0:0c31756924a2 52 #endif // ECB_MODE
Helmut64 0:0c31756924a2 53
Helmut64 0:0c31756924a2 54
Helmut64 0:0c31756924a2 55 #ifdef CBC_MODE
Helmut64 0:0c31756924a2 56
Helmut64 0:0c31756924a2 57 void AES128_CBC_encrypt_buffer(AES_CTX *ctx, uint8_t* output, const uint8_t* input, uint32_t length);
Helmut64 0:0c31756924a2 58 void AES128_CBC_decrypt_buffer(AES_CTX *ctx, uint8_t* output, const uint8_t* input, uint32_t length);
Helmut64 0:0c31756924a2 59
Helmut64 0:0c31756924a2 60 #endif // CBC_MODE
Helmut64 0:0c31756924a2 61
Helmut64 0:0c31756924a2 62 #ifdef __cplusplus
Helmut64 0:0c31756924a2 63 }
Helmut64 0:0c31756924a2 64 #endif
Helmut64 0:0c31756924a2 65
Helmut64 0:0c31756924a2 66 #endif //_AES128_H_