Skip to content

Commit 7453906

Browse files
committed
v1.1.0
- remove docker - fixes in cmake, docs, travis - add amd64-64-24k-pic - add benchmark
1 parent 71333e2 commit 7453906

File tree

98 files changed

+37618
-838
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+37618
-838
lines changed

.travis.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ matrix:
1414
apt:
1515
sources: ['ubuntu-toolchain-r-test']
1616
packages: ['gcc-5', 'g++-5']
17-
sonarcloud:
18-
organization:
1917
env:
2018
- COMPILERCC=gcc-5
2119
- COMPILERCXX=g++-5
@@ -45,14 +43,10 @@ matrix:
4543
- COMPILERCXX=clang++
4644

4745

48-
install:
49-
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; brew install openssl; fi
50-
51-
5246
script:
5347
- mkdir build
5448
- cd build
5549
- export CC=$COMPILERCC; export CXX=$COMPILERCXX
56-
- cmake ..
50+
- cmake .. -DEDIMPL=ref10 -DHASH=sha3_brainhub -DRANDOM=dev_urandom
5751
- make
5852
- ctest

CMakeLists.txt

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@ SET(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
55
SET(CMAKE_CXX_FLAGS "-std=c++14 -Wall")
66
SET(CMAKE_CXX_FLAGS_RELEASE "-O3")
77
SET(CMAKE_CXX_FLAGS_DEBUG "-g -Wextra -O0 -fdiagnostics-color")
8-
SET(CMAKE_C_FLAGS "-Wall -funroll-loops")
9-
SET(CMAKE_C_FLAGS_RELEASE "-O3")
10-
SET(CMAKE_C_FLAGS_DEBUG "-g -Wextra -O0 -fdiagnostics-color")
8+
SET(CMAKE_C_FLAGS "-Wall")
9+
SET(CMAKE_C_FLAGS_RELEASE "-O3 -funroll-loops -fomit-frame-pointer")
10+
SET(CMAKE_C_FLAGS_DEBUG "-g -Wextra -O0 -fdiagnostics-color ")
1111
SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules)
1212
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
1313
SET(CMAKE_EXPORT_COMPILE_COMMANDS "ON")
1414

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

1918
if(COVERAGE)
2019
include(cmake/coverage.cmake)
@@ -23,27 +22,26 @@ endif()
2322
include(cmake/dependencies.cmake)
2423
include(cmake/functions.cmake)
2524

26-
# auto by default
25+
## DEFAULTS
2726
if(NOT EDIMPL)
2827
set(EDIMPL "ref10")
2928
endif()
3029
if(NOT HASH)
3130
set(HASH "sha3_brainhub")
3231
endif()
3332
if(NOT RANDOM)
33+
# https://sockpuppet.org/blog/2014/02/25/safely-generate-random-numbers/
3434
set(RANDOM "dev_urandom")
3535
endif()
3636
if(NOT BUILD)
3737
set(BUILD "SHARED")
3838
endif()
3939

