diff --git a/CMakeLists.txt b/CMakeLists.txt index 83865a8..f7fc0dc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,91 +3,47 @@ cmake_minimum_required(VERSION 3.7.0) project(cruft-crypto CXX) -############################################################################### -list (APPEND sources - fwd.hpp - - hash/blake.cpp - hash/blake.hpp - hash/blake2.cpp - hash/blake2.hpp - hash/md2.cpp - hash/md2.hpp - hash/md4.cpp - hash/md4.hpp - hash/md5.cpp - hash/md5.hpp - hash/md6.cpp - hash/md6.hpp - hash/ripemd.cpp - hash/ripemd.hpp - hash/sha1.cpp - hash/sha1.hpp - hash/sha2.cpp - hash/sha2.hpp - - hash/pbkdf2.cpp - hash/pbkdf2.hpp - hash/hmac.cpp - hash/hmac.hpp - - hash/hotp.cpp - hash/hotp.hpp - - stream/chacha.cpp - stream/chacha.hpp - stream/rabbit.cpp - stream/rabbit.hpp - stream/rc4.cpp - stream/rc4.hpp - stream/salsa.cpp - stream/salsa.hpp - - block/rc5.cpp - block/rc5.hpp - block/rc6.cpp - block/rc6.hpp - block/speck.cpp - block/speck.hpp - block/tea.cpp - block/tea.hpp - block/xtea.cpp - block/xtea.hpp - block/xxtea.cpp - block/xxtea.hpp +list (APPEND components + hash/blake + hash/blake2 + hash/md2 + hash/md4 + hash/md5 + hash/md6 + hash/ripemd + hash/sha1 + hash/sha2 + hash/pbkdf2 + hash/hmac + hash/hotp + stream/chacha + stream/rabbit + stream/rc4 + stream/salsa + block/rc2 + block/rc5 + block/rc6 + block/speck + block/tea + block/xtea + block/xxtea ) +############################################################################### +list (APPEND sources fwd.hpp) +foreach (c ${components}) + list (APPEND sources "${c}.cpp" "${c}.hpp") +endforeach() + + option (TESTS "enable unit testing" ON) if (TESTS) include (CTest) enable_testing () - list (APPEND tests - hash/blake - hash/blake2 - hash/md2 - hash/md4 - hash/md5 - hash/md6 - hash/ripemd - hash/sha1 - hash/sha2 - - hash/hmac - hash/hotp - - stream/rc4 - stream/salsa - - block/speck - block/tea - block/xtea - block/xxtea - ) - - foreach (t ${tests}) + foreach (t ${components}) string(REPLACE "/" "_" name "test/${t}") add_executable(crypto_${name} test/${t}.cpp) target_link_libraries(crypto_${name} PRIVATE cruft-crypto) diff --git a/block/rc2.cpp b/block/rc2.cpp new file mode 100644 index 0000000..1f378fa --- /dev/null +++ b/block/rc2.cpp @@ -0,0 +1,13 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Copyright 2018 Danny Robson + */ + +#include "rc2.hpp" + + +/////////////////////////////////////////////////////////////////////////////// + diff --git a/block/rc2.hpp b/block/rc2.hpp new file mode 100644 index 0000000..21c878c --- /dev/null +++ b/block/rc2.hpp @@ -0,0 +1,32 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Copyright 2018 Danny Robson + */ + +#pragma once + +#include +#include + +#include +#include + +namespace cruft::crypto::block { + /// An implementation of the RC2 block cipher (RFC2268) + class rc2 { + public: + using word_t = u16; + static constexpr auto block_size = sizeof (word_t) * 4; + + explicit rc2 (cruft::view key); + + std::array encrypt (std::array src) const; + std::array decrypt (std::array src) const; + + private: + std::array m_key; + }; +} diff --git a/test/block/rc2.cpp b/test/block/rc2.cpp new file mode 100644 index 0000000..f1c59fd --- /dev/null +++ b/test/block/rc2.cpp @@ -0,0 +1,3 @@ +#include "block/rc2.hpp" + +int main () { } \ No newline at end of file diff --git a/test/block/rc5.cpp b/test/block/rc5.cpp new file mode 100644 index 0000000..2b7b1eb --- /dev/null +++ b/test/block/rc5.cpp @@ -0,0 +1 @@ +int main () { } diff --git a/test/block/rc6.cpp b/test/block/rc6.cpp new file mode 100644 index 0000000..2b7b1eb --- /dev/null +++ b/test/block/rc6.cpp @@ -0,0 +1 @@ +int main () { } diff --git a/test/hash/pbkdf2.cpp b/test/hash/pbkdf2.cpp new file mode 100644 index 0000000..2b7b1eb --- /dev/null +++ b/test/hash/pbkdf2.cpp @@ -0,0 +1 @@ +int main () { } diff --git a/test/stream/chacha.cpp b/test/stream/chacha.cpp new file mode 100644 index 0000000..2b7b1eb --- /dev/null +++ b/test/stream/chacha.cpp @@ -0,0 +1 @@ +int main () { } diff --git a/test/stream/rabbit.cpp b/test/stream/rabbit.cpp new file mode 100644 index 0000000..2b7b1eb --- /dev/null +++ b/test/stream/rabbit.cpp @@ -0,0 +1 @@ +int main () { }