TerenceGe / sr25519-donna

Pure C implementation of schnorrkel algorithm (sr25519)
Apache License 2.0
17 stars 5 forks source link
cryptography polkadot schnorrkel sr25519

+title: sr25519-donna

This is a pure C implementation of polkadot's key derivation and signing algorithm [[https://wiki.polkadot.network/docs/en/learn-cryptography][schnorrkel]]. The goal is to fully compatible with the original [[https://github.com/w3f/schnorrkel][rust version]]. The curve operations are based on [[https://github.com/floodyberry/ed25519-donna][ed25519-donna]]. [[https://github.com/w3f/Grants-Program/blob/master/applications/index.md#%EF%B8%8F-wave-6---q2-2020][file:https://github.com/w3f/Grants-Program/blob/master/static/img/Grants_Program.png?raw=true]]

add_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.

+END_SRC

[[https://github.com/TerenceGe/sr25519-donna/blob/954fc1ff50aa919a05b23e28695dc92cab510467/example/CMakeLists.txt#L13][example]]

typedef struct VrfResult { Sr25519SignatureResult result; bool is_less; } VrfResult;

+END_SRC

** vrf keypair 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. \

| param | description | | keypair | the output uniform keypair, 96 bytes long | | seed | the input mini secret key, 32 bytes long |

+BEGIN_SRC C

void sr25519_uniform_keypair_from_seed(sr25519_keypair keypair, const sr25519_mini_secret_key seed);

+END_SRC

| param | description | | uniform_keypair | the output uniform keypair, 96 bytes long | | ed25519_keypair | the ed25519 compatible keypair, 96 bytes long |

+BEGIN_SRC C

void sr25519_keypair_ed25519_to_uniform(sr25519_keypair uniform_keypair, const sr25519_keypair ed25519_keypair);

+END_SRC

[[https://github.com/TerenceGe/sr25519-donna/blob/7dd704c0530e7aad50c7ec8e6069725f6124645a/example/src/main.c#L148][example]]