Lines Matching defs:state

56 /* The number of columns comprising a state in AES. This is a constant
63 /* state - array holding the intermediate results during
192 /* This function adds the round key to state. The round key is added
193 to the state by an XOR function. */
194 static void AddRoundKey(__u8 round, state_t *state, const __u8 *RoundKey) {
198 (*state)[i][j] ^= RoundKey[(round * Nb * 4) + (i * Nb) + j];
213 /* MixColumns function mixes the columns of the state matrix. The
217 static void InvMixColumns(state_t *state) {
221 a = (*state)[i][0];
222 b = (*state)[i][1];
223 c = (*state)[i][2];
224 d = (*state)[i][3];
226 (*state)[i][0] = Multiply(a, 0x0e) ^ Multiply(b, 0x0b) ^ Multiply(c, 0x0d) ^
228 (*state)[i][1] = Multiply(a, 0x09) ^ Multiply(b, 0x0e) ^ Multiply(c, 0x0b) ^
230 (*state)[i][2] = Multiply(a, 0x0d) ^ Multiply(b, 0x09) ^ Multiply(c, 0x0e) ^
232 (*state)[i][3] = Multiply(a, 0x0b) ^ Multiply(b, 0x0d) ^ Multiply(c, 0x09) ^
239 /* The SubBytes Function Substitutes the values in the state matrix
241 static void InvSubBytes(state_t *state) {
251 __u8 k = (*state)[j][i];
252 (*state)[j][i] = k ? getSBoxInvert(k) : getSBoxInvert(0);
258 (*state)[j][i] = getSBoxInvert((*state)[j][i]);
264 static void InvShiftRows(state_t *state) {
268 temp = (*state)[3][1];
269 (*state)[3][1] = (*state)[2][1];
270 (*state)[2][1] = (*state)[1][1];
271 (*state)[1][1] = (*state)[0][1];
272 (*state)[0][1] = temp;
275 temp = (*state)[0][2];
276 (*state)[0][2] = (*state)[2][2];
277 (*state)[2][2] = temp;
279 temp = (*state)[1][2];
280 (*state)[1][2] = (*state)[3][2];
281 (*state)[3][2] = temp;
284 temp = (*state)[0][3];
285 (*state)[0][3] = (*state)[1][3];
286 (*state)[1][3] = (*state)[2][3];
287 (*state)[2][3] = (*state)[3][3];
288 (*state)[3][3] = temp;
291 static void InvCipher(state_t *state, const __u8 *RoundKey) {
292 /* Add the First round key to the state before starting the
294 AddRoundKey(Nr, state, RoundKey);
299 InvShiftRows(state);
300 InvSubBytes(state);
301 AddRoundKey(Nr - 1, state, RoundKey);
302 InvMixColumns(state);
304 InvShiftRows(state);
305 InvSubBytes(state);
306 AddRoundKey(Nr - 2, state, RoundKey);
307 InvMixColumns(state);
309 InvShiftRows(state);
310 InvSubBytes(state);
311 AddRoundKey(Nr - 3, state, RoundKey);
312 InvMixColumns(state);
314 InvShiftRows(state);
315 InvSubBytes(state);
316 AddRoundKey(Nr - 4, state, RoundKey);
317 InvMixColumns(state);
319 InvShiftRows(state);
320 InvSubBytes(state);
321 AddRoundKey(Nr - 5, state, RoundKey);
322 InvMixColumns(state);
324 InvShiftRows(state);
325 InvSubBytes(state);
326 AddRoundKey(Nr - 6, state, RoundKey);
327 InvMixColumns(state);
329 InvShiftRows(state);
330 InvSubBytes(state);
331 AddRoundKey(Nr - 7, state, RoundKey);
332 InvMixColumns(state);
334 InvShiftRows(state);
335 InvSubBytes(state);
336 AddRoundKey(Nr - 8, state, RoundKey);
337 InvMixColumns(state);
339 InvShiftRows(state);
340 InvSubBytes(state);
341 AddRoundKey(Nr - 9, state, RoundKey);
342 InvMixColumns(state);
344 InvShiftRows(state);
345 InvSubBytes(state);
346 AddRoundKey(Nr - 10, state, RoundKey);