This repository has been archived by the owner on Feb 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Check tweetnacl C version #41
Open
bkmgit
wants to merge
6
commits into
novifinancial:main
Choose a base branch
from
bkmgit:more-libraries
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
LIBBOTAN_INSTALL_DIR=$(pwd)/libbotan-build | ||
main: main.o | ||
g++ -o main main.o -L$(LIBBOTAN_INSTALL_DIR)/lib64 -lbotan-2 | ||
|
||
main.o: main.cpp | ||
g++ -c -I$(LIBBOTAN_INSTALL_DIR)/include/botan-2 main.cpp -o main.o |
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,17 @@ | ||
[Botan](https://botan.randombit.net) is available under a BSD-2-Clause license | ||
|
||
``` | ||
> wget https://botan.randombit.net/releases/Botan-2.19.2.tar.xz | ||
> tar -xf Botan-2.19.2.tar.xz | ||
> mkdir libbotan-build | ||
> export LIBBOTAN_INSTALL_DIR=$(pwd)/libbotan-build | ||
> cd Botan-2.19.2 | ||
> ./configure --prefix=$(LIBBOTAN_INSTALL_DIR) | ||
> make | ||
> make check | ||
> make install | ||
> cd .. | ||
> export LD_LIBRARY_PATH=$(pwd)/libbotan-build/lib64:$LD_LIBRARY_PATH | ||
> make | ||
> ./main | ||
``` |
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,71 @@ | ||
// Copyright (c) Facebook, Inc. and its affiliates. | ||
// Copyright (c) Benson Muite | ||
// | ||
// This source code is licensed under the APACHE 2.0 license found in | ||
// the LICENSE file in the root directory of this source tree. | ||
|
||
#include <botan/sodium.h> | ||
#include <stdio.h> | ||
|
||
#define MESSAGE_LEN 32 | ||
|
||
using namespace Botan::Sodium; | ||
int main(void) { | ||
if (sodium_init() < 0) { | ||
/* panic! the library couldn't be initialized, it is not safe to use */ | ||
printf("PANIC \n"); | ||
return 0; | ||
} | ||
|
||
unsigned char pk[crypto_sign_PUBLICKEYBYTES]; | ||
unsigned char message[MESSAGE_LEN]; | ||
uint8_t message_len = MESSAGE_LEN; | ||
unsigned char signature[crypto_sign_BYTES]; | ||
|
||
FILE *fp; | ||
int number_of_test_vectors = 0; | ||
char buff[255]; | ||
int pos; | ||
|
||
fp = fopen("../../cases.txt", "r+"); | ||
fscanf(fp, "%i", &number_of_test_vectors); | ||
// printf("Number of test vectors: %i\n", number_of_test_vectors); | ||
printf("\n|Botan |"); | ||
for (int i = 0; i < number_of_test_vectors; i++) { | ||
// reading the message | ||
fscanf(fp, "%s", buff); | ||
pos = 0; | ||
for (size_t count = 0; count < 32; count++) { | ||
sscanf(buff + 4 + pos, "%2hhx", &message[count]); | ||
pos += 2; | ||
} | ||
|
||
// reading the public key | ||
fscanf(fp, "%s", buff); // message 32 bytes | ||
pos = 0; | ||
for (size_t count = 0; count < 32; count++) { | ||
sscanf(buff + 4 + pos, "%2hhx", &pk[count]); | ||
pos += 2; | ||
} | ||
|
||
// reading the signature | ||
fscanf(fp, "%s", buff); | ||
pos = 0; | ||
for (size_t count = 0; count < 64; count++) { | ||
sscanf(buff + 4 + pos, "%2hhx", &signature[count]); | ||
pos += 2; | ||
} | ||
|
||
int result = crypto_sign_ed25519_verify_detached(signature, message, message_len, pk); | ||
|
||
if (result == -1) { | ||
printf(" X |"); | ||
/* Incorrect signature! */ | ||
} else { | ||
printf(" V |"); | ||
} | ||
} | ||
printf("\n"); | ||
fclose(fp); | ||
return 0; | ||
} |
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 @@ | ||
main: main.c | ||
gcc -o main monocypher-ed25519.c monocypher.c main.c -I$(PWD) |
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,13 @@ | ||
Monocypher is can be in the Public Domain or under a BSD 2 Clause | ||
license. It is available at | ||
https://monocypher.org | ||
|
||
|
||
``` | ||
> wget https://monocypher.org/download/monocypher-3.1.3.tar.gz | ||
> tar -xf monocypher-3.1.3.tar.gz | ||
> cp monocypher-3.1.3/src/monocypher.* . | ||
> cp monocypher-3.1.3/src/optional/monocypher-ed25519.* . | ||
> make | ||
> ./main | ||
``` |
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,71 @@ | ||
// Copyright (c) Facebook, Inc. and its affiliates. | ||
// Copyright (c) Benson Muite | ||
// | ||
// This source code is licensed under the APACHE 2.0 license found in | ||
// the LICENSE file in the root directory of this source tree. | ||
|
||
#include "monocypher.h" | ||
#include "monocypher-ed25519.h" | ||
#include <stdio.h> | ||
|
||
#define MESSAGE_LEN 32 | ||
#define crypto_sign_PUBLICKEYBYTES 32 | ||
#define crypto_sign_BYTES 64 | ||
|
||
int main(void) { | ||
|
||
unsigned char public_key[crypto_sign_PUBLICKEYBYTES]; | ||
unsigned char message[MESSAGE_LEN]; | ||
unsigned long long message_len = MESSAGE_LEN; | ||
unsigned char signature[crypto_sign_BYTES]; | ||
unsigned long long signature_len = crypto_sign_BYTES; | ||
|
||
FILE *fp; | ||
int number_of_test_vectors = 0; | ||
char buff[255]; | ||
int pos; | ||
|
||
fp = fopen("../../cases.txt", "r+"); | ||
fscanf(fp, "%i", &number_of_test_vectors); | ||
printf("Number of test vectors: %i\n", number_of_test_vectors); | ||
printf("\n|Monocypher |"); | ||
for (int i = 0; i < number_of_test_vectors; i++) { | ||
// reading the message | ||
fscanf(fp, "%s", buff); | ||
pos = 0; | ||
for (size_t count = 0; count < 32; count++) { | ||
sscanf(buff + 4 + pos, "%2hhx", &message[count]); | ||
pos += 2; | ||
} | ||
|
||
// reading the public key | ||
fscanf(fp, "%s", buff); // message 32 bytes | ||
pos = 0; | ||
for (size_t count = 0; count < 32; count++) { | ||
sscanf(buff + 4 + pos, "%2hhx", &public_key[count]); | ||
pos += 2; | ||
} | ||
|
||
// reading the signature | ||
fscanf(fp, "%s", buff); | ||
pos = 0; | ||
for (size_t count = 0; count < 64; count++) { | ||
sscanf(buff + 4 + pos, "%2hhx", &signature[count]); | ||
pos += 2; | ||
} | ||
|
||
int result = crypto_ed25519_check(signature, public_key, &message, message_len); | ||
|
||
if (result != 0) { | ||
printf(" X |"); | ||
// Incorrect signature! | ||
} else { | ||
printf(" V |"); | ||
} | ||
|
||
} | ||
|
||
printf("\n"); | ||
fclose(fp); | ||
return 0; | ||
} |
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 @@ | ||
main: main.c | ||
gcc -o main randombytes.c tweetnacl.c main.c -I$(PWD) |
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,14 @@ | ||
TweetNaCl is in the Public Domain and is available at | ||
https://tweetnacl.cr.yp.to/software.html | ||
|
||
Randombytes is available under MIT License and is available at | ||
https://github.com/dsprenkels/randombytes | ||
|
||
``` | ||
> wget https://tweetnacl.cr.yp.to/20140427/tweetnacl.c | ||
> wget https://tweetnacl.cr.yp.to/20140427/tweetnacl.h | ||
> wget https://raw.githubusercontent.com/dsprenkels/randombytes/4ca4200730d3d5e8f18a1728663287792ad5e227/randombytes.c | ||
> wget https://raw.githubusercontent.com/dsprenkels/randombytes/4ca4200730d3d5e8f18a1728663287792ad5e227/randombytes.h | ||
> make | ||
> ./main | ||
``` |
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,71 @@ | ||
// Copyright (c) Facebook, Inc. and its affiliates. | ||
// Copyright (c) Benson Muite | ||
// | ||
// This source code is licensed under the APACHE 2.0 license found in | ||
// the LICENSE file in the root directory of this source tree. | ||
|
||
#include "tweetnacl.h" | ||
#include <stdio.h> | ||
|
||
#define MESSAGE_LEN 32 | ||
|
||
int main(void) { | ||
|
||
unsigned char pk[crypto_sign_PUBLICKEYBYTES]; | ||
// Array message is larger than MESSAGE_LEN because | ||
// verification in TweetNACL uses the additional space | ||
unsigned char message[crypto_sign_BYTES + MESSAGE_LEN]; | ||
unsigned long long message_len = MESSAGE_LEN; | ||
unsigned char signed_message[crypto_sign_BYTES + MESSAGE_LEN]; | ||
unsigned long long signed_message_len = crypto_sign_BYTES + MESSAGE_LEN; | ||
|
||
FILE *fp; | ||
int number_of_test_vectors = 0; | ||
char buff[255]; | ||
int pos; | ||
|
||
fp = fopen("../../cases.txt", "r+"); | ||
fscanf(fp, "%i", &number_of_test_vectors); | ||
printf("Number of test vectors: %i\n", number_of_test_vectors); | ||
printf("\n|TweetNaCl |"); | ||
for (int i = 0; i < number_of_test_vectors; i++) { | ||
// reading the message | ||
fscanf(fp, "%s", buff); | ||
pos = 0; | ||
for (size_t count = 0; count < 32; count++) { | ||
sscanf(buff + 4 + pos, "%2hhx", &message[count]); | ||
sscanf(buff + 4 + pos, "%2hhx", &signed_message[count+64]); | ||
pos += 2; | ||
} | ||
|
||
// reading the public key | ||
fscanf(fp, "%s", buff); // message 32 bytes | ||
pos = 0; | ||
for (size_t count = 0; count < 32; count++) { | ||
sscanf(buff + 4 + pos, "%2hhx", &pk[count]); | ||
pos += 2; | ||
} | ||
|
||
// reading the signature | ||
fscanf(fp, "%s", buff); | ||
pos = 0; | ||
for (size_t count = 0; count < 64; count++) { | ||
sscanf(buff + 4 + pos, "%2hhx", &signed_message[count]); | ||
pos += 2; | ||
} | ||
|
||
int result = crypto_sign_open(message, &message_len, | ||
signed_message, signed_message_len, &pk[0]); | ||
if (result == -1) { | ||
printf(" X |"); | ||
// Incorrect signature! | ||
} else { | ||
printf(" V |"); | ||
} | ||
|
||
} | ||
|
||
printf("\n"); | ||
fclose(fp); | ||
return 0; | ||
} |
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,5 @@ | ||
|
||
|
||
LIBWOLFSSL_INSTALL_DIR=./wolfssl-install | ||
main: main.c | ||
gcc -o main main.c -I$(LIBWOLFSSL_INSTALL_DIR)/include -L$(LIBWOLFSSL_INSTALL_DIR)/lib -lwolfssl |
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,17 @@ | ||
wolfSSL is available under GPLv2 license as well as under | ||
commercial/custom licenses. | ||
|
||
``` | ||
> wget https://github.com/wolfSSL/wolfssl/archive/refs/tags/v5.5.3-stable.tar.gz | ||
> tar -xf v5.5.3-stable.tar.gz | ||
> export LIBWOLFSSL_INSTALL_PATH=$(pwd)/wolfssl-install | ||
> cd wolfssl-5.5.3-stable/ | ||
> ./autogen.sh | ||
> ./configure --prefix=$(LIBWOLFSSL_INSTALL_PATH) --enable-opensslextra --enable-opensslall --enable-curve25519 --enable-ed25519 | ||
> make | ||
> make install | ||
> cd .. | ||
> export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$LIBWOLFSSL_INSTALL_PATH/lib | ||
> make | ||
> ./main | ||
``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's highly possible that this is true in other implementations as well, but iirc we used X for both errors and unverified sigs. We can make a comment to track those and update holistically (for the other implementations too) in another PR, but in this PR use X.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Expect to add a few more libraries. Will update this on the next addition.