diff --git a/Makefile b/Makefile index a761c97..1b7ea3e 100644 --- a/Makefile +++ b/Makefile @@ -41,7 +41,7 @@ else LDFLAGS += -s -Wl,-Bstatic -static-libgcc -static-libstdc++ endif -all: $(I2PD_LIB) keygen keyinfo famtool routerinfo regaddr regaddr_3ld vain i2pbase64 offlinekeys b33address regaddralias +all: $(I2PD_LIB) keygen keyinfo famtool routerinfo regaddr regaddr_3ld vain i2pbase64 offlinekeys b33address regaddralias x25519 routerinfo: routerinfo.o $(I2PD_LIB) $(CXX) -o routerinfo routerinfo.o $(LDFLAGS) $(LIBS) @@ -75,6 +75,9 @@ b33address: b33address.o $(I2PD_LIB) regaddralias: regaddralias.o $(I2PD_LIB) $(CXX) -o regaddralias regaddralias.o $(LDFLAGS) $(LIBS) + +x25519: x25519.o $(I2PD_LIB) + $(CXX) -o x25519 x25519.o $(LDFLAGS) $(LIBS) .SUFFIXES: .SUFFIXES: .c .cc .C .cpp .o @@ -95,7 +98,7 @@ clean-obj: rm -f $(wildcard *.o) clean-bin: - rm -f b33address famtool i2pbase64 keygen keyinfo offlinekeys regaddr regaddr_3ld regaddralias routerinfo vain + rm -f b33address famtool i2pbase64 keygen keyinfo offlinekeys regaddr regaddr_3ld regaddralias routerinfo vain x25519 clean: clean-i2pd clean-obj clean-bin diff --git a/x25519.cpp b/x25519.cpp new file mode 100644 index 0000000..712f797 --- /dev/null +++ b/x25519.cpp @@ -0,0 +1,77 @@ +#include +#include +#include +#include +#include +#include "Base.h" + +#define KEYSIZE 32 +size_t len = KEYSIZE; + +struct BoxKeys +{ + uint8_t PublicKey[KEYSIZE]; + uint8_t PrivateKey[KEYSIZE]; +}; + +BoxKeys getKeyPair() +{ + BoxKeys keys; + + EVP_PKEY_CTX * Ctx; + EVP_PKEY * Pkey = nullptr; + Ctx = EVP_PKEY_CTX_new_id (NID_X25519, NULL); + + EVP_PKEY_keygen_init (Ctx); + EVP_PKEY_keygen (Ctx, &Pkey); + + EVP_PKEY_get_raw_public_key (Pkey, keys.PublicKey, &len); + EVP_PKEY_get_raw_private_key (Pkey, keys.PrivateKey, &len); + + EVP_PKEY_CTX_free(Ctx); + EVP_PKEY_free(Pkey); + + return keys; +} + +int main(int argc, char * argv[]) +{ + if (argc > 1) + { + std::string arg = static_cast(argv[1]); + if (arg == "--usage" || arg == "--help" || arg == "-h") + { + std::cout << "The x25519 keys are used for authentication with an encrypted LeaseSet.\n" + << "Server side:\n" + << " signaturetype = 11\n" + << " i2cp.leaseSetType = 5\n" + << " i2cp.leaseSetAuthType = 1\n" + << " i2cp.leaseSetClient.dh.210 = clientName:PublicKey\n" + << "Client side:\n" + << " i2cp.leaseSetPrivKey = PrivateKey\n\n" + << "https://i2pd.readthedocs.io/en/latest/user-guide/tunnels/" << std::endl; + + return 0; + } + } + + BoxKeys newKeys = getKeyPair(); + + size_t len_out = 50; + char b64Public[len_out] = {0}; + char b64Private[len_out] = {0}; + + i2p::data::ByteStreamToBase64 (newKeys.PublicKey, len, b64Public, len_out); + + std::cout << "PublicKey: "; + for (int i = 0; b64Public[i] != 0; ++i) + std::cout << b64Public[i]; + + i2p::data::ByteStreamToBase64 (newKeys.PrivateKey, len, b64Private, len_out); + + std::cout << "\nPrivateKey: "; + for (int i = 0; b64Private[i] != 0; ++i) + std::cout << b64Private[i]; + + return 0; +}