RadioShuttle Lib for the STM32 L4 Heltec Board

Dependents:   Turtle_RadioShuttle

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers aes.h Source File

aes.h

00001 #ifndef _AES128_H_
00002 #define _AES128_H_
00003 
00004 #include <stdint.h>
00005 
00006 #ifdef __cplusplus
00007 extern "C" {
00008 #endif
00009 
00010 // #define the macros below to 1/0 to enable/disable the mode of operation.
00011 //
00012 // CBC enables AES128 encryption in CBC-mode of operation and handles 0-padding.
00013 // ECB enables the basic ECB 16-byte block algorithm. Both can be enabled simultaneously.
00014 
00015 // The #ifndef-guard allows it to be configured before #include'ing or at compile time.
00016 #ifndef DISABLE_CBC_MODE
00017  #define CBC_MODE
00018 #endif
00019 
00020 #ifndef DISABLE_ECB_MODE
00021  #define ECB_MODE
00022 #endif
00023 
00024 /*****************************************************************************/
00025 /* Private variables:                                                        */
00026 /*****************************************************************************/
00027 // state - array holding the intermediate results during decryption.
00028 typedef uint8_t state_t[4][4];
00029 
00030 // Key length in bytes [128 bit]
00031 #define AES128_KEYLEN 16
00032 // The number of rounds in AES Cipher.
00033 #define Nr 10
00034 
00035 
00036 typedef struct {
00037     state_t* state;
00038     uint8_t RoundKey[176];  // The array that stores the round keys
00039 #ifdef CBC_MODE
00040     // uint8_t* Iv;
00041     uint8_t InitialVector[AES128_KEYLEN]; // Initial Vector used only for CBC mode
00042 #endif
00043 } AES_CTX;
00044 
00045 void AES128_InitContext(AES_CTX *ctx, const uint8_t* key, const uint8_t* initialVector);
00046 
00047 #ifdef ECB_MODE
00048 
00049 void AES128_ECB_encrypt(AES_CTX *ctx, const uint8_t* input, uint8_t *output);
00050 void AES128_ECB_decrypt(AES_CTX *ctx, const uint8_t* input, uint8_t *output);
00051 
00052 #endif // ECB_MODE
00053 
00054 
00055 #ifdef CBC_MODE
00056 
00057 void AES128_CBC_encrypt_buffer(AES_CTX *ctx, uint8_t* output, const uint8_t* input, uint32_t length);
00058 void AES128_CBC_decrypt_buffer(AES_CTX *ctx, uint8_t* output, const uint8_t* input, uint32_t length);
00059 
00060 #endif // CBC_MODE
00061 
00062 #ifdef __cplusplus
00063 }
00064 #endif
00065 
00066 #endif //_AES128_H_