Skip to content

Rust zero-alloc FFI library for crypto wallets generation

Notifications You must be signed in to change notification settings

Sssilencee/ksgen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

[ksgen] - Rust FFI library for crypto wallets generation

Supporting chains such as Bitcoin, Litecoin, EVM-based networks, Solana, Tron, and Move chains like Sui and Aptos. Accepts a password as an argument and provides an address and a secret key encrypted in Ethereum keystore format. The library is almost zero-alloc; it makes allocations only in error cases.

[installation]

  • Build the Rust library for the needed chains (available features: [aptos, bitcoin, ethereum, litecoin, solana, sui, tron]).
cargo build --features ethereum
  • Include the examples/c-ksgen/ksgen.h file to interoperate with ksgen via the C ABI or write your own. Don’t forget to link the library.

[C]

#include "ksgen.h"
gcc ksgen.c ../target/release/libksgen.a -o ksgen

[Go]

/*
#cgo LDFLAGS: -L ../../target/release -l ksgen
#include "../c-ksgen/ksgen.h"
*/
import "C"

[output]

typedef struct sized_str
{
    char *str;
    usize len;
} sized_str;

typedef struct cipherparams
{
    sized_str iv;
} cipherparams;

typedef struct kdfparams
{
    usize *dklen;
    u32 *n;
    u32 *r;
    u32 *p;
    sized_str salt;
} kdfparams;

typedef struct keystore
{
    sized_str cipher;
    cipherparams cipherparams;
    sized_str ciphertext;
    sized_str kdf;
    kdfparams kdfparams;
    sized_str mac;
} keystore;

[description]

  • cipher — all minimally-compliant implementations must support the “AES-128-CTR”
  • cipherparams (iv) — a 128-bit initial vector for the cipher
  • ciphertext — the password-encrypted secret key
  • kdf — key derivation function. Ethereum usually uses Scrypt or PBKDF2-SHA-256 hash functions, but this library supports only Scrypt
  • kdfparams
    • dklen — the output key len (bytes)
    • n — iterations count (affects memory and CPU usage). Sometimes can be a log₂ of n. For example, 13 = log₂(8192)
    • r — block size (affects memory and CPU usage)
    • p — parallelism, threads count (affects memory and CPU usage), usually is 1
    • salt — randomly generated bytes (64 bits minimum, 128 bits recommended)
  • mac — Keccak256 hash of a concatenated [..16] slice of the derived key and full ciphertext

About

Rust zero-alloc FFI library for crypto wallets generation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published