www.pudn.com > AES-128Bit-C51.rar > AES_Lib.h, change:2007-11-13,size:2508b


/*C***************************************************************************** 
* NAME:         AES_Lib.c 
*------------------------------------------------------------------------------- 
* Copyright (c) 北京迈特安技术发展有限公司. 
*------------------------------------------------------------------------------- 
* RELEASE:      梁锋 liangfeng@cnmta.com.cn 
* REVISION:     V1.0版 
*------------------------------------------------------------------------------- 
* PURPOSE: 
* AES(Advanced Encryption Standard)加密算法 
* 
* NOTES:        仅支持128位加密标准 
*******************************************************************************/ 
 
#ifndef AES_LIB_H 
#define AES_LIB_H 
 
/*_____ I N C L U D E S ______________________________________________________*/ 
 
#include <string.h> 
 
 
/*_____ M A C R O S __________________________________________________________*/ 
 
//定义可移植的数据类型 
typedef unsigned char AES_U8; 
typedef unsigned int  AES_U16; 
 
//存储在Flash中的存储类型定义(没有必要则用空格代替) 
#define CODE_MEM_TYP  code 
 
// AES only supports Nb=4 
#define Nb (4)          // number of columns in the state & expanded key 
 
#define Nr (10)         // number of rounds in encryption 
 
 
/*_____ D E F I N I T I O N __________________________________________________*/ 
 
/*_____ D E C L A R A T I O N ________________________________________________*/ 
 
void AES_ExpandKey(AES_U8 *key, AES_U8 *expKey); 
void AES_Encrypt(AES_U8 *in, AES_U8 *expKey, AES_U8 *out); 
void AES_Decrypt(AES_U8 *in, AES_U8 *expKey, AES_U8 *out); 
 
 
/****************************************************************************** 
                                Example 
#include <stdio.h> 
#include "AES_Lib.h" 
 
AES_U8 in[16]  = {0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77, 
                  0x88,0x99,0xaa,0xbb,0xcc,0xdd,0xee,0xff}; 
 
AES_U8 key[16] = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07, 
                  0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f}; 
AES_U8 out[16]; 
 
void main (void) 
{ 
AES_U8  expKey[4 * Nb * (Nr + 1)]; 
AES_U16 idx; 
 
    AES_ExpandKey (key, expKey);        // 
     
    AES_Encrypt (in, expKey, out); 
 
    for (idx=0; idx<16; idx++) 
    { 
        printf ("%.2x ", out[idx]); 
    } 
    printf ("\n"); 
 
    AES_Decrypt (out, expkey, in); 
     
    for (idx=0; idx<16; idx++) 
    { 
        printf ("%.2x ", in[idx]); 
    } 
    printf ("\n"); 
} 
******************************************************************************/ 
 
#endif /*AES_LIB_H*/