|
| 1 | +use necsim_core::cogs::HabitatToU64Injection; |
| 2 | +use necsim_core::landscape::IndexedLocation; |
| 3 | + |
1 | 4 | use aes_soft::cipher::generic_array::GenericArray; |
2 | 5 | use aes_soft::cipher::{BlockCipher, NewBlockCipher}; |
3 | 6 | use aes_soft::Aes128; |
@@ -63,11 +66,32 @@ impl necsim_core::cogs::RngCore for AesRng { |
63 | 66 | } |
64 | 67 | } |
65 | 68 |
|
66 | | -impl necsim_core::cogs::PrimeableRng for AesRng { |
67 | | - type Prime = [u8; 16]; |
| 69 | +impl<H: HabitatToU64Injection> necsim_core::cogs::PrimeableRng<H> for AesRng { |
| 70 | + fn prime_with(&mut self, habitat: &H, indexed_location: &IndexedLocation, time_index: u64) { |
| 71 | + let location_bytes = habitat |
| 72 | + .map_indexed_location_to_u64_injective(indexed_location) |
| 73 | + .to_le_bytes(); |
| 74 | + |
| 75 | + self.state[0] = location_bytes[0]; |
| 76 | + self.state[1] = location_bytes[1]; |
| 77 | + self.state[2] = location_bytes[2]; |
| 78 | + self.state[3] = location_bytes[3]; |
| 79 | + self.state[4] = location_bytes[4]; |
| 80 | + self.state[5] = location_bytes[5]; |
| 81 | + self.state[6] = location_bytes[6]; |
| 82 | + self.state[7] = location_bytes[7]; |
| 83 | + |
| 84 | + let time_index_bytes = time_index.to_le_bytes(); |
| 85 | + |
| 86 | + self.state[8] = time_index_bytes[0]; |
| 87 | + self.state[9] = time_index_bytes[1]; |
| 88 | + self.state[10] = time_index_bytes[2]; |
| 89 | + self.state[11] = time_index_bytes[3]; |
| 90 | + self.state[12] = time_index_bytes[4]; |
| 91 | + self.state[13] = time_index_bytes[5]; |
| 92 | + self.state[14] = time_index_bytes[6]; |
| 93 | + self.state[15] = time_index_bytes[7]; |
68 | 94 |
|
69 | | - fn prime_with(&mut self, prime: Self::Prime) { |
70 | | - self.state = prime; |
71 | 95 | self.cached = false; |
72 | 96 | } |
73 | 97 | } |
0 commit comments