I2P -> .NET

This commit is contained in:
Михаил Подивилов 2019-05-11 18:25:50 +03:00
parent f176f1909b
commit fdb0ce6703
272 changed files with 5702 additions and 8931 deletions

View file

@ -1,25 +1,25 @@
CXXFLAGS += -Wall -Wextra -pedantic -O0 -g -std=c++11 -D_GLIBCXX_USE_NANOSLEEP=1 -I../libi2pd/ -pthread -Wl,--unresolved-symbols=ignore-in-object-files
CXXFLAGS += -Wall -Wextra -pedantic -O0 -g -std=c++11 -D_GLIBCXX_USE_NANOSLEEP=1 -I../libdotnet/ -pthread -Wl,--unresolved-symbols=ignore-in-object-files
TESTS = test-gost test-gost-sig test-base-64 test-x25519 test-aeadchacha20poly1305
all: $(TESTS) run
test-http-%: ../libi2pd/HTTP.cpp test-http-%.cpp
test-http-%: ../libdotnet/HTTP.cpp test-http-%.cpp
$(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) $(INCFLAGS) -o $@ $^
test-base-%: ../libi2pd/Base.cpp test-base-%.cpp
test-base-%: ../libdotnet/Base.cpp test-base-%.cpp
$(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) $(INCFLAGS) -o $@ $^
test-gost: ../libi2pd/Gost.cpp ../libi2pd/I2PEndian.cpp test-gost.cpp
test-gost: ../libdotnet/Gost.cpp ../libdotnet/DotNetEndian.cpp test-gost.cpp
$(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) $(INCFLAGS) -o $@ $^ -lcrypto
test-gost-sig: ../libi2pd/Gost.cpp ../libi2pd/I2PEndian.cpp ../libi2pd/Crypto.cpp ../libi2pd/Log.cpp test-gost-sig.cpp
test-gost-sig: ../libdotnet/Gost.cpp ../libdotnet/DotNetEndian.cpp ../libdotnet/Crypto.cpp ../libdotnet/Log.cpp test-gost-sig.cpp
$(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) $(INCFLAGS) -o $@ $^ -lcrypto -lssl -lboost_system
test-x25519: ../libi2pd/Ed25519.cpp ../libi2pd/I2PEndian.cpp ../libi2pd/Log.cpp ../libi2pd/Crypto.cpp test-x25519.cpp
test-x25519: ../libdotnet/Ed25519.cpp ../libdotnet/DotNetEndian.cpp ../libdotnet/Log.cpp ../libdotnet/Crypto.cpp test-x25519.cpp
$(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) $(INCFLAGS) -o $@ $^ -lcrypto -lssl -lboost_system
test-aeadchacha20poly1305: ../libi2pd/Crypto.cpp ../libi2pd/ChaCha20.cpp ../libi2pd/Poly1305.cpp test-aeadchacha20poly1305.cpp
test-aeadchacha20poly1305: ../libdotnet/Crypto.cpp ../libdotnet/ChaCha20.cpp ../libdotnet/Poly1305.cpp test-aeadchacha20poly1305.cpp
$(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) $(INCFLAGS) -o $@ $^ -lcrypto -lssl -lboost_system
run: $(TESTS)

View file

@ -44,17 +44,17 @@ int main ()
{
uint8_t buf[114+16];
// test encryption
i2p::crypto::AEADChaCha20Poly1305 ((uint8_t *)text, 114, ad, 12, key, nonce, buf, 114 + 16, true);
dotnet::crypto::AEADChaCha20Poly1305 ((uint8_t *)text, 114, ad, 12, key, nonce, buf, 114 + 16, true);
assert (memcmp (buf, encrypted, 114) == 0);
assert (memcmp (buf + 114, tag, 16) == 0);
// test decryption
uint8_t buf1[114];
assert (i2p::crypto::AEADChaCha20Poly1305 (buf, 114, ad, 12, key, nonce, buf1, 114, false));
assert (dotnet::crypto::AEADChaCha20Poly1305 (buf, 114, ad, 12, key, nonce, buf1, 114, false));
assert (memcmp (buf1, text, 114) == 0);
// test encryption of multiple buffers
memcpy (buf, text, 114);
std::vector<std::pair<uint8_t*, std::size_t> > bufs{ std::make_pair (buf, 20), std::make_pair (buf + 20, 10), std::make_pair (buf + 30, 70), std::make_pair (buf + 100, 14) };
i2p::crypto::AEADChaCha20Poly1305Encrypt (bufs, key, nonce, buf + 114);
i2p::crypto::AEADChaCha20Poly1305 (buf, 114, nullptr, 0, key, nonce, buf1, 114, false);
dotnet::crypto::AEADChaCha20Poly1305Encrypt (bufs, key, nonce, buf + 114);
dotnet::crypto::AEADChaCha20Poly1305 (buf, 114, nullptr, 0, key, nonce, buf1, 114, false);
assert (memcmp (buf1, text, 114) == 0);
}

View file

