aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-11-23 18:13:40 +0000
committerlloyd <[email protected]>2008-11-23 18:13:40 +0000
commit36c4e419e899f650d32712594fc947f9f7960992 (patch)
tree9ed556e3acb55c935f7ba6e78960128355bac71e /src/utils
parent1bddfc5aeffc8ece20c18b4b8f6a9a006969ff80 (diff)
Move xor_into_buf to xor_buf.cpp. Also add a new template wrapper for
xoring integer values in.
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/info.txt1
-rw-r--r--src/utils/xor_buf.cpp27
-rw-r--r--src/utils/xor_buf.h21
3 files changed, 39 insertions, 10 deletions
diff --git a/src/utils/info.txt b/src/utils/info.txt
index ffc19c852..915ce50b0 100644
--- a/src/utils/info.txt
+++ b/src/utils/info.txt
@@ -42,5 +42,6 @@ util.cpp
util.h
version.cpp
version.h
+xor_buf.cpp
xor_buf.h
</add>
diff --git a/src/utils/xor_buf.cpp b/src/utils/xor_buf.cpp
new file mode 100644
index 000000000..df4e62db9
--- /dev/null
+++ b/src/utils/xor_buf.cpp
@@ -0,0 +1,27 @@
+/**
+* XOR operations
+* (C) 1999-2008 Jack Lloyd
+*/
+
+#include <botan/xor_buf.h>
+#include <botan/loadstor.h>
+
+namespace Botan {
+
+/**
+* Xor values into buffer
+*/
+u32bit xor_into_buf(byte buf[], u32bit buf_i, u32bit length,
+ const void* in_void, u32bit in_len)
+ {
+ const byte* in = static_cast<const byte*>(in_void);
+
+ for(u32bit i = 0; i != in_len; ++i)
+ {
+ buf[buf_i] ^= in[i];
+ buf_i = (buf_i + 1) % length;
+ }
+ return buf_i;
+ }
+
+}
diff --git a/src/utils/xor_buf.h b/src/utils/xor_buf.h
index 975ad0af6..bbc6d3eec 100644
--- a/src/utils/xor_buf.h
+++ b/src/utils/xor_buf.h
@@ -68,18 +68,19 @@ inline void xor_buf(byte out[],
}
/**
-* Xor values into buffer
+* XOR values into buffer. Might do RLE on input
*/
-inline u32bit xor_into_buf(byte buf[], u32bit buf_i, u32bit length,
- const void* in_void, u32bit in_len)
+u32bit xor_into_buf(byte buf[], u32bit buf_i, u32bit length,
+ const void* in_void, u32bit in_len);
+
+/**
+* XOR integer value (or something else, I guess) into buffer
+*/
+template<typename T>
+u32bit xor_into_buf(byte buf[], u32bit buf_i,
+ u32bit length, T in)
{
- const byte* in = static_cast<const byte*>(in_void);
- for(u32bit i = 0; i != in_len; ++i)
- {
- buf[buf_i] ^= in[i];
- buf_i = (buf_i + 1) % length;
- }
- return buf_i;
+ return xor_into_buf(buf, buf_i, length, &in, sizeof(in));
}
}