Turnstone Operating System
Loading...
Searching...
No Matches
aes.64.c File Reference

AES encryption and decryption functions. More...

#include <aes.h>
#include <memory.h>

Macros

#define GET_UINT32_LE(n, b, i)
 
#define PUT_UINT32_LE(n, b, i)
 
#define AES_FROUND(X0, X1, X2, X3, Y0, Y1, Y2, Y3)
 
#define AES_RROUND(X0, X1, X2, X3, Y0, Y1, Y2, Y3)
 
#define ROTL8(x)   ( ( x << 8 ) & 0xFFFFFFFF ) | ( x >> 24 )
 
#define XTIME(x)   ( ( x << 1 ) ^ ( ( x & 0x80 ) ? 0x1B : 0x00 ) )
 
#define MUL(x, y)   ( ( x && y ) ? pow[(log[x] + log[y]) % 255] : 0 )
 
#define MIX(x, y)   { y = ( (y << 1) | (y >> 7) ) & 0xFF; x ^= y; }
 
#define CPY128
 

Functions

 MODULE ("turnstone.lib.crypto")
 
int32_t aes_set_encryption_key (aes_context_t *ctx, const uint8_t *key, uint32_t keysize)
 
int32_t aes_set_decryption_key (aes_context_t *ctx, const uint8_t *key, uint32_t keysize)
 
void aes_init_keygen_tables (void)
 
int32_t aes_setkey (aes_context_t *ctx, int32_t mode, const uint8_t *key, uint32_t keysize)
 
int32_t aes_cipher (aes_context_t *ctx, const uint8_t input[16], uint8_t output[16])
 

Variables

static int32_t aes_tables_inited = 0
 
static uint8_t AES_FSb [256] = {0}
 
static uint32_t AES_FT0 [256] = {0}
 
static uint32_t AES_FT1 [256] = {0}
 
static uint32_t AES_FT2 [256] = {0}
 
static uint32_t AES_FT3 [256] = {0}
 
static uint8_t AES_RSb [256] = {0}
 
static uint32_t AES_RT0 [256] = {0}
 
static uint32_t AES_RT1 [256] = {0}
 
static uint32_t AES_RT2 [256] = {0}
 
static uint32_t AES_RT3 [256] = {0}
 
static uint32_t AES_RCON [10] = {0}
 

Detailed Description

AES encryption and decryption functions.

This work is licensed under TURNSTONE OS Public License. Please read and understand latest version of Licence.

Macro Definition Documentation

◆ AES_FROUND

#define AES_FROUND (   X0,
  X1,
  X2,
  X3,
  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8 ) & 0xFF ] ^ \
AES_RT2[ ( Y0 >> 16 ) & 0xFF ] ^ \
AES_RT3[ ( Y3 >> 24 ) & 0xFF ]; \
\
X3 = *RK++ ^ AES_RT0[ ( Y3 ) & 0xFF ] ^ \
AES_RT1[ ( Y2 >> 8 ) & 0xFF ] ^ \
AES_RT2[ ( Y1 >> 16 ) & 0xFF ] ^ \
AES_RT3[ ( Y0 >> 24 ) & 0xFF ]; \
}

◆ CPY128

#define CPY128
Value:
{ *RK++ = *SK++; *RK++ = *SK++; \
*RK++ = *SK++; *RK++ = *SK++; }

◆ GET_UINT32_LE

#define GET_UINT32_LE (   n,
  b,
 
)
Value:
{ \
(n) = ( (uint32_t) (b)[(i) ] ) \
| ( (uint32_t) (b)[(i) + 1] << 8 ) \
| ( (uint32_t) (b)[(i) + 2] << 16 ) \
| ( (uint32_t) (b)[(i) + 3] << 24 ); }
unsigned int uint32_t
Definition: types.h:38

◆ PUT_UINT32_LE

#define PUT_UINT32_LE (   n,
  b,
 
)
Value:
{ \
(b)[(i) ] = (uint8_t) ( (n) ); \
(b)[(i) + 1] = (uint8_t) ( (n) >> 8 ); \
(b)[(i) + 2] = (uint8_t) ( (n) >> 16 ); \
(b)[(i) + 3] = (uint8_t) ( (n) >> 24 ); }
unsigned char uint8_t
Definition: types.h:24