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 u8[] to u32 in a portable way
30 * s_vPutUINT32 - Convert from u32 to u8[] 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.
46 * static u32 s_dwGetUINT32(u8 * p); Get u32 from
47 * 4 bytes LSByte first
48 * static void s_vPutUINT32(u8* p, u32 val); Put u32 into
49 * 4 bytes LSByte first
51 static void s_vClear(void); /* Clear the internal message,
52 * resets the object to the
53 * state just after construction. */
54 static void s_vSetKey(u32 dwK0
, u32 dwK1
);
55 static void s_vAppendByte(u8 b
); /* Add a single byte to the internal
58 static u32 L
, R
; /* Current state */
59 static u32 K0
, K1
; /* Key */
60 static u32 M
; /* Message accumulator (single word) */
61 static unsigned int nBytesInM
; /* # bytes in M */
64 static u32 s_dwGetUINT32 (u8 * p)
65 // Convert from u8[] to u32 in a portable way
69 for (i = 0; i < 4; i++)
70 res |= (*p++) << (8*i);
74 static void s_vPutUINT32(u8 *p, u32 val)
75 // Convert from u32 to u8[] in a portable way
78 for (i = 0; i < 4; i++) {
79 *p++ = (u8) (val & 0xff);
85 static void s_vClear(void)
87 /* Reset the state to the empty message. */
94 static void s_vSetKey(u32 dwK0
, u32 dwK1
)
99 /* and reset the message */
103 static void s_vAppendByte(u8 b
)
105 /* Append the byte to our word-sized buffer */
106 M
|= b
<< (8*nBytesInM
);
108 /* Process the word if it is full. */
109 if (nBytesInM
>= 4) {
113 R
^= ((L
& 0xff00ff00) >> 8) | ((L
& 0x00ff00ff) << 8);
119 /* Clear the buffer */
125 void MIC_vInit(u32 dwK0
, u32 dwK1
)
128 s_vSetKey(dwK0
, dwK1
);
131 void MIC_vUnInit(void)
133 /* Wipe the key material */
137 /* And the other fields as well. */
138 /* Note that this sets (L,R) to (K0,K1) which is just fine. */
142 void MIC_vAppend(u8
* src
, unsigned int nBytes
)
146 s_vAppendByte(*src
++);
151 void MIC_vGetMIC(u32
* pdwL
, u32
* pdwR
)
153 /* Append the minimum padding */
159 /* and then zeroes until the length is a multiple of 4 */
160 while (nBytesInM
!= 0)
162 /* The s_vAppendByte function has already computed the result. */
165 /* Reset to the empty message. */