aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-11-23 19:26:20 +0000
committerlloyd <[email protected]>2008-11-23 19:26:20 +0000
commit2836919541635b1193212df2b24c6407f663c9f8 (patch)
tree150f46c93cff76b394abeb8704465f2b5fb6cd67 /src/utils
parentf27fcf05383888d98d2553f678b79bb56f04e402 (diff)
Use a simple run length encoding in xor_into_buf, so long blocks of spaces,
zero bytes, etc (relatively common, especially with the statistical pollers that use xor_into_buf) are removed. Counters wrap at 256.
Diffstat (limited to 'src/utils')
-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);