#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 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, | |||||
| i | ) |
Value:
{ \
(n) = ( (uint32) (b)[(i) ] << 24 ) \
| ( (uint32) (b)[(i) + 1] << 16 ) \
| ( (uint32) (b)[(i) + 2] << 8 ) \
| ( (uint32) (b)[(i) + 3] ); \
}
Definition at line 50 of file aes.c.
Referenced by aes_set_key(), des3_crypt(), des_crypt(), des_main_ks(), sha1_process(), and sha2_process().
| #define MUL | ( | x, | |||
| y | ) | ( ( x && y ) ? pow[(log[x] + log[y]) % 255] : 0 ) |
| #define PUT_UINT32_BE | ( | n, | |||
| b, | |||||
| i | ) |
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 59 of file aes.c.
Referenced by des3_crypt(), des_crypt(), sha1_finish(), and sha2_finish().
| #define ROTR8 | ( | x | ) |
Value:
( ( ( x << 24 ) & 0xFFFFFFFF ) | \
( ( x & 0xFFFFFFFF ) >> 8 ) )
Definition at line 103 of file aes.c.
Referenced by aes_gen_tables().
| #define uint32 unsigned long |
| #define uint8 unsigned char |
| #define XTIME | ( | x | ) | ( ( x << 1 ) ^ ( ( x & 0x80 ) ? 0x1B : 0x00 ) ) |
| void aes_cbc_decrypt | ( | aes_context * | ctx, | |
| unsigned char | iv[16], | |||
| unsigned char * | input, | |||
| unsigned char * | output, | |||
| int | len | |||
| ) |
AES-CBC buffer decryption.
| 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 825 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.
| 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 800 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] | |||
| ) |
| void aes_encrypt | ( | aes_context * | ctx, | |
| unsigned char | input[16], | |||
| unsigned char | output[16] | |||
| ) |
| static void aes_gen_tables | ( | void | ) | [static] |
| void aes_set_key | ( | aes_context * | ctx, | |
| uint8 * | key, | |||
| int | keysize | |||
| ) |
Definition at line 460 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.
uint8 FSb[256] [static] |
uint32 FT0[256] [static] |
uint32 FT1[256] [static] |
uint32 FT2[256] [static] |
uint32 FT3[256] [static] |
uint32 KT0[256] [static] |
uint32 KT1[256] [static] |
uint32 KT2[256] [static] |
uint32 KT3[256] [static] |
uint32 RCON[10] [static] |
uint8 RSb[256] [static] |
uint32 RT0[256] [static] |
uint32 RT1[256] [static] |
uint32 RT2[256] [static] |
uint32 RT3[256] [static] |
1.5.4