Skip to content

Commit

Permalink
v1.1.0
Browse files Browse the repository at this point in the history
- remove docker
- fixes in cmake, docs, travis
- add amd64-64-24k-pic
- add benchmark
  • Loading branch information
Warchant committed Dec 5, 2017
1 parent 71333e2 commit 7453906
Show file tree
Hide file tree
Showing 98 changed files with 37,618 additions and 838 deletions.
8 changes: 1 addition & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ matrix:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['gcc-5', 'g++-5']
sonarcloud:
organization:
env:
- COMPILERCC=gcc-5
- COMPILERCXX=g++-5
Expand Down Expand Up @@ -45,14 +43,10 @@ matrix:
- COMPILERCXX=clang++


install:
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; brew install openssl; fi


script:
- mkdir build
- cd build
- export CC=$COMPILERCC; export CXX=$COMPILERCXX
- cmake ..
- cmake .. -DEDIMPL=ref10 -DHASH=sha3_brainhub -DRANDOM=dev_urandom
- make
- ctest
30 changes: 17 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ SET(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
SET(CMAKE_CXX_FLAGS "-std=c++14 -Wall")
SET(CMAKE_CXX_FLAGS_RELEASE "-O3")
SET(CMAKE_CXX_FLAGS_DEBUG "-g -Wextra -O0 -fdiagnostics-color")
SET(CMAKE_C_FLAGS "-Wall -funroll-loops")
SET(CMAKE_C_FLAGS_RELEASE "-O3")
SET(CMAKE_C_FLAGS_DEBUG "-g -Wextra -O0 -fdiagnostics-color")
SET(CMAKE_C_FLAGS "-Wall")
SET(CMAKE_C_FLAGS_RELEASE "-O3 -funroll-loops -fomit-frame-pointer")
SET(CMAKE_C_FLAGS_DEBUG "-g -Wextra -O0 -fdiagnostics-color ")
SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules)
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
SET(CMAKE_EXPORT_COMPILE_COMMANDS "ON")

option(TESTING "Enable testing" ON)
option(COVERAGE "Enable coverage" ON)
option(AMD64_OPTIMIZED "Enable amd64-64-24k" OFF)

if(COVERAGE)
include(cmake/coverage.cmake)
Expand All @@ -23,27 +22,26 @@ endif()
include(cmake/dependencies.cmake)
include(cmake/functions.cmake)

# auto by default
## DEFAULTS
if(NOT EDIMPL)
set(EDIMPL "ref10")
endif()
if(NOT HASH)
set(HASH "sha3_brainhub")
endif()
if(NOT RANDOM)
# https://sockpuppet.org/blog/2014/02/25/safely-generate-random-numbers/
set(RANDOM "dev_urandom")
endif()
if(NOT BUILD)
set(BUILD "SHARED")
endif()

set(EDIMPL_OPTIONS ref10)
if(AMD64_OPTIMIZED)
list(APPEND EDIMPL_OPTIONS amd64-64-24k)
endif()