@ -3,7 +3,7 @@
#include "Base.h"
using namespace i2p::data;
using namespace dotnet::data;
int main() {
const char *in = "test";

View file

@ -18,15 +18,15 @@ const uint8_t example2[72] =
int main ()
{
uint8_t priv[64], pub[128], signature[128];
i2p::crypto::CreateGOSTR3410RandomKeys (i2p::crypto::eGOSTR3410TC26A512, priv, pub);
i2p::crypto::GOSTR3410_512_Signer signer (i2p::crypto::eGOSTR3410TC26A512, priv);
dotnet::crypto::CreateGOSTR3410RandomKeys (dotnet::crypto::eGOSTR3410TC26A512, priv, pub);
dotnet::crypto::GOSTR3410_512_Signer signer (dotnet::crypto::eGOSTR3410TC26A512, priv);
signer.Sign (example2, 72, signature);
i2p::crypto::GOSTR3410_512_Verifier verifier (i2p::crypto::eGOSTR3410TC26A512, pub);
dotnet::crypto::GOSTR3410_512_Verifier verifier (dotnet::crypto::eGOSTR3410TC26A512, pub);
assert (verifier.Verify (example2, 72, signature));
i2p::crypto::CreateGOSTR3410RandomKeys (i2p::crypto::eGOSTR3410CryptoProA, priv, pub);
i2p::crypto::GOSTR3410_256_Signer signer1 (i2p::crypto::eGOSTR3410CryptoProA, priv);
dotnet::crypto::CreateGOSTR3410RandomKeys (dotnet::crypto::eGOSTR3410CryptoProA, priv, pub);
dotnet::crypto::GOSTR3410_256_Signer signer1 (dotnet::crypto::eGOSTR3410CryptoProA, priv);
signer1.Sign (example2, 72, signature);
i2p::crypto::GOSTR3410_256_Verifier verifier1 (i2p::crypto::eGOSTR3410CryptoProA, pub);
dotnet::crypto::GOSTR3410_256_Verifier verifier1 (dotnet::crypto::eGOSTR3410CryptoProA, pub);
assert (verifier1.Verify (example2, 72, signature));
}

View file

@ -52,15 +52,15 @@ const uint8_t example2_hash_256[32] =
int main ()
{
uint8_t digest[64];
i2p::crypto::GOSTR3411_2012_512 (example1, 63, digest);
dotnet::crypto::GOSTR3411_2012_512 (example1, 63, digest);
assert(memcmp (digest, example1_hash_512, 64) == 0);
i2p::crypto::GOSTR3411_2012_256 (example1, 63, digest);
dotnet::crypto::GOSTR3411_2012_256 (example1, 63, digest);
assert(memcmp (digest, example1_hash_256, 32) == 0);
i2p::crypto::GOSTR3411_2012_512 (example2, 72, digest);
dotnet::crypto::GOSTR3411_2012_512 (example2, 72, digest);
assert(memcmp (digest, example2_hash_512, 64) == 0);
i2p::crypto::GOSTR3411_2012_256 (example2, 72, digest);
dotnet::crypto::GOSTR3411_2012_256 (example2, 72, digest);
assert(memcmp (digest, example2_hash_256, 32) == 0);
}

View file

@ -1,7 +1,7 @@
#include <cassert>
#include "../HTTP.h"
using namespace i2p::http;
using namespace dotnet::http;
int main() {
const char *buf =

View file

@ -1,7 +1,7 @@
#include <cassert>
#include "../HTTP.h"
using namespace i2p::http;
using namespace dotnet::http;
int main() {
HTTPReq *req;
@ -12,7 +12,7 @@ int main() {
buf =
"GET / HTTP/1.0\r\n"
"User-Agent: curl/7.26.0\r\n"
"Host: inr.i2p\r\n"
"Host: inr.dotnet\r\n"
"Accept: */*\r\n"
"\r\n"
"test";
@ -26,7 +26,7 @@ int main() {
assert(req->headers.count("Host") == 1);
assert(req->headers.count("Accept") == 1);
assert(req->headers.count("User-Agent") == 1);
assert(req->headers.find("Host")->second == "inr.i2p");
assert(req->headers.find("Host")->second == "inr.dotnet");
assert(req->headers.find("Accept")->second == "*/*");
assert(req->headers.find("User-Agent")->second == "curl/7.26.0");
delete req;
@ -64,8 +64,8 @@ int main() {
/* test: parsing slightly malformed request */
buf =
"GET http://inr.i2p HTTP/1.1\r\n"
"Host: stats.i2p\r\n"
"GET http://inr.dotnet HTTP/1.1\r\n"
"Host: stats.dotnet\r\n"
"Accept-Encoding: \r\n"
"Accept: */*\r\n"
"\r\n";
@ -73,12 +73,12 @@ int main() {
req = new HTTPReq;
assert((ret = req->parse(buf, len)) == len); /* no host header */
assert(req->method == "GET");
assert(req->uri == "http://inr.i2p");
assert(req->uri == "http://inr.dotnet");
assert(req->headers.size() == 3);
assert(req->headers.count("Host") == 1);
assert(req->headers.count("Accept") == 1);
assert(req->headers.count("Accept-Encoding") == 1);
assert(req->headers["Host"] == "stats.i2p");
assert(req->headers["Host"] == "stats.dotnet");
assert(req->headers["Accept"] == "*/*");
assert(req->headers["Accept-Encoding"] == "");
delete req;

View file

@ -1,7 +1,7 @@
#include <cassert>
#include "../HTTP.h"
using namespace i2p::http;
using namespace dotnet::http;
int main() {
HTTPRes *res;

View file

@ -1,7 +1,7 @@
#include <cassert>
#include "../HTTP.h"
using namespace i2p::http;
using namespace dotnet::http;
int main() {
std::map<std::string, std::string> params;

View file

@ -1,7 +1,7 @@
#include <cassert>
#include "../HTTP.h"
using namespace i2p::http;
using namespace dotnet::http;
int main() {
std::string in("/%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0/");

View file

@ -29,7 +29,7 @@ int main ()
{
uint8_t buf[32];
BN_CTX * ctx = BN_CTX_new ();
i2p::crypto::GetEd25519 ()->ScalarMul (u, k, buf, ctx);
dotnet::crypto::GetEd25519 ()->ScalarMul (u, k, buf, ctx);
BN_CTX_free (ctx);
assert(memcmp (buf, p, 32) == 0);
}