Brief analysis of CCMP encryption algorithm of wireless network encryption algorithm

 

Original address: http://www.jiamisoft.com/blog/2586-ccmpjiamisuanfa.html

[Guide] In order to strengthen the security of wireless networks and increase the difficulty of being cracked, the LAN/Metropolitan Area Network Standards Committee has proposed a new wireless network encryption algorithm CCMP. Explain the implementation process of encryption and decryption of the algorithm in detail, and give the corresponding code.

Wireless network products are being used by more and more people because of their flexibility, convenience, and wireless characteristics. But while we enjoy the many benefits of wireless networks, security issues have also brought us great confusion. The LAN/Metropolitan Area Network Standards Committee has successively proposed 3 standard encryption algorithms for wireless networks, namely WEP, TKIP, and CCMP encryption algorithms to protect our wireless network. Because the CCMP encryption algorithm uses a higher level of encryption standard CCMP encryption algorithm than TKIP, CCMP is considered to be a relatively safe and reliable encryption algorithm for wireless networks. Here I will give you a brief introduction to this encryption algorithm.

 

Before we analyze the CCMP encryption and decryption process, we first explain the CCMP core encryption algorithm AES, because both MIC and file encryption and decryption need to use this algorithm.

 

1. AES encryption algorithm 

 

The purpose of the AES encryption algorithm is to develop a new encoding algorithm that can ensure the security of government information. The key length can be 128, 192, 256bit. Its output is more random. The decryption of the ciphertext requires almost the entire ciphertext and the related ciphertext without knowing the key, and the ciphertext for encryption and decryption is separated. Security is very high.

 

The specific algorithm description of the AES encryption algorithm can be obtained from the FIPS _PUB 197 _nAd-vanced _encry ption standard document of NIST.

 

∥Encryption

Cipher(byte in(4*Nbj, byte out[4*Nb], word w[Nb*(Nr+lyyfm)] is the original text and out[] is the cipher text

Begin// _ _ _ _ _ w[] is the key string extended by the key

byte state[4,Nb]

state=m

AddRoundKey(srate, w[0, Nb-1D//Exclusive OR with the first line key string

for round=lstepl to Nr?

SubBytes(state)//state的S盒置换

ShiftRows(state)//接行移位

MixColumns(state)//按列变换

AddRoundKey(state, w[round*Nb, (round+ lyNb -1])//与第round行密钥串异或

end for

SubBytes(state)

 

ShiIIRows(state)

AddRoundKey(slaLe, w[NPNb, (Nr+l)*Nb-ll)

out= sLate

end

∥解密

InvCipher(bytc m[4*Nb], byte out[4*Nb], wordw[Nb*

(Nr+I)D

begin

byte swe[4,Nb]

state= in

AddRoundKey(state, w[Nr*Nb, (Nr+l)*Nb-lD

for round – Nr-1 step -l downt01

InvStuftRows(staLe)//按行移位的逆变换

InvSubBytes(state)//S盒置换的逆变换

AddRourtd Key(state,w[round*Nb, (round+I)*Nb-1])

InvMixColumns(sWe),,按列变换的逆变换

end for

InvShitIRows(staLe)

InvSubBytes(state)

AddRoundKey(state, w[0, Nb-1])

out= state

end

 

目前广泛使用的是rijndnal编写的AES加密算法,这个可以很轻松的从网上得到。

 

二、CCMP加密算法

 

了解了AES的加密和解密过程,接下来我们就开始说明CCMP的加密解密以及MIC的生成过程。CCMP的加密:首先我们从mpdu的MAC _Header提取结构AAD以及Nonce。如图1所示。AAD和Nonce提取办法如下:

 

然后我们计算出MIC,把它加入到数据域后面。生成8字节的CCMP Header与MAC Header组成加密帧的验证部分,这部分不需要加密。然后对数据域和MIC进行CTR( counter)模式的AES加密,量后加上FCS校验就生成了加密帧。

 

1、 MIC计算

 

CCMP的MIC计算是MPDUlevel的,与TKIP的MSDUlevel区射,提供更好的完叠性校验。首先把(Nonce,AAD,P(数据域原文))从左刭右组成一个序列,然后再补上一些D字节,使之成为16字节倍数的序列。然后把它分隔成n个16字节块,用BO,B1,…,Bn表示。接着使用CBC-MAC计算出MIC使用的T(MAC值),按照下列的算法计算:

 

x:= AES(k1 b0)

—k.|- AES(x,x? Bi) fori=l.,.,,n

T:= first-M-bytes( X~.)

其中AES(K,B)为密钥K的AES加密。T取X序列的低M个字节。M为MIC的长度。

 

特别的.B0,B1一……Bn序列中.B0是由Nonee组成的MIC IV.Bl.B2是由MAC Header也即AAD组成的MIC HEADERI,2;B3从开始就是数据域原文分翻成的16字节块。

 

Adata位当AAD长度大千0时置l,否列为0。后面3bit为NUC长度域,值为(M-2),2。最后为信息的长度域,值为1-1.2为信息长度的范围。一般M=8.L=2,列Flag为Ox59.量终的MIC值还需要将个值与后续CTR加密的so值【前M个字节)异或。表示如下:

 

MIC=T? _flrsL-M-bytes(SO).

 

2、CTR加密

 

取得7 MiC之后,就可以对数据域和MIC进行CTR加密.首先把数据城分钠成16个字节块,量后囊余的字节不用朴零.用Ai表示.MIC部分是单独CTR计算的。

 

Si= AES(K,CTR_PRELOAD(i)); //i从O刭m Ei=Si? Ai;UEi为加密好的16字节块

 

特别的对于数据域量后一个16字节块,可能不满16个字节,只有x(O<x<16)个字节,郝异或时,只要取Si中的前x个字节。

 

对予MIC部分

E(MIC)= S0:? MLC

CTR_PRELOAD(i)的结构如下:

Counter从i=0开始不断自增1

1个字节的Flag域:

 

只有最后3个bir的信息长度城。当L-2时,Flag值

 

为Ox01.

 

3、CCMP的解密

 

从加密的MPDU中得到CCMP Header与MACHeader.然后计算出AAD.Nonce.算出每个CTR PRELOAD.从而通过ctrR解密得到数据域原文以及rvnc.使用前一节MIC的计算方法算出当前的MIC.与解密后的rvnc比较,进行校验.在这里我们给出CTR解密的过程。

 

CTRN解密

 

对加密的数据城进行16字节分割,用EI表示。加密的rvnc.FCS前的8个字节,用E(MIC)表示,单独取出进行CTR解密,数据域的原文16宇节块,用Ai表示。

则解密过程如下:

 

si= AES(K,CTI乙PRELOAD(i》;仇从0到m

Ai=Si7 Ei=Si? Si? Ai;

 

特别的对于加密的数据域最后一个16字节块.可能不满16个字节,只有y(O<y<16)个字节,鄢异或时,只要取Si中的前y个字节。

 

对于MJC部分

MIC=S0?E(MIC)

 

通过上面的表述,你基本可以知道CCMP如何操作的。

 

CCMP的计算还是比较复杂,一方面可能增加了成本,一方面却大大加强了无线网络的安全.目前,它一般会和身份验证服务RADIUS以及密钢管理一起提供一个安全、可靠、可以信赖的无线环境。

 

小知识之CCMP :

 

CCMP(Counter CBC-MAC Protocol) 计数器模式密码块链消息完整码协议。

Guess you like

Origin blog.csdn.net/zhengjian1996/article/details/112917002