Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use new directory structure and includes, also CuckooMap #1

Merged
merged 13 commits into from Feb 19, 2017
58 changes: 26 additions & 32 deletions CMakeLists.txt
@@ -1,7 +1,9 @@


project(cryptoTools)
cmake_minimum_required(VERSION 3.6)
set(BUILD_CURVE ON CACHE BOOL "whether to build Curve.cpp- requires miracl")

set(CMAKE_C_FLAGS "-ffunction-sections -Wall -maes -msse2 -msse4.1 -mpclmul -Wfatal-errors -pthread")
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=c++14")

if($ENV{nasm} MATCHES "")
message(WARNING "\nnasm environment variable NOT defined!!!! This means the fast SHA1 function will not be used.")
Expand All @@ -12,8 +14,8 @@ if($ENV{nasm} MATCHES "")
add_custom_target(sha_asm)

else()
set(shaNasm "${CMAKE_SOURCE_DIR}/cryptoTools/Crypto/asm/sha_lnx.S")
set(shaNasmOutput "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/cryptoTools.dir/Crypto/sha_lnx.S.o")
set(shaNasm "${CMAKE_CURRENT_SOURCE_DIR}/cryptoTools/Crypto/asm/sha_lnx.S")
set(shaNasmOutput "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/cryptoTools.dir/cryptoTools/Crypto/sha_lnx.S.o")

