-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
196 changed files
with
46,271 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
Language: Cpp | ||
BasedOnStyle: Google | ||
BinPackParameters: true | ||
ExperimentalAutoDetectBinPacking: true | ||
AllowAllParametersOfDeclarationOnNextLine: false | ||
AllowShortCaseLabelsOnASingleLine: true | ||
AlignConsecutiveAssignments: true | ||
AlignOperands: true | ||
... | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
codecov: | ||
branch: default | ||
coverage: | ||
precision: 2 | ||
round: down | ||
range: 50...100 | ||
status: | ||
patch: | ||
default: | ||
target: 50 | ||
project: | ||
default: | ||
target: auto | ||
threshold: 0.05 | ||
tests: | ||
target: auto | ||
paths: "test/" | ||
changes: | ||
default: | ||
enabled: no | ||
parsers: | ||
gcovr: | ||
branch_detection: | ||
conditional: yes | ||
loop: yes | ||
method: no | ||
macro: no | ||
comment: | ||
layout: "reach, diff, flags, files, footer" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,3 +50,8 @@ modules.order | |
Module.symvers | ||
Mkfile.old | ||
dkms.conf | ||
|
||
cmake-build* | ||
.idea | ||
build | ||
.scannerwork |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
|
||
sudo: true | ||
|
||
language: cpp | ||
cache: | ||
apt: true | ||
|
||
matrix: | ||
include: | ||
- os: linux | ||
dist: trusty | ||
compiler: gcc | ||
addons: | ||
apt: | ||
sources: ['ubuntu-toolchain-r-test'] | ||
packages: ['gcc-5', 'g++-5'] | ||
sonarcloud: | ||
organization: | ||
env: | ||
- COMPILERCC=gcc-5 | ||
- COMPILERCXX=g++-5 | ||
|
||
- os: linux | ||
dist: trusty | ||
compiler: clang | ||
addons: | ||
apt: | ||
sources: ['llvm-toolchain-trusty-4.0'] | ||
packages: ['clang-4.0'] | ||
env: | ||
- COMPILERCC=clang-4.0 | ||
- COMPILERCXX=clang++-4.0 | ||
|
||
|
||
- os: osx | ||
compiler: gcc | ||
env: | ||
- COMPILERCC=gcc | ||
- COMPILERCXX=g++ | ||
|
||
- os: osx | ||
compiler: clang | ||
env: | ||
- COMPILERCC=clang | ||
- 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 .. | ||
- make | ||
- ctest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
cmake_minimum_required(VERSION 3.0) | ||
project(ed25519 C CXX) | ||
|
||
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_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) | ||
endif() | ||
|
||
include(cmake/dependencies.cmake) | ||
include(cmake/functions.cmake) | ||
|
||
# auto by default | ||
if(NOT EDIMPL) | ||
set(EDIMPL "ref10") | ||
endif() | ||
if(NOT HASH) | ||
set(HASH "sha3_brainhub") | ||
endif() | ||
if(NOT RANDOM) | ||
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() | ||
|
||
ENUM(EDIMPL "${EDIMPL}" "Ed25519 implementation" | ||
${EDIMPL_OPTIONS} | ||
) | ||
ENUM(HASH "${HASH}" "SHA implementation" | ||
sha2_openssl | ||
sha3_brainhub | ||
) | ||
ENUM(RANDOM "${RANDOM}" "RNG implementation" | ||
rand_openssl | ||
dev_random | ||
dev_urandom | ||
) | ||
ENUM(BUILD "${BUILD}" "library build type" | ||
SHARED | ||
STATIC | ||
) | ||
|
||
|
||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) | ||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/lib) | ||
add_subdirectory(lib) | ||
|
||
|
||
set(SOVERSION "1.0.0") | ||
set(LIBED25519_VERSION "${SOVERSION}-${EDIMPL}-${HASH}-${RANDOM}") | ||
|
||
|
||
add_library(ed25519 ${BUILD} | ||
src/ed25519.c | ||
) | ||
target_compile_definitions(ed25519 PUBLIC | ||
-DLIBED25519_VERSION=${LIBED25519_VERSION} | ||
) | ||
target_link_libraries(ed25519 | ||
${EDLIB} | ||
${HASH} | ||
${RANDOM} | ||
) | ||
install(TARGETS ed25519 | ||
LIBRARY DESTINATION lib | ||
ARCHIVE DESTINATION lib/static | ||
CONFIGURATIONS Release | ||
) | ||
set_target_properties(ed25519 PROPERTIES | ||
FRAMEWORK TRUE | ||
FRAMEWORK_VERSION C | ||
MACOSX_FRAMETWORK_IDENTIFIER warchant.ed25519 | ||
VERSION ${LIBED25519_VERSION} | ||
SOVERSION ${SOVERSION} | ||
PUBLIC_HEADER include/ed25519.h | ||
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "warchant" | ||
) | ||
|
||
|
||
if(TESTING) | ||
enable_testing() | ||
add_subdirectory(test) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,94 @@ | ||
# ed25519-sha3 | ||
ed25519 sha3 implementation | ||
[![](https://travis-ci.org/Warchant/ed25519.svg?branch=master)](https://travis-ci.org/Warchant/ed25519) | ||
[![codecov](https://codecov.io/gh/Warchant/ed25519/branch/master/graph/badge.svg)](https://codecov.io/gh/Warchant/ed25519) | ||
|
||
# Ed25519 digital signature algorithm | ||
|
||
|
||
Ed25519 digital signature algorithm is described in [RFC8032](https://tools.ietf.org/html/rfc8032). | ||
This repository aims to provide modularized implementation of this algorithm. | ||
|
||
Originally Ed25519 consists of three *modules*: | ||
- algorithm itself | ||
- SHA512 hash function | ||
- random number generator, to generate keypairs | ||
|
||
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: | ||
|
||
- `EDIMPL` | ||
- `ref10` - portable C implementation. | ||
- `amd64-64-24k` - optimized C++ ASM implementation, works only on Linux amd64. *Disabled by default*. To enable, use switch `-DAMD64_OPTIMIZED=ON`. | ||
- `HASH` | ||
- `sha2_openssl` - enabled only if OpenSSL is found | ||
- `sha3_brainhub` - default | ||
- `RANDOM` | ||
- `rand_openssl` - enabled only if OpenSSL is found | ||
- `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`: | ||
|
||
```bash | ||
$ cmake .. -DAMD64_OPTIMIZED=ON -DEDIMPL=amd64-64-24k -DHASH=sha3_brainhub -DRANDOM=dev_urandom -DBUILD=SHARED | ||
-- Target cppcheck enabled | ||
-- Target gcovr enabled | ||
-- EDIMPL=amd64-64-24k is selected (Ed25519 implementation) | ||
-- HASH=sha3_brainhub is selected (SHA implementation) | ||
-- RANDOM=dev_urandom is selected (RNG implementation) | ||
-- BUILD=SHARED is selected (library build type) | ||
-- Configuring done | ||
-- Generating done | ||
-- Build files have been written to: ... | ||
``` | ||
|
||
# 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 RNG is defined at [randombytes.h](./include/ed25519/randombytes.h) | ||
|
||
# Modules | ||
|
||
## ed25519 digital signature algorithm | ||
|
||
### `ref10` | ||
|
||
Portable but relatively slow C implementation, originally copied from SUPERCOP. | ||
Its API was redesigned to separate signature data from the *signed message* content. | ||
|
||
### `amd64-64-24k` | ||
|
||
Fast but non-portable C++ASM implementation, only for AMD64. To enable it, use switch `-DAMD64_OPTIMIZED=ON` | ||
Copied from SUPERCOP. | ||
Its API was redesigned to separate signature data from the *signed message* content. | ||
|
||
## SHA512 has function as a dependency of ed25519 | ||
|
||
### `sha2_openssl` | ||
|
||
Implementation of FIPS 180-4 SHA2 512 hash function, which uses openssl underneath. | ||
|
||
### `sha3_brainhub` | ||
|
||
Implementation of FIPS 202 SHA3 512 hash function taken from [brainhub repository](https://github.com/brainhub/SHA3IUF). | ||
Repository consisted of a single C file, which was adopted to be included in a project as a module. | ||
|
||
## PRNG implementation as a dependency of ed25519 | ||
|
||
To generate keypair ed25519 needs a source of randomness (entropy). | ||
|
||
This repository offers 3 implementations: | ||
- `rand_openssl` uses RAND_bytes from openssl | ||
- `dev_urandom` reads entropy from `/dev/urandom` | ||
- `dev_random` reads entropy from `/dev/random` (blocking call, uses busy waiting when user asks for more entropy than device can offer) | ||
|
||
# Authors | ||
|
||
[warchant](https://github.com/warchant) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
project(supercop_benchmark CXX) | ||
|
||
SET(CMAKE_CXX_FLAGS "-std=c++14 -Wall") | ||
SET(CMAKE_CXX_FLAGS_RELEASE "-funroll-loops -O3 -fomit-frame-pointer") | ||
SET(CMAKE_CXX_FLAGS_DEBUG "-g -Wextra -O0 -fdiagnostics-color") | ||
|
||
|
||
macro(bench name) | ||
add_executable(benchmark-${name} benchmark.cpp) | ||
target_link_libraries(benchmark-${name} | ||
${name} | ||
benchmark | ||
) | ||
endmacro() | ||
|
||
bench(ref) | ||
bench(ref10) | ||
bench(orlp-ed25519) | ||
|
||
if(AMD64) | ||
bench(amd64-51-30k) | ||
bench(amd64-64-24k) | ||
endif() | ||
|
Oops, something went wrong.