下载后可任意编辑ARM9 嵌入式平台 AES 加密程序——hayond,2011-11-7,ChengDu一、软件平台uc/os 中,任务堆栈为 20KB,二、硬件平台ARM9 CPU:S3C2440三、主程序调用void Task4(void *pdata)//AES{char szbuf[1024], sztmp[1024]; char *pkey = "iamvingo and liveiamvingo and liveiamvingo and liveiam liveiamvingo and liveiamvingo and liveiamvingo and liveiamvingo and liveiamvingo and live"; struct aes_ctx aes; int len ; while(1) { OSPrintf("\nEnter Task4\n"); //printf("\nAESTest Start!\n "); gen_tabs(); if(aes_set_key(&aes, (const u8 *)pkey , 128) != 0) { printf("can't set key : %s \n",pkey); } else { printf("aes_set_key() success!\n"); } printf("Please Input string to encrypt : \n"); while(Uart_GetString(szbuf) > 0 ) { len = strlen(szbuf); printf("Input len is : %d \n",len); printf("Input is :"); len=0; while(szbuf[len]) { printf(" %d",szbuf[len]); len++;下载后可任意编辑 } printf("\n"); aes_encrypt((struct aes_ctx *)&aes,(u8 *)sztmp,(const u8 *)szbuf); len = strlen(sztmp); printf("output len is : %d \n",len); len=0; printf("Encryp Result is :"); while(sztmp[len]) { printf(" %d",sztmp[len]); len++; } printf("\n"); aes_decrypt((struct aes_ctx *)&aes,(u8 *)szbuf,(const u8 *)sztmp); printf("\nDescrpy Result is : %s \n", szbuf); printf("Please Input string to encrypt : \n"); }/**/ OSTimeDly(1); }}四、程序代码#ifndef __AES_H__#define __AES_H__#define AES_MIN_KEY_SIZE 16#define AES_MAX_KEY_SIZE 32#define AES_BLOCK_SIZE 16extern unsigned char Uart_GetString(char *string);#define gets Uart_GetStringtypedef unsigned char u8;typedef signed char s8;typedef signed short s16;typedef unsigned short u16;typedef signed int s32;typedef unsigned int u32;typedef signed long long s64;typedef unsigned long long u64;typedef u16 __le16;下载后可任意编辑typedef u32 __le32;#define E_KEY (&ctx->buf[0])#define D_KEY (...