-
Notifications
You must be signed in to change notification settings - Fork 17
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
1 parent
649ed38
commit 2526e14
Showing
4 changed files
with
82 additions
and
0 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 @@ | ||
/build |
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,25 @@ | ||
cmake_minimum_required(VERSION 3.10) | ||
|
||
include(FetchContent) | ||
FetchContent_Declare(hacl | ||
DOWNLOAD_EXTRACT_TIMESTAMP TRUE | ||
GIT_REPOSITORY https://github.com/cryspen/hacl-packages/ | ||
GIT_TAG 88560a8b5bae5db890e11f1ea71376adfa767baf | ||
) | ||
FetchContent_MakeAvailable(hacl) | ||
|
||
project(hacl-blake-example) | ||
set(CMAKE_OSX_ARCHITECTURES arm64) | ||
|
||
add_executable(example blake-example.cc) | ||
|
||
# Add includes from HACL | ||
target_include_directories(example PRIVATE | ||
${hacl_SOURCE_DIR}/include | ||
${hacl_SOURCE_DIR}/build | ||
${hacl_SOURCE_DIR}/karamel/include | ||
${hacl_SOURCE_DIR}/karamel/krmllib/dist/minimal | ||
${hacl_SOURCE_DIR}/vale/include | ||
) | ||
# Link the HACL library | ||
target_link_libraries(example PRIVATE hacl) |
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,12 @@ | ||
# CMake Example | ||
|
||
This folder contains an example for how to use the HACL Packages C library in a | ||
CMake project. | ||
|
||
```sh | ||
mkdir build | ||
cd build | ||
cmake .. | ||
cmake --build . | ||
./example | ||
``` |
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,44 @@ | ||
/* | ||
* Copyright 2022 Cryspen Sarl | ||
* | ||
* Licensed under the Apache License, Version 2.0 or MIT. | ||
* - http://www.apache.org/licenses/LICENSE-2.0 | ||
* - http://opensource.org/licenses/MIT | ||
*/ | ||
#include "Hacl_Hash_Blake2.h" | ||
|
||
using namespace std; | ||
|
||
void print_hex_ln(size_t bytes_len, uint8_t *bytes) | ||
{ | ||
for (int i = 0; i < bytes_len; ++i) | ||
{ | ||
printf("%02x", bytes[i]); | ||
} | ||
|
||
printf("\n"); | ||
} | ||
|
||
int main(int argc, char const *argv[]) | ||
{ | ||
// Reserve memory for a 64 byte digest, i.e., | ||
// for a BLAKE2B run with full 512-bit output. | ||
uint32_t output_len = 64; | ||
uint8_t output[64]; | ||
|
||
// The message we want to hash. | ||
const char *message = "Hello, HACL Packages!"; | ||
uint32_t message_len = strlen(message); | ||
|
||
// BLAKE2B can be used as an HMAC, i.e., with a key. | ||
// We don't want to use a key here and thus provide a zero-sized key. | ||
uint32_t key_len = 0; | ||
uint8_t *key = 0; | ||
|
||
Hacl_Blake2b_32_blake2b( | ||
output_len, output, message_len, (uint8_t *)message, key_len, key); | ||
|
||
print_hex_ln(output_len, output); | ||
|
||
return 0; | ||
} |