add_custom_command(
OUTPUT ${shaNasmOutput}
Expand All @@ -28,22 +30,23 @@ else()
endif()


file(GLOB_RECURSE SRCS *.cpp)
file(GLOB_RECURSE SRCS cryptoTools/*.cpp)

if (NOT ${BUILD_CURVE})
list(REMOVE_ITEM SRCS ${CMAKE_CURRENT_SOURCE_DIR}/cryptoTools/Crypto/Curve.cpp)
endif()

include_directories(${CMAKE_SOURCE_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
add_library(cryptoTools STATIC ${SRCS} ${shaNasmOutput})
add_dependencies(cryptoTools sha_asm)


#############################################
# Install #
#############################################

# export cryptoTools headers too
install(DIRECTORY . DESTINATION include/${PROJECT_NAME} FILES_MATCHING PATTERN "*.h")
install(DIRECTORY cryptoTools DESTINATION include FILES_MATCHING PATTERN "*.h")
install(TARGETS cryptoTools DESTINATION lib/${PROJECT_NAME})

###########################################################################
###########################################################################
# Link external libraries #
# ----------------------- #
Expand All @@ -54,38 +57,29 @@ install(TARGETS cryptoTools DESTINATION lib/${PROJECT_NAME})
# #
###########################################################################



find_library(
MIRACL_LIB
NAMES miracl
HINTS "${Miracl_Dirs}/miracl/source/")

# if we cant fint it, throw an error
if(NOT MIRACL_LIB)
Message(${MIRACL_LIB})
message(FATAL_ERROR "Failed to find miracl at " ${Miracl_Lib_Dirs})
if (${BUILD_CURVE})
find_library(MIRACL_LIB NAMES miracl HINTS "${Miracl_Dirs}/miracl/source/")
# if we cant fint it, throw an error
if(NOT MIRACL_LIB)
Message(${MIRACL_LIB})
message(FATAL_ERROR "Failed to find miracl at " ${Miracl_Lib_Dirs})
endif()
endif()


set(Boost_USE_STATIC_LIBS ON) # only find static libs
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME ON)

find_package(Boost COMPONENTS system thread)
find_package(Boost COMPONENTS system thread)

if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIR})
#message( "Found Boost at ${Boost_LIBRARIES}")
include_directories(${Boost_INCLUDE_DIR})
else()
message(FATAL_ERROR "Failed to find boost at " ${Boost_Lib_Dirs} " Need system thread")
message(FATAL_ERROR "Failed to find boost at " ${Boost_Lib_Dirs} " Need system thread")
endif()

if (${BUILD_CURVE})
target_link_libraries(cryptoTools ${MIRACL_LIB})
endif()


#target_link_libraries(cryptoTools sha_asm)
target_link_libraries(cryptoTools ${MIRACL_LIB})
target_link_libraries(cryptoTools ${Boost_LIBRARIES})


#set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
2 changes: 1 addition & 1 deletion Common/ArrayView.h → cryptoTools/Common/ArrayView.h
@@ -1,6 +1,6 @@
#pragma once
// This file and the associated implementation has been placed in the public domain, waiving all copyright. No restrictions are placed on its use.
#include "cryptoTools/Common/Defines.h"
#include <cryptoTools/Common/Defines.h>
#include <vector>
#include <array>
namespace osuCrypto {
Expand Down
4 changes: 2 additions & 2 deletions Common/BitIterator.cpp → cryptoTools/Common/BitIterator.cpp
@@ -1,4 +1,4 @@
#include "BitIterator.h"
#include <cryptoTools/Common/BitIterator.h>

namespace osuCrypto
{
Expand All @@ -8,4 +8,4 @@ namespace osuCrypto
return (*mByte & mMask) >> mShift;
}

}
}
2 changes: 1 addition & 1 deletion Common/BitIterator.h → cryptoTools/Common/BitIterator.h
@@ -1,6 +1,6 @@
#pragma once
// This file and the associated implementation has been placed in the public domain, waiving all copyright. No restrictions are placed on its use.
#include "cryptoTools/Common/Defines.h"
#include <cryptoTools/Common/Defines.h>

namespace osuCrypto
{
Expand Down
8 changes: 4 additions & 4 deletions Common/BitVector.cpp → cryptoTools/Common/BitVector.cpp
@@ -1,4 +1,4 @@
#include "BitVector.h"
#include <cryptoTools/Common/BitVector.h>
#include <sstream>
#include <cstring>
namespace osuCrypto {
Expand Down Expand Up @@ -219,7 +219,7 @@ namespace osuCrypto {

for (u64 i = 0; i < size(); ++i)
{
#ifndef NDEBUG
#ifndef NDEBUG
if (u8(data[i] - '0') > 1) throw std::runtime_error("");
#endif

Expand All @@ -241,7 +241,7 @@ namespace osuCrypto {
if (mData[i] != rhs.mData[i]) { return false; }
}

// numBits = 4
// numBits = 4
// 00001010
// 11111010
// ^^^^ compare these
Expand Down Expand Up @@ -376,4 +376,4 @@ namespace osuCrypto {
return out;
}

}
}
10 changes: 5 additions & 5 deletions Common/BitVector.h → cryptoTools/Common/BitVector.h
@@ -1,11 +1,11 @@
#pragma once
// This file and the associated implementation has been placed in the public domain, waiving all copyright. No restrictions are placed on its use.

#include "cryptoTools/Common/Defines.h"
#include "cryptoTools/Network/Channel.h"
#include "cryptoTools/Crypto/PRNG.h"
#include "cryptoTools/Common/BitIterator.h"
#include "cryptoTools/Common/ArrayView.h"
#include <cryptoTools/Common/Defines.h>
#include <cryptoTools/Network/Channel.h>
#include <cryptoTools/Crypto/PRNG.h>
#include <cryptoTools/Common/BitIterator.h>
#include <cryptoTools/Common/ArrayView.h>
namespace osuCrypto {


Expand Down
15 changes: 7 additions & 8 deletions Common/ByteStream.cpp → cryptoTools/Common/ByteStream.cpp
@@ -1,8 +1,7 @@
#include <cryptoTools/Common/ByteStream.h>
#include <cryptoTools/Crypto/Commit.h>
#include <string.h>

#include "cryptoTools/Common/ByteStream.h"
#include <sstream>
#include "cryptoTools/Crypto/Commit.h"

namespace osuCrypto {

Expand Down Expand Up @@ -36,10 +35,10 @@ namespace osuCrypto {
if (l > mCapacity) {
u8* nd = new u8[l]();
memcpy(nd, mData, mPutHead*sizeof(u8));

if(mData)
delete[] mData;

mData = nd;
mCapacity = l;
}
Expand Down Expand Up @@ -118,11 +117,11 @@ namespace osuCrypto {
void ByteStream::append(const block& b)
{
append((const u8*)(&b), sizeof(block));
}
}

//void ByteStream::append(const blockRIOT& b, u64 l)
//{
// append((const u8*)(&b), l);
// append((const u8*)(&b), l);
//}
//
void ByteStream::append(const Commit& b)
Expand Down
59 changes: 29 additions & 30 deletions Common/ByteStream.h → cryptoTools/Common/ByteStream.h
@@ -1,16 +1,16 @@
#pragma once
// This file and the associated implementation has been placed in the public domain, waiving all copyright. No restrictions are placed on its use.

#include "cryptoTools/Common/Defines.h"
#include "cryptoTools/Network/Channel.h"
#include "ArrayView.h"
#include "MatrixView.h"
#include "cryptoTools/Common/BitIterator.h"
// This file and the associated implementation has been placed in the public domain, waiving all copyright. No restrictions are placed on its use.

#include <cryptoTools/Common/Defines.h>
#include <cryptoTools/Network/Channel.h>
#include <cryptoTools/Common/ArrayView.h>
#include <cryptoTools/Common/MatrixView.h>
#include <cryptoTools/Common/BitIterator.h>

namespace osuCrypto {

class Commit;
namespace osuCrypto {

class Commit;

template <class T>
class BSIterator
Expand All @@ -26,29 +26,29 @@ namespace osuCrypto {
mEnd(end)
{}

T& operator*()
{
T& operator*()
{
if (mCur >= mEnd || mCur < mBegin)
throw std::runtime_error("rt error at " LOCATION);

return *mCur;
return *mCur;
}

BSIterator& operator++()
{
++mCur;
if (mCur == mEnd)
throw std::runtime_error("rt error at " LOCATION);
return *this;
BSIterator& operator++()
{
++mCur;
if (mCur == mEnd)
throw std::runtime_error("rt error at " LOCATION);
return *this;
}

BSIterator operator++(int)
{
BSIterator ret(*this);
++mCur;
if (mCur > mEnd)
throw std::runtime_error("rt error at " LOCATION);
return ret;
BSIterator operator++(int)
{
BSIterator ret(*this);
++mCur;
if (mCur > mEnd)
throw std::runtime_error("rt error at " LOCATION);
return ret;
}

BSIterator& operator+(int i)
Expand Down Expand Up @@ -134,20 +134,19 @@ namespace osuCrypto {
friend std::ostream& operator<<(std::ostream& s, const ByteStream& o);
friend class PRNG;

public:
public:
typedef u8* pointer;
typedef u64 size_type;
typedef u8 value_type;

ByteStream(u64 size = 0, bool zero = true);
ByteStream(const ByteStream& os);
ByteStream(const pointer data, u64 length);

~ByteStream() { delete[] mData; }

/// <summary>The size of the unconsumed steam/data.</summary>
size_type size() const { return tellp() - tellg(); }

/// <summary>The capacity of the container.</summary>
size_type capacity() const { return mCapacity; }

Expand All @@ -174,7 +173,7 @@ namespace osuCrypto {

/// <summary>Grows the size of the underlying container to fit length bytes</summary>
void reserve(u64 length);

void resize(u64 size);

/// <summary>Copies length bytes starting at data to the end of the container tellp().</summary>
Expand Down