Cipher is the main function that encrypts the PlainText.
| 517 | |
| 518 | // Cipher is the main function that encrypts the PlainText. |
| 519 | static void Cipher(state_t* state, const uint8_t* RoundKey) |
| 520 | { |
| 521 | uint8_t round = 0; |
| 522 | |
| 523 | // Add the First round key to the state before starting the rounds. |
| 524 | AddRoundKey(0, state, RoundKey); |
| 525 | |
| 526 | // There will be Nr rounds. |
| 527 | // The first Nr-1 rounds are identical. |
| 528 | // These Nr rounds are executed in the loop below. |
| 529 | // Last one without MixColumns() |
| 530 | for (round = 1; ; ++round) |
| 531 | { |
| 532 | SubBytes(state); |
| 533 | ShiftRows(state); |
| 534 | if (round == Nr) { |
| 535 | break; |
| 536 | } |
| 537 | MixColumns(state); |
| 538 | AddRoundKey(round, state, RoundKey); |
| 539 | } |
| 540 | // Add round key to last round |
| 541 | AddRoundKey(Nr, state, RoundKey); |
| 542 | } |
| 543 | |
| 544 | #if (defined(CBC) && CBC == 1) || (defined(ECB) && ECB == 1) |
| 545 | static void InvCipher(state_t* state, const uint8_t* RoundKey) |
no test coverage detected