Commit 66932603 authored by Philip Woolford's avatar Philip Woolford
Browse files

Fix `buffer::pop`

The `pop()` function rotated the internal state in the wrong order, causing `pop()`s to overwrite `b`, `c` and `d` to be equal every time.
This has been fixed, and the `mut a` has been removed from `push()` too.
parent 74faa301
......@@ -174,10 +174,8 @@ impl State {
/// Write another 64-bit integer into the state.
pub fn push(&mut self, x: u64) {
let mut a = self.a;
// Mix `x` into `a`.
a = helper::diffuse(a ^ x);
let a = helper::diffuse(self.a ^ x);
// Rotate around.
// _______________________
......@@ -196,22 +194,20 @@ impl State {
///
/// Given the value of the most recently written u64 `last`, remove it from the state.
pub fn pop(&mut self, last: u64) {
// Decrese the written bytes counter.
self.written -= 8;
// Remove the recently written data.
self.d = helper::undiffuse(self.d) ^ last;
let mut a = self.a;
// Un-mix `last` from `d`. Removes the recently written data.
let d = helper::undiffuse(self.d) ^ last;
// Rotate back.
// _______________________
// v |
// a ----> b ----> c ----> d
self.a = self.d;
self.b = a;
self.c = self.b;
self.d = self.c;
self.c = self.b;
self.b = self.a;
self.a = d;
// Decrese the written bytes counter.
self.written -= 8;
}
/// Finalize the state.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment