-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
73 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
## | ||
# Puff - a Huff compiler in Racket | ||
# | ||
# @file | ||
# @version 0.1 | ||
|
||
KECCAK_LIB_DIR = rust_src/keccaklib | ||
KECCAK_LIB_TARGET_DIR = $(KECCAK_LIB_DIR)/target/release | ||
LIB_NAME = libkeccak_lib | ||
LIB_DIR = lib | ||
|
||
ifeq ($(OS),Windows_NT) | ||
LIB_EXT = .dll | ||
else | ||
UNAME_S := $(shell uname -s) | ||
ifeq ($(UNAME_S),Linux) | ||
LIB_EXT = .so | ||
endif | ||
ifeq ($(UNAME_S),Darwin) | ||
LIB_EXT = .dylib | ||
endif | ||
endif | ||
|
||
deps: build_rust copy_lib | ||
|
||
build_rust: | ||
@echo "Building Rust library..." | ||
cd $(KECCAK_LIB_DIR) && cargo build --release | ||
|
||
copy_lib: | ||
@echo "Copying library to $(LIB_DIR) directory..." | ||
mkdir -p $(LIB_DIR) | ||
cp $(KECCAK_LIB_TARGET_DIR)/$(LIB_NAME)$(LIB_EXT) $(LIB_DIR)/$(LIB_NAME)$(LIB_EXT) | ||
|
||
clean: | ||
@echo "Cleaning up..." | ||
cd $(KECCAK_LIB_DIR) && cargo clean | ||
rm -f $(LIB_DIR)/$(LIB_NAME)$(LIB_EXT) | ||
|
||
# end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "keccaklib" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[lib] | ||
name = "keccak_lib" | ||
crate-type = ["cdylib"] | ||
|
||
[dependencies] | ||
alloy-primitives = "0.8.8" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use alloy_primitives::utils::keccak256 as keccak; | ||
|
||
#[no_mangle] | ||
pub extern "C" fn keccak256(data_ptr: *const u8, data_len: usize, result_ptr: *mut u8) { | ||
let data = unsafe { std::slice::from_raw_parts(data_ptr, data_len) }; | ||
let hash = keccak(&data); | ||
let hash = hash.as_slice(); | ||
let result = unsafe { std::slice::from_raw_parts_mut(result_ptr, 32) }; | ||
result.copy_from_slice(hash); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters