#generate-keys #key #secret-key #primitive #hash #key-derivation #cryptonote

cryptonote-raw-crypto

Cryptography Primitives for Cryptonote

16 unstable releases (3 breaking)

0.5.7 Nov 6, 2019
0.5.6 Oct 30, 2019
0.5.2 Sep 23, 2019
0.4.0 Sep 16, 2019
0.1.4 Apr 17, 2019

#1 in #cryptonote

Download history 4/week @ 2024-02-18 64/week @ 2024-02-25 2/week @ 2024-03-03 5/week @ 2024-03-10

75 downloads per month
Used in cryptonote-wallet

GPL-3.0-or-later

5MB
11K SLoC

C 10K SLoC // 0.1% comments Rust 1K SLoC // 0.0% comments C++ 193 SLoC // 0.0% comments

raw-crypto Library For CryptoNote Based Crypto Currencies

codecov

Intro

Raw Crypto Library is to provide crypto implementations in C/C++ with rust. Currently the library has implemented all hash functions provided by the cryptonote foundation in it's referential coin forging code base.

Now this library provide the follow interfaces:

  1. Hash
    Hash::slow -> cn_slow_hash
    Hash::fast -> cn_fast_hash
    Hash::check_with_difficulty -> cryptonote::check_hash

  2. Chacha(with ChachaKey, ChachaIV generators)
    Chacha::generate -> chacha8

  3. Key
    Key::generate_private_key -> generate_private_key
    Key::secret_to_public -> secret_key_to_public_key
    Key::generate_key_pair -> generate_keys
    Key::check_public_key -> check_public_key
    Key::generate_key_derivation -> generate_key_derivation
    Key::derive_public_key -> derive_public_key
    Key::underive_public_key -> underive_public_key
    Key::derive_secret_key -> derive_secret_key
    Key::generate_signature -> generate_signature
    Key::check_signature -> check_signature
    Key::generate_key_image -> generate_key_image

  4. Ring
    Ring::generate_signature -> generate_ring_signature Ring::check_signature -> check_ring_signature

  5. Scalars
    EllipticCurveScalar::random -> random_scalar
    EllipticCurveScalar::check -> check_scalar
    EllipticCurveScalar::to_hash -> hash_to_scalar
    EllipticCurveScalar::from_hash -> hash_to_ec
    EllipticCurvePoint::from_hash -> hash_to_point

Usage

Usage can be found in tests.

    // Generate key
    let key = ChachaKey::generate(String::from(""));

    // Generate iv
    let iv = ChachaIV::from([0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18]);

    // Generate chacha object
    let chacha = Chacha::new(key, iv);

    // Prepare plain text
    let plain = *b"hello world!";

    // Encrypt with chacha8
    let cipher = chacha.encrypt(&plain[..]);

    // Encrypt again will get the original plain text
    let recipher = chacha.encrypt(&cipher[..]);

    // they should be equal
    assert!(plain == recipher.as_slice());

Dependencies