40-
set(EDIMPL_OPTIONS ref10)
41-
if(AMD64_OPTIMIZED)
42-
list(APPEND EDIMPL_OPTIONS amd64-64-24k)
43-
endif()
44-
40+
## OPTIONS
4541
ENUM(EDIMPL "${EDIMPL}" "Ed25519 implementation"
46-
${EDIMPL_OPTIONS}
42+
ref10
43+
amd64-64-24k
44+
amd64-64-24k-pic
4745
)
4846
ENUM(HASH "${HASH}" "SHA implementation"
4947
sha2_openssl
@@ -63,9 +61,10 @@ ENUM(BUILD "${BUILD}" "library build type"
6361
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
6462
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/lib)
6563
add_subdirectory(lib)
64+
add_subdirectory(benchmark)
6665

6766

68-
set(SOVERSION "1.0.0")
67+
set(SOVERSION "1.1.0")
6968
set(LIBED25519_VERSION "${SOVERSION}-${EDIMPL}-${HASH}-${RANDOM}")
7069

7170

@@ -89,7 +88,7 @@ set_target_properties(ed25519 PROPERTIES
8988
FRAMEWORK TRUE
9089
FRAMEWORK_VERSION C
9190
MACOSX_FRAMETWORK_IDENTIFIER warchant.ed25519
92-
VERSION ${LIBED25519_VERSION}
91+
VERSION ${SOVERSION}
9392
SOVERSION ${SOVERSION}
9493
PUBLIC_HEADER include/ed25519.h
9594
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "warchant"
@@ -100,3 +99,8 @@ if(TESTING)
10099
enable_testing()
101100
add_subdirectory(test)
102101
endif()
102+
103+
set_target_properties(${EDIMPL} PROPERTIES EXCLUDE_FROM_ALL FALSE)
104+
set_target_properties(${HASH} PROPERTIES EXCLUDE_FROM_ALL FALSE)
105+
set_target_properties(${RANDOM} PROPERTIES EXCLUDE_FROM_ALL FALSE)
106+

README.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,25 @@ This repository offers at least two different C implementations for every module
1616
Every implementation is tested and can be replaced with other at link-time.
1717
New implementations can be added as well.
1818

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

2121
- `EDIMPL`
2222
- `ref10` - portable C implementation.
23-
- `amd64-64-24k` - optimized C and ASM implementation, works only on Linux amd64. *Disabled by default*. To enable, use switch `-DAMD64_OPTIMIZED=ON`.
23+
- `amd64-64-24k` - optimized C and ASM implementation, works only on Linux amd64.
24+
- `amd64-64-24k-pic` - same as `amd64-64-24k`, but has fixes in ASM files, to allow *process independent code* (`-fPIC`) builds.
2425
- `HASH`
25-
- `sha2_openssl` - enabled only if OpenSSL is found
26+
- `sha2_openssl`
2627
- `sha3_brainhub` - default
2728
- `RANDOM`
28-
- `rand_openssl` - enabled only if OpenSSL is found
29+
- `rand_openssl`
2930
- `dev_urandom` - default
3031
- `dev_random`
3132
- `BUILD`
3233
- `STATIC`
3334
- `SHARED` - build ed25519 library as shared library (default)
3435

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

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

52+
**Note**: only those targets (including tests) will be built, which are specified in `EDIMPL`, `HASH`, `RANDOM` variables.
53+
5154
# API
5255

5356
- API for Ed25519 is defined at [ed25519.h](./include/ed25519/ed25519.h)
54-
- API for Hash is defined at [sha512.h](./include/ed25519/sha512.h)
57+
- API for SHA512 is defined at [sha512.h](./include/ed25519/sha512.h)
5558
- API for RNG is defined at [randombytes.h](./include/ed25519/randombytes.h)
5659

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

6669
### `amd64-64-24k`
6770

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

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

9295
# Authors
9396

94-
[warchant](https://github.com/warchant)
97+
[@warchant](https://github.com/warchant) - maintainer.
98+
99+
[@l4l](https://github.com/l4l) - added `amd64-64-24k-pic`.

benchmark/CMakeLists.txt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@ macro(bench name)
99
add_executable(benchmark-${name} benchmark.cpp)
1010
target_link_libraries(benchmark-${name}
1111
${name}
12+
${ARGN}
1213
benchmark
1314
)
1415
endmacro()
1516

16-
bench(ref)
17-
bench(ref10)
18-
bench(orlp-ed25519)
17+
bench(
18+
${EDIMPL}
19+
${HASH}
20+
${RANDOM}
21+
)
1922

20-
if(AMD64)
21-
bench(amd64-51-30k)
22-
bench(amd64-64-24k)
23-
endif()
2423

benchmark/benchmark.cpp

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include <benchmark/benchmark.h>
22

3-
#include "facade_helper.hpp"
4-
#include "sha512.h"
3+
#include "ed25519.h"
54

65
std::string random_str(size_t size) {
76
unsigned int SEED = 1337;
@@ -13,22 +12,22 @@ std::string random_str(size_t size) {
1312
return s;
1413
}
1514

16-
static void SignMsg(benchmark::State &state) {
15+
static void Sign(benchmark::State &state) {
1716
std::string msg;
18-
private_key_t priv;
19-
public_key_t pub;
20-
signature_t sig;
17+
private_key_t priv{};
18+
public_key_t pub{};
19+
signature_t sig{};
2120

2221
// use the same keypair for all signing operations
23-
ed25519_create_keypair(pub, priv);
22+
ed25519_create_keypair(&priv, &pub);
2423

2524
for (auto _ : state) {
2625
state.PauseTiming();
2726
msg = random_str(state.range(0));
2827
state.ResumeTiming();
2928

30-
ed25519_sign(sig, reinterpret_cast<const unsigned char *>(msg.data()),
31-
msg.size(), pub, priv);
29+
ed25519_sign(&sig, reinterpret_cast<const unsigned char *>(msg.data()),
30+
msg.size(), &pub, &priv);
3231
}
3332
}
3433

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

4140
// use the same keypair for all signing operations
42-
ed25519_create_keypair(pub, priv);
43-
ed25519_sign(sig, reinterpret_cast<const unsigned char *>(msg.data()),
44-
msg.size(), pub, priv);
41+
ed25519_create_keypair(&priv, &pub);
42+
ed25519_sign(&sig, reinterpret_cast<const unsigned char *>(msg.data()),
43+
msg.size(), &pub, &priv);
4544

4645
for (auto _ : state) {
47-
ed25519_verify(sig, reinterpret_cast<const unsigned char *>(msg.data()),
48-
msg.size(), pub);
46+
ed25519_verify(&sig, reinterpret_cast<const unsigned char *>(msg.data()),
47+
msg.size(), &pub);
4948
}
5049
}
5150

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

5857
// use the same keypair for all signing operations
59-
ed25519_create_keypair(pub, priv);
60-
ed25519_sign(sig, reinterpret_cast<const unsigned char *>(msg.data()),
61-
msg.size(), pub, priv);
58+
ed25519_create_keypair(&priv, &pub);
59+
ed25519_sign(&sig, reinterpret_cast<const unsigned char *>(msg.data()),
60+
msg.size(), &pub, &priv);
6261
// intentionally break the signature
63-
sig[0] = 0;
64-
sig[1] = 1;
62+
sig.data[0] = 0;
63+
sig.data[1] = 1;
6564

6665
for (auto _ : state) {
67-
ed25519_verify(sig, reinterpret_cast<const unsigned char *>(msg.data()),
68-
msg.size(), pub);
66+
ed25519_verify(&sig, reinterpret_cast<const unsigned char *>(msg.data()),
67+
msg.size(), &pub);
6968
}
7069
}
7170

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

7675
for (auto _ : state) {
77-
ed25519_create_keypair(pub, priv);
76+
ed25519_create_keypair(&priv, &pub);
77+
}
78+
}
79+
80+
static void SHA512(benchmark::State &state) {
81+
unsigned char hash[SHA_512_SIZE];
82+
std::string msg;
83+
84+
for (auto _ : state) {
85+
state.PauseTiming();
86+
msg = random_str(state.range(0));
87+
state.ResumeTiming();
88+
89+
sha512(hash, reinterpret_cast<const unsigned char *>(msg.data()),
90+
msg.size());
7891
}
7992
}
8093

81-
BENCHMARK(SignMsg)->RangeMultiplier(10)->Range(1, 1000000);
94+
BENCHMARK(Sign)->RangeMultiplier(10)->Range(1, 1000000);
95+
BENCHMARK(SHA512)->RangeMultiplier(10)->Range(1, 1000000);
8296
BENCHMARK(VerifyCorrectSig);
8397
BENCHMARK(VerifyIncorrectSig);
8498
BENCHMARK(GenerateKeypair);

cmake/dependencies.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,4 @@ set_directory_properties(PROPERTIES
88

99
find_package(gtest)
1010
find_package(benchmark)
11-
1211
find_package(OpenSSL)

cmake/functions.cmake

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,27 @@ function(ENUM variable check description)
6161
endfunction()
6262

6363

64-
function(getplatform out)
65-
message(STATUS ${CMAKE_SYSTEM_PROCESSOR})
64+
65+
macro(find_substring string substring out)
66+
string(FIND ${string} ${substring} RESULT)
67+
if(${RESULT} EQUAL -1)
68+
set(${out} FALSE)
69+
else()
70+
set(${out} TRUE)
71+
endif()
72+
endmacro()
73+
74+
75+
function(gethash target out)
76+
string(TOUPPER ${target} HASHUPPER)
77+
find_substring(${HASHUPPER} "SHA2" ISSHA2)
78+
find_substring(${HASHUPPER} "SHA3" ISSHA3)
79+
80+
if(ISSHA2)
81+
set(${out} "SHA2" PARENT_SCOPE)
82+
elseif(ISSHA3)
83+
set(${out} "SHA3" PARENT_SCOPE)
84+
else()
85+
message(FATAL_ERROR "${target} does not contain sha2/sha3 in name. Can't determine test set.")
86+
endif()
6687
endfunction()

0 commit comments

Comments
 (0)