aboutsummaryrefslogtreecommitdiff
path: root/lib/ed25519
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-11-05 01:45:06 +0100
committerdec05eba <dec05eba@protonmail.com>2020-11-05 01:45:06 +0100
commit2a8202e74846d191a321cca1202175af9db6107d (patch)
treea6f455caf07da1186851f343a237a4c4e4484f46 /lib/ed25519
parent8efa0ec17d8c262f9c3fd7603e8074f74a053708 (diff)
Convert to sibs projectHEADmaster
Diffstat (limited to 'lib/ed25519')
-rw-r--r--lib/ed25519/.gitignore5
-rw-r--r--lib/ed25519/project.conf5
-rw-r--r--lib/ed25519/test.c150
3 files changed, 10 insertions, 150 deletions
diff --git a/lib/ed25519/.gitignore b/lib/ed25519/.gitignore
new file mode 100644
index 0000000..636c6b9
--- /dev/null
+++ b/lib/ed25519/.gitignore
@@ -0,0 +1,5 @@
+# Compiled sibs files
+sibs-build/
+compile_commands.json
+tests/sibs-build/
+tests/compile_commands.json
diff --git a/lib/ed25519/project.conf b/lib/ed25519/project.conf
new file mode 100644
index 0000000..dafccdb
--- /dev/null
+++ b/lib/ed25519/project.conf
@@ -0,0 +1,5 @@
+[package]
+name = "ed25519"
+type = "static"
+version = "0.1.0"
+platforms = ["any"]
diff --git a/lib/ed25519/test.c b/lib/ed25519/test.c
deleted file mode 100644
index e2159a9..0000000
--- a/lib/ed25519/test.c
+++ /dev/null
@@ -1,150 +0,0 @@
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <time.h>
-
-/* #define ED25519_DLL */
-#include "src/ed25519.h"
-
-#include "src/ge.h"
-#include "src/sc.h"
-
-
-int main() {
- unsigned char public_key[32], private_key[64], seed[32], scalar[32];
- unsigned char other_public_key[32], other_private_key[64];
- unsigned char shared_secret[32], other_shared_secret[32];
- unsigned char signature[64];
-
- clock_t start;
- clock_t end;
- int i;
-
- const unsigned char message[] = "Hello, world!";
- const int message_len = strlen((char*) message);
-
- /* create a random seed, and a keypair out of that seed */
- ed25519_create_seed(seed);
- ed25519_create_keypair(public_key, private_key, seed);
-
- /* create signature on the message with the keypair */
- ed25519_sign(signature, message, message_len, public_key, private_key);
-
- /* verify the signature */
- if (ed25519_verify(signature, message, message_len, public_key)) {
- printf("valid signature\n");
- } else {
- printf("invalid signature\n");
- }
-
- /* create scalar and add it to the keypair */
- ed25519_create_seed(scalar);
- ed25519_add_scalar(public_key, private_key, scalar);
-
- /* create signature with the new keypair */
- ed25519_sign(signature, message, message_len, public_key, private_key);
-
- /* verify the signature with the new keypair */
- if (ed25519_verify(signature, message, message_len, public_key)) {
- printf("valid signature\n");
- } else {
- printf("invalid signature\n");
- }
-
- /* make a slight adjustment and verify again */
- signature[44] ^= 0x10;
- if (ed25519_verify(signature, message, message_len, public_key)) {
- printf("did not detect signature change\n");
- } else {
- printf("correctly detected signature change\n");
- }
-
- /* generate two keypairs for testing key exchange */
- ed25519_create_seed(seed);
- ed25519_create_keypair(public_key, private_key, seed);
- ed25519_create_seed(seed);
- ed25519_create_keypair(other_public_key, other_private_key, seed);
-
- /* create two shared secrets - from both perspectives - and check if they're equal */
- ed25519_key_exchange(shared_secret, other_public_key, private_key);
- ed25519_key_exchange(other_shared_secret, public_key, other_private_key);
-
- for (i = 0; i < 32; ++i) {
- if (shared_secret[i] != other_shared_secret[i]) {
- printf("key exchange was incorrect\n");
- break;
- }
- }
-
- if (i == 32) {
- printf("key exchange was correct\n");
- }
-
- /* test performance */
- printf("testing seed generation performance: ");
- start = clock();
- for (i = 0; i < 10000; ++i) {
- ed25519_create_seed(seed);
- }
- end = clock();
-
- printf("%fus per seed\n", ((double) ((end - start) * 1000)) / CLOCKS_PER_SEC / i * 1000);
-
-
- printf("testing key generation performance: ");
- start = clock();
- for (i = 0; i < 10000; ++i) {
- ed25519_create_keypair(public_key, private_key, seed);
- }
- end = clock();
-
- printf("%fus per keypair\n", ((double) ((end - start) * 1000)) / CLOCKS_PER_SEC / i * 1000);
-
- printf("testing sign performance: ");
- start = clock();
- for (i = 0; i < 10000; ++i) {
- ed25519_sign(signature, message, message_len, public_key, private_key);
- }
- end = clock();
-
- printf("%fus per signature\n", ((double) ((end - start) * 1000)) / CLOCKS_PER_SEC / i * 1000);
-
- printf("testing verify performance: ");
- start = clock();
- for (i = 0; i < 10000; ++i) {
- ed25519_verify(signature, message, message_len, public_key);
- }
- end = clock();
-
- printf("%fus per signature\n", ((double) ((end - start) * 1000)) / CLOCKS_PER_SEC / i * 1000);
-
-
- printf("testing keypair scalar addition performance: ");
- start = clock();
- for (i = 0; i < 10000; ++i) {
- ed25519_add_scalar(public_key, private_key, scalar);
- }
- end = clock();
-
- printf("%fus per keypair\n", ((double) ((end - start) * 1000)) / CLOCKS_PER_SEC / i * 1000);
-
- printf("testing public key scalar addition performance: ");
- start = clock();
- for (i = 0; i < 10000; ++i) {
- ed25519_add_scalar(public_key, NULL, scalar);
- }
- end = clock();
-
- printf("%fus per key\n", ((double) ((end - start) * 1000)) / CLOCKS_PER_SEC / i * 1000);
-
- printf("testing key exchange performance: ");
- start = clock();
- for (i = 0; i < 10000; ++i) {
- ed25519_key_exchange(shared_secret, other_public_key, private_key);
- }
- end = clock();
-
- printf("%fus per shared secret\n", ((double) ((end - start) * 1000)) / CLOCKS_PER_SEC / i * 1000);
-
- return 0;
-}