MCPcopy Create free account
hub / github.com/abbeycode/UnrarKit / keySched

Method keySched

Libraries/unrar/rijndael.cpp:332–401  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

330
331
332void Rijndael::keySched(byte key[_MAX_KEY_COLUMNS][4])
333{
334 int j,rconpointer = 0;
335
336 // Calculate the necessary round keys
337 // The number of calculations depends on keyBits and blockBits
338 int uKeyColumns = m_uRounds - 6;
339
340 byte tempKey[_MAX_KEY_COLUMNS][4];
341
342 // Copy the input key to the temporary key matrix
343
344 memcpy(tempKey,key,sizeof(tempKey));
345
346 int r = 0;
347 int t = 0;
348
349 // copy values into round key array
350 for(j = 0;(j < uKeyColumns) && (r <= m_uRounds); )
351 {
352 for(;(j < uKeyColumns) && (t < 4); j++, t++)
353 for (int k=0;k<4;k++)
354 m_expandedKey[r][t][k]=tempKey[j][k];
355
356 if(t == 4)
357 {
358 r++;
359 t = 0;
360 }
361 }
362
363 while(r <= m_uRounds)
364 {
365 tempKey[0][0] ^= S[tempKey[uKeyColumns-1][1]];
366 tempKey[0][1] ^= S[tempKey[uKeyColumns-1][2]];
367 tempKey[0][2] ^= S[tempKey[uKeyColumns-1][3]];
368 tempKey[0][3] ^= S[tempKey[uKeyColumns-1][0]];
369 tempKey[0][0] ^= rcon[rconpointer++];
370
371 if (uKeyColumns != 8)
372 for(j = 1; j < uKeyColumns; j++)
373 for (int k=0;k<4;k++)
374 tempKey[j][k] ^= tempKey[j-1][k];
375 else
376 {
377 for(j = 1; j < uKeyColumns/2; j++)
378 for (int k=0;k<4;k++)
379 tempKey[j][k] ^= tempKey[j-1][k];
380
381 tempKey[uKeyColumns/2][0] ^= S[tempKey[uKeyColumns/2 - 1][0]];
382 tempKey[uKeyColumns/2][1] ^= S[tempKey[uKeyColumns/2 - 1][1]];
383 tempKey[uKeyColumns/2][2] ^= S[tempKey[uKeyColumns/2 - 1][2]];
384 tempKey[uKeyColumns/2][3] ^= S[tempKey[uKeyColumns/2 - 1][3]];
385 for(j = uKeyColumns/2 + 1; j < uKeyColumns; j++)
386 for (int k=0;k<4;k++)
387 tempKey[j][k] ^= tempKey[j-1][k];
388 }
389 for(j = 0; (j < uKeyColumns) && (r <= m_uRounds); )

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected