You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a pure C implementation of polkadot’s key derivation and signing algorithm schnorrkel. The goal is to fully compatible with the original rust version. The curve operations are based on ed25519-donna.
Compilation
Default Options
git clone [email protected]:apliedblockchain/sr25519-donna-sgx.git
cd sr25519-donna
mkdir build &&cd build
cmake .. -DCMAKE_INSTALL_PREFIX=. && make install # The options "-DCMAKE_INSTALL_PREFIX=." will install library in the build folder, you can change the location if you want.
Random Options
This library uses a build-in random number generator by default. To use a custom random function, add -DSR25519_CUSTOMRANDOM=true for cmake
cmake .. -DSR25519_CUSTOMRANDOM=true
put your custom random implementation in sr25519-randombytes-custom.h. The random function must implement:
voidsr25519_randombytes(void*p, size_tlen);
Hash Options
This library uses a build-in sha2 hash function by default. To use a custom hash function, add -DSR25519_CUSTOMHASH=true for cmake
cmake .. -DSR25519_CUSTOMRANDOM=true
put your custom random implementation in sr25519-hash-custom.h. The random function must implement:
This library supports both 32bit and 64bit curve operations, the default is according to your machine.
Add -DSR25519_FORCE_32BIT to force the use of 32 bit routines even when compiling for 64 bit.
cmake .. -DSR25519_FORCE_32BIT=true
Test
./sr25519DonnaTests
Integration
include_directories(../build/include/) # replace it with your sr25519-donna installed location if requiredlink_directories(../build/lib/) # replace it with your sr25519-donna installed location if requiredadd_executable(yourApp ${SOURCE_FILES})
target_link_libraries(yourApp libsr25519_donna.dylib) # replace it with libsr25519_donna_static.a if you want to use static lib.
output combination of vrf output (32 bytes long) and vrf proof (64 bytes long)
keypair
keypair for signing, it should be an uniform keypair instead of ed25519 compatible, you can generated by sr25519_uniform_keypair_from_seed or converted by sr25519_keypair_ed25519_to_uniform
message and message_length
message arrary and length
threshold
the vrf threshold, 16 bytes long, if the raw output bytes is less than threshold, the is_less field of result strcut will be true
the corresponding public key that signing the message
message and message_length
message arrary and length
output
the signature for the message
proof
the proof of the signature
threshold
the vrf threshold, 16 bytes long, if the raw output bytes is less than threshold, the is_less field of result structure will be true. If errors, is_less field of the returned structure is not meant to contain a valid value
By default, the sr25519_keypair_from_seed functon creates keypair that contains half ed25519 bytes (which is compatible with the wasm crypto lib), vrf requires the keypair is uniform. In this case, you can use sr25519_uniform_keypair_from_seed for keypair creating or sr25519_keypair_ed25519_to_uniform for converting.