diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/block.rs | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/src/block.rs b/src/block.rs index abd7ff7..e9ba527 100644 --- a/src/block.rs +++ b/src/block.rs @@ -134,19 +134,24 @@ impl IndexMut<usize> for Block { impl Mul<u32> for Block { type Output = Block; - fn mul(self, rhs: u32) -> Block { - match rhs { - 0 => Block::NULL, - 1 => self, - 2 => { - let mut result = self << 1; - if self[0] & 0x80 != 0 { - result[15] ^= 135; + fn mul(mut self, mut rhs: u32) -> Block { + loop { + match rhs { + 0 => break Block::NULL, + 1 => break self, + 2 => { + let mut result = self << 1; + if self[0] & 0x80 != 0 { + result[15] ^= 135; + } + break result; } - result + _ if rhs % 2 == 0 => { + self = self * 2; + rhs = rhs / 2; + } + _ => break self * (rhs - 1) ^ self, } - _ if rhs % 2 == 0 => self * 2 * (rhs / 2), - _ => self * (rhs - 1) ^ self, } } } |