Skip to content

Translated into C# 10, added CMake support, a build script and various fixes. #28

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

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
5b3cec4
* Moved header files into dedicated include directory.
GlitchedPolygons Oct 8, 2020
3bbe738
Added CHANGELOG.
GlitchedPolygons Oct 8, 2020
3bafc2c
Prepared C# wrapper class.
GlitchedPolygons Oct 8, 2020
6431a27
Implemented function mappings and delegates inside C# wrapper class.
GlitchedPolygons Oct 8, 2020
a89df47
Finished implementing C# wrapper.
GlitchedPolygons Oct 9, 2020
11ccdd0
Added key conversion function ref10->orlp-ed25519.
GlitchedPolygons Oct 9, 2020
b9ead7d
Moved header files from dedicated include dir back into src/ (nevermi…
GlitchedPolygons Oct 9, 2020
542cc05
Added lib/ to C# wrapper project dir containing built shared librarie…
GlitchedPolygons Oct 9, 2020
b1b023e
Improved C# wrapper class.
GlitchedPolygons Oct 9, 2020
fafd567
Updated CHANGELOG and added csharp/README.md
GlitchedPolygons Oct 9, 2020
d6bf0c5
Only read 32 bytes from /dev/urandom for a seed.
GlitchedPolygons Oct 9, 2020
8f7ef72
Updated CMakeLists.txt for release 1.0.1
GlitchedPolygons Oct 9, 2020
295f052
modified: CHANGELOG
GlitchedPolygons Oct 9, 2020
b3949be
Updated csharp/lib/x64/linux/liborlp-ed25519.so
GlitchedPolygons Oct 9, 2020
8b91ec7
Updated mac dylib inside csharp/lib/
GlitchedPolygons Oct 9, 2020
6e9c2dc
Updated CHANGELOG.
GlitchedPolygons Oct 9, 2020
af73058
Improved lib path loader.
GlitchedPolygons Oct 30, 2020
b64c78a
Created ed25519_create_keypair_ref10 and ed25519_sign_ref10 functions…
GlitchedPolygons Jan 15, 2021
edaf364
Improved ref10 keypair generation function's readability.
GlitchedPolygons Jan 15, 2021
8d8e996
- Added .appveyor.yml
GlitchedPolygons Jan 16, 2022
d2c0da5
Modified .appveyor.yml
GlitchedPolygons Jan 16, 2022
9ae4d95
Modified .appveyor.yml
GlitchedPolygons Jan 16, 2022
4e99ed7
Updated CHANGELOG
GlitchedPolygons Jan 19, 2022
7c2d386
Added managed C# 10 translation to 'csharp/' subfolder and uploaded a…
GlitchedPolygons Feb 1, 2022
97e1bf6
Removed redundant namespace inside the managed C# lib.
GlitchedPolygons Feb 1, 2022
f6b6392
Create .gitattributes
GlitchedPolygons Feb 2, 2022
c3c35a5
Added KeyExchangeRef10 method for convenience and made NuGet package …
GlitchedPolygons Jun 27, 2022
2f061a0
Use CryptographicOperations.ZeroMemory to clear private key inside ma…
GlitchedPolygons Jun 28, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
version: 1.0.{build}
image:
- Ubuntu2004
- macos-mojave
- macos
for:
-
matrix:
only:
- image: Ubuntu2004
install:
- sh: git submodule update --init --recursive
- sh: export CC=clang
- sh: export CXX=clang++
before_build:
- sh: bash -eo pipefail test.sh
build_script:
- sh: sudo rm -rf build
- sh: bash -eo pipefail build.sh
artifacts:
- path: 'build\*.tar.gz'
-
matrix:
only:
- image: macos-mojave
install:
- sh: git submodule update --init --recursive
- sh: export CC=clang
- sh: export CXX=clang++
before_build:
- sh: bash -eo pipefail test.sh
build_script:
- sh: sudo rm -rf build
- sh: bash -eo pipefail build.sh
artifacts:
- path: 'build\*.tar.gz'
-
matrix:
only:
- image: macos
install:
- sh: git submodule update --init --recursive
- sh: export CC=clang
- sh: export CXX=clang++
before_build:
- sh: bash -eo pipefail test.sh
build_script:
- sh: sudo rm -rf build
- sh: bash -eo pipefail build.sh
artifacts:
- path: 'build\*.tar.gz'
83 changes: 83 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Copyright (C) 2016 Olivier Goffart <[email protected]>
#
# You may use this file under the terms of the 3-clause BSD license.
# See the file LICENSE from this package for details.

# This is the clang-format configuration style to be used by Qt,
# based on the rules from https://wiki.qt.io/Qt_Coding_Style and
# https://wiki.qt.io/Coding_Conventions

---
# Webkit style was loosely based on the Qt style
BasedOnStyle: WebKit

Standard: Cpp11

ColumnLimit: 500

# How much weight do extra characters after the line length limit have.
# PenaltyExcessCharacter: 4

# Disable reflow of qdoc comments: indentation rules are different.
# Translation comments are also excluded.
CommentPragmas: "^!|^:"

# We use template< without space.
SpaceAfterTemplateKeyword: false

# We want to break before the operators, but not before a '='.
BreakBeforeBinaryOperators: NonAssignment

# Braces are usually attached, but not after functions or class declarations.
BreakBeforeBraces: Custom
BraceWrapping:
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: true
AfterUnion: true
BeforeCatch: true
BeforeElse: true
IndentBraces: false

# When constructor initializers do not fit on one line, put them each on a new line.
ConstructorInitializerAllOnOneLineOrOnePerLine: true
# Indent initializers by 4 spaces
ConstructorInitializerIndentWidth: 4

# Indent width for line continuations.
ContinuationIndentWidth: 8

# No indentation for namespaces.
NamespaceIndentation: None

# Horizontally align arguments after an open bracket.
# The coding style does not specify the following, but this is what gives
# results closest to the existing code.
AlignAfterOpenBracket: DontAlign
AlwaysBreakTemplateDeclarations: Yes

# Ideally we should also allow less short function in a single line, but
# clang-format does not handle that.
AllowShortFunctionsOnASingleLine: Inline

# The coding style specifies some include order categories, but also tells to
# separate categories with an empty line. It does not specify the order within
# the categories. Since the SortInclude feature of clang-format does not
# re-order includes separated by empty lines, the feature is not used.
SortIncludes: false

# macros for which the opening brace stays attached.
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH, forever, Q_FOREVER, QBENCHMARK, QBENCHMARK_ONCE ]

