2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 * Purpose: The implementation of LIST data structure.
29 * s_dwGetUINT32 - Convert from BYTE[] to DWORD in a portable way
30 * s_vPutUINT32 - Convert from DWORD to BYTE[] in a portable way
31 * s_vClear - Reset the state to the empty message.
32 * s_vSetKey - Set the key.
33 * MIC_vInit - Set the key.
34 * s_vAppendByte - Append the byte to our word-sized buffer.
35 * MIC_vAppend - call s_vAppendByte.
36 * MIC_vGetMIC - Append the minimum padding and call s_vAppendByte.
45 /*--------------------- Static Definitions -------------------------*/
47 /*--------------------- Static Variables --------------------------*/
49 /*--------------------- Static Functions --------------------------*/
51 static DWORD s_dwGetUINT32(BYTE * p); // Get DWORD from 4 bytes LSByte first
52 static VOID s_vPutUINT32(BYTE* p, DWORD val); // Put DWORD into 4 bytes LSByte first
54 static VOID
s_vClear(void); // Clear the internal message,
55 // resets the object to the state just after construction.
56 static VOID
s_vSetKey(DWORD dwK0
, DWORD dwK1
);
57 static VOID
s_vAppendByte(BYTE b
); // Add a single byte to the internal message
59 /*--------------------- Export Variables --------------------------*/
60 static DWORD L
, R
; // Current state
62 static DWORD K0
, K1
; // Key
63 static DWORD M
; // Message accumulator (single word)
64 static UINT nBytesInM
; // # bytes in M
66 /*--------------------- Export Functions --------------------------*/
69 static DWORD s_dwGetUINT32 (BYTE * p)
70 // Convert from BYTE[] to DWORD in a portable way
76 res |= (*p++) << (8*i);
81 static VOID s_vPutUINT32 (BYTE* p, DWORD val)
82 // Convert from DWORD to BYTE[] in a portable way
87 *p++ = (BYTE) (val & 0xff);
93 static VOID
s_vClear (void)
95 // Reset the state to the empty message.
102 static VOID
s_vSetKey (DWORD dwK0
, DWORD dwK1
)
107 // and reset the message
111 static VOID
s_vAppendByte (BYTE b
)
113 // Append the byte to our word-sized buffer
114 M
|= b
<< (8*nBytesInM
);
116 // Process the word if it is full.
122 R
^= ((L
& 0xff00ff00) >> 8) | ((L
& 0x00ff00ff) << 8);
134 VOID
MIC_vInit (DWORD dwK0
, DWORD dwK1
)
137 s_vSetKey(dwK0
, dwK1
);
141 VOID
MIC_vUnInit (void)
143 // Wipe the key material
147 // And the other fields as well.
148 //Note that this sets (L,R) to (K0,K1) which is just fine.
152 VOID
MIC_vAppend (PBYTE src
, UINT nBytes
)
157 s_vAppendByte(*src
++);
162 VOID
MIC_vGetMIC (PDWORD pdwL
, PDWORD pdwR
)
164 // Append the minimum padding
170 // and then zeroes until the length is a multiple of 4
171 while( nBytesInM
!= 0 )
175 // The s_vAppendByte function has already computed the result.
178 // Reset to the empty message.