首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

这个循环是什么意思?

这个循环是什么意思?

for(SHAVM_cnt=0; SHAVM_cnt<16; SHAVM_cnt++) { SHAVM_MTword[SHAVM_cnt] = (((long)SHAVM_Message[SHAVM_cnt*4]&0x00FF) << 24L) | (((long)SHAVM_Message[SHAVM_cnt*4+1]&0x00FF) << 16L) | (((long)SHAVM_Message[SHAVM_cnt*4+2]&0x00FF) << 8L) | ((long)SHAVM_Message[SHAVM_cnt*4+3]&0x00FF); }
关于freescale的更多信息资料,欢迎访问http://www.yuan-ying.com
数组SHAVM_Message大小16*4=64。
SHAVM_Message每4个元素构成一个32位的DWORD。
SHAVM_Message的类型未知,但从程序看,只取了SHAVM_Message的低8bit填充到DWORD的相应位置中。
专业JTAG调试/测试/维修软件、Flash烧写/编程/加载软件  zhefar.com  http://shop35795558.taobao.com/
#include "SHAVM.h" // Message buffer xbyte SHAVM_Message[64]; // Hash buffer, in wrong order for Dallas MAC xlong SHAVM_Hash[5]; // MAC buffer, in right order for Dallas MAC xbyte SHAVM_MAC[20]; // Temp vars for SHA calculation static xlong SHAVM_MTword[80]; static dlong SHAVM_Temp; static dbyte SHAVM_cnt; //constants used in SHA computation static code long SHAVM_KTN[4] = { (long)0x5a827999, (long)0x6ed9eba1, (long)0x8f1bbcdc, (long)0xca62c1d6 }; //---------------------------------------------------------------------- // computes a SHA given the 64 byte MT digest buffer. The resulting 5 // long values are stored in the long array, hash. // // 'SHAVM_Message' - buffer containing the message digest // 'SHAVM_Hash' - result buffer // 'SHAVM_MAC' - result buffer, in order for Dallas part // void SHAVM_Compute() { for(SHAVM_cnt=0; SHAVM_cnt<16; SHAVM_cnt++) // 空出64B空间 { SHAVM_MTword[SHAVM_cnt] = (((long)SHAVM_Message[SHAVM_cnt*4]&0x00FF) << 24L) | (((long)SHAVM_Message[SHAVM_cnt*4+1]&0x00FF) << 16L) | (((long)SHAVM_Message[SHAVM_cnt*4+2]&0x00FF) << 8L) | ((long)SHAVM_Message[SHAVM_cnt*4+3]&0x00FF); } for(; SHAVM_cnt<80; SHAVM_cnt++) //deal with 512B data { SHAVM_Temp = SHAVM_MTword[SHAVM_cnt-3] ^ SHAVM_MTword[SHAVM_cnt-8] ^ SHAVM_MTword[SHAVM_cnt-14] ^ SHAVM_MTword[SHAVM_cnt-16]; SHAVM_MTword[SHAVM_cnt] //对最后一位处理实现0x01 = ((SHAVM_Temp << 1) & 0xFFFFFFFE) | ((SHAVM_Temp >> 31) & 0x00000001); } SHAVM_Hash[0] = 0x67452301; SHAVM_Hash[1] = 0xEFCDAB89; SHAVM_Hash[2] = 0x98BADCFE; SHAVM_Hash[3] = 0x10325476; SHAVM_Hash[4] = 0xC3D2E1F0; for(SHAVM_cnt=0; SHAVM_cnt<80; SHAVM_cnt++) { SHAVM_Temp = ((SHAVM_Hash[0] << 5) & 0xFFFFFFE0) | ((SHAVM_Hash[0] >> 27) & 0x0000001F); if(SHAVM_cnt<20) SHAVM_Temp += ((SHAVM_Hash[1]&SHAVM_Hash[2])|((~SHAVM_Hash[1])&SHAVM_Hash[3])); else if(SHAVM_cnt<40) SHAVM_Temp += (SHAVM_Hash[1]^SHAVM_Hash[2]^SHAVM_Hash[3]); else if(SHAVM_cnt<60) SHAVM_Temp += ((SHAVM_Hash[1]&SHAVM_Hash[2]) |(SHAVM_Hash[1]&SHAVM_Hash[3]) |(SHAVM_Hash[2]&SHAVM_Hash[3])); else SHAVM_Temp += (SHAVM_Hash[1]^SHAVM_Hash[2]^SHAVM_Hash[3]); SHAVM_Temp += SHAVM_Hash[4] + SHAVM_KTN[SHAVM_cnt/20] + SHAVM_MTword[SHAVM_cnt]; SHAVM_Hash[4] = SHAVM_Hash[3]; //gain 5 hash value SHAVM_Hash[3] = SHAVM_Hash[2]; SHAVM_Hash[2] = ((SHAVM_Hash[1] << 30) & 0xC0000000) | ((SHAVM_Hash[1] >> 2) & 0x3FFFFFFF); SHAVM_Hash[1] = SHAVM_Hash[0]; SHAVM_Hash[0] = SHAVM_Temp; } //iButtons use LSB first, so we have to turn //the result around a little bit. Instead of //result A-B-C-D-E, our result is E-D-C-B-A, //where each letter represents four bytes of //the result. for(SHAVM_cnt=0; SHAVM_cnt<5; SHAVM_cnt++) //gain 20 mac value { SHAVM_Temp = SHAVM_Hash[4-SHAVM_cnt]; SHAVM_MAC[((SHAVM_cnt)*4)+0] = (unsigned char)SHAVM_Temp; SHAVM_Temp >>= 8; SHAVM_MAC[((SHAVM_cnt)*4)+1] = (unsigned char)SHAVM_Temp; SHAVM_Temp >>= 8; SHAVM_MAC[((SHAVM_cnt)*4)+2] = (unsigned char)SHAVM_Temp; SHAVM_Temp >>= 8; SHAVM_MAC[((SHAVM_cnt)*4)+3] = (unsigned char)SHAVM_Temp; } } 这是一个SHA-1的算法.以前没接触过,原理的东西瞧了一大堆不理解,瞧程序又瞧不懂,贴上来问一问大家,解一下呀
关于freescale的更多信息资料,欢迎访问http://www.yuan-ying.com
这个函数是由4个for语句组成,如果说第一个的意思是初始化定义SHAVM_Message的话,那么后面是什么意思呀?

若对SAH-1感兴趣,我有一个不完整SHA-1简介.
yqq2006@163.com
关于freescale的更多信息资料,欢迎访问http://www.yuan-ying.com
返回列表