# Break constructor initializers before the colon and after the commas.
BreakConstructorInitializers: BeforeColon

IndentCaseLabels: true

# http://www.stroustrup.com/bs_faq2.html#whitespace
PointerAlignment: Left
PointerBindsToType: true
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
**/*.DS_Store
.idea/
*[Bb]uild*
!build.sh
!build.bat
!build-mingw.sh
50 changes: 50 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---

Raphael Beck, the 9th of October, 2020

---

As per the Zlib license used by this project, here are the changes
that I've applied, in order of importance/relevance:

* Added “ORLP_” prefix to declspec macro (to prevent possible collisions with other libraries making use of the same name).
* Added CMakeLists.txt and build.sh for easy packaging and inclusion into other projects.
* Added fix from orlp/ed25519 pull request #15: https://github.com/orlp/ed25519/pull/15
* Added fix from orlp/ed25519 issue #10: https://github.com/orlp/ed25519/issues/10
* Deleted .dll files inside repo.
* Adapted readme.md accordingly.
* Implemented C# wrapper class.
* Added this CHANGELOG file.

---

Raphael Beck, the 19th of January, 2022

---

* Added `.appveyor.yml`
* Added build and test shell scripts (both for Windows and Linux/Mac)
* Added feature flag to `CMakeLists.txt` for preventing potentially unnecessary `NULL`-checks
* Reformatted src code files (using a .clang-format file)
* * Aesthetic reasons only
* Simplified verify function a little bit
* * Rearranged the boolean logic parts to slightly reduce branching

---

Raphael Beck, the 01st of February, 2022

---

* Translated the library into C# 10 managed code
* Created NuGet package out of it and uploaded it to nuget.org:
* * https://www.nuget.org/packages/GlitchEd25519

---

Raphael Beck, the 27th of June, 2022

---

* Build XML documentation file for NuGet package
* Added `KeyExchangeRef10` method for convenience
111 changes: 111 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
cmake_minimum_required(VERSION 3.12)
project(orlp-ed25519 C)

set(CMAKE_C_STANDARD 11)

set(ORLP_ED25519_MAJOR 1)
set(ORLP_ED25519_MINOR 0)
set(ORLP_ED25519_PATCH 2)
set(ORLP_ED25519_VERSION_STRING "${ORLP_ED25519_MAJOR}.${ORLP_ED25519_MINOR}.${ORLP_ED25519_PATCH}")

option(ORLP_ED25519_DLL "Use as a DLL." OFF)
option(ORLP_ED25519_BUILD_DLL "Build as a DLL." OFF)
option(ORLP_ED25519_BUILD_TESTS "Build unit tests." OFF)
option(ORLP_ED25519_PACKAGE "Build the library and package it into a .tar.gz after successfully building." OFF)
option(ORLP_ED25519_NO_NULL_CHECKS "Strip some of the NULL safety checks from hot code paths to minimize branching (this increases necessity of ensuring never to pass NULL into the function arguments)." OFF)

if (${ORLP_ED25519_NO_NULL_CHECKS})
add_compile_definitions("ORLP_ED25519_NO_NULL_CHECKS=1")
endif ()

if (${ORLP_ED25519_BUILD_DLL})
add_compile_definitions("ORLP_ED25519_BUILD_DLL=1")
set(ORLP_ED25519_DLL ON)
endif ()

if (${ORLP_ED25519_DLL})
add_compile_definitions("ORLP_ED25519_DLL=1")
endif ()

if (WIN32)
set(CMAKE_RELEASE_POSTFIX "_v${ORLP_ED25519_MAJOR}")
endif ()

set(ORLP_ED25519_SRC
${CMAKE_CURRENT_LIST_DIR}/src/precomp_data.h
${CMAKE_CURRENT_LIST_DIR}/src/fixedint.h
${CMAKE_CURRENT_LIST_DIR}/src/ed25519.h
${CMAKE_CURRENT_LIST_DIR}/src/sha512.h
${CMAKE_CURRENT_LIST_DIR}/src/ge.h
${CMAKE_CURRENT_LIST_DIR}/src/fe.h
${CMAKE_CURRENT_LIST_DIR}/src/sc.h
${CMAKE_CURRENT_LIST_DIR}/src/ge.c
${CMAKE_CURRENT_LIST_DIR}/src/fe.c
${CMAKE_CURRENT_LIST_DIR}/src/sc.c
${CMAKE_CURRENT_LIST_DIR}/src/seed.c
${CMAKE_CURRENT_LIST_DIR}/src/sha512.c
${CMAKE_CURRENT_LIST_DIR}/src/keypair.c
${CMAKE_CURRENT_LIST_DIR}/src/sign.c
${CMAKE_CURRENT_LIST_DIR}/src/verify.c
${CMAKE_CURRENT_LIST_DIR}/src/add_scalar.c
${CMAKE_CURRENT_LIST_DIR}/src/key_exchange.c
${CMAKE_CURRENT_LIST_DIR}/src/key_convert.c
)

add_library(${PROJECT_NAME} ${ORLP_ED25519_SRC})

if (${ORLP_ED25519_BUILD_TESTS})
add_executable(run_tests ${ORLP_ED25519_SRC} ${CMAKE_CURRENT_LIST_DIR}/test.c)
target_include_directories(run_tests PUBLIC ${CMAKE_CURRENT_LIST_DIR}/src)

if (WIN32)
target_link_libraries(run_tests PUBLIC Advapi32)
endif ()
endif ()

if (${ORLP_ED25519_BUILD_DLL} OR BUILD_SHARED_LIBS)
set_target_properties(${PROJECT_NAME} PROPERTIES
VERSION ${ORLP_ED25519_VERSION_STRING}
SOVERSION ${ORLP_ED25519_MAJOR}
)
endif ()

if (${ORLP_ED25519_PACKAGE})

if (NOT ORLP_ED25519_SYSNAME)
set(ORLP_ED25519_SYSNAME ${CMAKE_SYSTEM_NAME})
endif ()

set_target_properties(${PROJECT_NAME} PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/bin"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/bin"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/bin"

ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/bin/debug"
LIBRARY_OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/bin/debug"
RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/bin/debug"

ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/bin/release"
LIBRARY_OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/bin/release"
RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/bin/release"
)

add_custom_command(TARGET ${PROJECT_NAME}
POST_BUILD COMMAND ${CMAKE_COMMAND}
-E copy ${CMAKE_CURRENT_LIST_DIR}/src/ed25519.h "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/include/orlp-ed25519/ed25519.h"
)

add_custom_command(TARGET ${PROJECT_NAME}
POST_BUILD COMMAND ${CMAKE_COMMAND}
-E copy ${CMAKE_CURRENT_LIST_DIR}/license.txt "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/license.txt"
)

string(TOLOWER "${PROJECT_NAME}-${ORLP_ED25519_VERSION_STRING}-${ORLP_ED25519_SYSNAME}-${CMAKE_HOST_SYSTEM_PROCESSOR}.tar.gz" ${PROJECT_NAME}_OUTPUT_ARCHIVE_FILENAME)

add_custom_command(TARGET ${PROJECT_NAME}
POST_BUILD COMMAND ${CMAKE_COMMAND}
-E tar "czvf" ${${PROJECT_NAME}_OUTPUT_ARCHIVE_FILENAME} ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}
)
endif ()

target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_LIST_DIR}/src)
22 changes: 22 additions & 0 deletions build-mingw.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

if [ "$(whoami)" = "root" ]; then
echo " Please don't run as root/using sudo..."
exit
fi

REPO=$(dirname "$0")
rm -rf "$REPO"/out
rm -rf "$REPO"/build-mingw
mkdir -p "$REPO"/build-mingw/include && cd "$REPO"/build-mingw || exit

cmake -G "MinGW Makefiles" -DBUILD_SHARED_LIBS=On -DORLP_ED25519_SYSNAME="mingw-w64" -DORLP_ED25519_BUILD_DLL=On -DORLP_ED25519_PACKAGE=On -DCMAKE_BUILD_TYPE=Release ..

mingw32-make.exe

cp -r ../include .

cd "$REPO" || exit

echo " Done. Exported build into $REPO/build-mingw"

12 changes: 12 additions & 0 deletions build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
SET i=%CD%
SET repo=%~dp0
SET out="%repo%\build"

if exist %out% ( rd /s /q %out% )
mkdir %out% && cd %out%

cmake -DBUILD_SHARED_LIBS=On -DORLP_ED25519_BUILD_DLL=On -DORLP_ED25519_PACKAGE=On -DCMAKE_BUILD_TYPE=Release ..

cmake --build . --config Release

cd %i%
32 changes: 32 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

if [ "$(whoami)" = "root" ]; then
echo " Please don't run as root/using sudo..."
exit
fi

PREVCC="$CC"
PREVCXX="$CXX"

if command -v clang &> /dev/null
then
echo "-- Clang found on system, great! Long live LLVM! :D"
export CC=clang
export CXX=clang++
fi

REPO=$(dirname "$0")
rm -rf "$REPO"/out
rm -rf "$REPO"/build
mkdir -p "$REPO"/build/include && cd "$REPO"/build || exit

cmake -DBUILD_SHARED_LIBS=On -DORLP_ED25519_BUILD_DLL=On -DORLP_ED25519_PACKAGE=On -DCMAKE_BUILD_TYPE=Release ..

cmake --build . --config Release

export CC="$PREVCC"
export CXX="$PREVCXX"

cd "$REPO" || exit

echo " Done. Exported build into $REPO/build"
1 change: 1 addition & 0 deletions csharp/managed/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.cs linguist-language=C#
Loading