aes加密c语言实现 编译结果图,AES加密C语言实现代码.doc

#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

aes加密代码,非常完整,包括加密解密。 AESCrypt File Format Description Items in quotes are a literal string. Words outside of quotes are a textual description of the contents. Fixed-valued octets are written in hexidecimal form (e.g., 0x01). The AESCrypt version 2 file format is as follows. 3 Octets - 'AES' 1 Octet - 0x02 (Version) 1 Octet - Reserved .... Start of repeating extension block section 2 Octet - Length in octets (in network byte order) of an extension identifier and contents. If 0x0000, then no further extensions exist and the next octet is the start of the Initialization Vector (IV). Following an extension, this length indicator would appear again to indicate presence or absense of another extension and the size of any such extension. nn Octets - Extension identifier. This is either a URI or an identifier defined by the AES developer community and documented on the standard extensions page, either of which is terminated by a single 0x00 octet. All extension identifiers are case sensitive. Examples of URIs: http://www.aescrypt.com/extensions/creator/ urn:oid:1.3.6.1.4.1.17090.55.14 urn:uuid:85519EA3-1DA6-45b9-9041-8CD368D8C086 Note: A URI was used to allow anybody to define extension types, though we should strive to define a standard set of extensions. Examples of standard extension identifiers: CREATED-DATE CREATED-BY A special extension is defined that has no name, but is merely a "container" for extensions to be added after the AES file is initially created. Such an extension avoids the need to read and re-write the entire file in order to add a small extension. Software tools that create AES files should insert a 128-octet "container" extension, placing a 0x00 in the first octet of the extension identifier field. Developers may then insert extensions into this "container" area and reduce the size of this "container" as necessary. If larger extensions are added or the "container" area is filled entirely, then reading and re-writing the entire file would be necessary to add additional extensions. nn Octets - The contents of the extension .... End of repeating extension block section 16 Octets - Initialization Vector (IV) used for encrypting the IV and symmetric key that is actually used to encrypt the bulk of the plaintext file. 48 Octets - Encrypted IV and 256-bit AES key used to encrypt the bulk of the file 16 octets - Initialization Vector 32 octets - encryption key 32 Octets - HMAC nn Octets - Encrypted message (2^64 octets max) 1 Octet - File size modulo 16 in least significant bit positions 32 Octets - HMAC Thus, the footprint of the file is at least 136 octets. The AESCrypt version 1 file format is as follows. 3 Octets - 'AES' 1 Octet - 0x01 (Version) 1 Octet - Reserved 16 Octets - Initialization Vector (IV) used for encrypting the IV and symmetric key that is actually used to encrypt the bulk of the plaintext file. 48 Octets - Encrypted IV and 256-bit AES key used to encrypt the bulk of the file 16 octets - Initialization Vector 32 octets - encryption key 32 Octets - HMAC nn Octets - Encrypted message (2^64 octets max) 1 Octet - File size modulo 16 in least significant bit positions 32 Octets - HMAC Thus, the footprint of the file is at least 134 octets. The AESCrypt version 0 file format is as follows. 3 Octets - 'AES' 1 Octet - 0x00 (Version) 1 Octet - File size modulo 16 in least significant bit positions 16 Octets - Initialization Vector (IV) nn Octets - Encrypted message (2^64 octets max) 32 Octets - HMAC Thus, the footprint of the file is at least 53 octets.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值