diff --git a/um_crypto/qmc/src/v2_rc4/cipher.rs b/um_crypto/qmc/src/v2_rc4/cipher.rs index ad63fba..602d410 100644 --- a/um_crypto/qmc/src/v2_rc4/cipher.rs +++ b/um_crypto/qmc/src/v2_rc4/cipher.rs @@ -31,8 +31,9 @@ impl QMC2RC4 { let n = self.key.len(); for (datum, offset) in data.iter_mut().zip(offset..) { - let idx = get_segment_key(offset as u64, self.key[offset % n], self.hash) as usize; - *datum ^= self.key[idx % n]; + let idx = get_segment_key(offset as u64, self.key[offset % n], self.hash); + let idx = idx % (n as u64); + *datum ^= self.key[idx as usize]; } } @@ -43,10 +44,11 @@ impl QMC2RC4 { let block_offset = offset % OTHER_SEGMENT_SIZE; let seed = self.key[id % n]; - let skip = get_segment_key(id as u64, seed, self.hash) % 512; + let skip = get_segment_key(id as u64, seed, self.hash); + let skip = (skip & 0x1FF) as usize; debug_assert!(data.len() <= OTHER_SEGMENT_SIZE - block_offset); - let key_stream = self.key_stream.iter().skip(skip as usize + block_offset); + let key_stream = self.key_stream.iter().skip(skip + block_offset); for (datum, &key) in data.iter_mut().zip(key_stream) { *datum ^= key; }