-
Notifications
You must be signed in to change notification settings - Fork 16
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
69 changed files
with
1,497 additions
and
304 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
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
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
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
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 |
---|---|---|
@@ -1,3 +1,9 @@ | ||
[submodule "crypto/crypto-cpp"] | ||
path = crypto/crypto-cpp | ||
[submodule "crypto/pedersen/crypto-cpp"] | ||
path = crypto/pedersen/crypto-cpp | ||
url = [email protected]:software-mansion-labs/crypto-cpp.git | ||
[submodule "crypto/poseidon/poseidon"] | ||
path = crypto/poseidon/poseidon | ||
url = [email protected]:THenry14/poseidon.git | ||
[submodule "cairo"] | ||
path = cairo | ||
url = [email protected]:starkware-libs/cairo.git |
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
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
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
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
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,79 @@ | ||
cmake_minimum_required (VERSION 3.5) | ||
if (NOT DEFINED CMAKE_CXX_COMPILER) | ||
set(CMAKE_CXX_COMPILER /usr/bin/clang++) | ||
endif() | ||
|
||
project(StarkwareCryptoLib VERSION 0.1.0 LANGUAGES CXX) | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
|
||
set(BOOST_ENABLE_CMAKE ON) | ||
|
||
include(FetchContent) | ||
FetchContent_Declare( | ||
googletest | ||
URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip | ||
) | ||
# For Windows: Prevent overriding the parent project's compiler/linker settings | ||
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) | ||
FetchContent_MakeAvailable(googletest) | ||
|
||
|
||
# Checking if current build supports __uint128_t and including boost if it doesn't. | ||
INCLUDE(CheckCXXSourceCompiles) | ||
check_cxx_source_compiles(" | ||
int main() { | ||
__uint128_t a = 0; | ||
return a; | ||
}" HAVE_UINT128) | ||
|
||
if (NOT HAVE_UINT128) | ||
FetchContent_Declare( | ||
boostorg | ||
URL https://boostorg.jfrog.io/artifactory/main/release/1.79.0/source/boost_1_79_0.tar.gz | ||
) | ||
|
||
FetchContent_GetProperties(boostorg) | ||
if (NOT boostorg_POPULATED) | ||
FetchContent_Populate(boostorg) | ||
endif () | ||
|
||
include_directories(${boostorg_SOURCE_DIR}) | ||
|
||
# For Windows: Prevent overriding the parent project's compiler/linker settings | ||
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) | ||
FetchContent_MakeAvailable(boostorg) | ||
endif() | ||
|
||
if (NOT DEFINED JAVA_INCLUDE_PATH) | ||
set(JAVA_AWT_LIBRARY NotNeeded) | ||
set(JAVA_JVM_LIBRARY NotNeeded) | ||
set(JAVA_AWT_INCLUDE_PATH NotNeeded) | ||
set(JAVA_INCLUDE_PATH "$ENV{JAVA_HOME}/include") | ||
set(JAVA_INCLUDE_PATH2 "$ENV{JAVA_HOME}/include/darwin;$ENV{JAVA_HOME}/include/linux") | ||
|
||
find_package(Java REQUIRED) | ||
find_package(JNI REQUIRED) | ||
include_directories(${JNI_INCLUDE_DIRS}) | ||
endif() | ||
|
||
include(CTest) | ||
enable_testing() | ||
include_directories("${CMAKE_SOURCE_DIR}/crypto-cpp/src") | ||
include_directories("${CMAKE_SOURCE_DIR}/bindings") | ||
|
||
if (NOT DEFINED CMAKE_BUILD_TYPE) | ||
set(CMAKE_BUILD_TYPE Debug) | ||
endif() | ||
|
||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -Werror -Wall -Wextra -fno-strict-aliasing -fPIC") | ||
|
||
set(CC_OPTIMIZE "-O3") | ||
|
||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g") | ||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${CC_OPTIMIZE}") | ||
|
||
add_subdirectory(crypto-cpp/src) | ||
add_subdirectory(bindings) | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
#! /bin/bash | ||
|
||
echo "Building crypto-cpp..." | ||
cmake -DCMAKE_BUILD_TYPE=Release -Bbuild -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" | ||
make -C build | ||
echo "Crypto-cpp built!" |
Submodule crypto-cpp
updated
from 000000 to 800004
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,24 @@ | ||
cmake_minimum_required (VERSION 3.5) | ||
|
||
project(poseidon) | ||
|
||
include_directories("${CMAKE_SOURCE_DIR}/poseidon/sources") | ||
include_directories("${CMAKE_SOURCE_DIR}/bindings") | ||
|
||
if (NOT DEFINED JAVA_INCLUDE_PATH) | ||
set(JAVA_AWT_LIBRARY NotNeeded) | ||
set(JAVA_JVM_LIBRARY NotNeeded) | ||
set(JAVA_AWT_INCLUDE_PATH NotNeeded) | ||
set(JAVA_INCLUDE_PATH "$ENV{JAVA_HOME}/include") | ||
set(JAVA_INCLUDE_PATH2 "$ENV{JAVA_HOME}/include/darwin;$ENV{JAVA_HOME}/include/linux") | ||
|
||
find_package(Java REQUIRED) | ||
find_package(JNI REQUIRED) | ||
include_directories(${JNI_INCLUDE_DIRS}) | ||
endif() | ||
|
||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror -O3 -fPIC") | ||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) | ||
|
||
add_subdirectory(poseidon) | ||
add_subdirectory(bindings) |
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,2 @@ | ||
add_library(poseidon_jni SHARED starknet_crypto_Poseidon.c) | ||
target_link_libraries(poseidon_jni poseidon) |
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,39 @@ | ||
#include <jni.h> | ||
|
||
#include "./starknet_crypto_Poseidon.h" | ||
#include "f251.h" | ||
#include "poseidon.h" | ||
#include "poseidon_rc.h" | ||
|
||
JNIEXPORT jobjectArray JNICALL Java_com_swmansion_starknet_crypto_Poseidon_hades | ||
(JNIEnv *env, jclass obj, jobjectArray values) { | ||
|
||
jsize num_rows = (*env)->GetArrayLength(env, values); | ||
jsize num_cols = (*env)->GetArrayLength(env, (*env)->GetObjectArrayElement(env, values, 0)); | ||
|
||
felt_t converted_values[3] = { {0} }; | ||
for (int i = 0; i < num_rows; i++) { | ||
jlongArray row = (*env)->GetObjectArrayElement(env, values, i); | ||
jlong *row_elems = (*env)->GetLongArrayElements(env, row, NULL); | ||
for (int j = 0; j < num_cols; j++) { | ||
converted_values[i][j] = (uint64_t) row_elems[j]; | ||
} | ||
(*env)->ReleaseLongArrayElements(env, row, row_elems, JNI_ABORT); | ||
} | ||
|
||
permutation_3(converted_values); | ||
|
||
jclass longArrayClass = (*env)->FindClass(env, "[J"); | ||
jobjectArray result = (*env)->NewObjectArray(env, 3, longArrayClass, NULL); | ||
for (int i = 0; i < 3; i++) { | ||
jlongArray row = (*env)->NewLongArray(env, 4); | ||
jlong* elements = (*env)->GetLongArrayElements(env, row, NULL); | ||
for (int j = 0; j < 4; j++) { | ||
elements[j] = (jlong)converted_values[i][j]; | ||
} | ||
(*env)->ReleaseLongArrayElements(env, row, elements, 0); | ||
(*env)->SetObjectArrayElement(env, result, i, row); | ||
} | ||
|
||
return result; | ||
} |
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,15 @@ | ||
#include <jni.h> | ||
|
||
#ifndef _Included_com_swmansion_starknet_crypto_Poseidon | ||
#define _Included_com_swmansion_starknet_crypto_Poseidon | ||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
JNIEXPORT jobjectArray JNICALL Java_com_swmansion_starknet_crypto_Poseidon_hades | ||
(JNIEnv *env, jclass obj, jobjectArray values); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
#endif |
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,6 @@ | ||
#! /bin/bash | ||
|
||
echo "Building poseidon..." | ||
cmake -Bbuild -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" | ||
make -C build | ||
echo "Poseidon built!" |
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
Oops, something went wrong.