/home/dko/projects/mobilec/trunk/src/security/xyssl-0.7/library/aes.c File Reference

#include <string.h>
#include "xyssl/aes.h"

Go to the source code of this file.

Defines

#define _CRT_SECURE_NO_DEPRECATE   1
#define uint8   unsigned char
#define uint32   unsigned long
#define GET_UINT32_BE(n, b, i)
#define PUT_UINT32_BE(n, b, i)
#define ROTR8(x)
#define XTIME(x)   ( ( x << 1 ) ^ ( ( x & 0x80 ) ? 0x1B : 0x00 ) )
#define MUL(x, y)   ( ( x && y ) ? pow[(log[x] + log[y]) % 255] : 0 )
#define AES_FROUND(X0, X1, X2, X3, Y0, Y1, Y2, Y3)
#define AES_RROUND(X0, X1, X2, X3, Y0, Y1, Y2, Y3)

Functions

static void aes_gen_tables (void)
void aes_set_key (aes_context *ctx, uint8 *key, int keysize)
void aes_encrypt (aes_context *ctx, unsigned char input[16], unsigned char output[16])
 AES block encryption (ECB mode).
void aes_decrypt (aes_context *ctx, unsigned char input[16], unsigned char output[16])
 AES block decryption (ECB mode).
void aes_cbc_encrypt (aes_context *ctx, unsigned char iv[16], unsigned char *input, unsigned char *output, int len)
 AES-CBC buffer encryption.
void aes_cbc_decrypt (aes_context *ctx, unsigned char iv[16], unsigned char *input, unsigned char *output, int len)
 AES-CBC buffer decryption.
int aes_self_test (int verbose)
 Checkup routine.

Variables

static uint8 FSb [256]
static uint32 FT0 [256]
static uint32 FT1 [256]
static uint32 FT2 [256]
static uint32 FT3 [256]
static uint8 RSb [256]
static uint32 RT0 [256]
static uint32 RT1 [256]
static uint32 RT2 [256]
static uint32 RT3 [256]
static uint32 RCON [10]
static uint32 KT0 [256]
static uint32 KT1 [256]
static uint32 KT2 [256]
static uint32 KT3 [256]
static const char _aes_src [] = "_aes_src"


Define Documentation

#define _CRT_SECURE_NO_DEPRECATE   1

Definition at line 28 of file aes.c.

#define AES_FROUND ( X0,
X1,
X2,
X3,
Y0,
Y1,
Y2,
Y3   ) 

Value:

{                                                       \
    RK += 4;                                            \
                                                        \
    X0 = RK[0] ^ FT0[ (uint8) ( Y0 >> 24 ) ] ^          \
                 FT1[ (uint8) ( Y1 >> 16 ) ] ^          \
                 FT2[ (uint8) ( Y2 >>  8 ) ] ^          \
                 FT3[ (uint8) ( Y3       ) ];           \
                                                        \
    X1 = RK[1] ^ FT0[ (uint8) ( Y1 >> 24 ) ] ^          \
                 FT1[ (uint8) ( Y2 >> 16 ) ] ^          \
                 FT2[ (uint8) ( Y3 >>  8 ) ] ^          \
                 FT3[ (uint8) ( Y0       ) ];           \
                                                        \
    X2 = RK[2] ^ FT0[ (uint8) ( Y2 >> 24 ) ] ^          \
                 FT1[ (uint8) ( Y3 >> 16 ) ] ^          \
                 FT2[ (uint8) ( Y0 >>  8 ) ] ^          \
                 FT3[ (uint8) ( Y1       ) ];           \
                                                        \
    X3 = RK[3] ^ FT0[ (uint8) ( Y3 >> 24 ) ] ^          \
                 FT1[ (uint8) ( Y0 >> 16 ) ] ^          \
                 FT2[ (uint8) ( Y1 >>  8 ) ] ^          \
                 FT3[ (uint8) ( Y2       ) ];           \
}

