资源预览内容
第1页 / 共11页
第2页 / 共11页
第3页 / 共11页
第4页 / 共11页
第5页 / 共11页
第6页 / 共11页
第7页 / 共11页
第8页 / 共11页
第9页 / 共11页
第10页 / 共11页
亲,该文档总共11页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
AES-256算法语实现AES是美国确的种级数据加密算法标准,它是种对数据分组进对称加密的算法,这种算法是由利时的Joan Daemen和Vincent Rijmen设计的,因此被称为RIJNDAE算法根据密钥长度的不同,AES标准区分为AES-128, AES-192, AES-256三种,密钥越长,对每数据分组进的加密步骤(加密轮数)也越多AES-128/192/256分别对应10/12/14轮加密步骤. AES-256对应的密钥长度为256bits, 其每数据分组都需要进14轮的加密运算,(若将初始轮+结束轮视为完整轮, 总共就是14轮)AES规定每数据分组长度均为128bits由于加密过程中每轮都需要个密钥,因此先需要从输密钥(也称为种密码)扩展出Nr(10/12/14)个密钥,总共是r+1个密钥AES加密步骤:密钥扩展(每轮加密都需要个密钥) - 初始轮加密(输密钥 AddRoundKey) 重复轮加密(扩展密钥SubBytes/ShiftRow/MixColumns/AddRoundKey) - 结束轮加密(扩展密钥 SubBytes/ShiftRows/AddRoundKey)AES解密步骤:密钥扩展(每轮解密都需要个密钥) - 初始轮解密(输密钥AddRoundKey) 重复轮解密(扩展密钥InvShiftRows/InvSubBytes/AddRoundKey/InvMixColumns) - 结束轮解密(扩展密钥InvShiftRows/InvSubBytes/AddRoundKey)加/解密步骤由以下基本算组成AddRoundKey: 加植密钥SubBytes: 字节代换InvSubBytes: 字节逆代换ShiftRow: 移位InvShiftRow: 逆移位MixColumn: 列混合InvMixColumn: 列逆混合AES的加密和解密互为逆过程, 因此两个过程其实可以相互交换对件进AES加密, 就是将件划分成多个数据分组,每个为128bit,然后对每个数据分组进如上所叙的加密处理参考资料:Advanced Encryption Standard (AES) (FIPS PUB 197) (November 26, 2001)Advanced Encryption Standard by Example (by Adam Berent)下是具体的AES-256加密解/密程序和注释程序内也包含了AES-128/AES-192相应的测试数据,如有兴趣可以选择不同标准进测试为了演便,程序只进了个分组的加密和解密运算并在密钥扩展和每轮计算后都将结果打印出来,以便与AES标准件中的例进较在Linux环境下编译和执: gcc -o aes256 aes256.c./aes256/*-This program is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License version 2 aspublished by the Free Software Foundation.A test for AES encryption (RIJNDAEL symmetric key encryption algorithm).Reference: 1. Advanced Encryption Standard (AES) (FIPS PUB 197) 2. Advanced Encryption Standard by Example (by Adam Berent)Note:Note:1. Standard and parameters. Key Size Block Size Number of Rounds (Nk words) (Nb words) (Nr)AES-128 4 4 10AES-192 6 4 12AES-256 8 4 14Midas Zhttps:/ #include #include /* S_BOX 盒 */static const uint8_t sbox256 = /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */ 0 x63, 0 x7C, 0 x77, 0 x7B, 0 xF2, 0 x6B, 0 x6F, 0 xC5, 0 x30, 0 x01, 0 x67, 0 x2B, 0 xFE, 0 xD7, 0 xAB, 0 x76, 0 xCA, 0 x82, 0 xC9, 0 x7D, 0 xFA, 0 x59, 0 x47, 0 xF0, 0 xAD, 0 xD4, 0 xA2, 0 xAF, 0 x9C, 0 xA4, 0 x72, 0 xC0, 0 xB7, 0 xFD, 0 x93, 0 x26, 0 x36, 0 x3F, 0 xF7, 0 xCC, 0 x34, 0 xA5, 0 xE5, 0 xF1, 0 x71, 0 xD8, 0 x31, 0 x15, 0 x04, 0 xC7, 0 x23, 0 xC3, 0 x18, 0 x96, 0 x05, 0 x9A, 0 x07, 0 x12, 0 x80, 0 xE2, 0 xEB, 0 x27, 0 xB2, 0 x75, 0 x09, 0 x83, 0 x2C, 0 x1A, 0 x1B, 0 x6E, 0 x5A, 0 xA0, 0 x52, 0 x3B, 0 xD6, 0 xB3, 0 x29, 0 xE3, 0 x2F, 0 x84, 0 x53, 0 xD1, 0 x00, 0 xED, 0 x20, 0 xFC, 0 xB1, 0 x5B, 0 x6A, 0 xCB, 0 xBE, 0 x39, 0 x4A, 0 x4C, 0 x58,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E, 0 xF0, 0 xB4, 0 xE6, 0 x73, 0 x96, 0 xAC, 0 x74, 0 x22, 0 xE7, 0 xAD, 0 x35, 0 x85, 0 xE2, 0 xF9, 0 x37, 0 xE8, 0 x1C, 0 x75, 0 xDF, 0 x6E, 0 x47, 0 xF1, 0 x1A, 0 x71, 0 x1D, 0 x29, 0 xC5, 0 x89, 0 x6F, 0 xB7, 0 x62, 0 x0E, 0 xAA, 0 x18, 0 xBE, 0 x1B, 0 xFC, 0 x56, 0 x3E, 0 x4B, 0 xC6, 0 xD2, 0 x79, 0 x20, 0 x9A, 0 xDB, 0 xC0, 0 xFE, 0 x
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号