aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/crypto-algorithms/.gitignore5
-rw-r--r--lib/crypto-algorithms/aes_test.c276
-rw-r--r--lib/crypto-algorithms/arcfour_test.c47
-rw-r--r--lib/crypto-algorithms/base64_test.c54
-rw-r--r--lib/crypto-algorithms/blowfish_test.c68
-rw-r--r--lib/crypto-algorithms/des_test.c83
-rw-r--r--lib/crypto-algorithms/md2_test.c58
-rw-r--r--lib/crypto-algorithms/md5_test.c60
-rw-r--r--lib/crypto-algorithms/project.conf5
-rw-r--r--lib/crypto-algorithms/rot-13_test.c44
-rw-r--r--lib/crypto-algorithms/sha1_test.c58
-rw-r--r--lib/crypto-algorithms/sha256_test.c61
-rw-r--r--lib/curve25519-donna/.gitignore7
-rw-r--r--lib/curve25519-donna/contrib/Curve25519Donna.c118
-rw-r--r--lib/curve25519-donna/contrib/Curve25519Donna.h53
-rw-r--r--lib/curve25519-donna/contrib/Curve25519Donna.java77
-rw-r--r--lib/curve25519-donna/contrib/make-snippets68
-rw-r--r--lib/curve25519-donna/project.conf5
-rw-r--r--lib/curve25519-donna/python-src/curve25519/__init__.py4
-rw-r--r--lib/curve25519-donna/python-src/curve25519/curve25519module.c105
-rw-r--r--lib/curve25519-donna/python-src/curve25519/keys.py46
-rw-r--r--lib/curve25519-donna/python-src/curve25519/test/__init__.py0
-rwxr-xr-xlib/curve25519-donna/python-src/curve25519/test/test_curve25519.py99
-rwxr-xr-xlib/curve25519-donna/python-src/curve25519/test/test_speed.py46
-rw-r--r--lib/curve25519-donna/test-curve25519.c54
-rw-r--r--lib/curve25519-donna/test-noncanon.c39
-rw-r--r--lib/curve25519-donna/test-sc-curve25519.c72
-rw-r--r--lib/curve25519-donna/test-sc-curve25519.s8
-rw-r--r--lib/ed25519/.gitignore5
-rw-r--r--lib/ed25519/project.conf5
-rw-r--r--lib/ed25519/test.c150
31 files changed, 32 insertions, 1748 deletions
diff --git a/lib/crypto-algorithms/.gitignore b/lib/crypto-algorithms/.gitignore
new file mode 100644
index 0000000..636c6b9
--- /dev/null
+++ b/lib/crypto-algorithms/.gitignore
@@ -0,0 +1,5 @@
+# Compiled sibs files
+sibs-build/
+compile_commands.json
+tests/sibs-build/
+tests/compile_commands.json
diff --git a/lib/crypto-algorithms/aes_test.c b/lib/crypto-algorithms/aes_test.c
deleted file mode 100644
index d49726d..0000000
--- a/lib/crypto-algorithms/aes_test.c
+++ /dev/null
@@ -1,276 +0,0 @@
-/*********************************************************************
-* Filename: aes_test.c
-* Author: Brad Conte (brad AT bradconte.com)
-* Copyright:
-* Disclaimer: This code is presented "as is" without any guarantees.
-* Details: Performs known-answer tests on the corresponding AES
- implementation. These tests do not encompass the full
- range of available test vectors and are not sufficient
- for FIPS-140 certification. However, if the tests pass
- it is very, very likely that the code is correct and was
- compiled properly. This code also serves as
- example usage of the functions.
-*********************************************************************/
-
-/*************************** HEADER FILES ***************************/
-#include <stdio.h>
-#include <memory.h>
-#include "aes.h"
-
-/*********************** FUNCTION DEFINITIONS ***********************/
-void print_hex(BYTE str[], int len)
-{
- int idx;
-
- for(idx = 0; idx < len; idx++)
- printf("%02x", str[idx]);
-}
-
-int aes_ecb_test()
-{
- WORD key_schedule[60], idx;
- BYTE enc_buf[128];
- BYTE plaintext[2][16] = {
- {0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a},
- {0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51}
- };
- BYTE ciphertext[2][16] = {
- {0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8},
- {0x59,0x1c,0xcb,0x10,0xd4,0x10,0xed,0x26,0xdc,0x5b,0xa7,0x4a,0x31,0x36,0x28,0x70}
- };
- BYTE key[1][32] = {
- {0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4}
- };
- int pass = 1;
-
- // Raw ECB mode.
- //printf("* ECB mode:\n");
- aes_key_setup(key[0], key_schedule, 256);
- //printf( "Key : ");
- //print_hex(key[0], 32);
-
- for(idx = 0; idx < 2; idx++) {
- aes_encrypt(plaintext[idx], enc_buf, key_schedule, 256);
- //printf("\nPlaintext : ");
- //print_hex(plaintext[idx], 16);
- //printf("\n-encrypted to: ");
- //print_hex(enc_buf, 16);
- pass = pass && !memcmp(enc_buf, ciphertext[idx], 16);
-
- aes_decrypt(ciphertext[idx], enc_buf, key_schedule, 256);
- //printf("\nCiphertext : ");
- //print_hex(ciphertext[idx], 16);
- //printf("\n-decrypted to: ");
- //print_hex(enc_buf, 16);
- pass = pass && !memcmp(enc_buf, plaintext[idx], 16);
-
- //printf("\n\n");
- }
-
- return(pass);
-}
-
-int aes_cbc_test()
-{
- WORD key_schedule[60];
- BYTE enc_buf[128];
- BYTE plaintext[1][32] = {
- {0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51}
- };
- BYTE ciphertext[2][32] = {
- {0xf5,0x8c,0x4c,0x04,0xd6,0xe5,0xf1,0xba,0x77,0x9e,0xab,0xfb,0x5f,0x7b,0xfb,0xd6,0x9c,0xfc,0x4e,0x96,0x7e,0xdb,0x80,0x8d,0x67,0x9f,0x77,0x7b,0xc6,0x70,0x2c,0x7d}
- };
- BYTE iv[1][16] = {
- {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f}
- };
- BYTE key[1][32] = {
- {0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4}
- };
- int pass = 1;
-
- //printf("* CBC mode:\n");
- aes_key_setup(key[0], key_schedule, 256);
-
- //printf( "Key : ");
- //print_hex(key[0], 32);
- //printf("\nIV : ");
- //print_hex(iv[0], 16);
-
- aes_encrypt_cbc(plaintext[0], 32, enc_buf, key_schedule, 256, iv[0]);
- //printf("\nPlaintext : ");
- //print_hex(plaintext[0], 32);
- //printf("\n-encrypted to: ");
- //print_hex(enc_buf, 32);
- //printf("\nCiphertext : ");
- //print_hex(ciphertext[0], 32);
- pass = pass && !memcmp(enc_buf, ciphertext[0], 32);
-
- //printf("\n\n");
- return(pass);
-}
-
-int aes_ctr_test()
-{
- WORD key_schedule[60];
- BYTE enc_buf[128];
- BYTE plaintext[1][32] = {
- {0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51}
- };
- BYTE ciphertext[1][32] = {
- {0x60,0x1e,0xc3,0x13,0x77,0x57,0x89,0xa5,0xb7,0xa7,0xf5,0x04,0xbb,0xf3,0xd2,0x28,0xf4,0x43,0xe3,0xca,0x4d,0x62,0xb5,0x9a,0xca,0x84,0xe9,0x90,0xca,0xca,0xf5,0xc5}
- };
- BYTE iv[1][16] = {
- {0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff},
- };
- BYTE key[1][32] = {
- {0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4}
- };
- int pass = 1;
-
- //printf("* CTR mode:\n");
- aes_key_setup(key[0], key_schedule, 256);
-
- //printf( "Key : ");
- //print_hex(key[0], 32);
- //printf("\nIV : ");
- //print_hex(iv[0], 16);
-
- aes_encrypt_ctr(plaintext[0], 32, enc_buf, key_schedule, 256, iv[0]);
- //printf("\nPlaintext : ");
- //print_hex(plaintext[0], 32);
- //printf("\n-encrypted to: ");
- //print_hex(enc_buf, 32);
- pass = pass && !memcmp(enc_buf, ciphertext[0], 32);
-
- aes_decrypt_ctr(ciphertext[0], 32, enc_buf, key_schedule, 256, iv[0]);
- //printf("\nCiphertext : ");
- //print_hex(ciphertext[0], 32);
- //printf("\n-decrypted to: ");
- //print_hex(enc_buf, 32);
- pass = pass && !memcmp(enc_buf, plaintext[0], 32);
-
- //printf("\n\n");
- return(pass);
-}
-
-int aes_ccm_test()
-{
- int mac_auth;
- WORD enc_buf_len;
- BYTE enc_buf[128];
- BYTE plaintext[3][32] = {
- {0x20,0x21,0x22,0x23},
- {0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f},
- {0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37}
- };
- BYTE assoc[3][32] = {
- {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07},
- {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f},
- {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13}
- };
- BYTE ciphertext[3][32 + 16] = {
- {0x71,0x62,0x01,0x5b,0x4d,0xac,0x25,0x5d},
- {0xd2,0xa1,0xf0,0xe0,0x51,0xea,0x5f,0x62,0x08,0x1a,0x77,0x92,0x07,0x3d,0x59,0x3d,0x1f,0xc6,0x4f,0xbf,0xac,0xcd},
- {0xe3,0xb2,0x01,0xa9,0xf5,0xb7,0x1a,0x7a,0x9b,0x1c,0xea,0xec,0xcd,0x97,0xe7,0x0b,0x61,0x76,0xaa,0xd9,0xa4,0x42,0x8a,0xa5,0x48,0x43,0x92,0xfb,0xc1,0xb0,0x99,0x51}
- };
- BYTE iv[3][16] = {
- {0x10,0x11,0x12,0x13,0x14,0x15,0x16},
- {0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17},
- {0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b}
- };
- BYTE key[1][32] = {
- {0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f}
- };
- int pass = 1;
-
- //printf("* CCM mode:\n");
- //printf("Key : ");
- //print_hex(key[0], 16);
-
- //print_hex(plaintext[0], 4);
- //print_hex(assoc[0], 8);
- //print_hex(ciphertext[0], 8);
- //print_hex(iv[0], 7);
- //print_hex(key[0], 16);
-
- aes_encrypt_ccm(plaintext[0], 4, assoc[0], 8, iv[0], 7, enc_buf, &enc_buf_len, 4, key[0], 128);
- //printf("\nNONCE : ");
- //print_hex(iv[0], 7);
- //printf("\nAssoc. Data : ");
- //print_hex(assoc[0], 8);
- //printf("\nPayload : ");
- //print_hex(plaintext[0], 4);
- //printf("\n-encrypted to: ");
- //print_hex(enc_buf, enc_buf_len);
- pass = pass && !memcmp(enc_buf, ciphertext[0], enc_buf_len);
-
- aes_decrypt_ccm(ciphertext[0], 8, assoc[0], 8, iv[0], 7, enc_buf, &enc_buf_len, 4, &mac_auth, key[0], 128);
- //printf("\n-Ciphertext : ");
- //print_hex(ciphertext[0], 8);
- //printf("\n-decrypted to: ");
- //print_hex(enc_buf, enc_buf_len);
- //printf("\nAuthenticated: %d ", mac_auth);
- pass = pass && !memcmp(enc_buf, plaintext[0], enc_buf_len) && mac_auth;
-
-
- aes_encrypt_ccm(plaintext[1], 16, assoc[1], 16, iv[1], 8, enc_buf, &enc_buf_len, 6, key[0], 128);
- //printf("\n\nNONCE : ");
- //print_hex(iv[1], 8);
- //printf("\nAssoc. Data : ");
- //print_hex(assoc[1], 16);
- //printf("\nPayload : ");
- //print_hex(plaintext[1], 16);
- //printf("\n-encrypted to: ");
- //print_hex(enc_buf, enc_buf_len);
- pass = pass && !memcmp(enc_buf, ciphertext[1], enc_buf_len);
-
- aes_decrypt_ccm(ciphertext[1], 22, assoc[1], 16, iv[1], 8, enc_buf, &enc_buf_len, 6, &mac_auth, key[0], 128);
- //printf("\n-Ciphertext : ");
- //print_hex(ciphertext[1], 22);
- //printf("\n-decrypted to: ");
- //print_hex(enc_buf, enc_buf_len);
- //printf("\nAuthenticated: %d ", mac_auth);
- pass = pass && !memcmp(enc_buf, plaintext[1], enc_buf_len) && mac_auth;
-
-
- aes_encrypt_ccm(plaintext[2], 24, assoc[2], 20, iv[2], 12, enc_buf, &enc_buf_len, 8, key[0], 128);
- //printf("\n\nNONCE : ");
- //print_hex(iv[2], 12);
- //printf("\nAssoc. Data : ");
- //print_hex(assoc[2], 20);
- //printf("\nPayload : ");
- //print_hex(plaintext[2], 24);
- //printf("\n-encrypted to: ");
- //print_hex(enc_buf, enc_buf_len);
- pass = pass && !memcmp(enc_buf, ciphertext[2], enc_buf_len);
-
- aes_decrypt_ccm(ciphertext[2], 32, assoc[2], 20, iv[2], 12, enc_buf, &enc_buf_len, 8, &mac_auth, key[0], 128);
- //printf("\n-Ciphertext : ");
- //print_hex(ciphertext[2], 32);
- //printf("\n-decrypted to: ");
- //print_hex(enc_buf, enc_buf_len);
- //printf("\nAuthenticated: %d ", mac_auth);
- pass = pass && !memcmp(enc_buf, plaintext[2], enc_buf_len) && mac_auth;
-
- //printf("\n\n");
- return(pass);
-}
-
-int aes_test()
-{
- int pass = 1;
-
- pass = pass && aes_ecb_test();
- pass = pass && aes_cbc_test();
- pass = pass && aes_ctr_test();
- pass = pass && aes_ccm_test();
-
- return(pass);
-}
-
-int main(int argc, char *argv[])
-{
- printf("AES Tests: %s\n", aes_test() ? "SUCCEEDED" : "FAILED");
-
- return(0);
-}
diff --git a/lib/crypto-algorithms/arcfour_test.c b/lib/crypto-algorithms/arcfour_test.c
deleted file mode 100644
index 985f8a7..0000000
--- a/lib/crypto-algorithms/arcfour_test.c
+++ /dev/null
@@ -1,47 +0,0 @@
-/*********************************************************************
-* Filename: arcfour_test.c
-* Author: Brad Conte (brad AT bradconte.com)
-* Copyright:
-* Disclaimer: This code is presented "as is" without any guarantees.
-* Details: Performs known-answer tests on the corresponding ARCFOUR
- implementation. These tests do not encompass the full
- range of available test vectors, however, if the tests
- pass it is very, very likely that the code is correct
- and was compiled properly. This code also serves as
- example usage of the functions.
-*********************************************************************/
-
-/*************************** HEADER FILES ***************************/
-#include <stdio.h>
-#include <memory.h>
-#include "arcfour.h"
-
-/*********************** FUNCTION DEFINITIONS ***********************/
-int rc4_test()
-{
- BYTE state[256];
- BYTE key[3][10] = {{"Key"}, {"Wiki"}, {"Secret"}};
- BYTE stream[3][10] = {{0xEB,0x9F,0x77,0x81,0xB7,0x34,0xCA,0x72,0xA7,0x19},
- {0x60,0x44,0xdb,0x6d,0x41,0xb7},
- {0x04,0xd4,0x6b,0x05,0x3c,0xa8,0x7b,0x59}};
- int stream_len[3] = {10,6,8};
- BYTE buf[1024];
- int idx;
- int pass = 1;
-
- // Only test the output stream. Note that the state can be reused.
- for (idx = 0; idx < 3; idx++) {
- arcfour_key_setup(state, key[idx], strlen(key[idx]));
- arcfour_generate_stream(state, buf, stream_len[idx]);
- pass = pass && !memcmp(stream[idx], buf, stream_len[idx]);
- }
-
- return(pass);
-}
-
-int main()
-{
- printf("ARCFOUR tests: %s\n", rc4_test() ? "SUCCEEDED" : "FAILED");
-
- return(0);
-}
diff --git a/lib/crypto-algorithms/base64_test.c b/lib/crypto-algorithms/base64_test.c
deleted file mode 100644
index c59cc98..0000000
--- a/lib/crypto-algorithms/base64_test.c
+++ /dev/null
@@ -1,54 +0,0 @@
-/*********************************************************************
-* Filename: blowfish_test.c
-* Author: Brad Conte (brad AT bradconte.com)
-* Copyright:
-* Disclaimer: This code is presented "as is" without any guarantees.
-* Details: Performs known-answer tests on the corresponding Base64
- implementation. These tests do not encompass the full
- range of available test vectors, however, if the tests
- pass it is very, very likely that the code is correct
- and was compiled properly. This code also serves as
- example usage of the functions.
-*********************************************************************/
-
-/*************************** HEADER FILES ***************************/
-#include <stdio.h>
-#include <memory.h>
-#include "base64.h"
-
-/*********************** FUNCTION DEFINITIONS ***********************/
-int base64_test()
-{
- BYTE text[3][1024] = {{"fo"},
- {"foobar"},
- {"Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure."}};
- BYTE code[3][1024] = {{"Zm8="},
- {"Zm9vYmFy"},
- {"TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz\nIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg\ndGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu\ndWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo\nZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4="}};
- BYTE buf[1024];
- size_t buf_len;
- int pass = 1;
- int idx;
-
- for (idx = 0; idx < 3; idx++) {
- buf_len = base64_encode(text[idx], buf, strlen(text[idx]), 1);
- pass = pass && ((buf_len == strlen(code[idx])) &&
- (buf_len == base64_encode(text[idx], NULL, strlen(text[idx]), 1)));
- pass = pass && !strcmp(code[idx], buf);
-
- memset(buf, 0, sizeof(buf));
- buf_len = base64_decode(code[idx], buf, strlen(code[idx]));
- pass = pass && ((buf_len == strlen(text[idx])) &&
- (buf_len == base64_decode(code[idx], NULL, strlen(code[idx]))));
- pass = pass && !strcmp(text[idx], buf);
- }
-
- return(pass);
-}
-
-int main()
-{
- printf("Base64 tests: %s\n", base64_test() ? "PASSED" : "FAILED");
-
- return 0;
-}
diff --git a/lib/crypto-algorithms/blowfish_test.c b/lib/crypto-algorithms/blowfish_test.c
deleted file mode 100644
index 0f0aa38..0000000
--- a/lib/crypto-algorithms/blowfish_test.c
+++ /dev/null
@@ -1,68 +0,0 @@
-/*********************************************************************
-* Filename: blowfish_test.c
-* Author: Brad Conte (brad AT bradconte.com)
-* Copyright:
-* Disclaimer: This code is presented "as is" without any guarantees.
-* Details: Performs known-answer tests on the corresponding Blowfish
- implementation. These tests do not encompass the full
- range of available test vectors, however, if the tests
- pass it is very, very likely that the code is correct
- and was compiled properly. This code also serves as
- example usage of the functions.
-*********************************************************************/
-
-/*************************** HEADER FILES ***************************/
-#include <stdio.h>
-#include <memory.h>
-#include "blowfish.h"
-
-/*********************** FUNCTION DEFINITIONS ***********************/
-int blowfish_test()
-{
- BYTE key1[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
- BYTE key2[8] = {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
- BYTE key3[24] = {0xF0,0xE1,0xD2,0xC3,0xB4,0xA5,0x96,0x87,
- 0x78,0x69,0x5A,0x4B,0x3C,0x2D,0x1E,0x0F,
- 0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77};
- BYTE p1[BLOWFISH_BLOCK_SIZE] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
- BYTE p2[BLOWFISH_BLOCK_SIZE] = {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
- BYTE p3[BLOWFISH_BLOCK_SIZE] = {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10};
-
- BYTE c1[BLOWFISH_BLOCK_SIZE] = {0x4e,0xf9,0x97,0x45,0x61,0x98,0xdd,0x78};
- BYTE c2[BLOWFISH_BLOCK_SIZE] = {0x51,0x86,0x6f,0xd5,0xb8,0x5e,0xcb,0x8a};
- BYTE c3[BLOWFISH_BLOCK_SIZE] = {0x05,0x04,0x4b,0x62,0xfa,0x52,0xd0,0x80};
-
- BYTE enc_buf[BLOWFISH_BLOCK_SIZE];
- BLOWFISH_KEY key;
- int pass = 1;
-
- // Test vector 1.
- blowfish_key_setup(key1, &key, BLOWFISH_BLOCK_SIZE);
- blowfish_encrypt(p1, enc_buf, &key);
- pass = pass && !memcmp(c1, enc_buf, BLOWFISH_BLOCK_SIZE);
- blowfish_decrypt(c1, enc_buf, &key);
- pass = pass && !memcmp(p1, enc_buf, BLOWFISH_BLOCK_SIZE);
-
- // Test vector 2.
- blowfish_key_setup(key2, &key, BLOWFISH_BLOCK_SIZE);
- blowfish_encrypt(p2, enc_buf, &key);
- pass = pass && !memcmp(c2, enc_buf, BLOWFISH_BLOCK_SIZE);
- blowfish_decrypt(c2, enc_buf, &key);
- pass = pass && !memcmp(p2, enc_buf, BLOWFISH_BLOCK_SIZE);
-
- // Test vector 3.
- blowfish_key_setup(key3, &key, 24);
- blowfish_encrypt(p3, enc_buf, &key);
- pass = pass && !memcmp(c3, enc_buf, BLOWFISH_BLOCK_SIZE);
- blowfish_decrypt(c3, enc_buf, &key);
- pass = pass && !memcmp(p3, enc_buf, BLOWFISH_BLOCK_SIZE);
-
- return(pass);
-}
-
-int main()
-{
- printf("Blowfish tests: %s\n", blowfish_test() ? "SUCCEEDED" : "FAILED");
-
- return(0);
-}
diff --git a/lib/crypto-algorithms/des_test.c b/lib/crypto-algorithms/des_test.c
deleted file mode 100644
index 3e46134..0000000
--- a/lib/crypto-algorithms/des_test.c
+++ /dev/null
@@ -1,83 +0,0 @@
-/*********************************************************************
-* Filename: des_test.c
-* Author: Brad Conte (brad AT bradconte.com)
-* Copyright:
-* Disclaimer: This code is presented "as is" without any guarantees.
-* Details: Performs known-answer tests on the corresponding DES
- implementation. These tests do not encompass the full
- range of available test vectors, however, if the tests
- pass it is very, very likely that the code is correct
- and was compiled properly. This code also serves as
- example usage of the functions.
-*********************************************************************/
-
-/*************************** HEADER FILES ***************************/
-#include <stdio.h>
-#include <memory.h>
-#include "des.h"
-
-/*********************** FUNCTION DEFINITIONS ***********************/
-int des_test()
-{
- BYTE pt1[DES_BLOCK_SIZE] = {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xE7};
- BYTE pt2[DES_BLOCK_SIZE] = {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF};
- BYTE pt3[DES_BLOCK_SIZE] = {0x54,0x68,0x65,0x20,0x71,0x75,0x66,0x63};
- BYTE ct1[DES_BLOCK_SIZE] = {0xc9,0x57,0x44,0x25,0x6a,0x5e,0xd3,0x1d};
- BYTE ct2[DES_BLOCK_SIZE] = {0x85,0xe8,0x13,0x54,0x0f,0x0a,0xb4,0x05};
- BYTE ct3[DES_BLOCK_SIZE] = {0xc9,0x57,0x44,0x25,0x6a,0x5e,0xd3,0x1d};
- BYTE ct4[DES_BLOCK_SIZE] = {0xA8,0x26,0xFD,0x8C,0xE5,0x3B,0x85,0x5F};
- BYTE key1[DES_BLOCK_SIZE] = {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF};
- BYTE key2[DES_BLOCK_SIZE] = {0x13,0x34,0x57,0x79,0x9B,0xBC,0xDF,0xF1};
- BYTE three_key1[DES_BLOCK_SIZE * 3] = {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF,
- 0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF,
- 0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF};
- BYTE three_key2[DES_BLOCK_SIZE * 3] = {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF,
- 0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF,0x01,
- 0x45,0x67,0x89,0xAB,0xCD,0xEF,0x01,0x23};
-
- BYTE schedule[16][6];
- BYTE three_schedule[3][16][6];
- BYTE buf[DES_BLOCK_SIZE];
- int pass = 1;
-
- des_key_setup(key1, schedule, DES_ENCRYPT);
- des_crypt(pt1, buf, schedule);
- pass = pass && !memcmp(ct1, buf, DES_BLOCK_SIZE);
-
- des_key_setup(key1, schedule, DES_DECRYPT);
- des_crypt(ct1, buf, schedule);
- pass = pass && !memcmp(pt1, buf, DES_BLOCK_SIZE);
-
- des_key_setup(key2, schedule, DES_ENCRYPT);
- des_crypt(pt2, buf, schedule);
- pass = pass && !memcmp(ct2, buf, DES_BLOCK_SIZE);
-
- des_key_setup(key2, schedule, DES_DECRYPT);
- des_crypt(ct2, buf, schedule);
- pass = pass && !memcmp(pt2, buf, DES_BLOCK_SIZE);
-
- three_des_key_setup(three_key1, three_schedule, DES_ENCRYPT);
- three_des_crypt(pt1, buf, three_schedule);
- pass = pass && !memcmp(ct3, buf, DES_BLOCK_SIZE);
-
- three_des_key_setup(three_key1, three_schedule, DES_DECRYPT);
- three_des_crypt(ct3, buf, three_schedule);
- pass = pass && !memcmp(pt1, buf, DES_BLOCK_SIZE);
-
- three_des_key_setup(three_key2, three_schedule, DES_ENCRYPT);
- three_des_crypt(pt3, buf, three_schedule);
- pass = pass && !memcmp(ct4, buf, DES_BLOCK_SIZE);
-
- three_des_key_setup(three_key2, three_schedule, DES_DECRYPT);
- three_des_crypt(ct4, buf, three_schedule);
- pass = pass && !memcmp(pt3, buf, DES_BLOCK_SIZE);
-
- return(pass);
-}
-
-int main()
-{
- printf("DES test: %s\n", des_test() ? "SUCCEEDED" : "FAILED");
-
- return(0);
-}
diff --git a/lib/crypto-algorithms/md2_test.c b/lib/crypto-algorithms/md2_test.c
deleted file mode 100644
index 883f20a..0000000
--- a/lib/crypto-algorithms/md2_test.c
+++ /dev/null
@@ -1,58 +0,0 @@
-/*********************************************************************
-* Filename: md2_test.c
-* Author: Brad Conte (brad AT bradconte.com)
-* Copyright:
-* Disclaimer: This code is presented "as is" without any guarantees.
-* Details: Performs known-answer tests on the corresponding MD2
- implementation. These tests do not encompass the full
- range of available test vectors, however, if the tests
- pass it is very, very likely that the code is correct
- and was compiled properly. This code also serves as
- example usage of the functions.
-*********************************************************************/
-
-/*************************** HEADER FILES ***************************/
-#include <stdio.h>
-#include <string.h>
-#include <memory.h>
-#include "md2.h"
-
-/*********************** FUNCTION DEFINITIONS ***********************/
-int md2_test()
-{
- BYTE text1[] = {"abc"};
- BYTE text2[] = {"abcdefghijklmnopqrstuvwxyz"};
- BYTE text3_1[] = {"ABCDEFGHIJKLMNOPQRSTUVWXYZabcde"};
- BYTE text3_2[] = {"fghijklmnopqrstuvwxyz0123456789"};
- BYTE hash1[MD2_BLOCK_SIZE] = {0xda,0x85,0x3b,0x0d,0x3f,0x88,0xd9,0x9b,0x30,0x28,0x3a,0x69,0xe6,0xde,0xd6,0xbb};
- BYTE hash2[MD2_BLOCK_SIZE] = {0x4e,0x8d,0xdf,0xf3,0x65,0x02,0x92,0xab,0x5a,0x41,0x08,0xc3,0xaa,0x47,0x94,0x0b};
- BYTE hash3[MD2_BLOCK_SIZE] = {0xda,0x33,0xde,0xf2,0xa4,0x2d,0xf1,0x39,0x75,0x35,0x28,0x46,0xc3,0x03,0x38,0xcd};
- BYTE buf[16];
- MD2_CTX ctx;
- int pass = 1;
-
- md2_init(&ctx);
- md2_update(&ctx, text1, strlen(text1));
- md2_final(&ctx, buf);
- pass = pass && !memcmp(hash1, buf, MD2_BLOCK_SIZE);
-
- // Note that the MD2 object can be re-used.
- md2_init(&ctx);
- md2_update(&ctx, text2, strlen(text2));
- md2_final(&ctx, buf);
- pass = pass && !memcmp(hash2, buf, MD2_BLOCK_SIZE);
-
- // Note that the data is added in two chunks.
- md2_init(&ctx);
- md2_update(&ctx, text3_1, strlen(text3_1));
- md2_update(&ctx, text3_2, strlen(text3_2));
- md2_final(&ctx, buf);
- pass = pass && !memcmp(hash3, buf, MD2_BLOCK_SIZE);
-
- return(pass);
-}
-
-int main()
-{
- printf("MD2 tests: %s\n", md2_test() ? "SUCCEEDED" : "FAILED");
-}
diff --git a/lib/crypto-algorithms/md5_test.c b/lib/crypto-algorithms/md5_test.c
deleted file mode 100644
index e945c8b..0000000
--- a/lib/crypto-algorithms/md5_test.c
+++ /dev/null
@@ -1,60 +0,0 @@
-/*********************************************************************
-* Filename: md5_test.c
-* Author: Brad Conte (brad AT bradconte.com)
-* Copyright:
-* Disclaimer: This code is presented "as is" without any guarantees.
-* Details: Performs known-answer tests on the corresponding MD5
- implementation. These tests do not encompass the full
- range of available test vectors, however, if the tests
- pass it is very, very likely that the code is correct
- and was compiled properly. This code also serves as
- example usage of the functions.
-*********************************************************************/
-
-/*************************** HEADER FILES ***************************/
-#include <stdio.h>
-#include <memory.h>
-#include <string.h>
-#include "md5.h"
-
-/*********************** FUNCTION DEFINITIONS ***********************/
-int md5_test()
-{
- BYTE text1[] = {""};
- BYTE text2[] = {"abc"};
- BYTE text3_1[] = {"ABCDEFGHIJKLMNOPQRSTUVWXYZabcde"};
- BYTE text3_2[] = {"fghijklmnopqrstuvwxyz0123456789"};
- BYTE hash1[MD5_BLOCK_SIZE] = {0xd4,0x1d,0x8c,0xd9,0x8f,0x00,0xb2,0x04,0xe9,0x80,0x09,0x98,0xec,0xf8,0x42,0x7e};
- BYTE hash2[MD5_BLOCK_SIZE] = {0x90,0x01,0x50,0x98,0x3c,0xd2,0x4f,0xb0,0xd6,0x96,0x3f,0x7d,0x28,0xe1,0x7f,0x72};
- BYTE hash3[MD5_BLOCK_SIZE] = {0xd1,0x74,0xab,0x98,0xd2,0x77,0xd9,0xf5,0xa5,0x61,0x1c,0x2c,0x9f,0x41,0x9d,0x9f};
- BYTE buf[16];
- MD5_CTX ctx;
- int pass = 1;
-
- md5_init(&ctx);
- md5_update(&ctx, text1, strlen(text1));
- md5_final(&ctx, buf);
- pass = pass && !memcmp(hash1, buf, MD5_BLOCK_SIZE);
-
- // Note the MD5 object can be reused.
- md5_init(&ctx);
- md5_update(&ctx, text2, strlen(text2));
- md5_final(&ctx, buf);
- pass = pass && !memcmp(hash2, buf, MD5_BLOCK_SIZE);
-
- // Note the data is being added in two chunks.
- md5_init(&ctx);
- md5_update(&ctx, text3_1, strlen(text3_1));
- md5_update(&ctx, text3_2, strlen(text3_2));
- md5_final(&ctx, buf);
- pass = pass && !memcmp(hash3, buf, MD5_BLOCK_SIZE);
-
- return(pass);
-}
-
-int main()
-{
- printf("MD5 tests: %s\n", md5_test() ? "SUCCEEDED" : "FAILED");
-
- return(0);
-}
diff --git a/lib/crypto-algorithms/project.conf b/lib/crypto-algorithms/project.conf
new file mode 100644
index 0000000..776dc58
--- /dev/null
+++ b/lib/crypto-algorithms/project.conf
@@ -0,0 +1,5 @@
+[package]
+name = "crypto-algorithms"
+type = "static"
+version = "0.1.0"
+platforms = ["any"]
diff --git a/lib/crypto-algorithms/rot-13_test.c b/lib/crypto-algorithms/rot-13_test.c
deleted file mode 100644
index a6fd01d..0000000
--- a/lib/crypto-algorithms/rot-13_test.c
+++ /dev/null
@@ -1,44 +0,0 @@
-/*********************************************************************
-* Filename: rot-13_test.c
-* Author: Brad Conte (brad AT bradconte.com)
-* Copyright:
-* Disclaimer: This code is presented "as is" without any guarantees.
-* Details: Performs known-answer tests on the corresponding ROT-13
- implementation. These tests do not encompass the full
- range of available test vectors, however, if the tests
- pass it is very, very likely that the code is correct
- and was compiled properly. This code also serves as
- example usage of the functions.
-*********************************************************************/
-
-/*************************** HEADER FILES ***************************/
-#include <stdio.h>
-#include <string.h>
-#include "rot-13.h"
-
-/*********************** FUNCTION DEFINITIONS ***********************/
-int rot13_test()
-{
- char text[] = {"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"};
- char code[] = {"NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm"};
- char buf[1024];
- int pass = 1;
-
- // To encode, just apply ROT-13.
- strcpy(buf, text);
- rot13(buf);
- pass = pass && !strcmp(code, buf);
-
- // To decode, just re-apply ROT-13.
- rot13(buf);
- pass = pass && !strcmp(text, buf);
-
- return(pass);
-}
-
-int main()
-{
- printf("ROT-13 tests: %s\n", rot13_test() ? "SUCCEEDED" : "FAILED");
-
- return(0);
-}
diff --git a/lib/crypto-algorithms/sha1_test.c b/lib/crypto-algorithms/sha1_test.c
deleted file mode 100644
index 6c78f7d..0000000
--- a/lib/crypto-algorithms/sha1_test.c
+++ /dev/null
@@ -1,58 +0,0 @@
-/*********************************************************************
-* Filename: sha1_test.c
-* Author: Brad Conte (brad AT bradconte.com)
-* Copyright:
-* Disclaimer: This code is presented "as is" without any guarantees.
-* Details: Performs known-answer tests on the corresponding SHA1
- implementation. These tests do not encompass the full
- range of available test vectors, however, if the tests
- pass it is very, very likely that the code is correct
- and was compiled properly. This code also serves as
- example usage of the functions.
-*********************************************************************/
-
-/*************************** HEADER FILES ***************************/
-#include <stdio.h>
-#include <memory.h>
-#include <string.h>
-#include "sha1.h"
-
-/*********************** FUNCTION DEFINITIONS ***********************/
-int sha1_test()
-{
- BYTE text1[] = {"abc"};
- BYTE text2[] = {"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"};
- BYTE text3[] = {"aaaaaaaaaa"};
- BYTE hash1[SHA1_BLOCK_SIZE] = {0xa9,0x99,0x3e,0x36,0x47,0x06,0x81,0x6a,0xba,0x3e,0x25,0x71,0x78,0x50,0xc2,0x6c,0x9c,0xd0,0xd8,0x9d};
- BYTE hash2[SHA1_BLOCK_SIZE] = {0x84,0x98,0x3e,0x44,0x1c,0x3b,0xd2,0x6e,0xba,0xae,0x4a,0xa1,0xf9,0x51,0x29,0xe5,0xe5,0x46,0x70,0xf1};
- BYTE hash3[SHA1_BLOCK_SIZE] = {0x34,0xaa,0x97,0x3c,0xd4,0xc4,0xda,0xa4,0xf6,0x1e,0xeb,0x2b,0xdb,0xad,0x27,0x31,0x65,0x34,0x01,0x6f};
- BYTE buf[SHA1_BLOCK_SIZE];
- int idx;
- SHA1_CTX ctx;
- int pass = 1;
-
- sha1_init(&ctx);
- sha1_update(&ctx, text1, strlen(text1));
- sha1_final(&ctx, buf);
- pass = pass && !memcmp(hash1, buf, SHA1_BLOCK_SIZE);
-
- sha1_init(&ctx);
- sha1_update(&ctx, text2, strlen(text2));
- sha1_final(&ctx, buf);
- pass = pass && !memcmp(hash2, buf, SHA1_BLOCK_SIZE);
-
- sha1_init(&ctx);
- for (idx = 0; idx < 100000; ++idx)
- sha1_update(&ctx, text3, strlen(text3));
- sha1_final(&ctx, buf);
- pass = pass && !memcmp(hash3, buf, SHA1_BLOCK_SIZE);
-
- return(pass);
-}
-
-int main()
-{
- printf("SHA1 tests: %s\n", sha1_test() ? "SUCCEEDED" : "FAILED");
-
- return(0);
-}
diff --git a/lib/crypto-algorithms/sha256_test.c b/lib/crypto-algorithms/sha256_test.c
deleted file mode 100644
index 6951c51..0000000
--- a/lib/crypto-algorithms/sha256_test.c
+++ /dev/null
@@ -1,61 +0,0 @@
-/*********************************************************************
-* Filename: sha256.c
-* Author: Brad Conte (brad AT bradconte.com)
-* Copyright:
-* Disclaimer: This code is presented "as is" without any guarantees.
-* Details: Performs known-answer tests on the corresponding SHA1
- implementation. These tests do not encompass the full
- range of available test vectors, however, if the tests
- pass it is very, very likely that the code is correct
- and was compiled properly. This code also serves as
- example usage of the functions.
-*********************************************************************/
-
-/*************************** HEADER FILES ***************************/
-#include <stdio.h>
-#include <memory.h>
-#include <string.h>
-#include "sha256.h"
-
-/*********************** FUNCTION DEFINITIONS ***********************/
-int sha256_test()
-{
- BYTE text1[] = {"abc"};
- BYTE text2[] = {"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"};
- BYTE text3[] = {"aaaaaaaaaa"};
- BYTE hash1[SHA256_BLOCK_SIZE] = {0xba,0x78,0x16,0xbf,0x8f,0x01,0xcf,0xea,0x41,0x41,0x40,0xde,0x5d,0xae,0x22,0x23,
- 0xb0,0x03,0x61,0xa3,0x96,0x17,0x7a,0x9c,0xb4,0x10,0xff,0x61,0xf2,0x00,0x15,0xad};
- BYTE hash2[SHA256_BLOCK_SIZE] = {0x24,0x8d,0x6a,0x61,0xd2,0x06,0x38,0xb8,0xe5,0xc0,0x26,0x93,0x0c,0x3e,0x60,0x39,
- 0xa3,0x3c,0xe4,0x59,0x64,0xff,0x21,0x67,0xf6,0xec,0xed,0xd4,0x19,0xdb,0x06,0xc1};
- BYTE hash3[SHA256_BLOCK_SIZE] = {0xcd,0xc7,0x6e,0x5c,0x99,0x14,0xfb,0x92,0x81,0xa1,0xc7,0xe2,0x84,0xd7,0x3e,0x67,
- 0xf1,0x80,0x9a,0x48,0xa4,0x97,0x20,0x0e,0x04,0x6d,0x39,0xcc,0xc7,0x11,0x2c,0xd0};
- BYTE buf[SHA256_BLOCK_SIZE];
- SHA256_CTX ctx;
- int idx;
- int pass = 1;
-
- sha256_init(&ctx);
- sha256_update(&ctx, text1, strlen(text1));
- sha256_final(&ctx, buf);
- pass = pass && !memcmp(hash1, buf, SHA256_BLOCK_SIZE);
-
- sha256_init(&ctx);
- sha256_update(&ctx, text2, strlen(text2));
- sha256_final(&ctx, buf);
- pass = pass && !memcmp(hash2, buf, SHA256_BLOCK_SIZE);
-
- sha256_init(&ctx);
- for (idx = 0; idx < 100000; ++idx)
- sha256_update(&ctx, text3, strlen(text3));
- sha256_final(&ctx, buf);
- pass = pass && !memcmp(hash3, buf, SHA256_BLOCK_SIZE);
-
- return(pass);
-}
-
-int main()
-{
- printf("SHA-256 tests: %s\n", sha256_test() ? "SUCCEEDED" : "FAILEd");
-
- return(0);
-}
diff --git a/lib/curve25519-donna/.gitignore b/lib/curve25519-donna/.gitignore
index ccabede..1d764d7 100644
--- a/lib/curve25519-donna/.gitignore
+++ b/lib/curve25519-donna/.gitignore
@@ -10,3 +10,10 @@
*.pyc
/dist
/MANIFEST
+
+
+# Compiled sibs files
+sibs-build/
+compile_commands.json
+tests/sibs-build/
+tests/compile_commands.json
diff --git a/lib/curve25519-donna/contrib/Curve25519Donna.c b/lib/curve25519-donna/contrib/Curve25519Donna.c
deleted file mode 100644
index 71b816c..0000000
--- a/lib/curve25519-donna/contrib/Curve25519Donna.c
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- James Robson
- Public domain.
-*/
-
-#include "Curve25519Donna.h"
-#include <stdio.h>
-#include <stdlib.h>
-
-extern void curve25519_donna(unsigned char *output, const unsigned char *a,
- const unsigned char *b);
-
-unsigned char*
-as_unsigned_char_array(JNIEnv* env, jbyteArray array, int* len);
-
-jbyteArray as_byte_array(JNIEnv* env, unsigned char* buf, int len);
-
-
-jbyteArray as_byte_array(JNIEnv* env, unsigned char* buf, int len) {
- jbyteArray array = (*env)->NewByteArray(env, len);
- (*env)->SetByteArrayRegion(env, array, 0, len, (jbyte*)buf);
-
- //int i;
- //for (i = 0;i < len;++i) printf("%02x",(unsigned int) buf[i]); printf(" ");
- //printf("\n");
-
- return array;
-}
-
-unsigned char*
-as_unsigned_char_array(JNIEnv* env, jbyteArray array, int* len) {
-
- *len = (*env)->GetArrayLength(env, array);
- unsigned char* buf = (unsigned char*)calloc(*len+1, sizeof(char));
- (*env)->GetByteArrayRegion (env, array, 0, *len, (jbyte*)buf);
- return buf;
-
-}
-
-JNIEXPORT jbyteArray JNICALL Java_Curve25519Donna_curve25519Donna
- (JNIEnv *env, jobject obj, jbyteArray a, jbyteArray b) {
-
- unsigned char o[32] = {0};
- int l1, l2;
- unsigned char* a1 = as_unsigned_char_array(env, a, &l1);
- unsigned char* b1 = as_unsigned_char_array(env, b, &l2);
-
- if ( !(l1 == 32 && l2 == 32) ) {
- fprintf(stderr, "Error, must be length 32");
- return NULL;
- }
-
-
- curve25519_donna(o, (const unsigned char*)a1, (const unsigned char*)b1);
-
- free(a1);
- free(b1);
-
- return as_byte_array(env, (unsigned char*)o, 32);
-}
-
-JNIEXPORT jbyteArray JNICALL Java_Curve25519Donna_makePrivate
- (JNIEnv *env, jobject obj, jbyteArray secret) {
-
- int len;
- unsigned char* k = as_unsigned_char_array(env, secret, &len);
-
- if (len != 32) {
- fprintf(stderr, "Error, must be length 32");
- return NULL;
- }
-
- k[0] &= 248;
- k[31] &= 127;
- k[31] |= 64;
- return as_byte_array(env, k, 32);
-}
-
-JNIEXPORT jbyteArray JNICALL Java_Curve25519Donna_getPublic
- (JNIEnv *env, jobject obj, jbyteArray privkey) {
-
- int len;
- unsigned char* private = as_unsigned_char_array(env, privkey, &len);
-
- if (len != 32) {
- fprintf(stderr, "Error, must be length 32");
- return NULL;
- }
-
- unsigned char pubkey[32];
- unsigned char basepoint[32] = {9};
-
- curve25519_donna(pubkey, private, basepoint);
- return as_byte_array(env, (unsigned char*)pubkey, 32);
-}
-
-JNIEXPORT jbyteArray JNICALL Java_Curve25519Donna_makeSharedSecret
- (JNIEnv *env, jobject obj, jbyteArray privkey, jbyteArray their_pubkey) {
-
- unsigned char shared_secret[32];
-
- int l1, l2;
- unsigned char* private = as_unsigned_char_array(env, privkey, &l1);
- unsigned char* pubkey = as_unsigned_char_array(env, their_pubkey, &l2);
-
- if ( !(l1 == 32 && l2 == 32) ) {
- fprintf(stderr, "Error, must be length 32");
- return NULL;
- }
-
- curve25519_donna(shared_secret, private, pubkey);
- return as_byte_array(env, (unsigned char*)shared_secret, 32);
-}
-
-JNIEXPORT void JNICALL Java_Curve25519Donna_helowrld
- (JNIEnv *env, jobject obj) {
- printf("helowrld\n");
-}
diff --git a/lib/curve25519-donna/contrib/Curve25519Donna.h b/lib/curve25519-donna/contrib/Curve25519Donna.h
deleted file mode 100644
index 3cd4ca0..0000000
--- a/lib/curve25519-donna/contrib/Curve25519Donna.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/* DO NOT EDIT THIS FILE - it is machine generated */
-#include <jni.h>
-/* Header for class Curve25519Donna */
-
-#ifndef _Included_Curve25519Donna
-#define _Included_Curve25519Donna
-#ifdef __cplusplus
-extern "C" {
-#endif
-/*
- * Class: Curve25519Donna
- * Method: curve25519Donna
- * Signature: ([B[B)[B
- */
-JNIEXPORT jbyteArray JNICALL Java_Curve25519Donna_curve25519Donna
- (JNIEnv *, jobject, jbyteArray, jbyteArray);
-
-/*
- * Class: Curve25519Donna
- * Method: makePrivate
- * Signature: ([B)[B
- */
-JNIEXPORT jbyteArray JNICALL Java_Curve25519Donna_makePrivate
- (JNIEnv *, jobject, jbyteArray);
-
-/*
- * Class: Curve25519Donna
- * Method: getPublic
- * Signature: ([B)[B
- */
-JNIEXPORT jbyteArray JNICALL Java_Curve25519Donna_getPublic
- (JNIEnv *, jobject, jbyteArray);
-
-/*
- * Class: Curve25519Donna
- * Method: makeSharedSecret
- * Signature: ([B[B)[B
- */
-JNIEXPORT jbyteArray JNICALL Java_Curve25519Donna_makeSharedSecret
- (JNIEnv *, jobject, jbyteArray, jbyteArray);
-
-/*
- * Class: Curve25519Donna
- * Method: helowrld
- * Signature: ()V
- */
-JNIEXPORT void JNICALL Java_Curve25519Donna_helowrld
- (JNIEnv *, jobject);
-
-#ifdef __cplusplus
-}
-#endif
-#endif
diff --git a/lib/curve25519-donna/contrib/Curve25519Donna.java b/lib/curve25519-donna/contrib/Curve25519Donna.java
deleted file mode 100644
index e28cb53..0000000
--- a/lib/curve25519-donna/contrib/Curve25519Donna.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- James Robson
- Public domain.
-*/
-
-public class Curve25519Donna {
-
- final protected static char[] hexArray = "0123456789ABCDEF".toCharArray();
-
- public static String bytesToHex(byte[] bytes) {
- char[] hexChars = new char[bytes.length * 2];
- int v;
- for ( int j = 0; j < bytes.length; j++ ) {
- v = bytes[j] & 0xFF;
- hexChars[j * 2] = hexArray[v >>> 4];
- hexChars[j * 2 + 1] = hexArray[v & 0x0F];
- }
- return new String(hexChars);
- }
-
- public native byte[] curve25519Donna(byte[] a, byte[] b);
- public native byte[] makePrivate(byte[] secret);
- public native byte[] getPublic(byte[] privkey);
- public native byte[] makeSharedSecret(byte[] privkey, byte[] theirPubKey);
- public native void helowrld();
-
- // Uncomment if your Java is 32-bit:
- //static { System.loadLibrary("Curve25519Donna"); }
-
- // Otherwise, load this 64-bit .jnilib:
- static { System.loadLibrary("Curve25519Donna_64"); }
-
- /*
- To give the old tires a kick (OSX):
- java -cp `pwd` Curve25519Donna
- */
- public static void main (String[] args) {
-
- Curve25519Donna c = new Curve25519Donna();
-
- // These should be 32 bytes long
- byte[] user1Secret = "abcdefghijklmnopqrstuvwxyz123456".getBytes();
- byte[] user2Secret = "654321zyxwvutsrqponmlkjihgfedcba".getBytes();
-
-
- // You can use the curve function directly...
-
- //byte[] o = c.curve25519Donna(a, b);
- //System.out.println("o = " + bytesToHex(o));
-
-
- // ... but it's not really necessary. Just use the following
- // convenience methods:
-
- byte[] privKey = c.makePrivate(user1Secret);
- byte[] pubKey = c.getPublic(privKey);
-
- byte[] privKey2 = c.makePrivate(user2Secret);
- byte[] pubKey2 = c.getPublic(privKey2);
-
- System.out.println("'user1' privKey = " + bytesToHex(privKey));
- System.out.println("'user1' pubKey = " + bytesToHex(pubKey));
- System.out.println("===================================================");
-
- System.out.println("'user2' privKey = " + bytesToHex(privKey2));
- System.out.println("'user2' pubKey = " + bytesToHex(pubKey2));
- System.out.println("===================================================");
-
-
- byte[] ss1 = c.makeSharedSecret(privKey, pubKey2);
- System.out.println("'user1' computes shared secret: " + bytesToHex(ss1));
-
- byte[] ss2 = c.makeSharedSecret(privKey2, pubKey);
- System.out.println("'user2' computes shared secret: " + bytesToHex(ss2));
-
- }
-}
diff --git a/lib/curve25519-donna/contrib/make-snippets b/lib/curve25519-donna/contrib/make-snippets
deleted file mode 100644
index 4568721..0000000
--- a/lib/curve25519-donna/contrib/make-snippets
+++ /dev/null
@@ -1,68 +0,0 @@
-CFLAGS=-Wmissing-prototypes -Wdeclaration-after-statement -O2 -Wall
-CC=clang
-
-
-targets: curve25519-donna.a curve25519-donna-c64.a
-
-test: test-donna test-donna-c64
-
-
-clean:
- rm -f java-src/*.class java-src/*.jnilib *.dylib *.o *.a *.pp test-curve25519-donna test-curve25519-donna-c64 speed-curve25519-donna speed-curve25519-donna-c64
-
-curve25519-donna.a: curve25519-donna.o
- ar -rc curve25519-donna.a curve25519-donna.o
- ranlib curve25519-donna.a
-
-
-##### OSX dynamic library (32- & 64-bit)
-
-curve25519donna.dylib: curve25519-donna.a curve25519-donna-c64.a
- $(CC) -m32 -fpic -shared -Wl,-all_load curve25519-donna.a -Wl,-all_load -o libcurve25519donna.dylib
- $(CC) -fpic -shared -Wl,-all_load curve25519-donna-c64.a -Wl,-all_load -o libcurve25519donna_64.dylib
-
-##### OSX/Java section hence
-
-# Java JNI - compiled for OSX (32- & 64-bit)
-Curve25519Donna.class:
- cd java-src; javah -jni Curve25519Donna; cd ..
- cd java-src; javac Curve25519Donna.java; cd ..
-
-Curve25519Donna.jnilib: curve25519-donna.a curve25519-donna-c64.a Curve25519Donna.class
- @echo "Building 32-bit..."
- clang -o java-src/libCurve25519Donna.jnilib $(CFLAGS) -lc -shared -m32 -I /System/Library/Frameworks/JavaVM.framework/Headers curve25519-donna.o java-src/Curve25519Donna.c
- @echo "Building 64-bit..."
- clang -o java-src/libCurve25519Donna_64.jnilib $(CFLAGS) -lc -shared -I /System/Library/Frameworks/JavaVM.framework/Headers curve25519-donna-c64.o java-src/Curve25519Donna.c
-
-##### OSX/Java section end
-
-curve25519-donna.o: curve25519-donna.c
- $(CC) -c curve25519-donna.c $(CFLAGS) -m32
-
-curve25519-donna-c64.a: curve25519-donna-c64.o
- ar -rc curve25519-donna-c64.a curve25519-donna-c64.o
- ranlib curve25519-donna-c64.a
-
-curve25519-donna-c64.o: curve25519-donna-c64.c
- $(CC) -c curve25519-donna-c64.c $(CFLAGS)
-
-test-donna: test-curve25519-donna
- ./test-curve25519-donna | head -123456 | tail -1
-
-test-donna-c64: test-curve25519-donna-c64
- ./test-curve25519-donna-c64 | head -123456 | tail -1
-
-test-curve25519-donna: test-curve25519.c curve25519-donna.a
- $(CC) -o test-curve25519-donna test-curve25519.c curve25519-donna.a $(CFLAGS) -m32
-
-test-curve25519-donna-c64: test-curve25519.c curve25519-donna-c64.a
- $(CC) -o test-curve25519-donna-c64 test-curve25519.c curve25519-donna-c64.a $(CFLAGS)
-
-speed-curve25519-donna: speed-curve25519.c curve25519-donna.a
- $(CC) -o speed-curve25519-donna speed-curve25519.c curve25519-donna.a $(CFLAGS) -m32
-
-speed-curve25519-donna-c64: speed-curve25519.c curve25519-donna-c64.a
- $(CC) -o speed-curve25519-donna-c64 speed-curve25519.c curve25519-donna-c64.a $(CFLAGS)
-
-test-sc-curve25519-donna-c64: test-sc-curve25519.c curve25519-donna-c64.a
- $(CC) -o test-sc-curve25519-donna-c64 -O test-sc-curve25519.c curve25519-donna-c64.a test-sc-curve25519.s $(CFLAGS)
diff --git a/lib/curve25519-donna/project.conf b/lib/curve25519-donna/project.conf
new file mode 100644
index 0000000..5ed7b82
--- /dev/null
+++ b/lib/curve25519-donna/project.conf
@@ -0,0 +1,5 @@
+[package]
+name = "curve25519-donna"
+type = "static"
+version = "0.1.0"
+platforms = ["any"]
diff --git a/lib/curve25519-donna/python-src/curve25519/__init__.py b/lib/curve25519-donna/python-src/curve25519/__init__.py
deleted file mode 100644
index 873ff57..0000000
--- a/lib/curve25519-donna/python-src/curve25519/__init__.py
+++ /dev/null
@@ -1,4 +0,0 @@
-
-from .keys import Private, Public
-
-hush_pyflakes = [Private, Public]; del hush_pyflakes
diff --git a/lib/curve25519-donna/python-src/curve25519/curve25519module.c b/lib/curve25519-donna/python-src/curve25519/curve25519module.c
deleted file mode 100644
index e309ec0..0000000
--- a/lib/curve25519-donna/python-src/curve25519/curve25519module.c
+++ /dev/null
@@ -1,105 +0,0 @@
-/* tell python that PyArg_ParseTuple(t#) means Py_ssize_t, not int */
-#define PY_SSIZE_T_CLEAN
-#include <Python.h>
-#if (PY_VERSION_HEX < 0x02050000)
- typedef int Py_ssize_t;
-#endif
-
-/* This is required for compatibility with Python 2. */
-#if PY_MAJOR_VERSION >= 3
- #include <bytesobject.h>
- #define y "y"
-#else
- #define PyBytes_FromStringAndSize PyString_FromStringAndSize
- #define y "t"
-#endif
-
-int curve25519_donna(char *mypublic,
- const char *secret, const char *basepoint);
-
-static PyObject *
-pycurve25519_makeprivate(PyObject *self, PyObject *args)
-{
- char *in1;
- Py_ssize_t in1len;
- if (!PyArg_ParseTuple(args, y"#:clamp", &in1, &in1len))
- return NULL;
- if (in1len != 32) {
- PyErr_SetString(PyExc_ValueError, "input must be 32-byte string");
- return NULL;
- }
- in1[0] &= 248;
- in1[31] &= 127;
- in1[31] |= 64;
- return PyBytes_FromStringAndSize((char *)in1, 32);
-}
-
-static PyObject *
-pycurve25519_makepublic(PyObject *self, PyObject *args)
-{
- const char *private;
- char mypublic[32];
- char basepoint[32] = {9};
- Py_ssize_t privatelen;
- if (!PyArg_ParseTuple(args, y"#:makepublic", &private, &privatelen))
- return NULL;
- if (privatelen != 32) {
- PyErr_SetString(PyExc_ValueError, "input must be 32-byte string");
- return NULL;
- }
- curve25519_donna(mypublic, private, basepoint);
- return PyBytes_FromStringAndSize((char *)mypublic, 32);
-}
-
-static PyObject *
-pycurve25519_makeshared(PyObject *self, PyObject *args)
-{
- const char *myprivate, *theirpublic;
- char shared_key[32];
- Py_ssize_t myprivatelen, theirpubliclen;
- if (!PyArg_ParseTuple(args, y"#"y"#:generate",
- &myprivate, &myprivatelen, &theirpublic, &theirpubliclen))
- return NULL;
- if (myprivatelen != 32) {
- PyErr_SetString(PyExc_ValueError, "input must be 32-byte string");
- return NULL;
- }
- if (theirpubliclen != 32) {
- PyErr_SetString(PyExc_ValueError, "input must be 32-byte string");
- return NULL;
- }
- curve25519_donna(shared_key, myprivate, theirpublic);
- return PyBytes_FromStringAndSize((char *)shared_key, 32);
-}
-
-
-static PyMethodDef
-curve25519_functions[] = {
- {"make_private", pycurve25519_makeprivate, METH_VARARGS, "data->private"},
- {"make_public", pycurve25519_makepublic, METH_VARARGS, "private->public"},
- {"make_shared", pycurve25519_makeshared, METH_VARARGS, "private+public->shared"},
- {NULL, NULL, 0, NULL},
-};
-
-#if PY_MAJOR_VERSION >= 3
- static struct PyModuleDef
- curve25519_module = {
- PyModuleDef_HEAD_INIT,
- "_curve25519",
- NULL,
- NULL,
- curve25519_functions,
- };
-
- PyObject *
- PyInit__curve25519(void)
- {
- return PyModule_Create(&curve25519_module);
- }
-#else
- PyMODINIT_FUNC
- init_curve25519(void)
- {
- (void)Py_InitModule("_curve25519", curve25519_functions);
- }
-#endif \ No newline at end of file
diff --git a/lib/curve25519-donna/python-src/curve25519/keys.py b/lib/curve25519-donna/python-src/curve25519/keys.py
deleted file mode 100644
index e131dac..0000000
--- a/lib/curve25519-donna/python-src/curve25519/keys.py
+++ /dev/null
@@ -1,46 +0,0 @@
-from . import _curve25519
-from hashlib import sha256
-import os
-
-# the curve25519 functions are really simple, and could be used without an
-# OOP layer, but it's a bit too easy to accidentally swap the private and
-# public keys that way.
-
-def _hash_shared(shared):
- return sha256(b"curve25519-shared:"+shared).digest()
-
-class Private:
- def __init__(self, secret=None, seed=None):
- if secret is None:
- if seed is None:
- secret = os.urandom(32)
- else:
- secret = sha256(b"curve25519-private:"+seed).digest()
- else:
- assert seed is None, "provide secret, seed, or neither, not both"
- if not isinstance(secret, bytes) or len(secret) != 32:
- raise TypeError("secret= must be 32-byte string")
- self.private = _curve25519.make_private(secret)
-
- def serialize(self):
- return self.private
-
- def get_public(self):
- return Public(_curve25519.make_public(self.private))
-
- def get_shared_key(self, public, hashfunc=None):
- if not isinstance(public, Public):
- raise ValueError("'public' must be an instance of Public")
- if hashfunc is None:
- hashfunc = _hash_shared
- shared = _curve25519.make_shared(self.private, public.public)
- return hashfunc(shared)
-
-class Public:
- def __init__(self, public):
- assert isinstance(public, bytes)
- assert len(public) == 32
- self.public = public
-
- def serialize(self):
- return self.public
diff --git a/lib/curve25519-donna/python-src/curve25519/test/__init__.py b/lib/curve25519-donna/python-src/curve25519/test/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/lib/curve25519-donna/python-src/curve25519/test/__init__.py
+++ /dev/null
diff --git a/lib/curve25519-donna/python-src/curve25519/test/test_curve25519.py b/lib/curve25519-donna/python-src/curve25519/test/test_curve25519.py
deleted file mode 100755
index b3a5447..0000000
--- a/lib/curve25519-donna/python-src/curve25519/test/test_curve25519.py
+++ /dev/null
@@ -1,99 +0,0 @@
-#! /usr/bin/env python
-
-import unittest
-
-from curve25519 import Private, Public
-from hashlib import sha1, sha256
-from binascii import hexlify
-
-class Basic(unittest.TestCase):
- def test_basic(self):
- secret1 = b"abcdefghijklmnopqrstuvwxyz123456"
- self.assertEqual(len(secret1), 32)
-
- secret2 = b"654321zyxwvutsrqponmlkjihgfedcba"
- self.assertEqual(len(secret2), 32)
- priv1 = Private(secret=secret1)
- pub1 = priv1.get_public()
- priv2 = Private(secret=secret2)
- pub2 = priv2.get_public()
- shared12 = priv1.get_shared_key(pub2)
- e = b"b0818125eab42a8ac1af5e8b9b9c15ed2605c2bbe9675de89e5e6e7f442b9598"
- self.assertEqual(hexlify(shared12), e)
- shared21 = priv2.get_shared_key(pub1)
- self.assertEqual(shared12, shared21)
-
- pub2a = Public(pub2.serialize())
- shared12a = priv1.get_shared_key(pub2a)
- self.assertEqual(hexlify(shared12a), e)
-
- def test_errors(self):
- priv1 = Private()
- self.assertRaises(ValueError, priv1.get_shared_key, priv1)
-
- def test_seed(self):
- # use 32-byte secret
- self.assertRaises(TypeError, Private, secret=123)
- self.assertRaises(TypeError, Private, secret=b"too short")
- secret1 = b"abcdefghijklmnopqrstuvwxyz123456"
- assert len(secret1) == 32
- priv1 = Private(secret=secret1)
- priv1a = Private(secret=secret1)
- priv1b = Private(priv1.serialize())
- self.assertEqual(priv1.serialize(), priv1a.serialize())
- self.assertEqual(priv1.serialize(), priv1b.serialize())
- e = b"6062636465666768696a6b6c6d6e6f707172737475767778797a313233343576"
- self.assertEqual(hexlify(priv1.serialize()), e)
-
- # the private key is a clamped form of the secret, so they won't
- # quite be the same
- p = Private(secret=b"\x00"*32)
- self.assertEqual(hexlify(p.serialize()), b"00"*31+b"40")
- p = Private(secret=b"\xff"*32)
- self.assertEqual(hexlify(p.serialize()), b"f8"+b"ff"*30+b"7f")
-
- # use arbitrary-length seed
- self.assertRaises(TypeError, Private, seed=123)
- priv1 = Private(seed=b"abc")
- priv1a = Private(seed=b"abc")
- priv1b = Private(priv1.serialize())
- self.assertEqual(priv1.serialize(), priv1a.serialize())
- self.assertEqual(priv1.serialize(), priv1b.serialize())
- self.assertRaises(AssertionError, Private, seed=b"abc", secret=b"no")
-
- priv1 = Private(seed=b"abc")
- priv1a = Private(priv1.serialize())
- self.assertEqual(priv1.serialize(), priv1a.serialize())
- self.assertRaises(AssertionError, Private, seed=b"abc", secret=b"no")
-
- # use built-in os.urandom
- priv2 = Private()
- priv2a = Private(priv2.private)
- self.assertEqual(priv2.serialize(), priv2a.serialize())
-
- # attempt to use both secret= and seed=, not allowed
- self.assertRaises(AssertionError, Private, seed=b"abc", secret=b"no")
-
- def test_hashfunc(self):
- priv1 = Private(seed=b"abc")
- priv2 = Private(seed=b"def")
- shared_sha256 = priv1.get_shared_key(priv2.get_public())
- e = b"da959ffe77ebeb4757fe5ba310e28ede425ae0d0ff5ec9c884e2d08f311cf5e5"
- self.assertEqual(hexlify(shared_sha256), e)
-
- # confirm the hash function remains what we think it is
- def myhash(shared_key):
- return sha256(b"curve25519-shared:"+shared_key).digest()
- shared_myhash = priv1.get_shared_key(priv2.get_public(), myhash)
- self.assertEqual(hexlify(shared_myhash), e)
-
- def hexhash(shared_key):
- return sha1(shared_key).hexdigest().encode()
- shared_hexhash = priv1.get_shared_key(priv2.get_public(), hexhash)
- self.assertEqual(shared_hexhash,
- b"80eec98222c8edc4324fb9477a3c775ce7c6c93a")
-
-
-if __name__ == "__main__":
- unittest.main()
-
diff --git a/lib/curve25519-donna/python-src/curve25519/test/test_speed.py b/lib/curve25519-donna/python-src/curve25519/test/test_speed.py
deleted file mode 100755
index 4d7e0c8..0000000
--- a/lib/curve25519-donna/python-src/curve25519/test/test_speed.py
+++ /dev/null
@@ -1,46 +0,0 @@
-#! /usr/bin/env python
-
-from time import time
-from curve25519 import Private
-
-count = 10000
-elapsed_get_public = 0.0
-elapsed_get_shared = 0.0
-
-def abbreviate_time(data):
- # 1.23s, 790ms, 132us
- if data is None:
- return ""
- s = float(data)
- if s >= 10:
- #return abbreviate.abbreviate_time(data)
- return "%d" % s
- if s >= 1.0:
- return "%.2fs" % s
- if s >= 0.01:
- return "%dms" % (1000*s)
- if s >= 0.001:
- return "%.1fms" % (1000*s)
- if s >= 0.000001:
- return "%.1fus" % (1000000*s)
- return "%dns" % (1000000000*s)
-
-def nohash(key): return key
-
-for i in range(count):
- p = Private()
- start = time()
- pub = p.get_public()
- elapsed_get_public += time() - start
- pub2 = Private().get_public()
- start = time()
- shared = p.get_shared_key(pub2) #, hashfunc=nohash)
- elapsed_get_shared += time() - start
-
-print("get_public: %s" % abbreviate_time(elapsed_get_public / count))
-print("get_shared: %s" % abbreviate_time(elapsed_get_shared / count))
-
-# these take about 560us-570us each (with the default compiler settings, -Os)
-# on my laptop, same with -O2
-# of which the python overhead is about 5us
-# and the get_shared_key() hash step adds about 5us
diff --git a/lib/curve25519-donna/test-curve25519.c b/lib/curve25519-donna/test-curve25519.c
deleted file mode 100644
index 591d871..0000000
--- a/lib/curve25519-donna/test-curve25519.c
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
-test-curve25519 version 20050915
-D. J. Bernstein
-Public domain.
-
-Tiny modifications by agl
-*/
-
-#include <stdio.h>
-
-extern void curve25519_donna(unsigned char *output, const unsigned char *a,
- const unsigned char *b);
-void doit(unsigned char *ek,unsigned char *e,unsigned char *k);
-
-void doit(unsigned char *ek,unsigned char *e,unsigned char *k)
-{
- int i;
-
- for (i = 0;i < 32;++i) printf("%02x",(unsigned int) e[i]); printf(" ");
- for (i = 0;i < 32;++i) printf("%02x",(unsigned int) k[i]); printf(" ");
- curve25519_donna(ek,e,k);
- for (i = 0;i < 32;++i) printf("%02x",(unsigned int) ek[i]); printf("\n");
-}
-
-unsigned char e1k[32];
-unsigned char e2k[32];
-unsigned char e1e2k[32];
-unsigned char e2e1k[32];
-unsigned char e1[32] = {3};
-unsigned char e2[32] = {5};
-unsigned char k[32] = {9};
-
-int
-main()
-{
- int loop;
- int i;
-
- for (loop = 0;loop < 10000;++loop) {
- doit(e1k,e1,k);
- doit(e2e1k,e2,e1k);
- doit(e2k,e2,k);
- doit(e1e2k,e1,e2k);
- for (i = 0;i < 32;++i) if (e1e2k[i] != e2e1k[i]) {
- printf("fail\n");
- return 1;
- }
- for (i = 0;i < 32;++i) e1[i] ^= e2k[i];
- for (i = 0;i < 32;++i) e2[i] ^= e1k[i];
- for (i = 0;i < 32;++i) k[i] ^= e1e2k[i];
- }
-
- return 0;
-}
diff --git a/lib/curve25519-donna/test-noncanon.c b/lib/curve25519-donna/test-noncanon.c
deleted file mode 100644
index 6de4e8d..0000000
--- a/lib/curve25519-donna/test-noncanon.c
+++ /dev/null
@@ -1,39 +0,0 @@
-/* This file can be used to test whether the code handles non-canonical curve
- * points (i.e. points with the 256th bit set) in the same way as the reference
- * implementation. */
-
-#include <stdint.h>
-#include <stdio.h>
-#include <string.h>
-
-extern void curve25519_donna(unsigned char *output, const unsigned char *a,
- const unsigned char *b);
-int
-main()
-{
- static const uint8_t point1[32] = {
- 0x25,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- };
- static const uint8_t point2[32] = {
- 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
- 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
- 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
- 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
- };
- static const uint8_t scalar[32] = { 1 };
- uint8_t out1[32], out2[32];
-
- curve25519_donna(out1, scalar, point1);
- curve25519_donna(out2, scalar, point2);
-
- if (0 == memcmp(out1, out2, sizeof(out1))) {
- fprintf(stderr, "Top bit not ignored.\n");
- return 1;
- }
-
- fprintf(stderr, "Top bit correctly ignored.\n");
- return 0;
-}
diff --git a/lib/curve25519-donna/test-sc-curve25519.c b/lib/curve25519-donna/test-sc-curve25519.c
deleted file mode 100644
index 14a7e3c..0000000
--- a/lib/curve25519-donna/test-sc-curve25519.c
+++ /dev/null
@@ -1,72 +0,0 @@
-#define _GNU_SOURCE
-
-#include <stdio.h>
-#include <string.h>
-#include <stdint.h>
-#include <math.h>
-
-extern void curve25519_donna(uint8_t *, const uint8_t *, const uint8_t *);
-extern uint64_t tsc_read();
-
-int
-main(int argc, char **argv) {
- uint8_t private_key[32], public[32], peer1[32], peer2[32], output[32];
- static const uint8_t basepoint[32] = {9};
- unsigned i;
- uint64_t sum = 0, sum_squares = 0, skipped = 0, mean;
- static const unsigned count = 200000;
-
- memset(private_key, 42, sizeof(private_key));
-
- private_key[0] &= 248;
- private_key[31] &= 127;
- private_key[31] |= 64;
-
- curve25519_donna(public, private_key, basepoint);
- memset(peer1, 0, sizeof(peer1));
- memset(peer2, 255, sizeof(peer2));
-
- for (i = 0; i < count; ++i) {
- const uint64_t start = tsc_read();
- curve25519_donna(output, peer1, public);
- const uint64_t end = tsc_read();
- const uint64_t delta = end - start;
- if (delta > 650000) {
- // something terrible happened (task switch etc)
- skipped++;
- continue;
- }
- sum += delta;
- sum_squares += (delta * delta);
- }
-
- mean = sum / ((uint64_t) count);
- printf("all 0: mean:%lu sd:%f skipped:%lu\n",
- mean,
- sqrt((double)(sum_squares/((uint64_t) count) - mean*mean)),
- skipped);
-
- sum = sum_squares = skipped = 0;
-
- for (i = 0; i < count; ++i) {
- const uint64_t start = tsc_read();
- curve25519_donna(output, peer2, public);
- const uint64_t end = tsc_read();
- const uint64_t delta = end - start;
- if (delta > 650000) {
- // something terrible happened (task switch etc)
- skipped++;
- continue;
- }
- sum += delta;
- sum_squares += (delta * delta);
- }
-
- mean = sum / ((uint64_t) count);
- printf("all 1: mean:%lu sd:%f skipped:%lu\n",
- mean,
- sqrt((double)(sum_squares/((uint64_t) count) - mean*mean)),
- skipped);
-
- return 0;
-}
diff --git a/lib/curve25519-donna/test-sc-curve25519.s b/lib/curve25519-donna/test-sc-curve25519.s
deleted file mode 100644
index 1da4f68..0000000
--- a/lib/curve25519-donna/test-sc-curve25519.s
+++ /dev/null
@@ -1,8 +0,0 @@
-.text
-.globl tsc_read
-
-tsc_read:
-rdtsc
-shl $32,%rdx
-or %rdx,%rax
-ret
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;
-}