#define AES_RROUND ( X0,
X1,
X2,
X3,
Y0,
Y1,
Y2,
Y3   ) 

Value:

{                                                       \
    RK += 4;                                            \
                                                        \
    X0 = RK[0] ^ RT0[ (uint8) ( Y0 >> 24 ) ] ^          \
                 RT1[ (uint8) ( Y3 >> 16 ) ] ^          \
                 RT2[ (uint8) ( Y2 >>  8 ) ] ^          \
                 RT3[ (uint8) ( Y1       ) ];           \
                                                        \
    X1 = RK[1] ^ RT0[ (uint8) ( Y1 >> 24 ) ] ^          \
                 RT1[ (uint8) ( Y0 >> 16 ) ] ^          \
                 RT2[ (uint8) ( Y3 >>  8 ) ] ^          \
                 RT3[ (uint8) ( Y2       ) ];           \
                                                        \
    X2 = RK[2] ^ RT0[ (uint8) ( Y2 >> 24 ) ] ^          \
                 RT1[ (uint8) ( Y1 >> 16 ) ] ^          \
                 RT2[ (uint8) ( Y0 >>  8 ) ] ^          \
                 RT3[ (uint8) ( Y3       ) ];           \
                                                        \
    X3 = RK[3] ^ RT0[ (uint8) ( Y3 >> 24 ) ] ^          \
                 RT1[ (uint8) ( Y2 >> 16 ) ] ^          \
                 RT2[ (uint8) ( Y1 >>  8 ) ] ^          \
                 RT3[ (uint8) ( Y0       ) ];           \
}

#define GET_UINT32_BE ( n,
b,
 ) 

Value:

{                                                       \
    (n) = ( (uint32) (b)[(i)    ] << 24 )        \
        | ( (uint32) (b)[(i) + 1] << 16 )        \
        | ( (uint32) (b)[(i) + 2] <<  8 )        \
        | ( (uint32) (b)[(i) + 3]       );       \
}

Definition at line 47 of file aes.c.

Referenced by aes_set_key(), des3_crypt(), des_crypt(), des_main_ks(), sha1_process(), and sha2_process().

#define MUL ( x,
 )     ( ( x && y ) ? pow[(log[x] + log[y]) % 255] : 0 )

Definition at line 103 of file aes.c.

Referenced by aes_gen_tables().

#define PUT_UINT32_BE ( n,
b,
 ) 

Value:

{                                                       \
    (b)[(i)    ] = (uint8) ( (n) >> 24 );       \
    (b)[(i) + 1] = (uint8) ( (n) >> 16 );       \
    (b)[(i) + 2] = (uint8) ( (n) >>  8 );       \
    (b)[(i) + 3] = (uint8) ( (n)       );       \
}

Definition at line 56 of file aes.c.

Referenced by des3_crypt(), des_crypt(), sha1_finish(), and sha2_finish().

#define ROTR8 (  ) 

Value:

( ( ( x << 24 ) & 0xFFFFFFFF ) | \
                   ( ( x & 0xFFFFFFFF ) >> 8 ) )

Definition at line 100 of file aes.c.

Referenced by aes_gen_tables().

#define uint32   unsigned long

Definition at line 40 of file aes.c.

Referenced by aes_gen_tables(), and aes_set_key().

#define uint8   unsigned char

Definition at line 36 of file aes.c.

Referenced by aes_gen_tables(), and aes_set_key().

#define XTIME (  )     ( ( x << 1 ) ^ ( ( x & 0x80 ) ? 0x1B : 0x00 ) )

Definition at line 102 of file aes.c.

Referenced by aes_gen_tables().


Function Documentation

void aes_cbc_decrypt ( aes_context ctx,
unsigned char  iv[16],
unsigned char *  input,
unsigned char *  output,
int  len 
)

AES-CBC buffer decryption.

Parameters:
ctx AES context
iv initialization vector (modified after use)
input buffer holding the ciphertext
output buffer holding the plaintext
len length of the data to be decrypted

