From 75d45ae988e67721a1854281edff05354686863d Mon Sep 17 00:00:00 2001 From: orignal Date: Wed, 8 Apr 2015 13:21:49 -0400 Subject: [PATCH] initial code for Ed25519 added --- Signature.cpp | 44 +++++++++++++++++++++++++++++++++++++ Win32/i2pd.vcxproj | 1 + build/CMakeLists.txt | 3 ++- build/autotools/Makefile.in | 6 +++-- filelist.mk | 7 +++--- 5 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 Signature.cpp diff --git a/Signature.cpp b/Signature.cpp new file mode 100644 index 00000000..a81d0603 --- /dev/null +++ b/Signature.cpp @@ -0,0 +1,44 @@ +#include +#include +#include "Signature.h" + +namespace i2p +{ +namespace crypto +{ + class Ed25519 + { + public: + + Ed25519 (): b(256) + { + q = CryptoPP::Integer::Power2 (255) - CryptoPP::Integer (19); // 2^255-19 + l = CryptoPP::Integer::Power2 (252) + CryptoPP::Integer ("27742317777372353535851937790883648493"); + // 2^252 + 27742317777372353535851937790883648493 + d = CryptoPP::Integer (-121665) * CryptoPP::Integer (121666).InverseMod (q); // -121665/121666 + } + + private: + + CryptoPP::ECP::Point Sum (CryptoPP::ECP::Point p1, CryptoPP::ECP::Point p2) + { + CryptoPP::Integer m = d*p1.x*p2.x*p1.y*p2.y, + x = a_times_b_mod_c (p1.x*p2.y + p2.x*p1.y, (CryptoPP::Integer::One() + m).InverseMod (q), q), + y = a_times_b_mod_c (p1.y*p2.y + p1.x*p2.x, (CryptoPP::Integer::One() - m).InverseMod (q), q); + return CryptoPP::ECP::Point {x, y}; + } + + CryptoPP::ECP::Point Mul (CryptoPP::ECP::Point p, CryptoPP::Integer e) + { + if (e.IsZero ()) return CryptoPP::ECP::Point {0, 1}; + return p; // TODO + } + + private: + + CryptoPP::Integer b, q, l, d; + }; +} +} + + diff --git a/Win32/i2pd.vcxproj b/Win32/i2pd.vcxproj index 4fc942ef..0eb82f3d 100644 --- a/Win32/i2pd.vcxproj +++ b/Win32/i2pd.vcxproj @@ -42,6 +42,7 @@ + diff --git a/build/CMakeLists.txt b/build/CMakeLists.txt index 78efe80e..4fb0ad37 100644 --- a/build/CMakeLists.txt +++ b/build/CMakeLists.txt @@ -40,7 +40,8 @@ set (COMMON_SRC "${CMAKE_SOURCE_DIR}/aes.cpp" "${CMAKE_SOURCE_DIR}/base64.cpp" "${CMAKE_SOURCE_DIR}/util.cpp" - "${CMAKE_SOURCE_DIR}/Datagram.cpp" + "${CMAKE_SOURCE_DIR}/Datagram.cpp" + "${CMAKE_SOURCE_DIR}/Signature.cpp" ) set (DAEMON_SRC diff --git a/build/autotools/Makefile.in b/build/autotools/Makefile.in index 053ca6a9..7bee7218 100644 --- a/build/autotools/Makefile.in +++ b/build/autotools/Makefile.in @@ -116,7 +116,7 @@ am_i2p_OBJECTS = AddressBook.$(OBJEXT) CryptoConst.$(OBJEXT) \ aes.$(OBJEXT) base64.$(OBJEXT) i2p.$(OBJEXT) util.$(OBJEXT) \ SAM.$(OBJEXT) Destination.$(OBJEXT) ClientContext.$(OBJEXT) \ Datagram.$(OBJEXT) SSUSession.$(OBJEXT) BOB.$(OBJEXT) \ - I2PControl.$(OBJEXT) Profiling.$(OBJEXT) + I2PControl.$(OBJEXT) Profiling.$(OBJEXT) Signature.$(OBJEXT) i2p_OBJECTS = $(am_i2p_OBJECTS) i2p_LDADD = $(LDADD) AM_V_P = $(am__v_P_@AM_V@) @@ -328,7 +328,7 @@ i2p_SOURCES = AddressBook.cpp CryptoConst.cpp Daemon.cpp \ TunnelGateway.cpp TunnelPool.cpp UPnP.cpp aes.cpp \ base64.cpp i2p.cpp util.cpp SAM.cpp Destination.cpp \ ClientContext.cpp DataFram.cpp SSUSession.cpp BOB.cpp \ - I2PControl.cpp Profiling.cpp \ + I2PControl.cpp Profiling.cpp Signature.cpp \ \ AddressBook.h CryptoConst.h Daemon.h ElGamal.h \ Garlic.h HTTPProxy.h HTTPServer.h I2NPProtocol.h \ @@ -493,6 +493,8 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ClientContext.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Datagram.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SSUSession.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Profiling.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Signature.Po@am__quote@ .cpp.o: @am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< diff --git a/filelist.mk b/filelist.mk index 876734c6..48298bc5 100644 --- a/filelist.mk +++ b/filelist.mk @@ -1,9 +1,10 @@ COMMON_SRC = \ CryptoConst.cpp Datagram.cpp Garlic.cpp I2NPProtocol.cpp LeaseSet.cpp \ Log.cpp NTCPSession.cpp NetDb.cpp Profiling.cpp Reseed.cpp RouterContext.cpp \ - RouterInfo.cpp SSU.cpp SSUSession.cpp SSUData.cpp Streaming.cpp Identity.cpp \ - TransitTunnel.cpp Transports.cpp Tunnel.cpp TunnelEndpoint.cpp TunnelPool.cpp \ - TunnelGateway.cpp Destination.cpp UPnP.cpp util.cpp aes.cpp base64.cpp + RouterInfo.cpp Signature.cpp SSU.cpp SSUSession.cpp SSUData.cpp Streaming.cpp \ + Identity.cpp TransitTunnel.cpp Transports.cpp Tunnel.cpp TunnelEndpoint.cpp \ + TunnelPool.cpp TunnelGateway.cpp Destination.cpp UPnP.cpp util.cpp aes.cpp \ + base64.cpp ifeq ($(UNAME),Darwin)