打印

CRC64ISO(d800000000000000)的16四字表长查表程序

[复制链接]
1912|4
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
hotpower|  楼主 | 2009-10-18 19:10 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
CRC64ISO(d800000000000000)的16四字表长查表程序
此文依据: http://blog.**/hotpower/272834/message.aspx
CRC位域4单表查表及建表原则:
左移位域4取列表16个,大端存储模式。右移位域4取行表16个,小端存储模式。
在CRC64ISO中CRC的多项式为:右移CRC64=X64+X36+X35+X33+...+1
即权值=0xd800000000000000,故建立16字节的CRC表格:
(参见:http://zh.wikipedia.org/zh-cn/%E5%BE%AA%E7%8E%AF%E5%86%97%E4%BD%99%E6%A0%A1%E9%AA%8C)
特别注意:
初值为0,只用一次,本次结果即为下次的初值,故与CRC表的构造无关。
网上CRC64的256个表为:
uint64 CRC64Table[256] = {                              
0x0000000000000000L, 0x01b0000000000000L, 0x0360000000000000L, 0x02d0000000000000L,//00
0x06c0000000000000L, 0x0770000000000000L, 0x05a0000000000000L, 0x0410000000000000L,
0x0d80000000000000L, 0x0c30000000000000L, 0x0ee0000000000000L, 0x0f50000000000000L,
0x0b40000000000000L, 0x0af0000000000000L, 0x0820000000000000L, 0x0990000000000000L,
0x1b00000000000000L, 0x1ab0000000000000L, 0x1860000000000000L, 0x19d0000000000000L,//10
0x1dc0000000000000L, 0x1c70000000000000L, 0x1ea0000000000000L, 0x1f10000000000000L,
0x1680000000000000L, 0x1730000000000000L, 0x15e0000000000000L, 0x1450000000000000L,
0x1040000000000000L, 0x11f0000000000000L, 0x1320000000000000L, 0x1290000000000000L,
0x3600000000000000L, 0x37b0000000000000L, 0x3560000000000000L, 0x34d0000000000000L,//20
0x30c0000000000000L, 0x3170000000000000L, 0x33a0000000000000L, 0x3210000000000000L,
0x3b80000000000000L, 0x3a30000000000000L, 0x38e0000000000000L, 0x3950000000000000L,
0x3d40000000000000L, 0x3cf0000000000000L, 0x3e20000000000000L, 0x3f90000000000000L,
0x2d00000000000000L, 0x2cb0000000000000L, 0x2e60000000000000L, 0x2fd0000000000000L,//30
0x2bc0000000000000L, 0x2a70000000000000L, 0x28a0000000000000L, 0x2910000000000000L,
0x2080000000000000L, 0x2130000000000000L, 0x23e0000000000000L, 0x2250000000000000L,
0x2640000000000000L, 0x27f0000000000000L, 0x2520000000000000L, 0x2490000000000000L,
0x6c00000000000000L, 0x6db0000000000000L, 0x6f60000000000000L, 0x6ed0000000000000L,//40
0x6ac0000000000000L, 0x6b70000000000000L, 0x69a0000000000000L, 0x6810000000000000L,
0x6180000000000000L, 0x6030000000000000L, 0x62e0000000000000L, 0x6350000000000000L,
0x6740000000000000L, 0x66f0000000000000L, 0x6420000000000000L, 0x6590000000000000L,
0x7700000000000000L, 0x76b0000000000000L, 0x7460000000000000L, 0x75d0000000000000L,//50
0x71c0000000000000L, 0x7070000000000000L, 0x72a0000000000000L, 0x7310000000000000L,
0x7a80000000000000L, 0x7b30000000000000L, 0x79e0000000000000L, 0x7850000000000000L,
0x7c40000000000000L, 0x7df0000000000000L, 0x7f20000000000000L, 0x7e90000000000000L,
0x5a00000000000000L, 0x5bb0000000000000L, 0x5960000000000000L, 0x58d0000000000000L,//60
0x5cc0000000000000L, 0x5d70000000000000L, 0x5fa0000000000000L, 0x5e10000000000000L,
0x5780000000000000L, 0x5630000000000000L, 0x54e0000000000000L, 0x5550000000000000L,
0x5140000000000000L, 0x50f0000000000000L, 0x5220000000000000L, 0x5390000000000000L,
0x4100000000000000L, 0x40b0000000000000L, 0x4260000000000000L, 0x43d0000000000000L,//70
0x47c0000000000000L, 0x4670000000000000L, 0x44a0000000000000L, 0x4510000000000000L,
0x4c80000000000000L, 0x4d30000000000000L, 0x4fe0000000000000L, 0x4e50000000000000L,
0x4a40000000000000L, 0x4bf0000000000000L, 0x4920000000000000L, 0x4890000000000000L,
//注意下行的0xd800000000000000L  
0xd800000000000000L, 0xd9b0000000000000L, 0xdb60000000000000L, 0xdad0000000000000L,//80 权值!!!
0xdec0000000000000L, 0xdf70000000000000L, 0xdda0000000000000L, 0xdc10000000000000L,
0xd580000000000000L, 0xd430000000000000L, 0xd6e0000000000000L, 0xd750000000000000L,
0xd340000000000000L, 0xd2f0000000000000L, 0xd020000000000000L, 0xd190000000000000L,
0xc300000000000000L, 0xc2b0000000000000L, 0xc060000000000000L, 0xc1d0000000000000L,//90
0xc5c0000000000000L, 0xc470000000000000L, 0xc6a0000000000000L, 0xc710000000000000L,
0xce80000000000000L, 0xcf30000000000000L, 0xcde0000000000000L, 0xcc50000000000000L,
0xc840000000000000L, 0xc9f0000000000000L, 0xcb20000000000000L, 0xca90000000000000L,
0xee00000000000000L, 0xefb0000000000000L, 0xed60000000000000L, 0xecd0000000000000L,//A0
0xe8c0000000000000L, 0xe970000000000000L, 0xeba0000000000000L, 0xea10000000000000L,
0xe380000000000000L, 0xe230000000000000L, 0xe0e0000000000000L, 0xe150000000000000L,
0xe540000000000000L, 0xe4f0000000000000L, 0xe620000000000000L, 0xe790000000000000L,
0xf500000000000000L, 0xf4b0000000000000L, 0xf660000000000000L, 0xf7d0000000000000L,//B0
0xf3c0000000000000L, 0xf270000000000000L, 0xf0a0000000000000L, 0xf110000000000000L,
0xf880000000000000L, 0xf930000000000000L, 0xfbe0000000000000L, 0xfa50000000000000L,
0xfe40000000000000L, 0xfff0000000000000L, 0xfd20000000000000L, 0xfc90000000000000L,
0xb400000000000000L, 0xb5b0000000000000L, 0xb760000000000000L, 0xb6d0000000000000L,//C0
0xb2c0000000000000L, 0xb370000000000000L, 0xb1a0000000000000L, 0xb010000000000000L,
0xb980000000000000L, 0xb830000000000000L, 0xbae0000000000000L, 0xbb50000000000000L,
0xbf40000000000000L, 0xbef0000000000000L, 0xbc20000000000000L, 0xbd90000000000000L,
0xaf00000000000000L, 0xaeb0000000000000L, 0xac60000000000000L, 0xadd0000000000000L,//D0
0xa9c0000000000000L, 0xa870000000000000L, 0xaaa0000000000000L, 0xab10000000000000L,
0xa280000000000000L, 0xa330000000000000L, 0xa1e0000000000000L, 0xa050000000000000L,
0xa440000000000000L, 0xa5f0000000000000L, 0xa720000000000000L, 0xa690000000000000L,
0x8200000000000000L, 0x83b0000000000000L, 0x8160000000000000L, 0x80d0000000000000L,//E0
0x84c0000000000000L, 0x8570000000000000L, 0x87a0000000000000L, 0x8610000000000000L,
0x8f80000000000000L, 0x8e30000000000000L, 0x8ce0000000000000L, 0x8d50000000000000L,
0x8940000000000000L, 0x88f0000000000000L, 0x8a20000000000000L, 0x8b90000000000000L,
0x9900000000000000L, 0x98b0000000000000L, 0x9a60000000000000L, 0x9bd0000000000000L,//F0
0x9fc0000000000000L, 0x9e70000000000000L, 0x9ca0000000000000L, 0x9d10000000000000L,
0x9480000000000000L, 0x9530000000000000L, 0x97e0000000000000L, 0x9650000000000000L,
0x9240000000000000L, 0x93f0000000000000L, 0x9120000000000000L, 0x9090000000000000L
};
即CRC位域8表:
CRC64Table[256]={
  CRC[0x0000000000000000L],CRC[0x0100000000000000L],
  ...,
  CRC[0xFE00000000000000L],CRC[0xFF00000000000000L]
};
特别注意对CRC表逆向出权值的方法(256表):
右移方式,CRC多项式即权值=CRC64Table[0x80]=
左移方式,CRC多项式即权值=CRC64Table[0x01]
本文采用CRC位域4查表方式,故表为:
CRC64Table[16]={CRC[0x00000000],CRC[0x10000000],...CRC[0xE0000000],CRC[0xF0000000]};
即右移方式取行表:
CRC64Table[16]={
0x0000000000000000L, 0x1b00000000000000L, 0x3600000000000000L, 0x2d00000000000000L,
0x6c00000000000000L, 0x7700000000000000L, 0x5a00000000000000L, 0x4100000000000000L,
//注意下行的0xd800000000000000L  
0xd800000000000000L, 0xc300000000000000L, 0xee00000000000000L, 0xf500000000000000L,
0xb400000000000000L, 0xaf00000000000000L, 0x8200000000000000L, 0x9900000000000000L,
};
uint64 GetCRC64(uint64 crcinit, uint64 crcval)
{//(可以不要初值crcinit,多字节CRC32时入口需要对crcval做处理)
unsigned char i;
uint64 crc=0;
  crcval = crcinit ^ crcval;//初值为0,只用一次,函数下次调用时crcinit=crc
  for(i = 0;i < 16;i ++)//8个字节位域4需要16次完成
  {//可认为是大端存储模式
    crc = (crc >> 4) ^ CRC64Table[(crc ^ crcval) & 0x0F];//位域宽4单表16个字节
    crcval >>= 4;//准备下一个位域,域宽4
  }
  return crc;//本次crc结果,做为下次GetCRC64()调用的初值crcinit,切记!!!
}

菜农HotPower@126.com  2009.10.18 于雁塔菜地

相关帖子

沙发
zyok| | 2009-10-18 19:22 | 只看该作者
沙发

使用特权

评论回复
板凳
hotpower|  楼主 | 2011-12-26 13:14 | 只看该作者
顶起来,掀起密码安全教育风暴~~~

使用特权

评论回复
地板
ningling_21| | 2011-12-26 14:30 | 只看该作者
顶起来...

使用特权

评论回复
5
hotpower|  楼主 | 2012-10-23 18:53 | 只看该作者
挖墓为2012.10.25菜农个人版《HotWC3密码体系》开版搜索

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1460

主题

21619

帖子

506

粉丝