Definition at line 822 of file aes.c.

Referenced by ssl_decrypt_buf().

void aes_cbc_encrypt ( aes_context ctx,
unsigned char  iv[16],
unsigned char *  input,
unsigned char *  output,
int  len 
)

AES-CBC buffer encryption.

Parameters:
ctx AES context
iv initialization vector (modified after use)
input buffer holding the plaintext
output buffer holding the ciphertext
len length of the data to be encrypted

Definition at line 797 of file aes.c.

Referenced by main(), and ssl_encrypt_buf().

void aes_decrypt ( aes_context ctx,
unsigned char  input[16],
unsigned char  output[16] 
)

AES block decryption (ECB mode).

Parameters:
ctx AES context
input ciphertext block
output plaintext block

Definition at line 706 of file aes.c.

Referenced by main().

void aes_encrypt ( aes_context ctx,
unsigned char  input[16],
unsigned char  output[16] 
)

AES block encryption (ECB mode).

AES block encryption (ECB mode)

Definition at line 615 of file aes.c.

Referenced by main().

static void aes_gen_tables ( void   )  [static]

Definition at line 105 of file aes.c.

References FSb, FT0, FT1, FT2, FT3, MUL, RCON, ROTR8, RSb, RT0, RT1, RT2, RT3, uint32, uint8, and XTIME.

Referenced by aes_set_key().

int aes_self_test ( int  verbose  ) 

Checkup routine.

Returns:
0 if successful, or 1 if the test failed

Definition at line 920 of file aes.c.

Referenced by main().

void aes_set_key ( aes_context ctx,
uint8 *  key,
int  keysize 
)

Definition at line 457 of file aes.c.

References aes_gen_tables(), aes_context::drk, aes_context::erk, FSb, GET_UINT32_BE, KT0, KT1, KT2, KT3, aes_context::nr, RCON, RT0, RT1, RT2, RT3, uint32, and uint8.


Variable Documentation

const char _aes_src[] = "_aes_src" [static]

Definition at line 847 of file aes.c.

uint8 FSb[256] [static]

Definition at line 77 of file aes.c.

Referenced by aes_gen_tables(), and aes_set_key().

uint32 FT0[256] [static]

Definition at line 78 of file aes.c.

Referenced by aes_gen_tables().

uint32 FT1[256] [static]

Definition at line 79 of file aes.c.

Referenced by aes_gen_tables().

uint32 FT2[256] [static]

Definition at line 80 of file aes.c.

Referenced by aes_gen_tables().

uint32 FT3[256] [static]

Definition at line 81 of file aes.c.

Referenced by aes_gen_tables().

uint32 KT0[256] [static]

Definition at line 449 of file aes.c.

Referenced by aes_set_key().

uint32 KT1[256] [static]

Definition at line 450 of file aes.c.

Referenced by aes_set_key().

uint32 KT2[256] [static]

Definition at line 451 of file aes.c.

Referenced by aes_set_key().

uint32 KT3[256] [static]

Definition at line 452 of file aes.c.

Referenced by aes_set_key().

uint32 RCON[10] [static]

Definition at line 95 of file aes.c.

Referenced by aes_gen_tables(), and aes_set_key().

uint8 RSb[256] [static]

Definition at line 86 of file aes.c.

Referenced by aes_gen_tables().

uint32 RT0[256] [static]

Definition at line 87 of file aes.c.

Referenced by aes_gen_tables(), and aes_set_key().

uint32 RT1[256] [static]

Definition at line 88 of file aes.c.

Referenced by aes_gen_tables(), and aes_set_key().

uint32 RT2[256] [static]

Definition at line 89 of file aes.c.

Referenced by aes_gen_tables(), and aes_set_key().

uint32 RT3[256] [static]

Definition at line 90 of file aes.c.

Referenced by aes_gen_tables(), and aes_set_key().


Generated on Fri May 16 14:49:56 2008 for Mobile-C by  doxygen 1.5.4