## OPTIONS
ENUM(EDIMPL "${EDIMPL}" "Ed25519 implementation"
${EDIMPL_OPTIONS}
ref10
amd64-64-24k
amd64-64-24k-pic
)
ENUM(HASH "${HASH}" "SHA implementation"
sha2_openssl
Expand All @@ -63,9 +61,10 @@ ENUM(BUILD "${BUILD}" "library build type"
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/lib)
add_subdirectory(lib)
add_subdirectory(benchmark)


set(SOVERSION "1.0.0")
set(SOVERSION "1.1.0")
set(LIBED25519_VERSION "${SOVERSION}-${EDIMPL}-${HASH}-${RANDOM}")


Expand All @@ -89,7 +88,7 @@ set_target_properties(ed25519 PROPERTIES
FRAMEWORK TRUE
FRAMEWORK_VERSION C
MACOSX_FRAMETWORK_IDENTIFIER warchant.ed25519
VERSION ${LIBED25519_VERSION}
VERSION ${SOVERSION}
SOVERSION ${SOVERSION}
PUBLIC_HEADER include/ed25519.h
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "warchant"
Expand All @@ -100,3 +99,8 @@ if(TESTING)
enable_testing()
add_subdirectory(test)
endif()

set_target_properties(${EDIMPL} PROPERTIES EXCLUDE_FROM_ALL FALSE)
set_target_properties(${HASH} PROPERTIES EXCLUDE_FROM_ALL FALSE)
set_target_properties(${RANDOM} PROPERTIES EXCLUDE_FROM_ALL FALSE)

21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,25 @@ This repository offers at least two different C implementations for every module
Every implementation is tested and can be replaced with other at link-time.
New implementations can be added as well.

During cmake time, users are able to choose any of these implementations using cmake definitions:
During CMake time, users are able to choose any of these implementations using cmake definitions:

- `EDIMPL`
- `ref10` - portable C implementation.
- `amd64-64-24k` - optimized C and ASM implementation, works only on Linux amd64. *Disabled by default*. To enable, use switch `-DAMD64_OPTIMIZED=ON`.
- `amd64-64-24k` - optimized C and ASM implementation, works only on Linux amd64.
- `amd64-64-24k-pic` - same as `amd64-64-24k`, but has fixes in ASM files, to allow *process independent code* (`-fPIC`) builds.
- `HASH`
- `sha2_openssl` - enabled only if OpenSSL is found
- `sha2_openssl`
- `sha3_brainhub` - default
- `RANDOM`
- `rand_openssl` - enabled only if OpenSSL is found
- `rand_openssl`
- `dev_urandom` - default
- `dev_random`
- `BUILD`
- `STATIC`
- `SHARED` - build ed25519 library as shared library (default)

**Example**:
We want to build shared library with amd64 implementation, SHA3 and PRNG, which reads entropy from `/dev/urandom`:
We want to build shared library with fast amd64 implementation, SHA3 and PRNG, which reads entropy from `/dev/urandom`:

```bash
$ cmake .. -DAMD64_OPTIMIZED=ON -DEDIMPL=amd64-64-24k -DHASH=sha3_brainhub -DRANDOM=dev_urandom -DBUILD=SHARED
Expand All @@ -48,10 +49,12 @@ $ cmake .. -DAMD64_OPTIMIZED=ON -DEDIMPL=amd64-64-24k -DHASH=sha3_brainhub -DRAN
-- Build files have been written to: ...
```

**Note**: only those targets (including tests) will be built, which are specified in `EDIMPL`, `HASH`, `RANDOM` variables.

# API

- API for Ed25519 is defined at [ed25519.h](./include/ed25519/ed25519.h)
- API for Hash is defined at [sha512.h](./include/ed25519/sha512.h)
- API for SHA512 is defined at [sha512.h](./include/ed25519/sha512.h)
- API for RNG is defined at [randombytes.h](./include/ed25519/randombytes.h)

# Modules
Expand All @@ -65,7 +68,7 @@ Its API was redesigned to separate signature data from the *signed message* cont

### `amd64-64-24k`

Fast but non-portable C and ASM implementation, only for AMD64. To enable it, use switch `-DAMD64_OPTIMIZED=ON`
Fast but non-portable C and ASM implementation, only for AMD64.
Copied from [supercop-20171020](http://bench.cr.yp.to/supercop.html).
Its API was redesigned to separate signature data from the *signed message* content.

Expand All @@ -91,4 +94,6 @@ This repository offers 3 implementations:

# Authors

[warchant](https://github.com/warchant)
[@warchant](https://github.com/warchant) - maintainer.

[@l4l](https://github.com/l4l) - added `amd64-64-24k-pic`.
13 changes: 6 additions & 7 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ macro(bench name)
add_executable(benchmark-${name} benchmark.cpp)
target_link_libraries(benchmark-${name}
${name}
${ARGN}
benchmark
)
endmacro()

bench(ref)
bench(ref10)
bench(orlp-ed25519)
bench(
${EDIMPL}
${HASH}
${RANDOM}
)

if(AMD64)
bench(amd64-51-30k)
bench(amd64-64-24k)
endif()

60 changes: 37 additions & 23 deletions benchmark/benchmark.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <benchmark/benchmark.h>

#include "facade_helper.hpp"
#include "sha512.h"
#include "ed25519.h"

std::string random_str(size_t size) {
unsigned int SEED = 1337;
Expand All @@ -13,22 +12,22 @@ std::string random_str(size_t size) {
return s;
}

static void SignMsg(benchmark::State &state) {
static void Sign(benchmark::State &state) {
std::string msg;
private_key_t priv;
public_key_t pub;
signature_t sig;
private_key_t priv{};
public_key_t pub{};
signature_t sig{};

// use the same keypair for all signing operations
ed25519_create_keypair(pub, priv);
ed25519_create_keypair(&priv, &pub);

for (auto _ : state) {
state.PauseTiming();
msg = random_str(state.range(0));
state.ResumeTiming();

ed25519_sign(sig, reinterpret_cast<const unsigned char *>(msg.data()),
msg.size(), pub, priv);
ed25519_sign(&sig, reinterpret_cast<const unsigned char *>(msg.data()),
msg.size(), &pub, &priv);
}
}

Expand All @@ -39,13 +38,13 @@ static void VerifyCorrectSig(benchmark::State &state) {
signature_t sig;

// use the same keypair for all signing operations
ed25519_create_keypair(pub, priv);
ed25519_sign(sig, reinterpret_cast<const unsigned char *>(msg.data()),
msg.size(), pub, priv);
ed25519_create_keypair(&priv, &pub);
ed25519_sign(&sig, reinterpret_cast<const unsigned char *>(msg.data()),
msg.size(), &pub, &priv);

for (auto _ : state) {
ed25519_verify(sig, reinterpret_cast<const unsigned char *>(msg.data()),
msg.size(), pub);
ed25519_verify(&sig, reinterpret_cast<const unsigned char *>(msg.data()),
msg.size(), &pub);
}
}

Expand All @@ -56,16 +55,16 @@ static void VerifyIncorrectSig(benchmark::State &state) {
signature_t sig;

// use the same keypair for all signing operations
ed25519_create_keypair(pub, priv);
ed25519_sign(sig, reinterpret_cast<const unsigned char *>(msg.data()),
msg.size(), pub, priv);
ed25519_create_keypair(&priv, &pub);
ed25519_sign(&sig, reinterpret_cast<const unsigned char *>(msg.data()),
msg.size(), &pub, &priv);
// intentionally break the signature
sig[0] = 0;
sig[1] = 1;
sig.data[0] = 0;
sig.data[1] = 1;

for (auto _ : state) {
ed25519_verify(sig, reinterpret_cast<const unsigned char *>(msg.data()),
msg.size(), pub);
ed25519_verify(&sig, reinterpret_cast<const unsigned char *>(msg.data()),
msg.size(), &pub);
}
}

Expand All @@ -74,11 +73,26 @@ static void GenerateKeypair(benchmark::State &state) {
public_key_t pub;

for (auto _ : state) {
ed25519_create_keypair(pub, priv);
ed25519_create_keypair(&priv, &pub);
}
}

static void SHA512(benchmark::State &state) {
unsigned char hash[SHA_512_SIZE];
std::string msg;

for (auto _ : state) {
state.PauseTiming();
msg = random_str(state.range(0));
state.ResumeTiming();

sha512(hash, reinterpret_cast<const unsigned char *>(msg.data()),
msg.size());
}
}

BENCHMARK(SignMsg)->RangeMultiplier(10)->Range(1, 1000000);
BENCHMARK(Sign)->RangeMultiplier(10)->Range(1, 1000000);
BENCHMARK(SHA512)->RangeMultiplier(10)->Range(1, 1000000);
BENCHMARK(VerifyCorrectSig);
BENCHMARK(VerifyIncorrectSig);
BENCHMARK(GenerateKeypair);
Expand Down
1 change: 0 additions & 1 deletion cmake/dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ set_directory_properties(PROPERTIES

find_package(gtest)
find_package(benchmark)

find_package(OpenSSL)
25 changes: 23 additions & 2 deletions cmake/functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,27 @@ function(ENUM variable check description)
endfunction()


function(getplatform out)
message(STATUS ${CMAKE_SYSTEM_PROCESSOR})

macro(find_substring string substring out)
string(FIND ${string} ${substring} RESULT)
if(${RESULT} EQUAL -1)
set(${out} FALSE)
else()
set(${out} TRUE)
endif()
endmacro()


function(gethash target out)
string(TOUPPER ${target} HASHUPPER)
find_substring(${HASHUPPER} "SHA2" ISSHA2)
find_substring(${HASHUPPER} "SHA3" ISSHA3)

if(ISSHA2)
set(${out} "SHA2" PARENT_SCOPE)
elseif(ISSHA3)
set(${out} "SHA3" PARENT_SCOPE)
else()
message(FATAL_ERROR "${target} does not contain sha2/sha3 in name. Can't determine test set.")
endif()
endfunction()
Loading

0 comments on commit 7453906

Please sign in to comment.