chore: update dependency
This commit is contained in:
@@ -502,3 +502,47 @@ pub fn aes_ctr_enc(input: &[u8], key: &[u8; 16], nonce: u64) -> Result<Vec<u8>>
|
||||
pub fn aes_ctr_dec(input: &[u8], key: &[u8; 16], nonce: u64) -> Result<Vec<u8>> {
|
||||
aes_ctr_enc(input, key, nonce)
|
||||
}
|
||||
|
||||
pub struct MT19937 {
|
||||
mt: [u32; 624],
|
||||
index: usize,
|
||||
}
|
||||
|
||||
impl MT19937 {
|
||||
pub fn new(seed: u32) -> Self {
|
||||
let mut mt = [0; 624];
|
||||
mt[0] = seed;
|
||||
for i in 1..624 {
|
||||
mt[i] = 0x6c078965u32
|
||||
.wrapping_mul(mt[i - 1] ^ (mt[i - 1] >> 30))
|
||||
.wrapping_add(i as u32)
|
||||
}
|
||||
let index = 0;
|
||||
MT19937 { mt, index }
|
||||
}
|
||||
|
||||
pub fn extract_number(&mut self) -> u32 {
|
||||
if self.index == 0 {
|
||||
self.generate_numbers();
|
||||
}
|
||||
let mut result = self.mt[self.index];
|
||||
|
||||
result ^= result >> 11;
|
||||
result ^= (result << 7) & 0x9d2c5680;
|
||||
result ^= (result << 15) & 0xefc60000;
|
||||
result ^= result >> 18;
|
||||
self.index = (self.index + 1) % 624;
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
fn generate_numbers(&mut self) {
|
||||
for i in 0..624 {
|
||||
let y: u32 = (self.mt[i] & 0x80000000) + (self.mt[(i + 1) % 624] & 0x7fffffff);
|
||||
self.mt[i] = self.mt[(i + 397) % 624] ^ (y >> 1);
|
||||
if y % 2 != 0 {
|
||||
self.mt[i] ^= 0x9908b0df;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user