From 9bcfe627321ddc81691b835dffaa6324ac4684a4 Mon Sep 17 00:00:00 2001 From: lloyd Date: Sun, 28 Sep 2008 19:29:24 +0000 Subject: Move all modules into src/ directory --- src/cipher/tea/modinfo.txt | 10 +++++++++ src/cipher/tea/tea.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++++++ src/cipher/tea/tea.h | 32 ++++++++++++++++++++++++++ 3 files changed, 98 insertions(+) create mode 100644 src/cipher/tea/modinfo.txt create mode 100644 src/cipher/tea/tea.cpp create mode 100644 src/cipher/tea/tea.h (limited to 'src/cipher/tea') diff --git a/src/cipher/tea/modinfo.txt b/src/cipher/tea/modinfo.txt new file mode 100644 index 000000000..6a0e76b15 --- /dev/null +++ b/src/cipher/tea/modinfo.txt @@ -0,0 +1,10 @@ +realname "TEA" + +define TEA + +load_on auto + + +tea.cpp +tea.h + diff --git a/src/cipher/tea/tea.cpp b/src/cipher/tea/tea.cpp new file mode 100644 index 000000000..c5bd1b1fa --- /dev/null +++ b/src/cipher/tea/tea.cpp @@ -0,0 +1,56 @@ +/************************************************* +* TEA Source File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#include +#include + +namespace Botan { + +/************************************************* +* TEA Encryption * +*************************************************/ +void TEA::enc(const byte in[], byte out[]) const + { + u32bit L = load_be(in, 0), R = load_be(in, 1); + + u32bit S = 0; + for(u32bit j = 0; j != 32; ++j) + { + S += 0x9E3779B9; + L += ((R << 4) + K[0]) ^ (R + S) ^ ((R >> 5) + K[1]); + R += ((L << 4) + K[2]) ^ (L + S) ^ ((L >> 5) + K[3]); + } + + store_be(out, L, R); + } + +/************************************************* +* TEA Decryption * +*************************************************/ +void TEA::dec(const byte in[], byte out[]) const + { + u32bit L = load_be(in, 0), R = load_be(in, 1); + + u32bit S = 0xC6EF3720; + for(u32bit j = 0; j != 32; ++j) + { + R -= ((L << 4) + K[2]) ^ (L + S) ^ ((L >> 5) + K[3]); + L -= ((R << 4) + K[0]) ^ (R + S) ^ ((R >> 5) + K[1]); + S -= 0x9E3779B9; + } + + store_be(out, L, R); + } + +/************************************************* +* TEA Key Schedule * +*************************************************/ +void TEA::key(const byte key[], u32bit) + { + for(u32bit j = 0; j != 4; ++j) + K[j] = load_be(key, j); + } + +} diff --git a/src/cipher/tea/tea.h b/src/cipher/tea/tea.h new file mode 100644 index 000000000..2fc9fe838 --- /dev/null +++ b/src/cipher/tea/tea.h @@ -0,0 +1,32 @@ +/************************************************* +* TEA Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_TEA_H__ +#define BOTAN_TEA_H__ + +#include + +namespace Botan { + +/************************************************* +* TEA * +*************************************************/ +class BOTAN_DLL TEA : public BlockCipher + { + public: + void clear() throw() { K.clear(); } + std::string name() const { return "TEA"; } + BlockCipher* clone() const { return new TEA; } + TEA() : BlockCipher(8, 16) {} + private: + void enc(const byte[], byte[]) const; + void dec(const byte[], byte[]) const; + void key(const byte[], u32bit); + SecureBuffer K; + }; + +} + +#endif -- cgit v1.2.3