3 // Michael.cpp Reference implementation for Michael
5 // Copyright (c) 2001 by MacFergus BV
6 // All rights reserved,
11 // Convert from U8[] to U32 in a portable way
17 res
|= (*p
++) << (8*i
);
24 void putUInt32(U8
*p
, U32 val
)
25 // Convert from U32 to U8[] in a portable way
30 *p
++ = (U8
)(val
& 0xff);
36 /***********************************************************************/
38 /* FUNCTION DESCRIPTION MICclear */
39 /* Initial variable require by MIC computation */
42 /* Liam,Hwu ZyDAS Technology Corporation */
44 /***********************************************************************/
45 void MICclear(MICvar
*MIC
)
47 // Reset the state to the empty message.
55 /***********************************************************************/
57 /* FUNCTION DESCRIPTION MICsetKey */
58 /* Set MIC key (Tx or Rx) */
61 /* Liam,Hwu ZyDAS Technology Corporation */
63 /***********************************************************************/
64 void MICsetKey(U8
*key
, MICvar
*MIC
)
67 MIC
->K0
= getUInt32(key
);
68 MIC
->K1
= getUInt32(key
+ 4);
72 printk(KERN_ERR
"mic->K0= %08x K1=%08x\n", (u32
)MIC
->K0
,(u32
)MIC
->K1
);
76 printk(KERN_ERR
"pMic is NULL\n");
77 // and reset the message
82 /***********************************************************************/
84 /* FUNCTION DESCRIPTION MICappendByte */
85 /* Compute MIC for adding a single byte */
88 /* Liam,Hwu ZyDAS Technology Corporation */
90 /***********************************************************************/
91 void MICappendByte(U8 b
, MICvar
*MIC
)
93 register int nBytesInM
= MIC
->nBytesInM
;
94 register U32 M
= MIC
->M
;
96 // Append the byte to our word-sized buffer
97 M
|= b
<< (8* nBytesInM
);
100 // Process the word if it is full.
102 register U32 L
= MIC
->L
;
103 register U32 R
= MIC
->R
;
108 R
^= ((L
& 0xff00ff00) >> 8) | ((L
& 0x00ff00ff) << 8);
124 MIC
->nBytesInM
= nBytesInM
;
129 void MICappendArr(U8
*pb
, MICvar
*MIC
, U32 Size
)
133 // Append the byte to our word-sized buffer
135 for (i
=0; i
<Size
; i
++){
136 MIC
->M
|= *pB
<< (8 * MIC
->nBytesInM
);
139 // Process the word if it is full.
140 if(MIC
->nBytesInM
>= 4){
142 MIC
->R
^= ROL32(MIC
->L
, 17);
144 MIC
->R
^= ((MIC
->L
& 0xff00ff00) >> 8) | ((MIC
->L
& 0x00ff00ff) << 8);
146 MIC
->R
^= ROL32(MIC
->L
, 3);
148 MIC
->R
^= ROR32(MIC
->L
, 2);
160 /***********************************************************************/
162 /* FUNCTION DESCRIPTION MICappendByte */
163 /* Compute MIC for adding a single byte */
166 /* Liam,Hwu ZyDAS Technology Corporation */
168 /***********************************************************************/
169 U8 MicTailPadding
[]={0x5a, 0, 0, 0, 0, 0, 0, 0, 0};
171 void MICgetMIC(U8
*dst
, MICvar
*MIC
)
174 // Append the minimum padding
175 //MICappendArr(MicTailPadding, MIC, 5+((4 -((MIC->nBytesInM+5) & 3)) & 3));
177 MICappendByte(0x5a, MIC
);
178 MICappendByte(0, MIC
);
179 MICappendByte(0, MIC
);
180 MICappendByte(0, MIC
);
181 MICappendByte(0, MIC
);
183 // and then zeroes until the length is a multiple of 4
184 // TKIP or AES , MIC stuff check., not used in WEP
185 while( MIC
->nBytesInM
!= 0 ){
186 if(loopCheck
++ > 10000)
188 printk("infinite loop occurs in %s\n", __FUNCTION__
);
193 MICappendByte(0, MIC
);
196 // The appendByte function has already computed the result.
197 putUInt32(dst
, MIC
->L
);
198 putUInt32(dst
+4, MIC
->R
);
200 // Reset to the empty message.