mirror of
https://github.com/eosswedenorg/libantelope
synced 2026-06-16 19:50:01 +02:00
Compare commits
No commits in common. "master" and "v0.1.7" have entirely different histories.
48 changed files with 319 additions and 1153 deletions
2
.github/workflows/package.yml
vendored
2
.github/workflows/package.yml
vendored
|
|
@ -62,7 +62,7 @@ jobs:
|
||||||
id: package
|
id: package
|
||||||
run: |
|
run: |
|
||||||
cmake --build build --config Release --target package
|
cmake --build build --config Release --target package
|
||||||
$FILE=(ls build/libantelope*.zip)
|
$FILE=(ls build/libeosio*.zip)
|
||||||
echo "::set-output name=filename::$FILE"
|
echo "::set-output name=filename::$FILE"
|
||||||
echo "::set-output name=name::$(([io.fileinfo]"$FILE").basename).zip"
|
echo "::set-output name=name::$(([io.fileinfo]"$FILE").basename).zip"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,10 @@ cmake_minimum_required(VERSION 3.15)
|
||||||
# --------------------------------
|
# --------------------------------
|
||||||
|
|
||||||
# Project name and version
|
# Project name and version
|
||||||
project(libantelope
|
project(libeosio
|
||||||
VERSION 0.2.2
|
VERSION 0.1.7
|
||||||
DESCRIPTION "C++ library for Antelope IO"
|
DESCRIPTION "C++ library for EOSIO"
|
||||||
HOMEPAGE_URL "https://github.com/eosswedenorg/libantelope"
|
HOMEPAGE_URL "https://github.com/eosswedenorg/libeosio"
|
||||||
LANGUAGES C CXX
|
LANGUAGES C CXX
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -34,23 +34,6 @@ set( CMAKE_CXX_STANDARD 11 )
|
||||||
set( CMAKE_CXX_STANDARD_REQUIRED ON )
|
set( CMAKE_CXX_STANDARD_REQUIRED ON )
|
||||||
set( CMAKE_CXX_EXTENSIONS OFF )
|
set( CMAKE_CXX_EXTENSIONS OFF )
|
||||||
|
|
||||||
add_compile_options(
|
|
||||||
"$<$<COMPILE_LANG_AND_ID:CXX,GNU>:-Wall;-Wconversion;-Wno-sign-conversion;-Wextra>"
|
|
||||||
"$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:/W3;-D_CRT_SECURE_NO_WARNINGS=1>"
|
|
||||||
|
|
||||||
# Debug
|
|
||||||
"$<$<CONFIG:Debug>:$<$<COMPILE_LANG_AND_ID:CXX,GNU>:-O0;-g>>"
|
|
||||||
"$<$<CONFIG:Debug>:$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:/Od;/Zi>>"
|
|
||||||
|
|
||||||
# Release
|
|
||||||
"$<$<CONFIG:Release>:$<$<COMPILE_LANG_AND_ID:CXX,GNU>:-O3>>"
|
|
||||||
"$<$<CONFIG:Release>:$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:/O2>>"
|
|
||||||
|
|
||||||
# MinSizeRel
|
|
||||||
"$<$<CONFIG:MinSizeRel>:$<$<COMPILE_LANG_AND_ID:CXX,GNU>:-Os>>"
|
|
||||||
"$<$<CONFIG:MinSizeRel>:$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:/O1>>"
|
|
||||||
)
|
|
||||||
|
|
||||||
# OpenSSL 3.0 deprecates some functions we use.
|
# OpenSSL 3.0 deprecates some functions we use.
|
||||||
# Adding this flag makes the compiler not spam warnings.
|
# Adding this flag makes the compiler not spam warnings.
|
||||||
add_compile_options(-D OPENSSL_API_COMPAT=0x10100000L)
|
add_compile_options(-D OPENSSL_API_COMPAT=0x10100000L)
|
||||||
|
|
@ -79,7 +62,6 @@ add_library( ${LIB_NAME} STATIC
|
||||||
target_include_directories( ${LIB_NAME}
|
target_include_directories( ${LIB_NAME}
|
||||||
PUBLIC
|
PUBLIC
|
||||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
|
||||||
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>
|
|
||||||
$<INSTALL_INTERFACE:include>
|
$<INSTALL_INTERFACE:include>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -92,9 +74,6 @@ endif()
|
||||||
include(OpenSSL)
|
include(OpenSSL)
|
||||||
target_link_libraries( ${LIB_NAME} PRIVATE OpenSSL::Crypto)
|
target_link_libraries( ${LIB_NAME} PRIVATE OpenSSL::Crypto)
|
||||||
|
|
||||||
# Hash implementation
|
|
||||||
set( LIBANTELOPE_HASHIMPL_OPENSSL 1 )
|
|
||||||
|
|
||||||
# EC Implementation
|
# EC Implementation
|
||||||
if (${EC_LIB} STREQUAL "libsecp256k1")
|
if (${EC_LIB} STREQUAL "libsecp256k1")
|
||||||
add_subdirectory( vendor/secp256k1 )
|
add_subdirectory( vendor/secp256k1 )
|
||||||
|
|
@ -128,9 +107,6 @@ endif()
|
||||||
|
|
||||||
message("-- Using Elliptic curve library: ${EC_LIB}")
|
message("-- Using Elliptic curve library: ${EC_LIB}")
|
||||||
|
|
||||||
# Generate config file
|
|
||||||
configure_file(src/config.in.h ${CMAKE_BINARY_DIR}/include/libantelope/config.h)
|
|
||||||
|
|
||||||
# --------------------------------
|
# --------------------------------
|
||||||
# Tests
|
# Tests
|
||||||
# --------------------------------
|
# --------------------------------
|
||||||
|
|
@ -167,7 +143,7 @@ install(TARGETS ${LIB_NAME} EXPORT ${PROJECT_NAME}Targets
|
||||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||||
)
|
)
|
||||||
install(DIRECTORY include/ ${CMAKE_BINARY_DIR}/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
||||||
|
|
||||||
# Readme and license
|
# Readme and license
|
||||||
install(FILES README.md LICENSE LICENSE.bitcoin
|
install(FILES README.md LICENSE LICENSE.bitcoin
|
||||||
|
|
|
||||||
115
README.md
115
README.md
|
|
@ -1,110 +1,133 @@
|
||||||

|

|
||||||
[](https://github.com/eosswedenorg/libantelope/releases/latest)
|
[](https://github.com/eosswedenorg/libeosio/releases/latest)
|
||||||
[](https://opensource.org/licenses/MIT)
|
[](https://opensource.org/licenses/MIT)
|
||||||
|
|
||||||
# libantelope
|
# libeosio
|
||||||
|
|
||||||
libantelope is an independent C++ library designed for Antelope IO (formerly known as libeosio). Please note that this repository is not affiliated with the official Antelope code.
|
Independent C++ library for [EOS](https://eos.io/)
|
||||||
|
|
||||||
|
NOTE: This repository has no connection to the official EOS code.
|
||||||
|
|
||||||
## Compiling the library
|
## Compiling the library
|
||||||
|
|
||||||
To compile this project, you will need the following:
|
You will need `openssl` development files (version 1.1 or later) to compile and `cmake 3.15` or later to compile this project.
|
||||||
|
|
||||||
- `openssl` development files (version 1.1 or later)
|
|
||||||
- `cmake 3.15` or later
|
|
||||||
|
|
||||||
### Elliptic curve backend
|
### Elliptic curve backend
|
||||||
|
|
||||||
The library offers two different backend implementations for the elliptic curve functionality:
|
There is two different backend implementation for the elliptic curve part of the library:
|
||||||
|
|
||||||
- `libsecp256k1`
|
* `OpenSSL` as mentioned before. however you still need to link to openssl even if it is not used as the EC backend
|
||||||
- `OpenSSL`: Although the default is to use `libsecp256k1` for optimization, you still need to link to OpenSSL as other parts of the codebase rely on it.
|
because more of the codebase uses it.
|
||||||
|
|
||||||
To switch the implementation, modify the `EC_LIB` variable in the cmake.
|
* `libsecp256k1`
|
||||||
|
|
||||||
|
Default is to use `libsecp256k1` as it is more optimized.
|
||||||
|
|
||||||
|
You can switch implementation by modifing the cmake variable `EC_LIB`.
|
||||||
|
|
||||||
### CMake
|
### CMake
|
||||||
|
|
||||||
You can install `cmake` by referring to the [official guide](https://cmake.org/install).
|
You can install `cmake` by reading the [official guide](https://cmake.org/install).
|
||||||
|
|
||||||
### Linux
|
### Linux
|
||||||
|
|
||||||
**NOTE:** Only Ubuntu versions `20.04` and `22.04` are officially supported.
|
**NOTE:** Only Ubuntu `20.04` and `22.04` is officially supported.
|
||||||
|
|
||||||
While the project should compile fine on most versions/distros, it is only tested and distributed for Ubuntu `20.04` and `22.04` by [Sw/eden](https://www.eossweden.org).
|
The project should compile fine on most versions/distros but it is only tested
|
||||||
|
and distributed for Ubuntu `20.04` and `22.04` by [Sw/eden](https://www.eossweden.org).
|
||||||
|
|
||||||
#### Dependencies
|
#### Dependencies
|
||||||
|
|
||||||
**Ubuntu (or other Debian-based distros)**
|
**Ubuntu (or other debian based distros)**
|
||||||
|
|
||||||
To install the necessary dependencies (compiler, `openssl`, and `cmake`), use the following `apt` command:
|
First you need to have a compiler, `openssl` and `cmake`. this can be installed with apt.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
apt-get install gcc g++ cmake libssl-dev
|
$ apt-get install gcc g++ cmake libssl-dev
|
||||||
```
|
```
|
||||||
|
If you need a newer version of cmake then apt provides.
|
||||||
If you require a newer version of `cmake`, you can refer to the [official CMake APT repository](https://apt.kitware.com/).
|
Checkout the official [CMake APT repository](https://apt.kitware.com/).
|
||||||
|
|
||||||
**Other**
|
**Other**
|
||||||
|
|
||||||
For other distros, please consult your package manager's manual to install `openssl`, `g++`, and `cmake`. If you need a newer version of `cmake`, you can follow the [official installation guide](https://cmake.org/install).
|
Consult your package manager's manual for getting `openssl`,`g++` and `cmake` installed.
|
||||||
|
|
||||||
|
If you need a newer version of cmake then your package manager provides. checkout the [official guide](https://cmake.org/install).
|
||||||
|
|
||||||
### MacOS
|
### MacOS
|
||||||
|
|
||||||
#### Dependencies
|
#### Dependencies
|
||||||
|
|
||||||
Ensure that you have a compiler installed. This project is known to build with `Xcode 11.0`, but other versions should work as well.
|
You must have a compiler installed. This project is known to build with `Xcode 11.0` but other versions should work.
|
||||||
|
|
||||||
To install `openssl` and `cmake`, you can use the following `brew` command:
|
|
||||||
|
|
||||||
|
You need to have openssl and cmake installed also, this can be done with this `brew` command:
|
||||||
```sh
|
```sh
|
||||||
brew install openssl cmake
|
$ brew install openssl cmake
|
||||||
```
|
```
|
||||||
|
|
||||||
If you require a newer version of `cmake`, refer to the [official installation guide](https://cmake.org/install).
|
If you need a newer version of cmake then brew provides. checkout the [official guide](https://cmake.org/install)
|
||||||
|
|
||||||
#### Build
|
#### Build
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
mkdir build && cd build
|
$ mkdir build && cd build
|
||||||
cmake .. && make
|
$ cmake .. && make
|
||||||
```
|
```
|
||||||
|
|
||||||
**MacOS:** If your `openssl` installation is not located at `/usr/local/opt/openssl@1.1`, you may need to pass the argument `-D OPENSSL_ROOT_DIR=/path/to/openssl` to `cmake` and specify the correct path.
|
**MacOS:** You may need to point `cmake` to `openssl` by passing the argument
|
||||||
|
`-D OPENSSL_ROOT_DIR=/usr/local/opt/openssl@1.1` if openssl is not under `/usr/local/opt/openssl@1.1` you need to find the correct path.
|
||||||
|
|
||||||
### Windows
|
### Windows
|
||||||
|
|
||||||
#### Dependencies
|
#### Dependencies
|
||||||
|
|
||||||
First, ensure that you have a compiler installed.
|
First you will need a compiler.
|
||||||
|
|
||||||
It is recommended to use [Build Tools for Visual Studio 2019](https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=BuildTools&rel=16) and select C++ during installation.
|
[Build Tools for Visual Studio 2019](https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=BuildTools&rel=16) (Selecting C++ during installation) is recommended.
|
||||||
|
|
||||||
By default, `cmake` will utilize the bundled OpenSSL package located at `vendor/openssl-1.1.1e-win-static.zip`. If you prefer to use a different version of OpenSSL, set the `OPENSSL_ROOT_DIR` to the directory where OpenSSL is located on your system:
|
By default `cmake` will use the bundled openssl package located at `vendor/openssl-1.1.1e-win-static.zip`
|
||||||
|
|
||||||
```sh
|
If you like to use an other version of OpenSSL then the static one bundled with this repo
|
||||||
cmake -D OPENSSL_ROOT_DIR=C:/path/to/openssl -B build
|
you need to set `OPENSSL_ROOT_DIR` to the directory where OpenSSL is located on the system.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
```
|
||||||
|
C:\repo> cmake -D OPENSSL_ROOT_DIR=C:/path/to/openssl -B build
|
||||||
```
|
```
|
||||||
|
|
||||||
**NOTE:** `cmake` uses forward slashes `/` for paths, even on Windows, so ensure that you use them when setting
|
**NOTE:** `cmake` uses forward slash `/` for path even for windows. so make sure you use that when setting `OPENSSL_ROOT_DIR`
|
||||||
|
|
||||||
`OPENSSL_ROOT_DIR`.
|
#### Build.
|
||||||
|
|
||||||
#### Build
|
Run cmake
|
||||||
|
|
||||||
Run `cmake`:
|
```
|
||||||
|
C:\repo> cmake -B build
|
||||||
```sh
|
C:\repo> cmake --build build --config Release
|
||||||
cmake -B build
|
|
||||||
cmake --build build --config Release
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Security Notice
|
## Security notice
|
||||||
|
|
||||||
The library performs elliptic curve cryptographic operations using either the `OpenSSL` or `libsecp256k1` libraries. The `libantelope` library ensures that sensitive cryptographic information is only stored in computer memory and not exposed to external sources. You are encouraged to inspect the source code and compile it yourself for verification purposes.
|
Elliptic curve crypthographic operations is done using either `OpenSSL` or `libsecp256k1` libraries.
|
||||||
|
This library (libeosio) will never expose sensitve cryptographic information
|
||||||
|
to anything but the computers memory.
|
||||||
|
You are free to inspect the source code and compile yourself to verify.
|
||||||
|
|
||||||
However, please use this library at your own risk. While both OpenSSL and libsecp256k1 are widely used and considered safe, we cannot guarantee the cryptographic security of the keys as it depends on the elliptic curve implementation.
|
However, use this at your own risk. we cannot guarantee that the keys are
|
||||||
|
cryptographically secure as this depends on the elliptic curve
|
||||||
|
implementation (alto both OpenSSL and libsecp256k1 are widely used and should be safe)
|
||||||
|
|
||||||
Please refer to the `LICENSE` file for more information.
|
Please read the `LICENSE` file.
|
||||||
|
|
||||||
|
```
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||||
|
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||||
|
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
||||||
|
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
||||||
|
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
```
|
||||||
|
|
||||||
## Author
|
## Author
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,26 +0,0 @@
|
||||||
# This script provides the libantelope as an import target
|
|
||||||
# ----------------------------------------------------------
|
|
||||||
#
|
|
||||||
# Use find_package() so cmake will find libantelope:
|
|
||||||
#
|
|
||||||
# find_package(libantelope) # No specific version
|
|
||||||
# find_package(libantelope REQUIRED) # No specific version, but the library must be found.
|
|
||||||
# find_package(libantelope 0.1) # any 0.1.x, but the library is optional.
|
|
||||||
# find_package(libeantelope 0.1.0) # 0.1.0 or greater, but the library is optional.
|
|
||||||
#
|
|
||||||
# Then you just link the you target with libantelope target:
|
|
||||||
#
|
|
||||||
# target_link_libraries( ${PROGRAM_EXE} PUBLIC libantelope )
|
|
||||||
#
|
|
||||||
# if you do not specify REQUIRED. you must check the variable libantelope_FOUND
|
|
||||||
# and and only link to it if it's defined:
|
|
||||||
#
|
|
||||||
# if (libantelope_FOUND)
|
|
||||||
# ...
|
|
||||||
# target_link_libraries( ${PROGRAM_EXE} PUBLIC libantelope )
|
|
||||||
# ..
|
|
||||||
# endif()
|
|
||||||
|
|
||||||
set( LIBANTELOPE_VERSION "@PROJECT_VERSION@" )
|
|
||||||
|
|
||||||
include ( "${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake" )
|
|
||||||
26
cmake/libeosioConfig.cmake.in
Normal file
26
cmake/libeosioConfig.cmake.in
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
# This script provides the libeosio as an import target
|
||||||
|
# ----------------------------------------------------------
|
||||||
|
#
|
||||||
|
# Use find_package() so cmake will find libeosio:
|
||||||
|
#
|
||||||
|
# find_package(libeosio) # No specific version
|
||||||
|
# find_package(libeosio REQUIRED) # No specific version, but the library must be found.
|
||||||
|
# find_package(libeosio 0.1) # any 0.1.x, but the library is optional.
|
||||||
|
# find_package(libeosio 0.1.0) # 0.1.0 or greater, but the library is optional.
|
||||||
|
#
|
||||||
|
# Then you just link the you target with eoskeygen target:
|
||||||
|
#
|
||||||
|
# target_link_libraries( ${PROGRAM_EXE} PUBLIC libeosio )
|
||||||
|
#
|
||||||
|
# if you do not specify REQUIRED. you must check the variable libeosio_FOUND
|
||||||
|
# and and only link to it if it's defined:
|
||||||
|
#
|
||||||
|
# if (libeosio_FOUND)
|
||||||
|
# ...
|
||||||
|
# target_link_libraries( ${PROGRAM_EXE} PUBLIC libeosio )
|
||||||
|
# ..
|
||||||
|
# endif()
|
||||||
|
|
||||||
|
set(LIBEOSIO_VERSION "@PROJECT_VERSION@")
|
||||||
|
|
||||||
|
include ( "${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake" )
|
||||||
|
|
@ -1,30 +0,0 @@
|
||||||
/**
|
|
||||||
* MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2019-2021 EOS Sw/eden
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
#ifndef LIBANTELOPE_HASH_H
|
|
||||||
#define LIBANTELOPE_HASH_H
|
|
||||||
|
|
||||||
#include <libantelope/hash/sha256.hpp>
|
|
||||||
#include <libantelope/hash/ripemd160.hpp>
|
|
||||||
|
|
||||||
#endif /* LIBANTELOPE_HASH_H */
|
|
||||||
|
|
@ -1,62 +0,0 @@
|
||||||
/**
|
|
||||||
* MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2019-2023 EOS Sw/eden
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
#ifndef LIBANTELOPE_HASH_RIPEMD160_H
|
|
||||||
#define LIBANTELOPE_HASH_RIPEMD160_H
|
|
||||||
|
|
||||||
#include <cstddef>
|
|
||||||
#include <libantelope/internal/hash.hpp>
|
|
||||||
|
|
||||||
namespace libantelope {
|
|
||||||
|
|
||||||
typedef unsigned char ripemd160_t[20];
|
|
||||||
|
|
||||||
typedef internal::ripemd160_state ripemd160_ctx_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize a ripmemd160_ctx_t structure
|
|
||||||
*/
|
|
||||||
int ripemd160_init(ripemd160_ctx_t* ctx);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update the RipeMD160 hash value with the contents in `data` up to `len` bytes.
|
|
||||||
* This can be called repeatedly to hash chunks of data.
|
|
||||||
*/
|
|
||||||
int ripemd160_update(ripemd160_ctx_t* ctx, const void *data, std::size_t len);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Places the RipeMD160 message digest in out variable.
|
|
||||||
* The ctx's internal state is reset after this operation.
|
|
||||||
*/
|
|
||||||
int ripemd160_final(ripemd160_ctx_t* ctx, ripemd160_t* out);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RipeMD160 hashing function.
|
|
||||||
* Hashes the content in `data` up to `len` bytes. The result is stored in `out`.
|
|
||||||
* Returns the same pointer as `out`.
|
|
||||||
*/
|
|
||||||
ripemd160_t* ripemd160(const unsigned char *data, std::size_t len, ripemd160_t* out);
|
|
||||||
|
|
||||||
} // namespace libantelope
|
|
||||||
|
|
||||||
#endif /* LIBANTELOPE_RIPEMD160_H */
|
|
||||||
|
|
@ -1,42 +0,0 @@
|
||||||
|
|
||||||
/**
|
|
||||||
* MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2019-2023 EOS Sw/eden
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
#ifndef LIBANTELOPE_INTERNAL_HASH_H
|
|
||||||
#define LIBANTELOPE_INTERNAL_HASH_H
|
|
||||||
|
|
||||||
#include <libantelope/config.h>
|
|
||||||
|
|
||||||
#ifdef LIBANTELOPE_HASHIMPL_OPENSSL
|
|
||||||
|
|
||||||
namespace libantelope { namespace internal {
|
|
||||||
|
|
||||||
typedef unsigned char sha256_state[112];
|
|
||||||
typedef unsigned char ripemd160_state[96];
|
|
||||||
} } // namespace libantelope::internal
|
|
||||||
|
|
||||||
#else
|
|
||||||
#error "Missing hash implementation"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* LIBANTELOPE_INTERNAL_INTERNAL_H */
|
|
||||||
|
|
@ -21,13 +21,13 @@
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#ifndef LIBANTELOPE_WIF_H
|
#ifndef LIBEOSIO_WIF_H
|
||||||
#define LIBANTELOPE_WIF_H
|
#define LIBEOSIO_WIF_H
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <libantelope/ec.hpp>
|
#include <libeosio/ec.hpp>
|
||||||
|
|
||||||
namespace libantelope {
|
namespace libeosio {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Key prefixes. (strings that is not equal to these prefixes are treated as legacy format.)
|
* Key prefixes. (strings that is not equal to these prefixes are treated as legacy format.)
|
||||||
|
|
@ -94,6 +94,6 @@ std::string wif_sig_encode(const ec_signature_t& sig);
|
||||||
*/
|
*/
|
||||||
bool wif_sig_decode(ec_signature_t& sig, const std::string& data);
|
bool wif_sig_decode(ec_signature_t& sig, const std::string& data);
|
||||||
|
|
||||||
} // namespace libantelope
|
} // namespace libeosio
|
||||||
|
|
||||||
#endif /* LIBANTELOPE_WIF_H */
|
#endif /* LIBEOSIO_WIF_H */
|
||||||
|
|
@ -21,13 +21,13 @@
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#ifndef LIBANTELOPE_BASE58_H
|
#ifndef LIBEOSIO_BASE58_H
|
||||||
#define LIBANTELOPE_BASE58_H
|
#define LIBEOSIO_BASE58_H
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace libantelope {
|
namespace libeosio {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base58 Encoding functions.
|
* Base58 Encoding functions.
|
||||||
|
|
@ -61,6 +61,6 @@ size_t is_base58(const std::string& str);
|
||||||
*/
|
*/
|
||||||
std::string& base58_strip(std::string& str);
|
std::string& base58_strip(std::string& str);
|
||||||
|
|
||||||
} //namespace libantelope
|
} //namespace libeosio
|
||||||
|
|
||||||
#endif /* LIBANTELOPE_BASE58_H */
|
#endif /* LIBEOSIO_BASE58_H */
|
||||||
|
|
@ -21,14 +21,14 @@
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#ifndef LIBANTELOPE_CHECKSUM_H
|
#ifndef LIBEOSIO_CHECKSUM_H
|
||||||
#define LIBANTELOPE_CHECKSUM_H
|
#define LIBEOSIO_CHECKSUM_H
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <libantelope/hash.hpp>
|
#include <libeosio/hash.hpp>
|
||||||
|
|
||||||
namespace libantelope {
|
namespace libeosio {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checksum size (in bytes)
|
* Checksum size (in bytes)
|
||||||
|
|
@ -68,6 +68,6 @@ inline bool checksum_validate(const unsigned char* data, std::size_t len) {
|
||||||
#define checksum_sha256d checksum<sha256_t, sha256d>
|
#define checksum_sha256d checksum<sha256_t, sha256d>
|
||||||
#define checksum_ripemd160 checksum<ripemd160_t, ripemd160>
|
#define checksum_ripemd160 checksum<ripemd160_t, ripemd160>
|
||||||
|
|
||||||
} // namespace libantelope
|
} // namespace libeosio
|
||||||
|
|
||||||
#endif /* LIBANTELOPE_CHECKSUM_H */
|
#endif /* LIBEOSIO_CHECKSUM_H */
|
||||||
|
|
@ -21,14 +21,14 @@
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#ifndef LIBANTELOPE_EC_H
|
#ifndef LIBEOSIO_EC_H
|
||||||
#define LIBANTELOPE_EC_H
|
#define LIBEOSIO_EC_H
|
||||||
|
|
||||||
#include <libantelope/hash.hpp>
|
#include <libeosio/hash.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
namespace libantelope {
|
namespace libeosio {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Elliptic curve private key size (in bytes)
|
* Elliptic curve private key size (in bytes)
|
||||||
|
|
@ -128,13 +128,13 @@ int ecdsa_recover(const sha256_t* digest, const ec_signature_t& sig, ec_pubkey_t
|
||||||
*/
|
*/
|
||||||
void ec_shutdown();
|
void ec_shutdown();
|
||||||
|
|
||||||
} // namespace libantelope
|
} // namespace libeosio
|
||||||
|
|
||||||
|
|
||||||
// Stream operators
|
// Stream operators
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& os, const libantelope::ec_privkey_t& pk);
|
std::ostream& operator<<(std::ostream& os, const libeosio::ec_privkey_t& pk);
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& os, const libantelope::ec_pubkey_t& pk);
|
std::ostream& operator<<(std::ostream& os, const libeosio::ec_pubkey_t& pk);
|
||||||
|
|
||||||
#endif /* LIBANTELOPE_EC_H */
|
#endif /* LIBEOSIO_EC_H */
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
/**
|
/**
|
||||||
* MIT License
|
* MIT License
|
||||||
*
|
*
|
||||||
* Copyright (c) 2019-2023 EOS Sw/eden
|
* Copyright (c) 2019-2021 EOS Sw/eden
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
@ -21,35 +21,19 @@
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#ifndef LIBANTELOPE_HASH_SHA256_H
|
#ifndef LIBEOSIO_HASH_H
|
||||||
#define LIBANTELOPE_HASH_SHA256_H
|
#define LIBEOSIO_HASH_H
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <libantelope/internal/hash.hpp>
|
|
||||||
|
|
||||||
namespace libantelope {
|
namespace libeosio {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hashes
|
||||||
|
*/
|
||||||
|
typedef unsigned char ripemd160_t[20];
|
||||||
typedef unsigned char sha256_t[32];
|
typedef unsigned char sha256_t[32];
|
||||||
|
|
||||||
typedef internal::sha256_state sha256_ctx_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize a sha256_ctx_t structure
|
|
||||||
*/
|
|
||||||
int sha256_init(sha256_ctx_t* ctx);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update the sha256 hash value with the contents in `data` up to `len` bytes.
|
|
||||||
* This can be called repeatedly to hash chunks of data.
|
|
||||||
*/
|
|
||||||
int sha256_update(sha256_ctx_t* ctx, const void *data, std::size_t len);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Place the message digest in out variable.
|
|
||||||
* The ctx's internal state is reset after this operation.
|
|
||||||
*/
|
|
||||||
int sha256_final(sha256_ctx_t* ctx, sha256_t* out);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sha256 hashing function.
|
* sha256 hashing function.
|
||||||
* Hashes the content in `data` up to `len` bytes. The result is stored in `out`.
|
* Hashes the content in `data` up to `len` bytes. The result is stored in `out`.
|
||||||
|
|
@ -64,6 +48,13 @@ sha256_t* sha256(const unsigned char *data, std::size_t len, sha256_t* out);
|
||||||
*/
|
*/
|
||||||
sha256_t* sha256d(const unsigned char *data, std::size_t len, sha256_t* out);
|
sha256_t* sha256d(const unsigned char *data, std::size_t len, sha256_t* out);
|
||||||
|
|
||||||
} // namespace libantelope
|
/**
|
||||||
|
* RipeMD160 hashing function.
|
||||||
|
* Hashes the content in `data` up to `len` bytes. The result is stored in `out`.
|
||||||
|
* Returns the same pointer as `out`.
|
||||||
|
*/
|
||||||
|
ripemd160_t* ripemd160(const unsigned char *data, std::size_t len, ripemd160_t* out);
|
||||||
|
|
||||||
#endif /* LIBANTELOPE_HASH_SHA256_H */
|
} // namespace libeosio
|
||||||
|
|
||||||
|
#endif /* LIBEOSIO_HASH_H */
|
||||||
16
src/WIF.cpp
16
src/WIF.cpp
|
|
@ -23,12 +23,12 @@
|
||||||
*/
|
*/
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <libantelope/base58.hpp>
|
#include <libeosio/base58.hpp>
|
||||||
#include <libantelope/checksum.hpp>
|
#include <libeosio/checksum.hpp>
|
||||||
#include <libantelope/WIF.hpp>
|
#include <libeosio/WIF.hpp>
|
||||||
#include "wif/codec.hpp"
|
#include "wif/codec.hpp"
|
||||||
|
|
||||||
namespace libantelope {
|
namespace libeosio {
|
||||||
|
|
||||||
const std::string WIF_PUB_LEG = "EOS";
|
const std::string WIF_PUB_LEG = "EOS";
|
||||||
const std::string WIF_PUB_K1 = "PUB_K1_";
|
const std::string WIF_PUB_K1 = "PUB_K1_";
|
||||||
|
|
@ -41,6 +41,7 @@ const wif_codec_t WIF_CODEC_LEG = wif_create_legacy_codec(WIF_PUB_LEG);
|
||||||
|
|
||||||
std::string wif_priv_encode(const ec_privkey_t& priv, const std::string& prefix) {
|
std::string wif_priv_encode(const ec_privkey_t& priv, const std::string& prefix) {
|
||||||
|
|
||||||
|
checksum_t check;
|
||||||
// 1 byte extra for legacy prefix prefix.
|
// 1 byte extra for legacy prefix prefix.
|
||||||
unsigned char buf[1 + EC_PRIVKEY_SIZE + CHECKSUM_SIZE] = { 0 };
|
unsigned char buf[1 + EC_PRIVKEY_SIZE + CHECKSUM_SIZE] = { 0 };
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
@ -58,7 +59,7 @@ std::string wif_priv_encode(const ec_privkey_t& priv, const std::string& prefix)
|
||||||
|
|
||||||
bool wif_priv_decode(ec_privkey_t& priv, const std::string& data) {
|
bool wif_priv_decode(ec_privkey_t& priv, const std::string& data) {
|
||||||
|
|
||||||
std::size_t offset;
|
uint8_t offset;
|
||||||
std::vector<unsigned char> buf;
|
std::vector<unsigned char> buf;
|
||||||
internal::priv_decoder_t decoder = internal::priv_decoder_legacy;
|
internal::priv_decoder_t decoder = internal::priv_decoder_legacy;
|
||||||
|
|
||||||
|
|
@ -99,7 +100,7 @@ std::string wif_pub_encode(const ec_pubkey_t& pub, const std::string& prefix) {
|
||||||
bool wif_pub_decode(ec_pubkey_t& pub, const std::string& data) {
|
bool wif_pub_decode(ec_pubkey_t& pub, const std::string& data) {
|
||||||
|
|
||||||
internal::pub_decoder_t decoder = internal::pub_decoder_legacy;
|
internal::pub_decoder_t decoder = internal::pub_decoder_legacy;
|
||||||
std::size_t offset;
|
int offset;
|
||||||
std::vector<unsigned char> buf;
|
std::vector<unsigned char> buf;
|
||||||
|
|
||||||
// Check prefix
|
// Check prefix
|
||||||
|
|
@ -130,6 +131,7 @@ void wif_print_key(const struct ec_keypair *key, const wif_codec_t& codec) {
|
||||||
|
|
||||||
bool wif_sig_decode(ec_signature_t& sig, const std::string& data) {
|
bool wif_sig_decode(ec_signature_t& sig, const std::string& data) {
|
||||||
|
|
||||||
|
checksum_t checksum;
|
||||||
std::vector<unsigned char> buf;
|
std::vector<unsigned char> buf;
|
||||||
|
|
||||||
if (data.substr(0, WIF_SIG_K1.length()) != WIF_SIG_K1) {
|
if (data.substr(0, WIF_SIG_K1.length()) != WIF_SIG_K1) {
|
||||||
|
|
@ -152,4 +154,4 @@ std::string wif_sig_encode(const ec_signature_t& sig) {
|
||||||
return WIF_SIG_K1 + base58_encode(buf, buf + sizeof(buf));
|
return WIF_SIG_K1 + base58_encode(buf, buf + sizeof(buf));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace libantelope
|
} // namespace libeosio
|
||||||
|
|
|
||||||
|
|
@ -25,13 +25,12 @@
|
||||||
* Based on code from https://github.com/bitcoin/bitcoin/blob/f1e2f2a85962c1664e4e55471061af0eaa798d40/src/base58.cpp
|
* Based on code from https://github.com/bitcoin/bitcoin/blob/f1e2f2a85962c1664e4e55471061af0eaa798d40/src/base58.cpp
|
||||||
*/
|
*/
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstdint>
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <libantelope/base58.hpp>
|
#include <libeosio/base58.hpp>
|
||||||
|
|
||||||
namespace libantelope {
|
namespace libeosio {
|
||||||
|
|
||||||
static const char charmap[59] = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
static const char charmap[59] = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
||||||
static const int8_t table[256] = {
|
static const int8_t table[256] = {
|
||||||
|
|
@ -121,7 +120,7 @@ bool base58_decode(const char* psz, std::vector<unsigned char>& out) {
|
||||||
psz++;
|
psz++;
|
||||||
}
|
}
|
||||||
// Allocate enough space in big-endian base256 representation.
|
// Allocate enough space in big-endian base256 representation.
|
||||||
std::size_t size = strlen(psz) * 733 /1000 + 1; // log(58) / log(256), rounded up.
|
int size = strlen(psz) * 733 /1000 + 1; // log(58) / log(256), rounded up.
|
||||||
std::vector<unsigned char> b256(size);
|
std::vector<unsigned char> b256(size);
|
||||||
// Process the characters.
|
// Process the characters.
|
||||||
|
|
||||||
|
|
@ -133,7 +132,7 @@ bool base58_decode(const char* psz, std::vector<unsigned char>& out) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (std::vector<unsigned char>::reverse_iterator it = b256.rbegin(); (carry != 0 || i < length) && (it != b256.rend()); ++it, ++i) {
|
for (std::vector<unsigned char>::reverse_iterator it = b256.rbegin(); (carry != 0 || i < length) && (it != b256.rend()); ++it, ++i) {
|
||||||
carry += 58 * (*it);
|
carry += 58 * (*it);
|
||||||
*it = (unsigned char) (carry % 256);
|
*it = carry % 256;
|
||||||
carry /= 256;
|
carry /= 256;
|
||||||
}
|
}
|
||||||
assert(carry == 0);
|
assert(carry == 0);
|
||||||
|
|
@ -191,4 +190,4 @@ std::string& base58_strip(std::string &str) {
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace libantelope
|
} // namespace libeosio
|
||||||
|
|
|
||||||
|
|
@ -1,38 +0,0 @@
|
||||||
/*
|
|
||||||
* MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2019-2023 EOS Sw/eden
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
#ifndef LIBANTELOPE_CONFIG_H
|
|
||||||
#define LIBANTELOPE_CONFIG_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Hash implementation */
|
|
||||||
#cmakedefine LIBANTELOPE_HASHIMPL_OPENSSL
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* LIBANTELOPE_CONFIG_H */
|
|
||||||
|
|
@ -21,11 +21,11 @@
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#include <libantelope/ec.hpp>
|
#include <libeosio/ec.hpp>
|
||||||
|
|
||||||
std::ostream& _hex(std::ostream& os, const unsigned char *b, std::size_t sz) {
|
std::ostream& _hex(std::ostream& os, const unsigned char *b, std::size_t sz) {
|
||||||
os << "[ " << std::hex;
|
os << "[ " << std::hex;
|
||||||
for (std::size_t i = 0; i < sz; i++) {
|
for (int i = 0; i < sz; i++) {
|
||||||
unsigned int v = b[i];
|
unsigned int v = b[i];
|
||||||
|
|
||||||
os << "0x";
|
os << "0x";
|
||||||
|
|
@ -38,10 +38,10 @@ std::ostream& _hex(std::ostream& os, const unsigned char *b, std::size_t sz) {
|
||||||
return os << std::oct << " ]";
|
return os << std::oct << " ]";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& os, const libantelope::ec_privkey_t& k) {
|
std::ostream& operator<<(std::ostream& os, const libeosio::ec_privkey_t& k) {
|
||||||
return _hex(os, k.data(), k.size());
|
return _hex(os, k.data(), k.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& os, const libantelope::ec_pubkey_t& k) {
|
std::ostream& operator<<(std::ostream& os, const libeosio::ec_pubkey_t& k) {
|
||||||
return _hex(os, k.data(), k.size());
|
return _hex(os, k.data(), k.size());
|
||||||
}
|
}
|
||||||
|
|
@ -23,10 +23,10 @@
|
||||||
*/
|
*/
|
||||||
#include <secp256k1.h>
|
#include <secp256k1.h>
|
||||||
#include <secp256k1_ecdh.h>
|
#include <secp256k1_ecdh.h>
|
||||||
#include <libantelope/ec.hpp>
|
#include <libeosio/ec.hpp>
|
||||||
#include "rng.h"
|
#include "rng.h"
|
||||||
|
|
||||||
namespace libantelope {
|
namespace libeosio {
|
||||||
|
|
||||||
secp256k1_context* ctx;
|
secp256k1_context* ctx;
|
||||||
|
|
||||||
|
|
@ -90,4 +90,4 @@ int ec_generate_key(struct ec_keypair *pair) {
|
||||||
return ec_get_publickey(&pair->secret, &pair->pub);
|
return ec_get_publickey(&pair->secret, &pair->pub);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace libantelope
|
} // namespace libeosio
|
||||||
|
|
|
||||||
|
|
@ -23,9 +23,10 @@
|
||||||
*/
|
*/
|
||||||
#include <secp256k1.h>
|
#include <secp256k1.h>
|
||||||
#include <secp256k1_recovery.h>
|
#include <secp256k1_recovery.h>
|
||||||
#include <libantelope/ec.hpp>
|
#include <libeosio/ec.hpp>
|
||||||
|
#include "rng.h"
|
||||||
|
|
||||||
namespace libantelope {
|
namespace libeosio {
|
||||||
|
|
||||||
extern secp256k1_context* ctx;
|
extern secp256k1_context* ctx;
|
||||||
|
|
||||||
|
|
@ -39,7 +40,6 @@ int is_canonical(const unsigned char *d) {
|
||||||
static int extended_nonce_function( unsigned char *nonce32, const unsigned char *msg32,
|
static int extended_nonce_function( unsigned char *nonce32, const unsigned char *msg32,
|
||||||
const unsigned char *key32, const unsigned char* algo16,
|
const unsigned char *key32, const unsigned char* algo16,
|
||||||
void* data, unsigned int attempt ) {
|
void* data, unsigned int attempt ) {
|
||||||
(void)attempt; // "use" the variable here to shutup compiler about unsed variable.
|
|
||||||
return secp256k1_nonce_function_rfc6979(nonce32, msg32, key32, algo16, nullptr, *(unsigned int*) data);
|
return secp256k1_nonce_function_rfc6979(nonce32, msg32, key32, algo16, nullptr, *(unsigned int*) data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -57,7 +57,7 @@ int ecdsa_sign(const ec_privkey_t& key, const sha256_t* digest, ec_signature_t&
|
||||||
secp256k1_ecdsa_recoverable_signature_serialize_compact(ctx, sig.data() + 1, &v, &s);
|
secp256k1_ecdsa_recoverable_signature_serialize_compact(ctx, sig.data() + 1, &v, &s);
|
||||||
|
|
||||||
if (is_canonical(sig.data())) {
|
if (is_canonical(sig.data())) {
|
||||||
sig[0] = (unsigned char) (27 + 4 + v);
|
sig[0] = 27 + 4 + v;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -115,4 +115,4 @@ int ecdsa_recover(const sha256_t* digest, const ec_signature_t& sig, ec_pubkey_t
|
||||||
return len != EC_PUBKEY_SIZE ? -1 : 0;
|
return len != EC_PUBKEY_SIZE ? -1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace libantelope
|
} // namespace libeosio
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,6 @@
|
||||||
* EXAMPLES_COPYING or https://creativecommons.org/publicdomain/zero/1.0 *
|
* EXAMPLES_COPYING or https://creativecommons.org/publicdomain/zero/1.0 *
|
||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
|
|
||||||
#ifndef LIBANTELOPE_LIBSECP256K1_RNG_H
|
|
||||||
#define LIBANTELOPE_LIBSECP256K1_RNG_H
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is an attempt at collecting best practice methods for obtaining randomness with different operating systems.
|
* This file is an attempt at collecting best practice methods for obtaining randomness with different operating systems.
|
||||||
* It may be out-of-date. Consult the documentation of the operating system before considering to use the methods below.
|
* It may be out-of-date. Consult the documentation of the operating system before considering to use the methods below.
|
||||||
|
|
@ -42,17 +39,12 @@
|
||||||
|
|
||||||
static int fill_random(unsigned char* data, size_t size) {
|
static int fill_random(unsigned char* data, size_t size) {
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
/* Disable C4267 Warning (dataloss when casting variable to smaller size) temporarily */
|
|
||||||
#pragma warning( push )
|
|
||||||
#pragma warning( disable: 4267 )
|
|
||||||
NTSTATUS res = BCryptGenRandom(NULL, data, size, BCRYPT_USE_SYSTEM_PREFERRED_RNG);
|
NTSTATUS res = BCryptGenRandom(NULL, data, size, BCRYPT_USE_SYSTEM_PREFERRED_RNG);
|
||||||
#pragma warning( pop )
|
|
||||||
if (res != STATUS_SUCCESS || size > ULONG_MAX) {
|
if (res != STATUS_SUCCESS || size > ULONG_MAX) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(__linux__) || defined(__FreeBSD__)
|
#elif defined(__linux__) || defined(__FreeBSD__)
|
||||||
/* If `getrandom(2)` is not available you should fallback to /dev/urandom */
|
/* If `getrandom(2)` is not available you should fallback to /dev/urandom */
|
||||||
ssize_t res = getrandom(data, size, 0);
|
ssize_t res = getrandom(data, size, 0);
|
||||||
|
|
@ -73,5 +65,3 @@ static int fill_random(unsigned char* data, size_t size) {
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* LIBANTELOPE_LIBSECP256K1_RNG_H */
|
|
||||||
|
|
@ -24,10 +24,10 @@
|
||||||
#include <openssl/ec.h>
|
#include <openssl/ec.h>
|
||||||
#include <openssl/bn.h>
|
#include <openssl/bn.h>
|
||||||
#include <openssl/hmac.h>
|
#include <openssl/hmac.h>
|
||||||
#include <libantelope/ec.hpp>
|
#include <libeosio/ec.hpp>
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
|
||||||
namespace libantelope {
|
namespace libeosio {
|
||||||
|
|
||||||
BN_CTX *ctx = NULL;
|
BN_CTX *ctx = NULL;
|
||||||
EC_KEY *k = NULL;
|
EC_KEY *k = NULL;
|
||||||
|
|
@ -121,4 +121,4 @@ int ec_generate_key(struct ec_keypair *pair) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace libantelope
|
} // namespace libeosio
|
||||||
|
|
|
||||||
|
|
@ -24,10 +24,10 @@
|
||||||
#include <openssl/ec.h>
|
#include <openssl/ec.h>
|
||||||
#include <openssl/bn.h>
|
#include <openssl/bn.h>
|
||||||
#include <openssl/ecdsa.h>
|
#include <openssl/ecdsa.h>
|
||||||
#include <libantelope/ec.hpp>
|
#include <libeosio/ec.hpp>
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
|
||||||
namespace libantelope {
|
namespace libeosio {
|
||||||
|
|
||||||
extern BN_CTX *ctx;
|
extern BN_CTX *ctx;
|
||||||
|
|
||||||
|
|
@ -182,4 +182,4 @@ err2: EC_KEY_free(ec_key);
|
||||||
err1: return ret;
|
err1: return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace libantelope
|
} // namespace libeosio
|
||||||
|
|
@ -23,21 +23,9 @@
|
||||||
*/
|
*/
|
||||||
#include <openssl/sha.h>
|
#include <openssl/sha.h>
|
||||||
#include <openssl/ripemd.h>
|
#include <openssl/ripemd.h>
|
||||||
#include <libantelope/hash.hpp>
|
#include <libeosio/hash.hpp>
|
||||||
|
|
||||||
namespace libantelope {
|
namespace libeosio {
|
||||||
|
|
||||||
int sha256_init(sha256_ctx_t* ctx) {
|
|
||||||
return SHA256_Init((SHA256_CTX*)ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
int sha256_update(sha256_ctx_t* ctx, const void *data, std::size_t len) {
|
|
||||||
return SHA256_Update((SHA256_CTX*)ctx, data, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
int sha256_final(sha256_ctx_t* ctx, sha256_t* out) {
|
|
||||||
return SHA256_Final((unsigned char*) out, (SHA256_CTX*)ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
sha256_t* sha256(const unsigned char *data, std::size_t len, sha256_t* out) {
|
sha256_t* sha256(const unsigned char *data, std::size_t len, sha256_t* out) {
|
||||||
return (sha256_t *) SHA256(data, len, (unsigned char*) out);
|
return (sha256_t *) SHA256(data, len, (unsigned char*) out);
|
||||||
|
|
@ -48,20 +36,8 @@ sha256_t* sha256d(const unsigned char *data, std::size_t len, sha256_t* out) {
|
||||||
return (sha256_t *) SHA256((unsigned char*) out, 32, (unsigned char*) out);
|
return (sha256_t *) SHA256((unsigned char*) out, 32, (unsigned char*) out);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ripemd160_init(ripemd160_ctx_t* ctx) {
|
|
||||||
return RIPEMD160_Init((RIPEMD160_CTX*)ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
int ripemd160_update(ripemd160_ctx_t* ctx, const void *data, std::size_t len) {
|
|
||||||
return RIPEMD160_Update((RIPEMD160_CTX*)ctx, data, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
int ripemd160_final(ripemd160_ctx_t* ctx, ripemd160_t* out) {
|
|
||||||
return RIPEMD160_Final((unsigned char*) out, (RIPEMD160_CTX*)ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
ripemd160_t* ripemd160(const unsigned char *data, std::size_t len, ripemd160_t* out) {
|
ripemd160_t* ripemd160(const unsigned char *data, std::size_t len, ripemd160_t* out) {
|
||||||
return (ripemd160_t *) RIPEMD160(data, len, (unsigned char*) out);
|
return (ripemd160_t *) RIPEMD160(data, len, (unsigned char*) out);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace libantelope
|
} // namespace libeosio
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,8 @@
|
||||||
#include <openssl/ec.h>
|
#include <openssl/ec.h>
|
||||||
#include <openssl/hmac.h>
|
#include <openssl/hmac.h>
|
||||||
|
|
||||||
#ifndef LIBANTELOPE_OPENSSL_INTERNAL_H
|
#ifndef LIBEOSIO_OPENSSL_INTERNAL_H
|
||||||
#define LIBANTELOPE_OPENSSL_INTERNAL_H
|
#define LIBEOSIO_OPENSSL_INTERNAL_H
|
||||||
|
|
||||||
#define EC_KEY_new_secp256k1() (EC_KEY_new_by_curve_name( NID_secp256k1 ))
|
#define EC_KEY_new_secp256k1() (EC_KEY_new_by_curve_name( NID_secp256k1 ))
|
||||||
|
|
||||||
|
|
@ -62,4 +62,4 @@ int ECDSA_SIG_unserialize_rs(const unsigned char *sig, BIGNUM **r, BIGNUM **s, i
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* LIBANTELOPE_OPENSSL_INTERNAL_H */
|
#endif /* LIBEOSIO_OPENSSL_INTERNAL_H */
|
||||||
|
|
@ -21,13 +21,13 @@
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#ifndef LIBANTELOPE_CODEC_H
|
#ifndef LIBEOSIO_CODEC_H
|
||||||
#define LIBANTELOPE_CODEC_H
|
#define LIBEOSIO_CODEC_H
|
||||||
|
|
||||||
#include <libantelope/WIF.hpp>
|
#include <libeosio/WIF.hpp>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace libantelope { namespace internal {
|
namespace libeosio { namespace internal {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Public-key encoders
|
* Public-key encoders
|
||||||
|
|
@ -79,6 +79,6 @@ typedef bool (*sig_decoder_t)(const std::vector<unsigned char>& buf, ec_signatur
|
||||||
|
|
||||||
bool sig_decoder_k1(const std::vector<unsigned char>& buf, ec_signature_t& sig);
|
bool sig_decoder_k1(const std::vector<unsigned char>& buf, ec_signature_t& sig);
|
||||||
|
|
||||||
}} // namespace libantelope::internal
|
}} // namespace libeosio::internal
|
||||||
|
|
||||||
#endif /* LIBANTELOPE_CODEC_H */
|
#endif /* LIBEOSIO_CODEC_H */
|
||||||
|
|
|
||||||
|
|
@ -22,32 +22,31 @@
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <libantelope/checksum.hpp>
|
#include <libeosio/checksum.hpp>
|
||||||
#include <libantelope/hash/ripemd160.hpp>
|
#include <vector>
|
||||||
#include "codec.hpp"
|
#include "codec.hpp"
|
||||||
|
|
||||||
namespace libantelope { namespace internal {
|
namespace libeosio { namespace internal {
|
||||||
|
|
||||||
// Just to make it "harder" the calculated checksum for a signature (k1) and pub/priv keys in k1/r1 format.
|
// Just to make it "harder" the calculated checksum for a signature (k1) and pub/priv keys in k1/r1 format.
|
||||||
// has a suffix that is not present in the WIF encoded string.
|
// has a suffix that is not present in the WIF encoded string.
|
||||||
// So this function is a quick hack to calculate it.
|
// So this function is a quick hack to calculate it.
|
||||||
void _checksum_suffix(const unsigned char *in, size_t size, checksum_t check) {
|
//
|
||||||
ripemd160_ctx_t ctx;
|
// Should implement and use Init/Update/Finalize hash functions to do it inplace.
|
||||||
ripemd160_t md;
|
void _checksum_suffix(const unsigned char *in, size_t size, const char *suffix, checksum_t check) {
|
||||||
|
std::vector<unsigned char> buf(size + 2);
|
||||||
|
|
||||||
ripemd160_init(&ctx);
|
memcpy(buf.data(), in, size);
|
||||||
ripemd160_update(&ctx, in, size);
|
memcpy(buf.data() + size, suffix, 2);
|
||||||
ripemd160_update(&ctx, "K1", 2);
|
|
||||||
ripemd160_final(&ctx, &md);
|
|
||||||
|
|
||||||
std::memcpy(check, md, CHECKSUM_SIZE);
|
return checksum_ripemd160(buf.data(), buf.size(), (unsigned char*) check);
|
||||||
}
|
}
|
||||||
|
|
||||||
void pub_encoder_k1(const ec_pubkey_t& key, unsigned char *buf) {
|
void pub_encoder_k1(const ec_pubkey_t& key, unsigned char *buf) {
|
||||||
|
|
||||||
checksum_t check;
|
checksum_t check;
|
||||||
|
|
||||||
_checksum_suffix(key.data(), EC_PUBKEY_SIZE, check);
|
_checksum_suffix(key.data(), EC_PUBKEY_SIZE, "K1", check);
|
||||||
|
|
||||||
memcpy(buf, key.data(), EC_PUBKEY_SIZE);
|
memcpy(buf, key.data(), EC_PUBKEY_SIZE);
|
||||||
memcpy(buf + EC_PUBKEY_SIZE, check, CHECKSUM_SIZE);
|
memcpy(buf + EC_PUBKEY_SIZE, check, CHECKSUM_SIZE);
|
||||||
|
|
@ -57,7 +56,7 @@ bool pub_decoder_k1(const std::vector<unsigned char>& buf, ec_pubkey_t& key) {
|
||||||
|
|
||||||
checksum_t check;
|
checksum_t check;
|
||||||
|
|
||||||
_checksum_suffix(buf.data(), EC_PUBKEY_SIZE, check);
|
_checksum_suffix(buf.data(), EC_PUBKEY_SIZE, "K1", check);
|
||||||
|
|
||||||
if (memcmp(buf.data() + EC_PUBKEY_SIZE, check, CHECKSUM_SIZE)) {
|
if (memcmp(buf.data() + EC_PUBKEY_SIZE, check, CHECKSUM_SIZE)) {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -70,7 +69,7 @@ bool pub_decoder_k1(const std::vector<unsigned char>& buf, ec_pubkey_t& key) {
|
||||||
size_t priv_encoder_k1(const ec_privkey_t& priv, unsigned char *buf) {
|
size_t priv_encoder_k1(const ec_privkey_t& priv, unsigned char *buf) {
|
||||||
checksum_t check;
|
checksum_t check;
|
||||||
|
|
||||||
_checksum_suffix(priv.data(), EC_PRIVKEY_SIZE, check);
|
_checksum_suffix(priv.data(), EC_PRIVKEY_SIZE, "K1", check);
|
||||||
|
|
||||||
memcpy(buf, priv.data(), priv.size());
|
memcpy(buf, priv.data(), priv.size());
|
||||||
memcpy(buf + EC_PRIVKEY_SIZE, check, CHECKSUM_SIZE);
|
memcpy(buf + EC_PRIVKEY_SIZE, check, CHECKSUM_SIZE);
|
||||||
|
|
@ -85,7 +84,7 @@ bool priv_decoder_k1(const std::vector<unsigned char>& buf, ec_privkey_t& priv)
|
||||||
}
|
}
|
||||||
|
|
||||||
checksum_t check;
|
checksum_t check;
|
||||||
_checksum_suffix(buf.data(), EC_PRIVKEY_SIZE, check);
|
_checksum_suffix(buf.data(), EC_PRIVKEY_SIZE, "K1", check);
|
||||||
if (memcmp(buf.data() + EC_PRIVKEY_SIZE, check, CHECKSUM_SIZE)) {
|
if (memcmp(buf.data() + EC_PRIVKEY_SIZE, check, CHECKSUM_SIZE)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -98,7 +97,7 @@ void sig_encoder_k1(const ec_signature_t& sig, unsigned char *buf) {
|
||||||
|
|
||||||
checksum_t check;
|
checksum_t check;
|
||||||
|
|
||||||
_checksum_suffix(sig.data(), EC_SIGNATURE_SIZE, check);
|
_checksum_suffix(sig.data(), EC_SIGNATURE_SIZE, "K1", check);
|
||||||
|
|
||||||
memcpy(buf, sig.data(), sig.size());
|
memcpy(buf, sig.data(), sig.size());
|
||||||
memcpy(buf + EC_SIGNATURE_SIZE, check, CHECKSUM_SIZE);
|
memcpy(buf + EC_SIGNATURE_SIZE, check, CHECKSUM_SIZE);
|
||||||
|
|
@ -113,7 +112,7 @@ bool sig_decoder_k1(const std::vector<unsigned char>& buf, ec_signature_t& sig)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate checksum
|
// Calculate checksum
|
||||||
_checksum_suffix(buf.data(), EC_SIGNATURE_SIZE, check);
|
_checksum_suffix(buf.data(), EC_SIGNATURE_SIZE, "K1", check);
|
||||||
|
|
||||||
// And validate
|
// And validate
|
||||||
if (memcmp(buf.data() + EC_SIGNATURE_SIZE, check, CHECKSUM_SIZE)) {
|
if (memcmp(buf.data() + EC_SIGNATURE_SIZE, check, CHECKSUM_SIZE)) {
|
||||||
|
|
@ -126,4 +125,4 @@ bool sig_decoder_k1(const std::vector<unsigned char>& buf, ec_signature_t& sig)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}} // namespace libantelope::internal
|
}} // namespace libeosio::internal
|
||||||
|
|
@ -22,10 +22,10 @@
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <libantelope/checksum.hpp>
|
#include <libeosio/checksum.hpp>
|
||||||
#include "codec.hpp"
|
#include "codec.hpp"
|
||||||
|
|
||||||
namespace libantelope { namespace internal {
|
namespace libeosio { namespace internal {
|
||||||
|
|
||||||
#define PRIV_KEY_PREFIX 0x80 /* 0x80 for "Bitcoin mainnet". Always used by EOS. */
|
#define PRIV_KEY_PREFIX 0x80 /* 0x80 for "Bitcoin mainnet". Always used by EOS. */
|
||||||
|
|
||||||
|
|
@ -77,4 +77,4 @@ bool priv_decoder_legacy(const std::vector<unsigned char>& buf, ec_privkey_t& pr
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}} // namespace libantelope::internal
|
}} // namespace libeosio::internal
|
||||||
|
|
@ -1,13 +1,7 @@
|
||||||
|
|
||||||
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/doctest.cmake)
|
|
||||||
|
|
||||||
set(TEST_SRC
|
set(TEST_SRC
|
||||||
main.cpp
|
main.cpp
|
||||||
|
|
||||||
# hash
|
|
||||||
hash/sha256.cpp
|
|
||||||
hash/ripemd160.cpp
|
|
||||||
|
|
||||||
# ec
|
# ec
|
||||||
ec/generate.cpp
|
ec/generate.cpp
|
||||||
ec/pubkey.cpp
|
ec/pubkey.cpp
|
||||||
|
|
@ -32,7 +26,10 @@ add_executable(doctest ${TEST_SRC})
|
||||||
target_link_libraries(doctest PRIVATE ${LIB_NAME})
|
target_link_libraries(doctest PRIVATE ${LIB_NAME})
|
||||||
target_include_directories(doctest PRIVATE ${CMAKE_CURRENT_LIST_DIR}/include)
|
target_include_directories(doctest PRIVATE ${CMAKE_CURRENT_LIST_DIR}/include)
|
||||||
|
|
||||||
doctest_discover_tests(doctest)
|
add_test(
|
||||||
|
NAME doctest
|
||||||
|
COMMAND $<TARGET_FILE:doctest> -ni -fc
|
||||||
|
)
|
||||||
|
|
||||||
if (WITH_BENCHMARK)
|
if (WITH_BENCHMARK)
|
||||||
add_subdirectory( benchmark )
|
add_subdirectory( benchmark )
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#include <libantelope/WIF.hpp>
|
#include <libeosio/WIF.hpp>
|
||||||
#include <libantelope/ec.hpp>
|
#include <libeosio/ec.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <doctest.h>
|
#include <doctest.h>
|
||||||
|
|
@ -8,7 +8,7 @@ TEST_CASE("WIF::wif_priv_decode [legacy]") {
|
||||||
struct testcase {
|
struct testcase {
|
||||||
std::string name;
|
std::string name;
|
||||||
std::string key;
|
std::string key;
|
||||||
libantelope::ec_privkey_t expected;
|
libeosio::ec_privkey_t expected;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -22,9 +22,9 @@ TEST_CASE("WIF::wif_priv_decode [legacy]") {
|
||||||
|
|
||||||
SUBCASE(it->name.c_str()) {
|
SUBCASE(it->name.c_str()) {
|
||||||
|
|
||||||
libantelope::ec_privkey_t result;
|
libeosio::ec_privkey_t result;
|
||||||
|
|
||||||
CHECK( libantelope::wif_priv_decode(result, it->key) );
|
CHECK( libeosio::wif_priv_decode(result, it->key) );
|
||||||
CHECK( result == it->expected );
|
CHECK( result == it->expected );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -35,7 +35,7 @@ TEST_CASE("WIF::wif_priv_decode [K1]") {
|
||||||
struct testcase {
|
struct testcase {
|
||||||
std::string name;
|
std::string name;
|
||||||
std::string key;
|
std::string key;
|
||||||
libantelope::ec_privkey_t expected;
|
libeosio::ec_privkey_t expected;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -49,9 +49,9 @@ TEST_CASE("WIF::wif_priv_decode [K1]") {
|
||||||
|
|
||||||
SUBCASE(it->name.c_str()) {
|
SUBCASE(it->name.c_str()) {
|
||||||
|
|
||||||
libantelope::ec_privkey_t result;
|
libeosio::ec_privkey_t result;
|
||||||
|
|
||||||
CHECK( libantelope::wif_priv_decode(result, it->key) );
|
CHECK( libeosio::wif_priv_decode(result, it->key) );
|
||||||
CHECK( result == it->expected );
|
CHECK( result == it->expected );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#include <libantelope/WIF.hpp>
|
#include <libeosio/WIF.hpp>
|
||||||
#include <libantelope/ec.hpp>
|
#include <libeosio/ec.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <doctest.h>
|
#include <doctest.h>
|
||||||
|
|
@ -9,20 +9,20 @@ TEST_CASE("WIF::wif_priv_encode [Legacy]") {
|
||||||
struct testcase {
|
struct testcase {
|
||||||
std::string name;
|
std::string name;
|
||||||
const std::string prefix;
|
const std::string prefix;
|
||||||
libantelope::ec_privkey_t key;
|
libeosio::ec_privkey_t key;
|
||||||
std::string expected;
|
std::string expected;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<struct testcase> tests {
|
std::vector<struct testcase> tests {
|
||||||
{ "one", libantelope::WIF_PVT_LEG, { 0x0C, 0x28, 0xFC, 0xA3, 0x86, 0xC7, 0xA2, 0x27, 0x60, 0x0B, 0x2F, 0xE5, 0x0B, 0x7C, 0xAE, 0x11, 0xEC, 0x86, 0xD3, 0xBF, 0x1F, 0xBE, 0x47, 0x1B, 0xE8, 0x98, 0x27, 0xE1, 0x9D,0x72,0xAA,0x1D}, "5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ" },
|
{ "one", libeosio::WIF_PVT_LEG, { 0x0C, 0x28, 0xFC, 0xA3, 0x86, 0xC7, 0xA2, 0x27, 0x60, 0x0B, 0x2F, 0xE5, 0x0B, 0x7C, 0xAE, 0x11, 0xEC, 0x86, 0xD3, 0xBF, 0x1F, 0xBE, 0x47, 0x1B, 0xE8, 0x98, 0x27, 0xE1, 0x9D,0x72,0xAA,0x1D}, "5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ" },
|
||||||
{ "two", libantelope::WIF_PVT_LEG, { 0x9F, 0xE3, 0xE3, 0x2B, 0x3C, 0x4B, 0x6B, 0x91, 0x6E, 0x20, 0x6C, 0xB0, 0x91, 0xDF, 0x1F, 0x5E, 0x34, 0x32, 0x88, 0x0B, 0x41, 0x33, 0x86, 0xBD, 0xF2, 0x92, 0xFF, 0x23, 0x06, 0x43, 0xF2, 0x8C}, "5K2hm8apqz281ANDQdtVzifpxcXFTqG5E7Fc6Q5V2ssqPRQ3urJ" },
|
{ "two", libeosio::WIF_PVT_LEG, { 0x9F, 0xE3, 0xE3, 0x2B, 0x3C, 0x4B, 0x6B, 0x91, 0x6E, 0x20, 0x6C, 0xB0, 0x91, 0xDF, 0x1F, 0x5E, 0x34, 0x32, 0x88, 0x0B, 0x41, 0x33, 0x86, 0xBD, 0xF2, 0x92, 0xFF, 0x23, 0x06, 0x43, 0xF2, 0x8C}, "5K2hm8apqz281ANDQdtVzifpxcXFTqG5E7Fc6Q5V2ssqPRQ3urJ" },
|
||||||
{ "three", libantelope::WIF_PVT_LEG, { 0x59, 0x3A, 0x51, 0xB5, 0x5D, 0x56, 0xAA, 0xF0, 0x5B, 0xD9, 0xD1, 0x0E, 0x6B, 0x88, 0x6D, 0xF9, 0xC4, 0x37, 0x09, 0xB2, 0x4C, 0xEC, 0xBB, 0x63, 0x68, 0x92, 0xC2, 0x94, 0x31, 0x48, 0x71, 0x8C}, "5JVanYq9HPvuKgr2FjATYB9NvTsJ4a3CAj5oPYKbr1Ja5MRLsZX" }
|
{ "three", libeosio::WIF_PVT_LEG, { 0x59, 0x3A, 0x51, 0xB5, 0x5D, 0x56, 0xAA, 0xF0, 0x5B, 0xD9, 0xD1, 0x0E, 0x6B, 0x88, 0x6D, 0xF9, 0xC4, 0x37, 0x09, 0xB2, 0x4C, 0xEC, 0xBB, 0x63, 0x68, 0x92, 0xC2, 0x94, 0x31, 0x48, 0x71, 0x8C}, "5JVanYq9HPvuKgr2FjATYB9NvTsJ4a3CAj5oPYKbr1Ja5MRLsZX" }
|
||||||
};
|
};
|
||||||
|
|
||||||
for(auto it = tests.begin(); it != tests.end(); it++) {
|
for(auto it = tests.begin(); it != tests.end(); it++) {
|
||||||
|
|
||||||
SUBCASE(it->name.c_str()) {
|
SUBCASE(it->name.c_str()) {
|
||||||
CHECK( libantelope::wif_priv_encode(it->key, it->prefix) == it->expected );
|
CHECK( libeosio::wif_priv_encode(it->key, it->prefix) == it->expected );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -32,20 +32,20 @@ TEST_CASE("WIF::wif_priv_encode [K1]") {
|
||||||
struct testcase {
|
struct testcase {
|
||||||
std::string name;
|
std::string name;
|
||||||
const std::string prefix;
|
const std::string prefix;
|
||||||
libantelope::ec_privkey_t key;
|
libeosio::ec_privkey_t key;
|
||||||
std::string expected;
|
std::string expected;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<struct testcase> tests {
|
std::vector<struct testcase> tests {
|
||||||
{ "one", libantelope::WIF_PVT_K1, { 0x0C, 0x28, 0xFC, 0xA3, 0x86, 0xC7, 0xA2, 0x27, 0x60, 0x0B, 0x2F, 0xE5, 0x0B, 0x7C, 0xAE, 0x11, 0xEC, 0x86, 0xD3, 0xBF, 0x1F, 0xBE, 0x47, 0x1B, 0xE8, 0x98, 0x27, 0xE1, 0x9D,0x72,0xAA,0x1D}, "PVT_K1_6Mcb23muAxyXaSMhmB6B1mqkvLdWhtuFZmnZsxDczHRvQdp32" },
|
{ "one", libeosio::WIF_PVT_K1, { 0x0C, 0x28, 0xFC, 0xA3, 0x86, 0xC7, 0xA2, 0x27, 0x60, 0x0B, 0x2F, 0xE5, 0x0B, 0x7C, 0xAE, 0x11, 0xEC, 0x86, 0xD3, 0xBF, 0x1F, 0xBE, 0x47, 0x1B, 0xE8, 0x98, 0x27, 0xE1, 0x9D,0x72,0xAA,0x1D}, "PVT_K1_6Mcb23muAxyXaSMhmB6B1mqkvLdWhtuFZmnZsxDczHRvQdp32" },
|
||||||
{ "two", libantelope::WIF_PVT_K1, { 0x9F, 0xE3, 0xE3, 0x2B, 0x3C, 0x4B, 0x6B, 0x91, 0x6E, 0x20, 0x6C, 0xB0, 0x91, 0xDF, 0x1F, 0x5E, 0x34, 0x32, 0x88, 0x0B, 0x41, 0x33, 0x86, 0xBD, 0xF2, 0x92, 0xFF, 0x23, 0x06, 0x43, 0xF2, 0x8C}, "PVT_K1_2DRBT8jmXT8k9ywNSSbufvhk1hLFhPzWJBpsE2jo12CDoFhcc1" },
|
{ "two", libeosio::WIF_PVT_K1, { 0x9F, 0xE3, 0xE3, 0x2B, 0x3C, 0x4B, 0x6B, 0x91, 0x6E, 0x20, 0x6C, 0xB0, 0x91, 0xDF, 0x1F, 0x5E, 0x34, 0x32, 0x88, 0x0B, 0x41, 0x33, 0x86, 0xBD, 0xF2, 0x92, 0xFF, 0x23, 0x06, 0x43, 0xF2, 0x8C}, "PVT_K1_2DRBT8jmXT8k9ywNSSbufvhk1hLFhPzWJBpsE2jo12CDoFhcc1" },
|
||||||
{ "three", libantelope::WIF_PVT_K1, { 0x59, 0x3A, 0x51, 0xB5, 0x5D, 0x56, 0xAA, 0xF0, 0x5B, 0xD9, 0xD1, 0x0E, 0x6B, 0x88, 0x6D, 0xF9, 0xC4, 0x37, 0x09, 0xB2, 0x4C, 0xEC, 0xBB, 0x63, 0x68, 0x92, 0xC2, 0x94, 0x31, 0x48, 0x71, 0x8C}, "PVT_K1_gJCsP4CwMv4gTkDXiZT8QFhs3NrSB7Sv22ANGrc8Svun9uC9C" }
|
{ "three", libeosio::WIF_PVT_K1, { 0x59, 0x3A, 0x51, 0xB5, 0x5D, 0x56, 0xAA, 0xF0, 0x5B, 0xD9, 0xD1, 0x0E, 0x6B, 0x88, 0x6D, 0xF9, 0xC4, 0x37, 0x09, 0xB2, 0x4C, 0xEC, 0xBB, 0x63, 0x68, 0x92, 0xC2, 0x94, 0x31, 0x48, 0x71, 0x8C}, "PVT_K1_gJCsP4CwMv4gTkDXiZT8QFhs3NrSB7Sv22ANGrc8Svun9uC9C" }
|
||||||
};
|
};
|
||||||
|
|
||||||
for(auto it = tests.begin(); it != tests.end(); it++) {
|
for(auto it = tests.begin(); it != tests.end(); it++) {
|
||||||
|
|
||||||
SUBCASE(it->name.c_str()) {
|
SUBCASE(it->name.c_str()) {
|
||||||
CHECK( libantelope::wif_priv_encode(it->key, it->prefix) == it->expected );
|
CHECK( libeosio::wif_priv_encode(it->key, it->prefix) == it->expected );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#include <libantelope/WIF.hpp>
|
#include <libeosio/WIF.hpp>
|
||||||
#include <libantelope/ec.hpp>
|
#include <libeosio/ec.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <doctest.h>
|
#include <doctest.h>
|
||||||
|
|
@ -8,7 +8,7 @@ TEST_CASE("WIF::wif_pub_decode [legacy]") {
|
||||||
struct testcase {
|
struct testcase {
|
||||||
const char* name;
|
const char* name;
|
||||||
std::string key;
|
std::string key;
|
||||||
libantelope::ec_pubkey_t expected;
|
libeosio::ec_pubkey_t expected;
|
||||||
bool expectedRet;
|
bool expectedRet;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -24,9 +24,9 @@ TEST_CASE("WIF::wif_pub_decode [legacy]") {
|
||||||
for(auto it = tests.begin(); it != tests.end(); it++) {
|
for(auto it = tests.begin(); it != tests.end(); it++) {
|
||||||
|
|
||||||
SUBCASE(it->name) {
|
SUBCASE(it->name) {
|
||||||
libantelope::ec_pubkey_t result = { 0x0 };
|
libeosio::ec_pubkey_t result = { 0x0 };
|
||||||
|
|
||||||
CHECK( libantelope::wif_pub_decode(result, it->key) == it->expectedRet );
|
CHECK( libeosio::wif_pub_decode(result, it->key) == it->expectedRet );
|
||||||
CHECK( result == it->expected );
|
CHECK( result == it->expected );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -36,7 +36,7 @@ TEST_CASE("WIF::wif_pub_decode [k1]") {
|
||||||
struct testcase {
|
struct testcase {
|
||||||
const char* name;
|
const char* name;
|
||||||
std::string key;
|
std::string key;
|
||||||
libantelope::ec_pubkey_t expected;
|
libeosio::ec_pubkey_t expected;
|
||||||
bool expectedRet;
|
bool expectedRet;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -52,9 +52,9 @@ TEST_CASE("WIF::wif_pub_decode [k1]") {
|
||||||
for(auto it = tests.begin(); it != tests.end(); it++) {
|
for(auto it = tests.begin(); it != tests.end(); it++) {
|
||||||
|
|
||||||
SUBCASE(it->name) {
|
SUBCASE(it->name) {
|
||||||
libantelope::ec_pubkey_t result = { 0x0 };
|
libeosio::ec_pubkey_t result = { 0x0 };
|
||||||
|
|
||||||
CHECK( libantelope::wif_pub_decode(result, it->key) == it->expectedRet );
|
CHECK( libeosio::wif_pub_decode(result, it->key) == it->expectedRet );
|
||||||
CHECK( result == it->expected );
|
CHECK( result == it->expected );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#include <libantelope/WIF.hpp>
|
#include <libeosio/WIF.hpp>
|
||||||
#include <libantelope/ec.hpp>
|
#include <libeosio/ec.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <doctest.h>
|
#include <doctest.h>
|
||||||
|
|
@ -8,20 +8,20 @@ TEST_CASE("WIF::wif_pub_encode [legacy]") {
|
||||||
struct testcase {
|
struct testcase {
|
||||||
std::string name;
|
std::string name;
|
||||||
const std::string prefix;
|
const std::string prefix;
|
||||||
libantelope::ec_pubkey_t key;
|
libeosio::ec_pubkey_t key;
|
||||||
std::string expected;
|
std::string expected;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<struct testcase> tests {
|
std::vector<struct testcase> tests {
|
||||||
{ "one", libantelope::WIF_PUB_LEG, { 0x03, 0x7a, 0x0e, 0x6b, 0xfd, 0xe4, 0xf1, 0xad, 0x36, 0x3f, 0x3a, 0xf9, 0xe0, 0x93, 0x63, 0x5a, 0xa9, 0x99, 0x21, 0x15, 0xbc, 0x23, 0x35, 0x75, 0x13, 0x69, 0x55, 0xee, 0x3f, 0xf8, 0xfd, 0x97, 0xec }, "EOS7kzJ5iFBmQWWT1LiWgAiocESD7TTNuuPCdYREUQysruq8VeFKy" },
|
{ "one", libeosio::WIF_PUB_LEG, { 0x03, 0x7a, 0x0e, 0x6b, 0xfd, 0xe4, 0xf1, 0xad, 0x36, 0x3f, 0x3a, 0xf9, 0xe0, 0x93, 0x63, 0x5a, 0xa9, 0x99, 0x21, 0x15, 0xbc, 0x23, 0x35, 0x75, 0x13, 0x69, 0x55, 0xee, 0x3f, 0xf8, 0xfd, 0x97, 0xec }, "EOS7kzJ5iFBmQWWT1LiWgAiocESD7TTNuuPCdYREUQysruq8VeFKy" },
|
||||||
{ "two", libantelope::WIF_PUB_LEG, { 0x02, 0x5e, 0x94, 0xa5, 0xe7, 0x9f, 0x66, 0x37, 0x55, 0x7e, 0xc2, 0x28, 0x30, 0x40, 0x82, 0x9a, 0x38, 0x72, 0x10, 0x96, 0x6e, 0x15, 0xb7, 0xa5, 0x8a, 0x27, 0x9a, 0x71, 0x06, 0xa7, 0x64, 0x23, 0x30 }, "EOS5c9HkNCJLDebe2Wvapp8bpB38Pf1QWNpkrsFy3mshg7DZfPNeA" },
|
{ "two", libeosio::WIF_PUB_LEG, { 0x02, 0x5e, 0x94, 0xa5, 0xe7, 0x9f, 0x66, 0x37, 0x55, 0x7e, 0xc2, 0x28, 0x30, 0x40, 0x82, 0x9a, 0x38, 0x72, 0x10, 0x96, 0x6e, 0x15, 0xb7, 0xa5, 0x8a, 0x27, 0x9a, 0x71, 0x06, 0xa7, 0x64, 0x23, 0x30 }, "EOS5c9HkNCJLDebe2Wvapp8bpB38Pf1QWNpkrsFy3mshg7DZfPNeA" },
|
||||||
{ "three", libantelope::WIF_PUB_LEG, { 0x03, 0xd4, 0xc6, 0x2a, 0xdc, 0x11, 0x1c, 0x65, 0x7a, 0x9f, 0x5b, 0xba, 0x96, 0x3f, 0xbb, 0x2a, 0x69, 0x2e, 0xc5, 0x4a, 0x48, 0x3b, 0xa3, 0x5f, 0x2a, 0x37, 0x6c, 0x59, 0x95, 0xb1, 0x95, 0x1c, 0xc9 }, "EOS8SwZMY8DChbbmRKS3wdHCAbv1VWgTRmQEDSaLyJk8pG4wm8BJF" }
|
{ "three", libeosio::WIF_PUB_LEG, { 0x03, 0xd4, 0xc6, 0x2a, 0xdc, 0x11, 0x1c, 0x65, 0x7a, 0x9f, 0x5b, 0xba, 0x96, 0x3f, 0xbb, 0x2a, 0x69, 0x2e, 0xc5, 0x4a, 0x48, 0x3b, 0xa3, 0x5f, 0x2a, 0x37, 0x6c, 0x59, 0x95, 0xb1, 0x95, 0x1c, 0xc9 }, "EOS8SwZMY8DChbbmRKS3wdHCAbv1VWgTRmQEDSaLyJk8pG4wm8BJF" }
|
||||||
};
|
};
|
||||||
|
|
||||||
for(auto it = tests.begin(); it != tests.end(); it++) {
|
for(auto it = tests.begin(); it != tests.end(); it++) {
|
||||||
|
|
||||||
SUBCASE(it->name.c_str()) {
|
SUBCASE(it->name.c_str()) {
|
||||||
CHECK( libantelope::wif_pub_encode(it->key, it->prefix) == it->expected );
|
CHECK( libeosio::wif_pub_encode(it->key, it->prefix) == it->expected );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -30,7 +30,7 @@ TEST_CASE("WIF::wif_pub_encode [custom prefix]") {
|
||||||
|
|
||||||
struct testcase {
|
struct testcase {
|
||||||
std::string name;
|
std::string name;
|
||||||
libantelope::ec_pubkey_t key;
|
libeosio::ec_pubkey_t key;
|
||||||
std::string expected;
|
std::string expected;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -43,7 +43,7 @@ TEST_CASE("WIF::wif_pub_encode [custom prefix]") {
|
||||||
for(auto it = tests.begin(); it != tests.end(); it++) {
|
for(auto it = tests.begin(); it != tests.end(); it++) {
|
||||||
|
|
||||||
SUBCASE(it->name.c_str()) {
|
SUBCASE(it->name.c_str()) {
|
||||||
CHECK( libantelope::wif_pub_encode(it->key, "ZYX") == it->expected );
|
CHECK( libeosio::wif_pub_encode(it->key, "ZYX") == it->expected );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -52,20 +52,20 @@ TEST_CASE("WIF::wif_pub_encode [k1]") {
|
||||||
struct testcase {
|
struct testcase {
|
||||||
std::string name;
|
std::string name;
|
||||||
const std::string prefix;
|
const std::string prefix;
|
||||||
libantelope::ec_pubkey_t key;
|
libeosio::ec_pubkey_t key;
|
||||||
std::string expected;
|
std::string expected;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<struct testcase> tests {
|
std::vector<struct testcase> tests {
|
||||||
{ "one", libantelope::WIF_PUB_K1, { 0x03, 0x7a, 0x0e, 0x6b, 0xfd, 0xe4, 0xf1, 0xad, 0x36, 0x3f, 0x3a, 0xf9, 0xe0, 0x93, 0x63, 0x5a, 0xa9, 0x99, 0x21, 0x15, 0xbc, 0x23, 0x35, 0x75, 0x13, 0x69, 0x55, 0xee, 0x3f, 0xf8, 0xfd, 0x97, 0xec }, "PUB_K1_7kzJ5iFBmQWWT1LiWgAiocESD7TTNuuPCdYREUQysruq7AxzWu" },
|
{ "one", libeosio::WIF_PUB_K1, { 0x03, 0x7a, 0x0e, 0x6b, 0xfd, 0xe4, 0xf1, 0xad, 0x36, 0x3f, 0x3a, 0xf9, 0xe0, 0x93, 0x63, 0x5a, 0xa9, 0x99, 0x21, 0x15, 0xbc, 0x23, 0x35, 0x75, 0x13, 0x69, 0x55, 0xee, 0x3f, 0xf8, 0xfd, 0x97, 0xec }, "PUB_K1_7kzJ5iFBmQWWT1LiWgAiocESD7TTNuuPCdYREUQysruq7AxzWu" },
|
||||||
{ "two", libantelope::WIF_PUB_K1, { 0x02, 0x5e, 0x94, 0xa5, 0xe7, 0x9f, 0x66, 0x37, 0x55, 0x7e, 0xc2, 0x28, 0x30, 0x40, 0x82, 0x9a, 0x38, 0x72, 0x10, 0x96, 0x6e, 0x15, 0xb7, 0xa5, 0x8a, 0x27, 0x9a, 0x71, 0x06, 0xa7, 0x64, 0x23, 0x30 }, "PUB_K1_5c9HkNCJLDebe2Wvapp8bpB38Pf1QWNpkrsFy3mshg7DViSUUa" },
|
{ "two", libeosio::WIF_PUB_K1, { 0x02, 0x5e, 0x94, 0xa5, 0xe7, 0x9f, 0x66, 0x37, 0x55, 0x7e, 0xc2, 0x28, 0x30, 0x40, 0x82, 0x9a, 0x38, 0x72, 0x10, 0x96, 0x6e, 0x15, 0xb7, 0xa5, 0x8a, 0x27, 0x9a, 0x71, 0x06, 0xa7, 0x64, 0x23, 0x30 }, "PUB_K1_5c9HkNCJLDebe2Wvapp8bpB38Pf1QWNpkrsFy3mshg7DViSUUa" },
|
||||||
{ "three", libantelope::WIF_PUB_K1, { 0x03, 0xd4, 0xc6, 0x2a, 0xdc, 0x11, 0x1c, 0x65, 0x7a, 0x9f, 0x5b, 0xba, 0x96, 0x3f, 0xbb, 0x2a, 0x69, 0x2e, 0xc5, 0x4a, 0x48, 0x3b, 0xa3, 0x5f, 0x2a, 0x37, 0x6c, 0x59, 0x95, 0xb1, 0x95, 0x1c, 0xc9 }, "PUB_K1_8SwZMY8DChbbmRKS3wdHCAbv1VWgTRmQEDSaLyJk8pG4wKBXpw" }
|
{ "three", libeosio::WIF_PUB_K1, { 0x03, 0xd4, 0xc6, 0x2a, 0xdc, 0x11, 0x1c, 0x65, 0x7a, 0x9f, 0x5b, 0xba, 0x96, 0x3f, 0xbb, 0x2a, 0x69, 0x2e, 0xc5, 0x4a, 0x48, 0x3b, 0xa3, 0x5f, 0x2a, 0x37, 0x6c, 0x59, 0x95, 0xb1, 0x95, 0x1c, 0xc9 }, "PUB_K1_8SwZMY8DChbbmRKS3wdHCAbv1VWgTRmQEDSaLyJk8pG4wKBXpw" }
|
||||||
};
|
};
|
||||||
|
|
||||||
for(auto it = tests.begin(); it != tests.end(); it++) {
|
for(auto it = tests.begin(); it != tests.end(); it++) {
|
||||||
|
|
||||||
SUBCASE(it->name.c_str()) {
|
SUBCASE(it->name.c_str()) {
|
||||||
CHECK( libantelope::wif_pub_encode(it->key, it->prefix) == it->expected );
|
CHECK( libeosio::wif_pub_encode(it->key, it->prefix) == it->expected );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#include <libantelope/WIF.hpp>
|
#include <libeosio/WIF.hpp>
|
||||||
#include <libantelope/ec.hpp>
|
#include <libeosio/ec.hpp>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <doctest.h>
|
#include <doctest.h>
|
||||||
|
|
||||||
|
|
@ -8,7 +8,7 @@ TEST_CASE("WIF::wif_sig_decode") {
|
||||||
struct testcase {
|
struct testcase {
|
||||||
const char *name;
|
const char *name;
|
||||||
std::string input;
|
std::string input;
|
||||||
libantelope::ec_signature_t expected;
|
libeosio::ec_signature_t expected;
|
||||||
bool expectedRet;
|
bool expectedRet;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -87,9 +87,9 @@ TEST_CASE("WIF::wif_sig_decode") {
|
||||||
|
|
||||||
for(auto it = tests.begin(); it != tests.end(); it++) {
|
for(auto it = tests.begin(); it != tests.end(); it++) {
|
||||||
SUBCASE(it->name) {
|
SUBCASE(it->name) {
|
||||||
libantelope::ec_signature_t result;
|
libeosio::ec_signature_t result;
|
||||||
|
|
||||||
CHECK( libantelope::wif_sig_decode(result, it->input) == it->expectedRet );
|
CHECK( libeosio::wif_sig_decode(result, it->input) == it->expectedRet );
|
||||||
|
|
||||||
if (it->expectedRet == true) {
|
if (it->expectedRet == true) {
|
||||||
CHECK( result == it->expected );
|
CHECK( result == it->expected );
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#include <libantelope/WIF.hpp>
|
#include <libeosio/WIF.hpp>
|
||||||
#include <libantelope/ec.hpp>
|
#include <libeosio/ec.hpp>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <doctest.h>
|
#include <doctest.h>
|
||||||
|
|
||||||
|
|
@ -7,7 +7,7 @@ TEST_CASE("WIF::wif_sig_encode") {
|
||||||
|
|
||||||
struct testcase {
|
struct testcase {
|
||||||
const char *name;
|
const char *name;
|
||||||
libantelope::ec_signature_t sig;
|
libeosio::ec_signature_t sig;
|
||||||
std::string expected;
|
std::string expected;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
@ -47,7 +47,7 @@ TEST_CASE("WIF::wif_sig_encode") {
|
||||||
|
|
||||||
for(auto it = tests.begin(); it != tests.end(); it++) {
|
for(auto it = tests.begin(); it != tests.end(); it++) {
|
||||||
SUBCASE(it->name) {
|
SUBCASE(it->name) {
|
||||||
CHECK( libantelope::wif_sig_encode(it->sig) == it->expected );
|
CHECK( libeosio::wif_sig_encode(it->sig) == it->expected );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#include <libantelope/base58.hpp>
|
#include <libeosio/base58.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <doctest.h>
|
#include <doctest.h>
|
||||||
|
|
@ -41,7 +41,7 @@ TEST_CASE("base58_decode") {
|
||||||
|
|
||||||
std::vector<unsigned char> expectedOut(it->expectedOut.begin(), it->expectedOut.end());
|
std::vector<unsigned char> expectedOut(it->expectedOut.begin(), it->expectedOut.end());
|
||||||
|
|
||||||
CHECK( libantelope::base58_decode(it->in, result) == it->expectedReturn );
|
CHECK( libeosio::base58_decode(it->in, result) == it->expectedReturn );
|
||||||
CHECK( result == expectedOut );
|
CHECK( result == expectedOut );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#include <libantelope/base58.hpp>
|
#include <libeosio/base58.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <doctest.h>
|
#include <doctest.h>
|
||||||
|
|
@ -28,7 +28,7 @@ TEST_CASE("base58::base58_encode") {
|
||||||
for(auto it = tests.begin(); it != tests.end(); it++) {
|
for(auto it = tests.begin(); it != tests.end(); it++) {
|
||||||
|
|
||||||
SUBCASE(it->name) {
|
SUBCASE(it->name) {
|
||||||
CHECK( libantelope::base58_encode(it->in) == it->expected );
|
CHECK( libeosio::base58_encode(it->in) == it->expected );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#include <libantelope/base58.hpp>
|
#include <libeosio/base58.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <doctest.h>
|
#include <doctest.h>
|
||||||
|
|
@ -23,7 +23,7 @@ TEST_CASE("base58::is_base58 [string]") {
|
||||||
for(auto it = tests.begin(); it != tests.end(); it++) {
|
for(auto it = tests.begin(); it != tests.end(); it++) {
|
||||||
|
|
||||||
SUBCASE(it->name) {
|
SUBCASE(it->name) {
|
||||||
CHECK(libantelope::is_base58(it->input) == it->expected);
|
CHECK(libeosio::is_base58(it->input) == it->expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -35,18 +35,18 @@ TEST_CASE("base58::is_base58 [char]") {
|
||||||
|
|
||||||
SUBCASE("valid") {
|
SUBCASE("valid") {
|
||||||
|
|
||||||
for(std::size_t i = 0; i < valid_alphabet.length(); i++) {
|
for(int i = 0; i < valid_alphabet.length(); i++) {
|
||||||
char ch = valid_alphabet[i];
|
char ch = valid_alphabet[i];
|
||||||
|
|
||||||
CHECK(libantelope::is_base58(ch));
|
CHECK(libeosio::is_base58(ch));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SUBCASE("invalid") {
|
SUBCASE("invalid") {
|
||||||
for(std::size_t i = 0; i < invalid_alphabet.length(); i++) {
|
for(int i = 0; i < invalid_alphabet.length(); i++) {
|
||||||
char ch = invalid_alphabet[i];
|
char ch = invalid_alphabet[i];
|
||||||
|
|
||||||
CHECK_FALSE(libantelope::is_base58(ch));
|
CHECK_FALSE(libeosio::is_base58(ch));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -22,15 +22,15 @@
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <libantelope/ec.hpp>
|
#include <libeosio/ec.hpp>
|
||||||
#include <libantelope/WIF.hpp>
|
#include <libeosio/WIF.hpp>
|
||||||
|
|
||||||
|
|
||||||
std::chrono::duration<float> _run(size_t num_keys) {
|
std::chrono::duration<float> _run(size_t num_keys) {
|
||||||
auto start = std::chrono::steady_clock::now();
|
auto start = std::chrono::steady_clock::now();
|
||||||
for(size_t i = 0; i < num_keys; i++) {
|
for(size_t i = 0; i < num_keys; i++) {
|
||||||
struct libantelope::ec_keypair k;
|
struct libeosio::ec_keypair k;
|
||||||
libantelope::ec_generate_key(&k);
|
libeosio::ec_generate_key(&k);
|
||||||
}
|
}
|
||||||
return std::chrono::steady_clock::now() - start;
|
return std::chrono::steady_clock::now() - start;
|
||||||
}
|
}
|
||||||
|
|
@ -48,13 +48,13 @@ void test(size_t num_keys) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
libantelope::ec_init();
|
libeosio::ec_init();
|
||||||
|
|
||||||
test(1000);
|
test(1000);
|
||||||
test(10000);
|
test(10000);
|
||||||
test(100000);
|
test(100000);
|
||||||
|
|
||||||
libantelope::ec_shutdown();
|
libeosio::ec_shutdown();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -1,189 +0,0 @@
|
||||||
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
||||||
# file Copyright.txt or https://cmake.org/licensing for details.
|
|
||||||
|
|
||||||
#[=======================================================================[.rst:
|
|
||||||
doctest
|
|
||||||
-----
|
|
||||||
|
|
||||||
This module defines a function to help use the doctest test framework.
|
|
||||||
|
|
||||||
The :command:`doctest_discover_tests` discovers tests by asking the compiled test
|
|
||||||
executable to enumerate its tests. This does not require CMake to be re-run
|
|
||||||
when tests change. However, it may not work in a cross-compiling environment,
|
|
||||||
and setting test properties is less convenient.
|
|
||||||
|
|
||||||
This command is intended to replace use of :command:`add_test` to register
|
|
||||||
tests, and will create a separate CTest test for each doctest test case. Note
|
|
||||||
that this is in some cases less efficient, as common set-up and tear-down logic
|
|
||||||
cannot be shared by multiple test cases executing in the same instance.
|
|
||||||
However, it provides more fine-grained pass/fail information to CTest, which is
|
|
||||||
usually considered as more beneficial. By default, the CTest test name is the
|
|
||||||
same as the doctest name; see also ``TEST_PREFIX`` and ``TEST_SUFFIX``.
|
|
||||||
|
|
||||||
.. command:: doctest_discover_tests
|
|
||||||
|
|
||||||
Automatically add tests with CTest by querying the compiled test executable
|
|
||||||
for available tests::
|
|
||||||
|
|
||||||
doctest_discover_tests(target
|
|
||||||
[TEST_SPEC arg1...]
|
|
||||||
[EXTRA_ARGS arg1...]
|
|
||||||
[WORKING_DIRECTORY dir]
|
|
||||||
[TEST_PREFIX prefix]
|
|
||||||
[TEST_SUFFIX suffix]
|
|
||||||
[PROPERTIES name1 value1...]
|
|
||||||
[ADD_LABELS value]
|
|
||||||
[TEST_LIST var]
|
|
||||||
[JUNIT_OUTPUT_DIR dir]
|
|
||||||
)
|
|
||||||
|
|
||||||
``doctest_discover_tests`` sets up a post-build command on the test executable
|
|
||||||
that generates the list of tests by parsing the output from running the test
|
|
||||||
with the ``--list-test-cases`` argument. This ensures that the full
|
|
||||||
list of tests is obtained. Since test discovery occurs at build time, it is
|
|
||||||
not necessary to re-run CMake when the list of tests changes.
|
|
||||||
However, it requires that :prop_tgt:`CROSSCOMPILING_EMULATOR` is properly set
|
|
||||||
in order to function in a cross-compiling environment.
|
|
||||||
|
|
||||||
Additionally, setting properties on tests is somewhat less convenient, since
|
|
||||||
the tests are not available at CMake time. Additional test properties may be
|
|
||||||
assigned to the set of tests as a whole using the ``PROPERTIES`` option. If
|
|
||||||
more fine-grained test control is needed, custom content may be provided
|
|
||||||
through an external CTest script using the :prop_dir:`TEST_INCLUDE_FILES`
|
|
||||||
directory property. The set of discovered tests is made accessible to such a
|
|
||||||
script via the ``<target>_TESTS`` variable.
|
|
||||||
|
|
||||||
The options are:
|
|
||||||
|
|
||||||
``target``
|
|
||||||
Specifies the doctest executable, which must be a known CMake executable
|
|
||||||
target. CMake will substitute the location of the built executable when
|
|
||||||
running the test.
|
|
||||||
|
|
||||||
``TEST_SPEC arg1...``
|
|
||||||
Specifies test cases, wildcarded test cases, tags and tag expressions to
|
|
||||||
pass to the doctest executable with the ``--list-test-cases`` argument.
|
|
||||||
|
|
||||||
``EXTRA_ARGS arg1...``
|
|
||||||
Any extra arguments to pass on the command line to each test case.
|
|
||||||
|
|
||||||
``WORKING_DIRECTORY dir``
|
|
||||||
Specifies the directory in which to run the discovered test cases. If this
|
|
||||||
option is not provided, the current binary directory is used.
|
|
||||||
|
|
||||||
``TEST_PREFIX prefix``
|
|
||||||
Specifies a ``prefix`` to be prepended to the name of each discovered test
|
|
||||||
case. This can be useful when the same test executable is being used in
|
|
||||||
multiple calls to ``doctest_discover_tests()`` but with different
|
|
||||||
``TEST_SPEC`` or ``EXTRA_ARGS``.
|
|
||||||
|
|
||||||
``TEST_SUFFIX suffix``
|
|
||||||
Similar to ``TEST_PREFIX`` except the ``suffix`` is appended to the name of
|
|
||||||
every discovered test case. Both ``TEST_PREFIX`` and ``TEST_SUFFIX`` may
|
|
||||||
be specified.
|
|
||||||
|
|
||||||
``PROPERTIES name1 value1...``
|
|
||||||
Specifies additional properties to be set on all tests discovered by this
|
|
||||||
invocation of ``doctest_discover_tests``.
|
|
||||||
|
|
||||||
``ADD_LABELS value``
|
|
||||||
Specifies if the test labels should be set automatically.
|
|
||||||
|
|
||||||
``TEST_LIST var``
|
|
||||||
Make the list of tests available in the variable ``var``, rather than the
|
|
||||||
default ``<target>_TESTS``. This can be useful when the same test
|
|
||||||
executable is being used in multiple calls to ``doctest_discover_tests()``.
|
|
||||||
Note that this variable is only available in CTest.
|
|
||||||
|
|
||||||
``JUNIT_OUTPUT_DIR dir``
|
|
||||||
If specified, the parameter is passed along with ``--reporters=junit``
|
|
||||||
and ``--out=`` to the test executable. The actual file name is the same
|
|
||||||
as the test target, including prefix and suffix. This should be used
|
|
||||||
instead of EXTRA_ARGS to avoid race conditions writing the XML result
|
|
||||||
output when using parallel test execution.
|
|
||||||
|
|
||||||
#]=======================================================================]
|
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
|
||||||
function(doctest_discover_tests TARGET)
|
|
||||||
cmake_parse_arguments(
|
|
||||||
""
|
|
||||||
""
|
|
||||||
"TEST_PREFIX;TEST_SUFFIX;WORKING_DIRECTORY;TEST_LIST;JUNIT_OUTPUT_DIR"
|
|
||||||
"TEST_SPEC;EXTRA_ARGS;PROPERTIES;ADD_LABELS"
|
|
||||||
${ARGN}
|
|
||||||
)
|
|
||||||
|
|
||||||
if(NOT _WORKING_DIRECTORY)
|
|
||||||
set(_WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
|
|
||||||
endif()
|
|
||||||
if(NOT _TEST_LIST)
|
|
||||||
set(_TEST_LIST ${TARGET}_TESTS)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
## Generate a unique name based on the extra arguments
|
|
||||||
string(SHA1 args_hash "${_TEST_SPEC} ${_EXTRA_ARGS}")
|
|
||||||
string(SUBSTRING ${args_hash} 0 7 args_hash)
|
|
||||||
|
|
||||||
# Define rule to generate test list for aforementioned test executable
|
|
||||||
set(ctest_include_file "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_include-${args_hash}.cmake")
|
|
||||||
set(ctest_tests_file "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_tests-${args_hash}.cmake")
|
|
||||||
get_property(crosscompiling_emulator
|
|
||||||
TARGET ${TARGET}
|
|
||||||
PROPERTY CROSSCOMPILING_EMULATOR
|
|
||||||
)
|
|
||||||
add_custom_command(
|
|
||||||
TARGET ${TARGET} POST_BUILD
|
|
||||||
BYPRODUCTS "${ctest_tests_file}"
|
|
||||||
COMMAND "${CMAKE_COMMAND}"
|
|
||||||
-D "TEST_TARGET=${TARGET}"
|
|
||||||
-D "TEST_EXECUTABLE=$<TARGET_FILE:${TARGET}>"
|
|
||||||
-D "TEST_EXECUTOR=${crosscompiling_emulator}"
|
|
||||||
-D "TEST_WORKING_DIR=${_WORKING_DIRECTORY}"
|
|
||||||
-D "TEST_SPEC=${_TEST_SPEC}"
|
|
||||||
-D "TEST_EXTRA_ARGS=${_EXTRA_ARGS}"
|
|
||||||
-D "TEST_PROPERTIES=${_PROPERTIES}"
|
|
||||||
-D "TEST_ADD_LABELS=${_ADD_LABELS}"
|
|
||||||
-D "TEST_PREFIX=${_TEST_PREFIX}"
|
|
||||||
-D "TEST_SUFFIX=${_TEST_SUFFIX}"
|
|
||||||
-D "TEST_LIST=${_TEST_LIST}"
|
|
||||||
-D "TEST_JUNIT_OUTPUT_DIR=${_JUNIT_OUTPUT_DIR}"
|
|
||||||
-D "CTEST_FILE=${ctest_tests_file}"
|
|
||||||
-P "${_DOCTEST_DISCOVER_TESTS_SCRIPT}"
|
|
||||||
VERBATIM
|
|
||||||
)
|
|
||||||
|
|
||||||
file(WRITE "${ctest_include_file}"
|
|
||||||
"if(EXISTS \"${ctest_tests_file}\")\n"
|
|
||||||
" include(\"${ctest_tests_file}\")\n"
|
|
||||||
"else()\n"
|
|
||||||
" add_test(${TARGET}_NOT_BUILT-${args_hash} ${TARGET}_NOT_BUILT-${args_hash})\n"
|
|
||||||
"endif()\n"
|
|
||||||
)
|
|
||||||
|
|
||||||
if(NOT CMAKE_VERSION VERSION_LESS 3.10)
|
|
||||||
# Add discovered tests to directory TEST_INCLUDE_FILES
|
|
||||||
set_property(DIRECTORY
|
|
||||||
APPEND PROPERTY TEST_INCLUDE_FILES "${ctest_include_file}"
|
|
||||||
)
|
|
||||||
else()
|
|
||||||
# Add discovered tests as directory TEST_INCLUDE_FILE if possible
|
|
||||||
get_property(test_include_file_set DIRECTORY PROPERTY TEST_INCLUDE_FILE SET)
|
|
||||||
if(NOT ${test_include_file_set})
|
|
||||||
set_property(DIRECTORY
|
|
||||||
PROPERTY TEST_INCLUDE_FILE "${ctest_include_file}"
|
|
||||||
)
|
|
||||||
else()
|
|
||||||
message(FATAL_ERROR
|
|
||||||
"Cannot set more than one TEST_INCLUDE_FILE"
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
###############################################################################
|
|
||||||
|
|
||||||
set(_DOCTEST_DISCOVER_TESTS_SCRIPT
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}/doctestAddTests.cmake
|
|
||||||
)
|
|
||||||
|
|
@ -1,120 +0,0 @@
|
||||||
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
||||||
# file Copyright.txt or https://cmake.org/licensing for details.
|
|
||||||
|
|
||||||
set(prefix "${TEST_PREFIX}")
|
|
||||||
set(suffix "${TEST_SUFFIX}")
|
|
||||||
set(spec ${TEST_SPEC})
|
|
||||||
set(extra_args ${TEST_EXTRA_ARGS})
|
|
||||||
set(properties ${TEST_PROPERTIES})
|
|
||||||
set(add_labels ${TEST_ADD_LABELS})
|
|
||||||
set(junit_output_dir "${TEST_JUNIT_OUTPUT_DIR}")
|
|
||||||
set(script)
|
|
||||||
set(suite)
|
|
||||||
set(tests)
|
|
||||||
|
|
||||||
function(add_command NAME)
|
|
||||||
set(_args "")
|
|
||||||
foreach(_arg ${ARGN})
|
|
||||||
if(_arg MATCHES "[^-./:a-zA-Z0-9_]")
|
|
||||||
set(_args "${_args} [==[${_arg}]==]") # form a bracket_argument
|
|
||||||
else()
|
|
||||||
set(_args "${_args} ${_arg}")
|
|
||||||
endif()
|
|
||||||
endforeach()
|
|
||||||
set(script "${script}${NAME}(${_args})\n" PARENT_SCOPE)
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
# Run test executable to get list of available tests
|
|
||||||
if(NOT EXISTS "${TEST_EXECUTABLE}")
|
|
||||||
message(FATAL_ERROR
|
|
||||||
"Specified test executable '${TEST_EXECUTABLE}' does not exist"
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if("${spec}" MATCHES .)
|
|
||||||
set(spec "--test-case=${spec}")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
execute_process(
|
|
||||||
COMMAND ${TEST_EXECUTOR} "${TEST_EXECUTABLE}" ${spec} --list-test-cases
|
|
||||||
OUTPUT_VARIABLE output
|
|
||||||
RESULT_VARIABLE result
|
|
||||||
WORKING_DIRECTORY "${TEST_WORKING_DIR}"
|
|
||||||
)
|
|
||||||
if(NOT ${result} EQUAL 0)
|
|
||||||
message(FATAL_ERROR
|
|
||||||
"Error running test executable '${TEST_EXECUTABLE}':\n"
|
|
||||||
" Result: ${result}\n"
|
|
||||||
" Output: ${output}\n"
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
string(REPLACE "\n" ";" output "${output}")
|
|
||||||
|
|
||||||
# Parse output
|
|
||||||
foreach(line ${output})
|
|
||||||
if("${line}" STREQUAL "===============================================================================" OR "${line}" MATCHES [==[^\[doctest\] ]==])
|
|
||||||
continue()
|
|
||||||
endif()
|
|
||||||
set(test ${line})
|
|
||||||
set(labels "")
|
|
||||||
if(${add_labels})
|
|
||||||
# get test suite that test belongs to
|
|
||||||
execute_process(
|
|
||||||
COMMAND ${TEST_EXECUTOR} "${TEST_EXECUTABLE}" --test-case=${test} --list-test-suites
|
|
||||||
OUTPUT_VARIABLE labeloutput
|
|
||||||
RESULT_VARIABLE labelresult
|
|
||||||
WORKING_DIRECTORY "${TEST_WORKING_DIR}"
|
|
||||||
)
|
|
||||||
if(NOT ${labelresult} EQUAL 0)
|
|
||||||
message(FATAL_ERROR
|
|
||||||
"Error running test executable '${TEST_EXECUTABLE}':\n"
|
|
||||||
" Result: ${labelresult}\n"
|
|
||||||
" Output: ${labeloutput}\n"
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
string(REPLACE "\n" ";" labeloutput "${labeloutput}")
|
|
||||||
foreach(labelline ${labeloutput})
|
|
||||||
if("${labelline}" STREQUAL "===============================================================================" OR "${labelline}" MATCHES [==[^\[doctest\] ]==])
|
|
||||||
continue()
|
|
||||||
endif()
|
|
||||||
list(APPEND labels ${labelline})
|
|
||||||
endforeach()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(NOT "${junit_output_dir}" STREQUAL "")
|
|
||||||
# turn testname into a valid filename by replacing all special characters with "-"
|
|
||||||
string(REGEX REPLACE "[/\\:\"|<>]" "-" test_filename "${test}")
|
|
||||||
set(TEST_JUNIT_OUTPUT_PARAM "--reporters=junit" "--out=${junit_output_dir}/${prefix}${test_filename}${suffix}.xml")
|
|
||||||
else()
|
|
||||||
unset(TEST_JUNIT_OUTPUT_PARAM)
|
|
||||||
endif()
|
|
||||||
# use escape commas to handle properly test cases with commas inside the name
|
|
||||||
string(REPLACE "," "\\," test_name ${test})
|
|
||||||
# ...and add to script
|
|
||||||
add_command(add_test
|
|
||||||
"${prefix}${test}${suffix}"
|
|
||||||
${TEST_EXECUTOR}
|
|
||||||
"${TEST_EXECUTABLE}"
|
|
||||||
"--test-case=${test_name}"
|
|
||||||
"${TEST_JUNIT_OUTPUT_PARAM}"
|
|
||||||
${extra_args}
|
|
||||||
)
|
|
||||||
add_command(set_tests_properties
|
|
||||||
"${prefix}${test}${suffix}"
|
|
||||||
PROPERTIES
|
|
||||||
WORKING_DIRECTORY "${TEST_WORKING_DIR}"
|
|
||||||
${properties}
|
|
||||||
LABELS ${labels}
|
|
||||||
)
|
|
||||||
unset(labels)
|
|
||||||
list(APPEND tests "${prefix}${test}${suffix}")
|
|
||||||
endforeach()
|
|
||||||
|
|
||||||
# Create a list of all discovered tests, which users may use to e.g. set
|
|
||||||
# properties on the tests
|
|
||||||
add_command(set ${TEST_LIST} ${tests})
|
|
||||||
|
|
||||||
# Write CTest script
|
|
||||||
file(WRITE "${CTEST_FILE}" "${script}")
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#include <libantelope/ec.hpp>
|
#include <libeosio/ec.hpp>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <doctest.h>
|
#include <doctest.h>
|
||||||
|
|
||||||
|
|
@ -6,9 +6,9 @@ TEST_CASE("ec::ecdsa_recover") {
|
||||||
|
|
||||||
struct testcase {
|
struct testcase {
|
||||||
const char *name;
|
const char *name;
|
||||||
libantelope::sha256_t dgst;
|
libeosio::sha256_t dgst;
|
||||||
libantelope::ec_signature_t sig;
|
libeosio::ec_signature_t sig;
|
||||||
libantelope::ec_pubkey_t expected;
|
libeosio::ec_pubkey_t expected;
|
||||||
int expectedRet;
|
int expectedRet;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -85,19 +85,19 @@ TEST_CASE("ec::ecdsa_recover") {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
libantelope::ec_init();
|
libeosio::ec_init();
|
||||||
|
|
||||||
for(auto it = tests.begin(); it != tests.end(); it++) {
|
for(auto it = tests.begin(); it != tests.end(); it++) {
|
||||||
SUBCASE(it->name) {
|
SUBCASE(it->name) {
|
||||||
libantelope::ec_pubkey_t result;
|
libeosio::ec_pubkey_t result;
|
||||||
|
|
||||||
CHECK( libantelope::ecdsa_recover(&it->dgst, it->sig, result) == it->expectedRet );
|
CHECK( libeosio::ecdsa_recover(&it->dgst, it->sig, result) == it->expectedRet );
|
||||||
|
|
||||||
if (it->expectedRet == 0) {
|
if (it->expectedRet == 0) {
|
||||||
CHECK( result == it->expected );
|
CHECK( result == it->expected );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
libantelope::ec_shutdown();
|
libeosio::ec_shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#include <libantelope/ec.hpp>
|
#include <libeosio/ec.hpp>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <doctest.h>
|
#include <doctest.h>
|
||||||
|
|
||||||
|
|
@ -6,9 +6,9 @@ TEST_CASE("ec::ecdsa_sign") {
|
||||||
|
|
||||||
struct testcase {
|
struct testcase {
|
||||||
const char *name;
|
const char *name;
|
||||||
libantelope::ec_privkey_t key;
|
libeosio::ec_privkey_t key;
|
||||||
libantelope::ec_pubkey_t pub;
|
libeosio::ec_pubkey_t pub;
|
||||||
libantelope::sha256_t dgst;
|
libeosio::sha256_t dgst;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<testcase> tests = {
|
std::vector<testcase> tests = {
|
||||||
|
|
@ -92,24 +92,24 @@ TEST_CASE("ec::ecdsa_sign") {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
libantelope::ec_init();
|
libeosio::ec_init();
|
||||||
|
|
||||||
for(auto it = tests.begin(); it != tests.end(); it++) {
|
for(auto it = tests.begin(); it != tests.end(); it++) {
|
||||||
SUBCASE(it->name) {
|
SUBCASE(it->name) {
|
||||||
libantelope::ec_signature_t result;
|
libeosio::ec_signature_t result;
|
||||||
|
|
||||||
CHECK( libantelope::ecdsa_sign(it->key, &it->dgst, result) == 0 );
|
CHECK( libeosio::ecdsa_sign(it->key, &it->dgst, result) == 0 );
|
||||||
|
|
||||||
// Need to use verify here as different implemententations produces different signatures.
|
// Need to use verify here as different implemententations produces different signatures.
|
||||||
// (i have tested eosjs, eos-go and ofc libantelope)
|
// (i have tested eosjs, eos-go and ofc libeosio)
|
||||||
// However, the signatures are correct and can be validated by all implementations.
|
// However, the signatures are correct and can be validated by all implementations.
|
||||||
//
|
//
|
||||||
// Now, how do we know that ecdsa_verify is correct?
|
// Now, how do we know that ecdsa_verify is correct?
|
||||||
// well, in escdsa_verify.cpp there are tests that checks hardcoded signatures generated by different implementations and should be fine.
|
// well, in escdsa_verify.cpp there are tests that checks hardcoded signatures generated by different implementations and should be fine.
|
||||||
|
|
||||||
CHECK( libantelope::ecdsa_verify(&it->dgst, result, it->pub) == 0);
|
CHECK( libeosio::ecdsa_verify(&it->dgst, result, it->pub) == 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
libantelope::ec_shutdown();
|
libeosio::ec_shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#include <libantelope/ec.hpp>
|
#include <libeosio/ec.hpp>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <doctest.h>
|
#include <doctest.h>
|
||||||
|
|
||||||
|
|
@ -6,9 +6,9 @@ TEST_CASE("ec::ecdsa_verify") {
|
||||||
|
|
||||||
struct testcase {
|
struct testcase {
|
||||||
const char *name;
|
const char *name;
|
||||||
libantelope::sha256_t dgst;
|
libeosio::sha256_t dgst;
|
||||||
libantelope::ec_pubkey_t pubkey;
|
libeosio::ec_pubkey_t pubkey;
|
||||||
libantelope::ec_signature_t sig;
|
libeosio::ec_signature_t sig;
|
||||||
int expected;
|
int expected;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -176,14 +176,14 @@ TEST_CASE("ec::ecdsa_verify") {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
libantelope::ec_init();
|
libeosio::ec_init();
|
||||||
|
|
||||||
for(auto it = tests.begin(); it != tests.end(); it++) {
|
for(auto it = tests.begin(); it != tests.end(); it++) {
|
||||||
SUBCASE(it->name) {
|
SUBCASE(it->name) {
|
||||||
CHECK( libantelope::ecdsa_verify(&it->dgst, it->sig, it->pubkey) == it->expected );
|
CHECK( libeosio::ecdsa_verify(&it->dgst, it->sig, it->pubkey) == it->expected );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
libantelope::ec_shutdown();
|
libeosio::ec_shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,18 @@
|
||||||
#include <libantelope/ec.hpp>
|
#include <libeosio/ec.hpp>
|
||||||
#include <doctest.h>
|
#include <doctest.h>
|
||||||
|
|
||||||
TEST_CASE("ec::generate") {
|
TEST_CASE("ec::generate") {
|
||||||
|
|
||||||
libantelope::ec_init();
|
libeosio::ec_init();
|
||||||
|
|
||||||
libantelope::ec_pubkey_t result;
|
libeosio::ec_pubkey_t result;
|
||||||
libantelope::ec_keypair pair;
|
libeosio::ec_keypair pair;
|
||||||
CHECK(libantelope::ec_generate_key(&pair) == 0);
|
CHECK(libeosio::ec_generate_key(&pair) == 0);
|
||||||
|
|
||||||
// Can't test much because... well the private key should be random :)
|
// Can't test much because... well the private key should be random :)
|
||||||
// But alteast verify that the public key belongs to the private key.
|
// But alteast verify that the public key belongs to the private key.
|
||||||
CHECK(libantelope::ec_get_publickey(&pair.secret, &result) == 0);
|
CHECK(libeosio::ec_get_publickey(&pair.secret, &result) == 0);
|
||||||
CHECK( result == pair.pub );
|
CHECK( result == pair.pub );
|
||||||
|
|
||||||
libantelope::ec_shutdown();
|
libeosio::ec_shutdown();
|
||||||
}
|
}
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#include <libantelope/ec.hpp>
|
#include <libeosio/ec.hpp>
|
||||||
#include <libantelope/WIF.hpp>
|
#include <libeosio/WIF.hpp>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <doctest.h>
|
#include <doctest.h>
|
||||||
|
|
||||||
|
|
@ -8,8 +8,8 @@ TEST_CASE("ec::pubkey") {
|
||||||
|
|
||||||
struct testcase {
|
struct testcase {
|
||||||
std::string name;
|
std::string name;
|
||||||
libantelope::ec_privkey_t priv;
|
libeosio::ec_privkey_t priv;
|
||||||
libantelope::ec_pubkey_t expected;
|
libeosio::ec_pubkey_t expected;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<struct testcase> tests {
|
std::vector<struct testcase> tests {
|
||||||
|
|
@ -125,16 +125,16 @@ TEST_CASE("ec::pubkey") {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
libantelope::ec_init();
|
libeosio::ec_init();
|
||||||
|
|
||||||
for(auto it = tests.begin(); it != tests.end(); it++) {
|
for(auto it = tests.begin(); it != tests.end(); it++) {
|
||||||
|
|
||||||
SUBCASE(it->name.c_str()) {
|
SUBCASE(it->name.c_str()) {
|
||||||
libantelope::ec_pubkey_t result;
|
libeosio::ec_pubkey_t result;
|
||||||
CHECK( libantelope::ec_get_publickey(&it->priv, &result) == 0 );
|
CHECK( libeosio::ec_get_publickey(&it->priv, &result) == 0 );
|
||||||
CHECK( result == it->expected );
|
CHECK( result == it->expected );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
libantelope::ec_shutdown();
|
libeosio::ec_shutdown();
|
||||||
}
|
}
|
||||||
|
|
@ -1,118 +0,0 @@
|
||||||
#include <libantelope/hash/ripemd160.hpp>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
#include <testing.h>
|
|
||||||
|
|
||||||
TEST_CASE("hash::ripemd160::ripemd160") {
|
|
||||||
|
|
||||||
struct testcase {
|
|
||||||
const char *name;
|
|
||||||
std::string input;
|
|
||||||
libantelope::ripemd160_t expected;
|
|
||||||
bool valid;
|
|
||||||
};
|
|
||||||
|
|
||||||
std::vector<testcase> tests = {
|
|
||||||
{
|
|
||||||
"valid #1",
|
|
||||||
"Morbi at egestas risus. Praesent blandit pharetra urna, nec porttitor risus sodales eu. Cras et volutpat elit, porta dapibus ipsum. Donec facilisis, eros nec imperdiet tristique, purus eros malesuada neque, quis interdum nisl risus nec leo.",
|
|
||||||
{
|
|
||||||
0xd9, 0x6a, 0x48, 0xf8, 0x2b, 0x39, 0xa9, 0x9f,
|
|
||||||
0x22, 0xba, 0x3e, 0x01, 0x58, 0x5b, 0x15, 0xc7,
|
|
||||||
0x7b, 0x0e, 0x5f, 0x50,
|
|
||||||
},
|
|
||||||
true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"valid #2",
|
|
||||||
"Donec eget mattis velit, vel vulputate sem. Suspendisse vulputate dolor vel est facilisis congue. Nulla non leo nulla. Proin lorem elit, sagittis eget congue in, pellentesque sed nisi. In pulvinar tortor fermentum suscipit varius.",
|
|
||||||
{
|
|
||||||
0x87, 0x1b, 0x87, 0xde, 0x2e, 0xb6, 0x8b, 0xb6,
|
|
||||||
0xdc, 0x29, 0xe7, 0x40, 0xc3, 0xd1, 0x99, 0x42,
|
|
||||||
0xad, 0x1a, 0xe3, 0x57
|
|
||||||
},
|
|
||||||
true
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
for(auto it = tests.begin(); it != tests.end(); it++) {
|
|
||||||
SUBCASE(it->name) {
|
|
||||||
libantelope::ripemd160_t dgst;
|
|
||||||
|
|
||||||
CHECK( libantelope::ripemd160((const unsigned char*) it->input.c_str(), it->input.size(), &dgst) == &dgst );
|
|
||||||
|
|
||||||
CHECK_PRED(doctest::toString(dgst), doctest::toString(it->expected), it->valid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("hash::ripemd160::init/update/final") {
|
|
||||||
|
|
||||||
struct testcase {
|
|
||||||
const char *name;
|
|
||||||
std::vector<std::string> inputs;
|
|
||||||
libantelope::ripemd160_t expected;
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
char _; // ripemd160_t can't be last, wierd compiler bug on MSVC
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
std::vector<testcase> tests = {
|
|
||||||
{
|
|
||||||
"valid #1",
|
|
||||||
{
|
|
||||||
"tortor in congue luctus, tortor sapien condimentum quam, ac congue enim lacus vitae erat. Mauris dapibus eros bibendum",
|
|
||||||
"Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
0x30, 0x77, 0xaf, 0x6b, 0x43, 0x0b, 0x94, 0x8d,
|
|
||||||
0x59, 0x4e, 0xc7, 0xbb, 0x1a, 0x2b, 0xc3, 0x08,
|
|
||||||
0xaa, 0xf0, 0x75, 0x3a
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"valid #2",
|
|
||||||
{
|
|
||||||
"Cras suscipit, mi sit amet pretium blandit, massa felis aliquet eros",
|
|
||||||
"Aenean efficitur nibh quis enim mollis blandit",
|
|
||||||
"Vestibulum posuere tempus mi nec cursus"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
0xf1, 0xcf, 0xea, 0xf7, 0xef, 0x3a, 0x0f, 0x80,
|
|
||||||
0x26, 0x75, 0x40, 0x75, 0xe0, 0x9d, 0x89, 0x05,
|
|
||||||
0xd1, 0x29, 0xe5, 0xf6
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"valid #3",
|
|
||||||
{
|
|
||||||
"Donec nec blandit dui. Nulla et tempus odio, id fermentum neque. Nam vitae nunc leo. Aliquam dictum velit nec neque dignissim maximus nec at tellus",
|
|
||||||
"Proin elementum porttitor odio, ut ullamcorper justo rutrum in. Proin dignissim nec diam a eleifend. Duis consequat ultrices purus sed finibus",
|
|
||||||
"Donec eget ante dictum, scelerisque metus eget, mollis velit. Curabitur elementum fermentum lorem, a fringilla velit ultrices non"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
0xbb, 0x25, 0x58, 0xa9, 0xd0, 0xc1, 0x23, 0xef,
|
|
||||||
0x55, 0xac, 0x2d, 0x8c, 0xd5, 0xd6, 0xe1, 0x49,
|
|
||||||
0x00, 0x5d, 0x86, 0xe8
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
for(auto it = tests.begin(); it != tests.end(); it++) {
|
|
||||||
SUBCASE(it->name) {
|
|
||||||
libantelope::ripemd160_ctx_t ctx;
|
|
||||||
libantelope::ripemd160_t dgst;
|
|
||||||
|
|
||||||
CHECK_EQ(libantelope::ripemd160_init(&ctx), 1);
|
|
||||||
|
|
||||||
for (auto in_it = it->inputs.begin(); in_it != it->inputs.end(); in_it++ ) {
|
|
||||||
CHECK_EQ(libantelope::ripemd160_update(&ctx, (const unsigned char*) in_it->c_str(), in_it->size()), 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
CHECK_EQ(libantelope::ripemd160_final(&ctx, &dgst), 1);
|
|
||||||
|
|
||||||
CHECK( doctest::toString(dgst) == doctest::toString(it->expected) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,180 +0,0 @@
|
||||||
#include <libantelope/hash/sha256.hpp>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
#include <testing.h>
|
|
||||||
|
|
||||||
TEST_CASE("hash::sha256::sha256") {
|
|
||||||
|
|
||||||
struct testcase {
|
|
||||||
const char *name;
|
|
||||||
std::string input;
|
|
||||||
libantelope::sha256_t expected;
|
|
||||||
bool valid;
|
|
||||||
};
|
|
||||||
|
|
||||||
std::vector<testcase> tests = {
|
|
||||||
{
|
|
||||||
"valid #1",
|
|
||||||
"Suspendisse ut tincidunt quam. Praesent scelerisque risus vitae est consectetur, sed facilisis sem luctus. Praesent aliquet eros quis leo sodales, eget blandit diam scelerisque.",
|
|
||||||
{
|
|
||||||
0x1e, 0x54, 0x96, 0x86, 0x2f, 0x39, 0x44, 0xea,
|
|
||||||
0x42, 0xa9, 0x0f, 0xad, 0x56, 0x79, 0x4b, 0x77,
|
|
||||||
0x8f, 0xcc, 0x54, 0xf7, 0x7a, 0x32, 0x60, 0x37,
|
|
||||||
0x4b, 0xac, 0xd5, 0x65, 0x74, 0xf7, 0xcf, 0x6c
|
|
||||||
},
|
|
||||||
true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"valid #2",
|
|
||||||
"Phasellus consectetur augue vitae massa vulputate placerat. Pellentesque nec eros a velit bibendum venenatis sit amet et augue. Morbi malesuada facilisis consequat.",
|
|
||||||
{
|
|
||||||
0x7c, 0x79, 0x4a, 0xf4, 0x9b, 0x5b, 0xb4, 0x0c,
|
|
||||||
0xef, 0x4f, 0xaa, 0x65, 0xa4, 0x7c, 0x5f, 0xc5,
|
|
||||||
0x95, 0x69, 0x49, 0x99, 0x6b, 0x08, 0x9b, 0xc0,
|
|
||||||
0x40, 0x2d, 0x57, 0x8a, 0x90, 0x02, 0x42, 0x32,
|
|
||||||
},
|
|
||||||
true
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
for(auto it = tests.begin(); it != tests.end(); it++) {
|
|
||||||
SUBCASE(it->name) {
|
|
||||||
libantelope::sha256_t dgst;
|
|
||||||
|
|
||||||
CHECK( libantelope::sha256((const unsigned char*) it->input.c_str(), it->input.size(), &dgst) == &dgst );
|
|
||||||
|
|
||||||
CHECK_PRED(doctest::toString(dgst), doctest::toString(it->expected), it->valid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("hash::sha256::sha256d") {
|
|
||||||
|
|
||||||
struct testcase {
|
|
||||||
const char *name;
|
|
||||||
std::string input;
|
|
||||||
libantelope::sha256_t expected;
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
char _; // sha256_t can't be last, wierd compiler bug on MSVC
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
std::vector<testcase> tests = {
|
|
||||||
{
|
|
||||||
"valid #1",
|
|
||||||
"Suspendisse ut tincidunt quam. Praesent scelerisque risus vitae est consectetur, sed facilisis sem luctus. Praesent aliquet eros quis leo sodales, eget blandit diam scelerisque.",
|
|
||||||
{
|
|
||||||
0x4b, 0x6f, 0xa1, 0xf6, 0x30, 0x1e, 0xbe, 0x4a,
|
|
||||||
0xc7, 0xef, 0x1e, 0x55, 0x3e, 0xdb, 0xc1, 0x31,
|
|
||||||
0x1f, 0x6b, 0xf5, 0xc8, 0x04, 0xe9, 0x0e, 0xe3,
|
|
||||||
0xbe, 0x66, 0x01, 0xbf, 0x70, 0x9f, 0x8e, 0x80,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"valid #2",
|
|
||||||
"Vivamus ut elementum justo. Vestibulum lobortis rutrum libero sollicitudin aliquet. Nullam tempor urna non odio iaculis, sed pretium quam porttitor. Pellentesque pretium, justo vitae tristique porttitor, diam massa pulvinar neque, sed lacinia mi nulla sed nisi.",
|
|
||||||
{
|
|
||||||
0x1f, 0x3f, 0x1c, 0x48, 0xf6, 0xee, 0x24, 0x1f,
|
|
||||||
0x6c, 0x41, 0x86, 0x69, 0xe3, 0x2f, 0x5e, 0x4d,
|
|
||||||
0xa5, 0x51, 0x04, 0x8b, 0x11, 0x35, 0x47, 0xad,
|
|
||||||
0x7e, 0xd9, 0xfb, 0x2e, 0x59, 0xee, 0x66, 0x21,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"valid #3",
|
|
||||||
"Praesent ultrices consequat risus luctus faucibus.",
|
|
||||||
{
|
|
||||||
0xd5, 0x5f, 0x9c, 0xda, 0x2d, 0x93, 0x32, 0xc2,
|
|
||||||
0x9b, 0xb1, 0xbb, 0x14, 0x55, 0x80, 0x72, 0xb7,
|
|
||||||
0xba, 0x13, 0xa8, 0xc6, 0xa6, 0xbc, 0x65, 0xfc,
|
|
||||||
0x49, 0xe0, 0x3b, 0x23, 0x04, 0x2a, 0x92, 0x8d,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
for(auto it = tests.begin(); it != tests.end(); it++) {
|
|
||||||
SUBCASE(it->name) {
|
|
||||||
libantelope::sha256_t dgst;
|
|
||||||
|
|
||||||
CHECK( libantelope::sha256d((const unsigned char*) it->input.c_str(), it->input.size(), &dgst) == &dgst );
|
|
||||||
|
|
||||||
CHECK( doctest::toString(dgst) == doctest::toString(it->expected) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("hash::sha256::init/update/final") {
|
|
||||||
|
|
||||||
struct testcase {
|
|
||||||
const char *name;
|
|
||||||
std::vector<std::string> inputs;
|
|
||||||
libantelope::sha256_t expected;
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
char _; // sha256_t can't be last, wierd compiler bug on MSVC
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
std::vector<testcase> tests = {
|
|
||||||
{
|
|
||||||
"valid #1",
|
|
||||||
{
|
|
||||||
"Donec vestibulum enim commodo, faucibus nisi non, mattis quam.",
|
|
||||||
"Nam sed nunc dapibus, auctor risus placerat, aliquet dolor",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
0x48, 0xc2, 0x34, 0x93, 0x3d, 0xae, 0x0d, 0xd0,
|
|
||||||
0x28, 0xff, 0x5c, 0xa0, 0xca, 0xb1, 0x0a, 0xa3,
|
|
||||||
0xe2, 0xa0, 0xa4, 0x7e, 0xb2, 0x71, 0xa5, 0x28,
|
|
||||||
0x41, 0x03, 0x72, 0x20, 0xb5, 0x23, 0xc3, 0x67,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"valid #2",
|
|
||||||
{
|
|
||||||
"In tempus, lectus ac molestie venenatis, enim purus suscipit tortor",
|
|
||||||
"sed sodales massa condimentum a",
|
|
||||||
"Integer sit amet pretium magna",
|
|
||||||
"Aenean non accumsan eros. Donec imperdiet justo tempor magna tincidunt malesuada",
|
|
||||||
"Duis eu tortor ac massa sagittis elementum"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
0xfb, 0x12, 0x31, 0x9c, 0x2c, 0xe4, 0x94, 0x29,
|
|
||||||
0xc9, 0xd3, 0xc7, 0x84, 0x0c, 0x58, 0x3d, 0x4c,
|
|
||||||
0xde, 0xb5, 0x36, 0x59, 0x46, 0x69, 0xe1, 0x63,
|
|
||||||
0xc5, 0x75, 0xb6, 0x94, 0x41, 0x5a, 0xd4, 0x62,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"valid #3",
|
|
||||||
{
|
|
||||||
"Donec tempus pellentesque lobortis. Integer pellentesque feugiat enim ac suscipit. Curabitur urna quam, condimentum sed bibendum eu",
|
|
||||||
"Nullam lacinia ligula at ex gravida fermentum. Integer scelerisque accumsan iaculis. Suspendisse quis eros ut orci sollicitudin dignissim",
|
|
||||||
"Nulla ligula tortor, tristique eget feugiat non, vehicula sit amet velit. Proin fermentum sagittis tincidunt. Nullam condimentum dapibus magna",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
0x19, 0xfb, 0x71, 0xb1, 0x47, 0x01, 0x7f, 0xf5,
|
|
||||||
0xeb, 0xda, 0xc2, 0xd8, 0xe7, 0xab, 0xc9, 0xcb,
|
|
||||||
0xea, 0x7d, 0x13, 0xa0, 0x2e, 0xe8, 0x48, 0x94,
|
|
||||||
0x67, 0xc5, 0x14, 0xbf, 0x7d, 0x6f, 0x96, 0x83,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
for(auto it = tests.begin(); it != tests.end(); it++) {
|
|
||||||
SUBCASE(it->name) {
|
|
||||||
libantelope::sha256_ctx_t ctx;
|
|
||||||
libantelope::sha256_t dgst;
|
|
||||||
|
|
||||||
CHECK_EQ(libantelope::sha256_init(&ctx), 1);
|
|
||||||
|
|
||||||
for (auto in_it = it->inputs.begin(); in_it != it->inputs.end(); in_it++ ) {
|
|
||||||
CHECK_EQ(libantelope::sha256_update(&ctx, (const unsigned char*) in_it->c_str(), in_it->size()), 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
CHECK_EQ(libantelope::sha256_final(&ctx, &dgst), 1);
|
|
||||||
|
|
||||||
CHECK( doctest::toString(dgst) == doctest::toString(it->expected) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
#ifndef LIBANTELOPE_TESTING_H
|
|
||||||
#define LIBANTELOPE_TESTING_H
|
|
||||||
|
|
||||||
#include <doctest.h>
|
|
||||||
|
|
||||||
#define CHECK_PRED(a,b,pred) if (pred) { CHECK_EQ((a), (b)); } else { CHECK_NE((a), (b)); }
|
|
||||||
|
|
||||||
#endif /* LIBANTELOPE_TESTING_H */
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue