/***************************************************************************** * Author: Valient Gough * ***************************************************************************** * Copyright (c) 2004, Valient Gough * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by the * Free Software Foundation, either version 3 of the License, or (at your * option) any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #include "cipher/NullCipher.h" #include "base/Range.h" #include "base/Interface.h" #include "base/shared_ptr.h" #include using namespace std; namespace encfs { static Interface NullInterface = makeInterface( "nullCipher", 1, 0, 0 ); static Range NullKeyRange(0); static Range NullBlockRange(1,4096,1); static shared_ptr NewNullCipher(const Interface &iface, int keyLen) { (void)keyLen; return shared_ptr( new NullCipher( iface ) ); } const bool HiddenCipher = true; static bool NullCipher_registered = Cipher::Register("Null", "Non encrypting cipher. For testing only!", NullInterface, NullKeyRange, NullBlockRange, NewNullCipher, HiddenCipher); class NullKey : public AbstractCipherKey { public: NullKey() {} virtual ~NullKey() {} }; class NullDestructor { public: NullDestructor() {} NullDestructor(const NullDestructor &) {} ~NullDestructor() {} NullDestructor &operator = (const NullDestructor &){ return *this; } void operator ()(NullKey *&) {} }; shared_ptr gNullKey( new NullKey(), NullDestructor() ); NullCipher::NullCipher(const Interface &iface_) { this->iface = iface_; } NullCipher::~NullCipher() { } Interface NullCipher::interface() const { return iface; } CipherKey NullCipher::newKey(const char *, int, int &, long, const byte *, int ) { return gNullKey; } CipherKey NullCipher::newKey(const char *, int) { return gNullKey; } CipherKey NullCipher::newRandomKey() { return gNullKey; } bool NullCipher::randomize( byte *buf, int len, bool ) const { memset( buf, 0, len ); return true; } uint64_t NullCipher::MAC_64(const byte *, int , const CipherKey &, uint64_t *) const { return 0; } CipherKey NullCipher::readKey( const byte *, const CipherKey &, bool) { return gNullKey; } void NullCipher::writeKey(const CipherKey &, byte *, const CipherKey &) { } bool NullCipher::compareKey(const CipherKey &A_, const CipherKey &B_) const { shared_ptr A = dynamic_pointer_cast(A_); shared_ptr B = dynamic_pointer_cast(B_); return A.get() == B.get(); } int NullCipher::encodedKeySize() const { return 0; } int NullCipher::keySize() const { return 0; } int NullCipher::cipherBlockSize() const { return 1; } bool NullCipher::streamEncode( byte *src, int len, uint64_t iv64, const CipherKey &key) const { (void)src; (void)len; (void)iv64; (void)key; return true; } bool NullCipher::streamDecode( byte *src, int len, uint64_t iv64, const CipherKey &key) const { (void)src; (void)len; (void)iv64; (void)key; return true; } bool NullCipher::blockEncode( byte *, int , uint64_t, const CipherKey & ) const { return true; } bool NullCipher::blockDecode( byte *, int, uint64_t, const CipherKey & ) const { return true; } bool NullCipher::Enabled() { return true; } } // namespace encfs