aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/block/des/desx.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/block/des/desx.cpp')
-rw-r--r--src/lib/block/des/desx.cpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/lib/block/des/desx.cpp b/src/lib/block/des/desx.cpp
new file mode 100644
index 000000000..879e73ee9
--- /dev/null
+++ b/src/lib/block/des/desx.cpp
@@ -0,0 +1,62 @@
+/*
+* DES
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#include <botan/desx.h>
+#include <botan/internal/xor_buf.h>
+
+namespace Botan {
+
+/*
+* DESX Encryption
+*/
+void DESX::encrypt_n(const byte in[], byte out[], size_t blocks) const
+ {
+ for(size_t i = 0; i != blocks; ++i)
+ {
+ xor_buf(out, in, &K1[0], BLOCK_SIZE);
+ des.encrypt(out);
+ xor_buf(out, &K2[0], BLOCK_SIZE);
+
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
+ }
+ }
+
+/*
+* DESX Decryption
+*/
+void DESX::decrypt_n(const byte in[], byte out[], size_t blocks) const
+ {
+ for(size_t i = 0; i != blocks; ++i)
+ {
+ xor_buf(out, in, &K2[0], BLOCK_SIZE);
+ des.decrypt(out);
+ xor_buf(out, &K1[0], BLOCK_SIZE);
+
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
+ }
+ }
+
+/*
+* DESX Key Schedule
+*/
+void DESX::key_schedule(const byte key[], size_t)
+ {
+ K1.assign(key, key + 8);
+ des.set_key(key + 8, 8);
+ K2.assign(key + 16, key + 24);
+ }
+
+void DESX::clear()
+ {
+ des.clear();
+ zap(K1);
+ zap(K2);
+ }
+
+}