2008-01-07 09:09:04 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* Author: Valient Gough <vgough@pobox.com>
|
|
|
|
*
|
|
|
|
*****************************************************************************
|
|
|
|
* Copyright (c) 2004, Valient Gough
|
|
|
|
*
|
2012-10-22 07:30:55 +02:00
|
|
|
* 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.
|
2008-01-07 09:09:04 +01:00
|
|
|
*
|
2012-10-22 07:30:55 +02:00
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
2008-01-07 09:09:04 +01:00
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
2012-10-22 07:30:55 +02:00
|
|
|
* 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/>.
|
2008-01-07 09:09:04 +01:00
|
|
|
*/
|
|
|
|
|
2013-11-16 19:24:07 +01:00
|
|
|
#include "NullCipher.h"
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2013-11-16 19:24:07 +01:00
|
|
|
#include <cstring>
|
2015-06-18 06:56:43 +02:00
|
|
|
#include <memory>
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2015-06-18 07:59:04 +02:00
|
|
|
#include "Cipher.h"
|
2013-11-16 19:24:07 +01:00
|
|
|
#include "Interface.h"
|
2015-06-18 06:56:43 +02:00
|
|
|
#include "Range.h"
|
2008-01-07 09:09:04 +01:00
|
|
|
|
|
|
|
using namespace std;
|
2015-06-18 05:33:57 +02:00
|
|
|
|
|
|
|
namespace encfs {
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2014-10-19 04:19:33 +02:00
|
|
|
static Interface NullInterface("nullCipher", 1, 0, 0);
|
2008-01-07 09:09:04 +01:00
|
|
|
static Range NullKeyRange(0);
|
2014-10-19 04:19:33 +02:00
|
|
|
static Range NullBlockRange(1, 4096, 1);
|
2008-01-07 09:09:04 +01:00
|
|
|
|
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));
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2014-10-19 04:19:33 +02:00
|
|
|
class NullKey : public AbstractCipherKey {
|
|
|
|
public:
|
|
|
|
NullKey() {}
|
|
|
|
virtual ~NullKey() {}
|
2008-01-07 09:09:04 +01:00
|
|
|
};
|
|
|
|
|
2014-10-19 04:19:33 +02:00
|
|
|
class NullDestructor {
|
|
|
|
public:
|
|
|
|
NullDestructor() {}
|
|
|
|
NullDestructor(const NullDestructor &) {}
|
|
|
|
~NullDestructor() {}
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2014-10-19 04:19:33 +02:00
|
|
|
NullDestructor &operator=(const NullDestructor &) { return *this; }
|
|
|
|
void operator()(NullKey *&) {}
|
2008-01-07 09:09:04 +01:00
|
|
|
};
|
2015-06-18 05:33:57 +02:00
|
|
|
std::shared_ptr<AbstractCipherKey> gNullKey(new NullKey(), NullDestructor());
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2014-10-19 04:19:33 +02:00
|
|
|
NullCipher::NullCipher(const Interface &iface_) { this->iface = iface_; }
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2014-10-19 04:19:33 +02:00
|
|
|
NullCipher::~NullCipher() {}
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2014-10-19 04:19:33 +02:00
|
|
|
Interface NullCipher::interface() const { return iface; }
|
2008-08-17 09:26:52 +02:00
|
|
|
|
2014-10-19 04:19:33 +02:00
|
|
|
CipherKey NullCipher::newKey(const char *, int, int &, long,
|
|
|
|
const unsigned char *, int) {
|
|
|
|
return gNullKey;
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
2014-10-19 04:19:33 +02:00
|
|
|
CipherKey NullCipher::newKey(const char *, int) { return gNullKey; }
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2014-10-19 04:19:33 +02:00
|
|
|
CipherKey NullCipher::newRandomKey() { return gNullKey; }
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2014-10-19 04:19:33 +02:00
|
|
|
bool NullCipher::randomize(unsigned char *buf, int len, bool) const {
|
|
|
|
memset(buf, 0, len);
|
|
|
|
return true;
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
2014-10-19 04:19:33 +02:00
|
|
|
uint64_t NullCipher::MAC_64(const unsigned char *, int, const CipherKey &,
|
|
|
|
uint64_t *) const {
|
|
|
|
return 0;
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
2014-10-19 04:19:33 +02:00
|
|
|
CipherKey NullCipher::readKey(const unsigned char *, const CipherKey &, bool) {
|
|
|
|
return gNullKey;
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
2014-10-19 04:19:33 +02:00
|
|
|
void NullCipher::writeKey(const CipherKey &, unsigned char *,
|
|
|
|
const CipherKey &) {}
|
2008-01-07 09:09:04 +01:00
|
|
|
|
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();
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
2014-10-19 04:19:33 +02:00
|
|
|
int NullCipher::encodedKeySize() const { return 0; }
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2014-10-19 04:19:33 +02:00
|
|
|
int NullCipher::keySize() const { return 0; }
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2014-10-19 04:19:33 +02:00
|
|
|
int NullCipher::cipherBlockSize() const { return 1; }
|
2008-01-07 09:09:04 +01:00
|
|
|
|
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;
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
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;
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
2014-10-19 04:19:33 +02:00
|
|
|
bool NullCipher::blockEncode(unsigned char *, int, uint64_t,
|
|
|
|
const CipherKey &) const {
|
|
|
|
return true;
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
2014-10-19 04:19:33 +02:00
|
|
|
bool NullCipher::blockDecode(unsigned char *, int, uint64_t,
|
|
|
|
const CipherKey &) const {
|
|
|
|
return true;
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
2014-10-19 04:19:33 +02:00
|
|
|
bool NullCipher::Enabled() { return true; }
|
2015-06-18 05:33:57 +02:00
|
|
|
|
|
|
|
} // namespace encfs
|