diff --git a/apps/enclave/Makefile b/apps/enclave/Makefile index 499868fcc..34b45f0a1 100644 --- a/apps/enclave/Makefile +++ b/apps/enclave/Makefile @@ -41,6 +41,7 @@ LIBS = -lsam -ltomcrypt # OBJS = $(OBJDIR)/bigint.o \ + $(OBJDIR)/chk.o \ $(OBJDIR)/logger.o \ $(OBJDIR)/main.o \ $(OBJDIR)/peers.o \ diff --git a/apps/enclave/src/chk.cpp b/apps/enclave/src/chk.cpp new file mode 100644 index 000000000..59b3506d2 --- /dev/null +++ b/apps/enclave/src/chk.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2004, Matthew P. Cashdollar + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the author nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "platform.hpp" +#include "chk.hpp" + +Chk::Chk(const uchar_t* plaintext, size_t size, const string& mime_type) + : data_size(size), mime_type(mime_type) +{ + encrypt(plaintext); +} + +void Chk::encrypt(const uchar_t *pt) +{ + int rc = register_cipher(&twofish_desc); + assert(rc != -1); + + uchar_t key[CRYPT_KEY_SIZE], iv[CRYPT_BLOCK_SIZE]; + prng.get_bytes(key, CRYPT_KEY_SIZE); + prng.get_bytes(iv, CRYPT_BLOCK_SIZE); + + symmetric_CTR ctr; + rc = ctr_start(find_cipher("twofish"), iv, key, CRYPT_KEY_SIZE, 0, &ctr); + assert(rc == CRYPT_OK); + + ct = new uchar_t[data_size]; + rc = ctr_encrypt(pt, ct, data_size, &ctr); + assert(rc == CRYPT_OK); +} diff --git a/apps/enclave/src/chk.hpp b/apps/enclave/src/chk.hpp new file mode 100644 index 000000000..8767d5ea4 --- /dev/null +++ b/apps/enclave/src/chk.hpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2004, Matthew P. Cashdollar + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the author nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef CHK_HPP +#define CHK_HPP + +class Chk { + public: + //Chk(const uchar_t* cypertext, size_t size); + Chk(const uchar_t* plaintext, size_t size, const string& mime_type); + ~Chk(void) { delete ct; } + + private: + static const size_t CRYPT_BLOCK_SIZE = 16; + static const size_t CRYPT_KEY_SIZE = 32; + + void encrypt(const uchar_t *pt); + + uchar_t* ct; // cyphertext + const size_t data_size; + const string& mime_type; // I hate mimes. +}; + +#endif // CHK_HPP diff --git a/apps/enclave/src/logger.cpp b/apps/enclave/src/logger.cpp index 9ef448a35..44dc7e470 100644 --- a/apps/enclave/src/logger.cpp +++ b/apps/enclave/src/logger.cpp @@ -31,7 +31,8 @@ #include "platform.hpp" #include "logger.hpp" -Logger::Logger(const string& file): file(file) +Logger::Logger(const string& file) + : file(file) { loglevel = priority = debug; logf.open(file.c_str(), ios::app);