diff --git a/makefile b/makefile index 9554d96..edcfb6d 100644 --- a/makefile +++ b/makefile @@ -20,6 +20,7 @@ CFLAGS += -Wno-unused-result CFLAGS += -Wno-unused-local-typedefs CFLAGS += -Wno-unused-const-variable CFLAGS += -Wno-unused-macros +CFLAGS += -lsodium CFLAGS += -O3 CFLAGS += -g diff --git a/src/main.cpp b/src/main.cpp index c51cec7..722eb32 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,8 +1,16 @@ #include #include +#include #include "point.hpp" +unsigned char ed25519_pk[crypto_sign_PUBLICKEYBYTES]; +unsigned char ed25519_sk[crypto_sign_SECRETKEYBYTES]; +unsigned char ed25519_seed[crypto_sign_SEEDBYTES]; +unsigned char edwards25519_pk[crypto_scalarmult_ed25519_BYTES]; +unsigned char edwards25519_sk[crypto_scalarmult_ed25519_SCALARBYTES]; +unsigned char h[crypto_hash_sha512_BYTES]; + template struct Option { private: T value; @@ -11,6 +19,12 @@ template struct Option { public: Option() : is_some(false) {} Option(T value) : value(value), is_some(true) {} + + T unwrap() { + if (!is_some) + throw std::runtime_error("Option is empty"); + return value; + } }; // Templated alias for unique_ptr @@ -21,6 +35,16 @@ template Box Enbox(Args &&...args) { } int main(int argc, char *argv[]) { + if (sodium_init() < 0) { + return 1; + } + + // create an Ed25519 keypair + crypto_sign_keypair(ed25519_pk, ed25519_sk); + + // Extract the seed from the Ed25519 secret key + crypto_sign_ed25519_sk_to_seed(ed25519_seed, ed25519_sk); + Point p = Point(10, 5); std::cout << p << std::endl; p.move(5, 5); @@ -33,6 +57,9 @@ int main(int argc, char *argv[]) { Box p_box = std::make_unique(10, 5); Box p_box2 = Enbox(10, 5); + Box> p_box3 = Enbox>(Point(10, 5)); + + p_box3->unwrap().move(5, 5); std::cout << p << std::endl; std::cout << *p_box << std::endl;