diff options
Diffstat (limited to 'src/block.rs')
-rw-r--r-- | src/block.rs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/block.rs b/src/block.rs index e63062e..abd7ff7 100644 --- a/src/block.rs +++ b/src/block.rs @@ -53,6 +53,17 @@ impl Block { } Block(block) } + + /// Computes self * 2^exponent + /// + /// Ensures that there's no overflow in computing 2^exponent. + pub fn exp(&self, exponent: u32) -> Block { + match exponent { + _ if exponent < 32 => *self * (1 << exponent), + _ if exponent % 2 == 0 => self.exp(exponent / 2).exp(exponent / 2), + _ => (*self * 2).exp(exponent - 1), + } + } } impl From<[u8; 16]> for Block { |