aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/utils/xor_buf.cpp21
-rw-r--r--src/utils/xor_buf.h4
2 files changed, 22 insertions, 3 deletions
diff --git a/src/utils/xor_buf.cpp b/src/utils/xor_buf.cpp
index df4e62db9..779be81c3 100644
--- a/src/utils/xor_buf.cpp
+++ b/src/utils/xor_buf.cpp
@@ -16,11 +16,28 @@ u32bit xor_into_buf(byte buf[], u32bit buf_i, u32bit length,
{
const byte* in = static_cast<const byte*>(in_void);
+ byte last = 0;
+ byte count = 0;
+
for(u32bit i = 0; i != in_len; ++i)
{
- buf[buf_i] ^= in[i];
- buf_i = (buf_i + 1) % length;
+ if(in[i] != last)
+ {
+ buf[buf_i] ^= last;
+ buf_i = (buf_i + 1) % length;
+
+ buf[buf_i] ^= count;
+ buf_i = (buf_i + 1) % length;
+
+ last = in[i];
+ count = 1;
+ }
+ else
+ ++count;
}
+
+ // final values of last, count are thrown away
+
return buf_i;
}
diff --git a/src/utils/xor_buf.h b/src/utils/xor_buf.h
index 74bfeef0b..076877e02 100644
--- a/src/utils/xor_buf.h
+++ b/src/utils/xor_buf.h
@@ -68,7 +68,9 @@ inline void xor_buf(byte out[],
}
/**
-* XOR values into buffer. Might do RLE on input
+* XOR values into buffer. Uses RLE compression
+* Intended for use in entropy sources to gather collected
+* data into a buffer to pass to an RNG.
*/
u32bit xor_into_buf(byte buf[], u32bit buf_i, u32bit length,
const void* in_void, u32bit in_len);