资源简介
C语言 3DES、AES、RC6、TEA、RSA、MD5、SHA1、SHA256加密源码
代码片段和文件信息
#define BPOLY 0x1b //!< Lower 8 bits of (x^8+x^4+x^3+x+1) ie. (x^4+x^3+x+1).
#define BLOCKSIZE 16 //!< Block size in number of bytes.
#define KEY_COUNT 3
#if KEY_COUNT == 1
#define KEYBITS 128 //!< Use AES128.
#elif KEY_COUNT == 2
#define KEYBITS 192 //!< Use AES196.
#elif KEY_COUNT == 3
#define KEYBITS 256 //!< Use AES256.
#else
#error Use 1 2 or 3 keys!
#endif
#if KEYBITS == 128
#define ROUNDS 10 //!< Number of rounds.
#define KEYLENGTH 16 //!< Key length in number of bytes.
#elif KEYBITS == 192
#define ROUNDS 12 //!< Number of rounds.
#define KEYLENGTH 24 //!< // Key length in number of bytes.
#elif KEYBITS == 256
#define ROUNDS 14 //!< Number of rounds.
#define KEYLENGTH 32 //!< Key length in number of bytes.
#else
#error Key must be 128 192 or 256 bits!
#endif
#define EXPANDED_KEY_SIZE (BLOCKSIZE * (ROUNDS+1)) //!< 176 208 or 240 bytes.
unsigned char AES_Key_Table[32] =
{
0xd0 0x94 0x3f 0x8c 0x29 0x76 0x15 0xd8
0x20 0x40 0xe3 0x27 0x45 0xd8 0x48 0xad
0xea 0x8b 0x2a 0x73 0x16 0xe9 0xb0 0x49
0x45 0xb3 0x39 0x28 0x0a 0xc3 0x28 0x3c
};
unsigned char block1[256]; //!< Workspace 1.
unsigned char block2[256]; //!< Worksapce 2.
unsigned char tempbuf[256];
unsigned char *powTbl; //!< Final location of exponentiation lookup table.
unsigned char *logTbl; //!< Final location of logarithm lookup table.
unsigned char *sBox; //!< Final location of s-box.
unsigned char *sBoxInv; //!< Final location of inverse s-box.
unsigned char *expandedKey; //!< Final location of expanded key.
void CalcPowLog(unsigned char *powTbl unsigned char *logTbl)
{
unsigned char i = 0;
unsigned char t = 1;
do {
// Use 0x03 as root for exponentiation and logarithms.
powTbl[i] = t;
logTbl[t] = i;
i++;
// Muliply t by 3 in GF(2^8).
t ^= (t << 1) ^ (t & 0x80 ? BPOLY : 0);
}while( t != 1 ); // Cyclic properties ensure that i < 255.
powTbl[255] = powTbl[0]; // 255 = ‘-0‘ 254 = -1 etc.
}
void CalcSBox( unsigned char * sBox )
{
unsigned char i rot;
unsigned char temp;
unsigned char result;
// Fill all entries of sBox[].
i = 0;
do {
//Inverse in GF(2^8).
if( i > 0 )
{
temp = powTbl[ 255 - logTbl[i] ];
}
else
{
temp = 0;
}
// Affine transformation in GF(2).
result = temp ^ 0x63; // Start with adding a vector in GF(2).
for( rot = 0; rot < 4; rot++ )
{
// Rotate left.
temp = (temp<<1) | (temp>>7);
// Add rotated byte in GF(2).
result ^= temp;
}
// Put result in table.
sBox[i] = result;
} while( ++i != 0 );
}
void CalcSBoxInv( unsigned char * sBox unsigned char * sBoxInv )
{
unsigned char i = 0;
unsigned char j = 0;
// Iterate through all elements in sBoxInv using i.
do {
// Search through sBox using j.
do {
// Check if current j is the inverse of current i.
if( sBox[ j ] == i )
{
// If s
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 11630 2012-04-12 20:55 MD5.C
文件 4863 2012-04-12 21:31 RC6.C
文件 979 2012-04-13 01:10 RSA.C
文件 7720 2012-04-12 20:58 SHA1.C
文件 7633 2012-04-12 20:55 SHA256.C
文件 2055 2012-04-12 21:55 TEA.C
文件 13233 2012-04-12 21:42 AES.c
文件 12757 2012-04-12 21:37 DES.C
----------- --------- ---------- ----- ----
60870 8
相关资源
- AES、DES加密算法C语言源码
- md5加密算法 C语言经过测试验证完整版
- aes加密算法matlab
- AES128 C语言实现源码及应用例程
- c语言rc4加密算法调试通过
- C语言实现的文字加密与解密小程序(
- C语言实现的DES加密算法
- CMAC(AES128)Verilog实现
- aes加密算法的verilog和c++代码
- vc 源码 md5字符串加密算法 绝对可以用
- DES加密算法C++类
- Hill密码加密算法的C++实现Hill密码解密
- zw_AES加密算法c语言实现代码.zip
- RSA加密算法的C语言实现
- SM4国密加密算法C语言实现
- 字符串的RSA加密与解密 c语言实现
- AES-128加密算法,C语言实现
- AES(ECB、CBC、CFB、CTR)128/192/256加密算
- 200种加密算法(源码)
- DES两密三重(DES加密算法)
- MD5加密算法C++实现
- AES128-cbc快速查表法
- 全部古典密码加密与解密的C语言程序
- [C++]AES全文件加解密
- Playfire加密算法C语言实现
- SHA1加密算法源代码
- rsa加密算法 c语言实现
- sha1加密算法C++实现
- AES 加密算法源代码20091025 C++版
- AES128/192/256加解密C语言源码
评论
共有 条评论