Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/Safeheron/tss-rsa-cpp

A library for tss-rsa according to paper Practical Threshold Signatures.
https://github.com/Safeheron/tss-rsa-cpp

Last synced: about 2 months ago
JSON representation

A library for tss-rsa according to paper Practical Threshold Signatures.

Awesome Lists containing this project

README

        

# tss-rsa-cpp

![img](doc/logo.png)

This software implements a library for tss-rsa according to paper [Practical Threshold Signatures](https://www.iacr.org/archive/eurocrypt2000/1807/18070209-new.pdf).

The library comes with serialize/deserialize support to be used in higher level code to implement networking.

# Prerequisites

- [OpenSSL](https://github.com/openssl/openssl#documentation). See the [OpenSSL Installation Instructions](./doc/OpenSSL-Installation.md)
- [Protocol Buffers](https://github.com/protocolbuffers/protobuf.git). See the [Protocol Buffers Installation Instructions](./doc/Protocol-Buffers-Installation.md)
- [crypto-suites-cpp](https://github.com/safeheron/crypto-suites-cpp.git). See the [crypto-suites-cpp Installation Instructions](https://github.com/safeheron/crypto-suites-cpp/blob/main/README.md#build-and-install). **Version v0.8.0 or later required**.

# Build and Install

Linux and Mac are supported now. After obtaining the Source, have a look at the installation script.

```shell
git clone https://github.com/safeheron/tss-rsa-cpp.git
cd tss-rsa-cpp
mkdir build && cd build
# Run "cmake .. -DOPENSSL_ROOT_DIR=Your-Root-Directory-of-OPENSSL" instead of the command below on Mac OS.
cmake .. -DENABLE_TESTS=ON
# Add the path to the LD_LIBRARY_PATH environment variable on Mac OS; Ignore it on Linux
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/lib/
make
make test
sudo make install
```

More platforms such as Windows would be supported soon.

# To start using crypto-tss-rsa-cpp

## CMake

CMake is your best option. It supports building on Linux, MacOS and Windows (soon) but also has a good chance of working on other platforms (no promises!). cmake has good support for crosscompiling and can be used for targeting the Android platform.

To build crypto-tss-rsa-cpp from source, follow the BUILDING guide.

The canonical way to discover dependencies in CMake is the find_package command.

```shell
project(XXXX)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_BUILD_TYPE "Release")

find_package(PkgConfig REQUIRED)
pkg_search_module(PROTOBUF REQUIRED protobuf) # this looks for *.pc file
#set(OPENSSL_USE_STATIC_LIBS TRUE)
find_package(OpenSSL REQUIRED)
find_package(SafeheronCryptoSuites REQUIRED)
find_package(CryptoTSSRSA REQUIRED)

add_executable(${PROJECT_NAME} XXXX.cpp)
target_include_directories(${PROJECT_NAME} PUBLIC
${SafeheronCryptoSuites_INCLUDE_DIRS}
${CryptoTSSRSA_INCLUDE_DIRS}
${PROTOBUF_INCLUDE_DIRS}
)

target_link_libraries(${PROJECT_NAME} PUBLIC
SafeheronCryptoSuites
CryptoTSSRSA
OpenSSL::Crypto
${PROTOBUF_LINK_LIBRARIES}
pthread )
```

# Usage

It's an example where the key length is 1024, the number of parties is 3 and threshold is 2.
```c++
#include "crypto-bn/bn.h"
#include "exception/safeheron_exceptions.h"
#include "crypto-tss-rsa/tss_rsa.h"
#include "crypto-encode/hex.h"

using safeheron::bignum::BN;
using safeheron::tss_rsa::RSAPrivateKeyShare;
using safeheron::tss_rsa::RSAPublicKey;
using safeheron::tss_rsa::RSAKeyMeta;
using safeheron::tss_rsa::RSASigShare;
using safeheron::tss_rsa::KeyGenParam;
using safeheron::exception::LocatedException;
using safeheron::exception::OpensslException;
using safeheron::exception::BadAllocException;
using safeheron::exception::RandomSourceException;

int main(int argc, char **argv) {
std::string json_str;
std::string doc("12345678123456781234567812345678");

// Key Generation
int key_bits_length = 1024;
int k = 2;
int l = 3;
std::vector priv_arr;
RSAPublicKey pub;
RSAKeyMeta key_meta;
bool status = safeheron::tss_rsa::GenerateKey(key_bits_length, l, k, priv_arr, pub, key_meta);
key_meta.ToJsonString(json_str);
std::cout << "key meta data: " << json_str << std::endl;

pub.ToJsonString(json_str);
std::cout << "public key: " << json_str << std::endl;

priv_arr[0].ToJsonString(json_str);
std::cout << "private key share 1: " << json_str << std::endl;
priv_arr[2].ToJsonString(json_str);
std::cout << "private key share 3: " << json_str << std::endl;

// Prepare
std::string doc_pss = safeheron::tss_rsa::EncodeEMSA_PSS(doc, key_bits_length, safeheron::tss_rsa::SaltLength::AutoLength);
std::cout << "doc_pss: " << safeheron::encode::hex::EncodeToHex(doc) << std::endl;
// Party 1 sign.
RSASigShare sig_share0 = priv_arr[0].Sign(doc_pss, key_meta, pub);
sig_share0.ToJsonString(json_str);
std::cout << "signature share 1: " << json_str << std::endl;
// Party 3 sign.
RSASigShare sig_share2 = priv_arr[2].Sign(doc_pss, key_meta, pub);
sig_share2.ToJsonString(json_str);
std::cout << "signature share 3: " << json_str << std::endl;

// Combine signatures
// Distributed signature
std::vector sig_share_arr;
for(int i = 0; i < l; i++) {
sig_share_arr.emplace_back(priv_arr[i].Sign(doc_pss, key_meta, pub));
}
BN sig;
bool ok = safeheron::tss_rsa::CombineSignatures(doc_pss, sig_share_arr, pub, key_meta, sig);
std::cout << "succeed to sign: " << ok <