Returns an array of 10 + 1 round keys that are calculated by using Rijndael key schedule @return array of 10 + 1 round keys
(BigInteger initialKey)
| 2428 | * @return array of 10 + 1 round keys |
| 2429 | */ |
| 2430 | public static BigInteger[] keyExpansion(BigInteger initialKey) { |
| 2431 | BigInteger[] roundKeys = { |
| 2432 | initialKey, |
| 2433 | BigInteger.ZERO, |
| 2434 | BigInteger.ZERO, |
| 2435 | BigInteger.ZERO, |
| 2436 | BigInteger.ZERO, |
| 2437 | BigInteger.ZERO, |
| 2438 | BigInteger.ZERO, |
| 2439 | BigInteger.ZERO, |
| 2440 | BigInteger.ZERO, |
| 2441 | BigInteger.ZERO, |
| 2442 | BigInteger.ZERO, |
| 2443 | }; |
| 2444 | |
| 2445 | // initialize rcon iteration |
| 2446 | int rconCounter = 1; |
| 2447 | |
| 2448 | for (int i = 1; i < 11; i++) { |
| 2449 | // get the previous 32 bits the key |
| 2450 | BigInteger t = roundKeys[i - 1].remainder(new BigInteger("100000000", 16)); |
| 2451 | |
| 2452 | // split previous key into 8-bit segments |
| 2453 | BigInteger[] prevKey = { |
| 2454 | roundKeys[i - 1].remainder(new BigInteger("100000000", 16)), |
| 2455 | roundKeys[i - 1].remainder(new BigInteger("10000000000000000", 16)).divide(new BigInteger("100000000", 16)), |
| 2456 | roundKeys[i - 1].remainder(new BigInteger("1000000000000000000000000", 16)).divide(new BigInteger("10000000000000000", 16)), |
| 2457 | roundKeys[i - 1].divide(new BigInteger("1000000000000000000000000", 16)), |
| 2458 | }; |
| 2459 | |
| 2460 | // run schedule core |
| 2461 | t = scheduleCore(t, rconCounter); |
| 2462 | rconCounter += 1; |
| 2463 | |
| 2464 | // Calculate partial round key |
| 2465 | BigInteger t0 = t.xor(prevKey[3]); |
| 2466 | BigInteger t1 = t0.xor(prevKey[2]); |
| 2467 | BigInteger t2 = t1.xor(prevKey[1]); |
| 2468 | BigInteger t3 = t2.xor(prevKey[0]); |
| 2469 | |
| 2470 | // Join round key segments |
| 2471 | t2 = t2.multiply(new BigInteger("100000000", 16)); |
| 2472 | t1 = t1.multiply(new BigInteger("10000000000000000", 16)); |
| 2473 | t0 = t0.multiply(new BigInteger("1000000000000000000000000", 16)); |
| 2474 | roundKeys[i] = t0.add(t1).add(t2).add(t3); |
| 2475 | } |
| 2476 | return roundKeys; |
| 2477 | } |
| 2478 | |
| 2479 | /** |
| 2480 | * representation of the input 128-bit block as an array of 8-bit integers. |