Skip to content

🧩 keccaky is a Gleam library for computing Keccak SHA3-256 hashes using a NIF built tiny-keccak Rust crate

Notifications You must be signed in to change notification settings

vidalpaul/keccaky

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Keccaky

Keccaky is a high-performance Keccak (SHA-3) implementation with a Gleam interface, providing easy access to Keccak-256 hashing through a Rust backend. The project leverages Rust's efficient hashing algorithms and integrates them with Gleam for high-level usage.

Features

  • Keccak-256 Hashing: Provides Keccak-256 hash functionality using the tiny-keccak Rust library.
  • Gleam Integration: Exposes the hashing functionality to Gleam via an FFI layer.
  • Cross-Language Compatibility: Utilizes Rust for performance and Gleam for ease of use and safety.

Installation

Rust Setup

  1. Clone the Repository:

    git clone https://github.com/vidalpaul/keccaky.git
    cd keccaky
  2. Build the Rust Library: Ensure you have Rust installed. Build the Rust shared library:

    cargo build --release

    The shared library will be available in the target/release directory.

Gleam Setup

  1. Install Gleam: Follow the Gleam installation instructions if you haven't already.

  2. Build the Gleam Project: Ensure the shared library is placed in the correct directory (src/native or specified path). Then build the Gleam project:

    gleam build

Usage

Rust FFI

The Rust function keccak_256 is exposed to Gleam. The function signature is:

extern "C" fn keccak_256(input_ptr: *const u8, input_len: usize, output_ptr: *mut u8);

Gleam Integration

In Gleam, you can call the Keccak-256 hash function using:

import gleam/erlang
import gleam/ffi

// External function declaration for FFI
@external(erlang, "keccak_ffi", "keccak_256")
fn keccak_256(input: ffi.Buffer, input_len: Int, output: ffi.Buffer) -> Nil

// Function to hash a string using Keccak-256
pub fn hash_keccak_256(input: String) -> Result(String, Nil) {
  let input_bytes = erlang.binary_to_list(erlang.bitstring_to_binary(input))
  let output_size = 32
  let output_bytes = ffi.Buffer.from_binary(erlang.binary_init(output_size, 0))

  keccak_256(input_bytes, List.length(input_bytes), output_bytes)

  let output_binary = ffi.Buffer.to_binary(output_bytes)
  Ok(erlang.binary_to_string(output_binary))
}

Testing

To ensure everything is working correctly, run tests in Rust and Gleam:

  • Rust Tests:

    cargo test
  • Gleam Tests:

    gleam test

Contributing

Feel free to contribute by submitting issues or pull requests. Ensure all contributions adhere to the project's coding standards and pass existing tests.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contact

For any questions or further information, please contact [email protected].

About

🧩 keccaky is a Gleam library for computing Keccak SHA3-256 hashes using a NIF built tiny-keccak Rust crate

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published