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 unsigned char [] to unsigned long in a portable way
30 * s_vPutUINT32 - Convert from unsigned long to unsigned char [] 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 void s_vClear(void); // Clear the internal message,
52 // resets the object to the state just after construction.
53 static void s_vSetKey(u32 dwK0, u32 dwK1);
54 static void s_vAppendByte(unsigned char b); // Add a single byte to the internal message
56 /*--------------------- Export Variables --------------------------*/
57 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
63 /*--------------------- Export Functions --------------------------*/
65 static void s_vClear(void)
67 // Reset the state to the empty message.
74 static void s_vSetKey(u32 dwK0, u32 dwK1)
79 // and reset the message
83 static void s_vAppendByte(unsigned char b)
85 // Append the byte to our word-sized buffer
86 M |= b << (8*nBytesInM);
88 // Process the word if it is full.
93 R ^= ((L & 0xff00ff00) >> 8) | ((L & 0x00ff00ff) << 8);
105 void MIC_vInit(u32 dwK0, u32 dwK1)
108 s_vSetKey(dwK0, dwK1);
111 void MIC_vUnInit(void)
113 // Wipe the key material
117 // And the other fields as well.
118 //Note that this sets (L,R) to (K0,K1) which is just fine.
122 void MIC_vAppend(unsigned char *src, unsigned int nBytes)
126 s_vAppendByte(*src++);
131 void MIC_vGetMIC(u32 *pdwL, u32 *pdwR)
133 // Append the minimum padding
139 // and then zeroes until the length is a multiple of 4
140 while (nBytesInM != 0)
143 // The s_vAppendByte function has already computed the result.
146 // Reset to the empty message.