Skip to content

Commit

Permalink
docs: replace hex representation of a^-1(x) with decimal representation
Browse files Browse the repository at this point in the history
  • Loading branch information
eightfilms committed Jul 2, 2024
1 parent 9ba903e commit eac8674
Showing 1 changed file with 2 additions and 27 deletions.
29 changes: 2 additions & 27 deletions src/encryption/symmetric/aes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,12 +342,8 @@ where [(); N / 8]:
/// Mix columns is done as such:
///
/// Each column of bytes is treated as a 4-term polynomial, multiplied modulo x^4 + 1 with a
/// fixed polynomial a^-1(x) = {0b}x^3 + {0d}x^2 + {09}x + {0e}, where {xy} represents a
/// hexadecimal number, x being the higher 4 bits, and y being the lower 4 bits.
///
/// eg: {0b} == 0000_1011 == 11
///
/// This is done using matrix multiplication.
/// fixed polynomial a^-1(x) = 11x^3 + 13x^2 + 9x + 14, which is the inverse of the polynomial
/// used in [`Self::mix_columns`]. This is done using matrix multiplication.
fn inv_mix_columns(state: &mut State) {
for col in state.0.iter_mut() {
let tmp = *col;
Expand Down Expand Up @@ -375,27 +371,6 @@ where [(); N / 8]:
}
}

fn multiply(col: u8, multiplicant: usize) -> u8 {
let mut product = 0;
let mut col = col;
let mut mult = multiplicant;

for _ in 0..8 {
if mult & 1 == 1 {
product ^= col;
}

let hi_bit = col & 0x80;
col <<= 1;
if hi_bit == 0x80 {
col ^= 0x1B;
}

mult >>= 1;
}
return product & 0xFF;
}

/// In AES, rotword() is just a one-byte left circular shift.
fn rotate_word(word: &mut [u8; 4]) { word.rotate_left(1) }

Expand Down

0 comments on commit eac8674

Please sign in to comment.