Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aarch64 support with CMake. #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
cmake_minimum_required(VERSION 3.21)
project(Picnic C)

set(CMAKE_C_STANDARD 99)

# WARNING_FLAGS=-Wall -Wextra -Wpedantic -Wshadow
# we need to remove -Werror since there are two unused functions in KeccakP-1600-reference.c that causes warnings.
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wpedantic -Wshadow")
# CFLAGS= -O2 -march=native $(WARNING_FLAGS) -std=gnu99 -D__LINUX__ -D__X64__ -I./sha3
# NISTKATFLAGS = -Wno-sign-compare -Wno-unused-but-set-variable -Wno-unused-parameter -Wno-unused-result
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-sign-compare -Wno-unused-but-set-variable -Wno-unused-parameter -Wno-unused-result")
# add other configs for aarch64
IF (${CMAKE_SYSTEM_PROCESSOR} MATCHES "(aarch64)|(arm64)")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv8-a+simd+crypto+crc -D _ARM64_")
ELSE ()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native -D _AMD64_")
ENDIF ()

# build type
IF (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
ENDIF ()
message(STATUS "Build type (CMAKE_BUILD_TYPE): ${CMAKE_BUILD_TYPE}")
IF (${CMAKE_BUILD_TYPE} MATCHES Debug)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -ggdb")
ELSEIF (${CMAKE_BUILD_TYPE} MATCHES Release)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2")
ENDIF ()

add_subdirectory(sha3)

add_library(
picnic
SHARED
hash.c
lowmc_constants.c
picnic.c
picnic_impl.c
picnic3_impl.c
picnic_types.c
tree.c
)

target_include_directories(
picnic
PUBLIC
sha3
)

target_link_libraries(
picnic
PUBLIC
shake
)

# tool
add_executable(create_test_vectors create_test_vectors.c)
target_link_libraries(
create_test_vectors
PUBLIC
picnic
)

add_executable(example example.c)
target_link_libraries(
example
PUBLIC
picnic
)

# test cases
add_executable(kats_test kats_test.c)
target_link_libraries(
kats_test
PUBLIC
picnic
)
add_executable(tree_test tree_test.c)
target_link_libraries(
tree_test
PUBLIC
picnic
)
add_executable(unit_test unit_test.c)
target_link_libraries(
unit_test
PUBLIC
picnic
)

enable_testing()
add_test(tree_test tree_test)
add_test(unit_test unit_test)
add_test(kats_test kats_test)
61 changes: 0 additions & 61 deletions Makefile

This file was deleted.

30 changes: 25 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,41 @@ The library is provided under the MIT License. The authors are Steven Goldfeder

The library builds a static library. The public API surface is defined in [picnic.h](https://github.com/Microsoft/Picnic/blob/master/picnic.h).

## `aarch64` Support

The library is modified for supporting `aarch64` (including MacBook). The modifications contain:

- From makefile to CMake: Replace `makefile` to `CMakeList.txt`.
- `kat_test.c`, line 18: change `#define KATDIR "kats"` to `#define KATDIR "../kats"`.
- `picnic_impl.c`, line 806: change `#if defined(__LINUX__)` to `#if defined(__LINUX__) || defined(__linux__) || defined(__MACH__)`.

## Linux Build Instructions

Tested on Ubuntu Linux, and the Windows Subsystem for Linux on Windows 10 (build 1709).
Tested on MacBook (Apple M1 Pro), Ubuntu Linux, and the Windows Subsystem for Linux on Windows 10 (build 1709).

### Compile

```shell
mkdir build # you must create a sub-dictionary, otherwise `kats_test` would fail (because `KATDIR` is defined as `../kats`).
cd build
cmake ..
make
make test
```

### Example

1. `make`
This will build the project. `make debug` will build with symbols.
```shell
./example
```

2. `./example`
Runs an example program that exercises the keygen, sign, verify and
serialization APIs. See [example.c](https://github.com/Microsoft/Picnic/blob/master/example.c).


## Windows Build Instructions

Tested on Windows 10 with Visual Studio 2017.
Tested on Windows 10 with Visual Studio 2022 (community version).

Open the solution in `VisualStudio\picnic.sln`, and build the projects.

Expand Down
2 changes: 1 addition & 1 deletion kats_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <stdlib.h>

#ifndef KATDIR
#define KATDIR "kats"
#define KATDIR "../kats"
#endif
#define PICNIC_CONCAT2(a, b) a##_##b
#define PICNIC_CONCAT(a, b) PICNIC_CONCAT2(a, b)
Expand Down
2 changes: 1 addition & 1 deletion picnic_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ void mpc_LowMC(randomTape_t* tapes, view_t views[3],
int random_bytes_default(uint8_t* buf, size_t len)
{

#if defined(__LINUX__)
#if defined(__LINUX__) || defined(__linux__) || defined(__MACH__)
FILE* urandom = fopen("/dev/urandom", "r");
if (urandom == NULL) {
return -1;
Expand Down
7 changes: 7 additions & 0 deletions sha3/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
add_library(
shake
SHARED
KeccakHash.c
KeccakP-1600-reference.c
KeccakSpongeWidth1600.c
)
20 changes: 0 additions & 20 deletions sha3/Makefile

This file was deleted.