encfs/cipher/NullCipher.cpp

142 lines
4.0 KiB
C++
Raw Normal View History

/*****************************************************************************
* Author: Valient Gough <vgough@pobox.com>
*
*****************************************************************************
* 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
2014-10-19 04:19:33 +02:00
* 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 <http://www.gnu.org/licenses/>.
*/
#include "NullCipher.h"
#include <cstring>
2015-06-18 06:56:43 +02:00
#include <memory>
2015-06-18 07:59:04 +02:00
#include "Cipher.h"
#include "Interface.h"
2015-06-18 06:56:43 +02:00
#include "Range.h"
using namespace std;
2015-06-18 05:33:57 +02:00
namespace encfs {
2014-10-19 04:19:33 +02:00
static Interface NullInterface("nullCipher", 1, 0, 0);
static Range NullKeyRange(0);
2014-10-19 04:19:33 +02:00
static Range NullBlockRange(1, 4096, 1);
2015-06-18 05:33:57 +02:00
static std::shared_ptr<Cipher> NewNullCipher(const Interface &iface,
int keyLen) {
2014-10-19 04:19:33 +02:00
(void)keyLen;
2015-06-18 05:33:57 +02:00
return std::shared_ptr<Cipher>(new NullCipher(iface));
}
const bool HiddenCipher = true;
2014-10-19 04:19:33 +02:00
static bool NullCipher_registered = Cipher::Register(
"Null", "Non encrypting cipher. For testing only!", NullInterface,
NullKeyRange, NullBlockRange, NewNullCipher, HiddenCipher);
2014-10-19 04:19:33 +02:00
class NullKey : public AbstractCipherKey {
public:
NullKey() {}
virtual ~NullKey() {}
};
2014-10-19 04:19:33 +02:00
class NullDestructor {
public:
NullDestructor() {}
NullDestructor(const NullDestructor &) {}
~NullDestructor() {}
2014-10-19 04:19:33 +02:00
NullDestructor &operator=(const NullDestructor &) { return *this; }
void operator()(NullKey *&) {}
};
2015-06-18 05:33:57 +02:00
std::shared_ptr<AbstractCipherKey> gNullKey(new NullKey(), NullDestructor());
2014-10-19 04:19:33 +02:00
NullCipher::NullCipher(const Interface &iface_) { this->iface = iface_; }
2014-10-19 04:19:33 +02:00
NullCipher::~NullCipher() {}
2014-10-19 04:19:33 +02:00
Interface NullCipher::interface() const { return iface; }
2014-10-19 04:19:33 +02:00
CipherKey NullCipher::newKey(const char *, int, int &, long,
const unsigned char *, int) {
return gNullKey;
}
2014-10-19 04:19:33 +02:00
CipherKey NullCipher::newKey(const char *, int) { return gNullKey; }
2014-10-19 04:19:33 +02:00
CipherKey NullCipher::newRandomKey() { return gNullKey; }
2014-10-19 04:19:33 +02:00
bool NullCipher::randomize(unsigned char *buf, int len, bool) const {
memset(buf, 0, len);
return true;
}
2014-10-19 04:19:33 +02:00
uint64_t NullCipher::MAC_64(const unsigned char *, int, const CipherKey &,
uint64_t *) const {
return 0;
}
2014-10-19 04:19:33 +02:00
CipherKey NullCipher::readKey(const unsigned char *, const CipherKey &, bool) {
return gNullKey;
}
2014-10-19 04:19:33 +02:00
void NullCipher::writeKey(const CipherKey &, unsigned char *,
const CipherKey &) {}
2014-10-19 04:19:33 +02:00
bool NullCipher::compareKey(const CipherKey &A_, const CipherKey &B_) const {
2015-06-18 05:33:57 +02:00
std::shared_ptr<NullKey> A = dynamic_pointer_cast<NullKey>(A_);
std::shared_ptr<NullKey> B = dynamic_pointer_cast<NullKey>(B_);
2014-10-19 04:19:33 +02:00
return A.get() == B.get();
}
2014-10-19 04:19:33 +02:00
int NullCipher::encodedKeySize() const { return 0; }
2014-10-19 04:19:33 +02:00
int NullCipher::keySize() const { return 0; }
2014-10-19 04:19:33 +02:00
int NullCipher::cipherBlockSize() const { return 1; }
2014-10-19 04:19:33 +02:00
bool NullCipher::streamEncode(unsigned char *src, int len, uint64_t iv64,
const CipherKey &key) const {
(void)src;
(void)len;
(void)iv64;
(void)key;
return true;
}
2014-10-19 04:19:33 +02:00
bool NullCipher::streamDecode(unsigned char *src, int len, uint64_t iv64,
const CipherKey &key) const {
(void)src;
(void)len;
(void)iv64;
(void)key;
return true;
}
2014-10-19 04:19:33 +02:00
bool NullCipher::blockEncode(unsigned char *, int, uint64_t,
const CipherKey &) const {
return true;
}
2014-10-19 04:19:33 +02:00
bool NullCipher::blockDecode(unsigned char *, int, uint64_t,
const CipherKey &) const {
return true;
}
2014-10-19 04:19:33 +02:00
bool NullCipher::Enabled() { return true; }
2015-06-18 05:33:57 +02:00
} // namespace encfs