mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-15 17:59:58 +00:00
commit
c023051fe4
2
.github/workflows/build-windows.yml
vendored
2
.github/workflows/build-windows.yml
vendored
@ -133,6 +133,8 @@ jobs:
|
||||
git clone https://github.com/msys2/MINGW-packages
|
||||
cd MINGW-packages
|
||||
git checkout 4cbb366edf2f268ac3146174b40ce38604646fc5 mingw-w64-boost
|
||||
cd mingw-w64-boost
|
||||
sed -i 's/boostorg.jfrog.io\/artifactory\/main/archives.boost.io/' PKGBUILD
|
||||
|
||||
# headers
|
||||
- name: Get headers package version
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2024, The PurpleI2P Project
|
||||
* Copyright (c) 2013-2025, The PurpleI2P Project
|
||||
*
|
||||
* This file is part of Purple i2pd project and licensed under BSD3
|
||||
*
|
||||
@ -154,6 +154,17 @@ namespace config {
|
||||
("socksproxy.i2p.streaming.profile", value<std::string>()->default_value("1"), "SOCKS Proxy bandwidth usage profile. 1 - bulk(high), 2- interactive(low)")
|
||||
;
|
||||
|
||||
options_description shareddest("Shared local destination options");
|
||||
shareddest.add_options()
|
||||
("shareddest.inbound.length", value<std::string>()->default_value("3"), "Shared local destination inbound tunnel length")
|
||||
("shareddest.outbound.length", value<std::string>()->default_value("3"), "Shared local destination outbound tunnel length")
|
||||
("shareddest.inbound.quantity", value<std::string>()->default_value("3"), "Shared local destination inbound tunnels quantity")
|
||||
("shareddest.outbound.quantity", value<std::string>()->default_value("3"), "Shared local destination outbound tunnels quantity")
|
||||
("shareddest.i2cp.leaseSetType", value<std::string>()->default_value("3"), "Shared local destination's LeaseSet type")
|
||||
("shareddest.i2cp.leaseSetEncType", value<std::string>()->default_value("0,4"), "Shared local destination's LeaseSet encryption type")
|
||||
("shareddest.i2p.streaming.profile", value<std::string>()->default_value("2"), "Shared local destination bandwidth usage profile. 1 - bulk(high), 2- interactive(low)")
|
||||
;
|
||||
|
||||
options_description sam("SAM bridge options");
|
||||
sam.add_options()
|
||||
("sam.enabled", value<bool>()->default_value(true), "Enable or disable SAM Application bridge")
|
||||
@ -341,6 +352,7 @@ namespace config {
|
||||
.add(httpserver)
|
||||
.add(httpproxy)
|
||||
.add(socksproxy)
|
||||
.add(shareddest)
|
||||
.add(sam)
|
||||
.add(bob)
|
||||
.add(i2cp)
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2024, The PurpleI2P Project
|
||||
* Copyright (c) 2013-2025, The PurpleI2P Project
|
||||
*
|
||||
* This file is part of Purple i2pd project and licensed under BSD3
|
||||
*
|
||||
@ -597,7 +597,8 @@ namespace client
|
||||
m_ExcludedFloodfills.clear ();
|
||||
m_PublishReplyToken = 0;
|
||||
// schedule verification
|
||||
m_PublishVerificationTimer.expires_from_now (boost::posix_time::seconds(PUBLISH_VERIFICATION_TIMEOUT));
|
||||
m_PublishVerificationTimer.expires_from_now (boost::posix_time::seconds(PUBLISH_VERIFICATION_TIMEOUT +
|
||||
(m_Pool ? m_Pool->GetRng ()() % PUBLISH_VERIFICATION_TIMEOUT_VARIANCE : 0)));
|
||||
m_PublishVerificationTimer.async_wait (std::bind (&LeaseSetDestination::HandlePublishVerificationTimer,
|
||||
shared_from_this (), std::placeholders::_1));
|
||||
}
|
||||
@ -676,8 +677,8 @@ namespace client
|
||||
m_ExcludedFloodfills.clear ();
|
||||
m_PublishReplyToken = 1; // dummy non-zero value
|
||||
// try again after a while
|
||||
LogPrint (eLogInfo, "Destination: Can't publish LeasetSet because destination is not ready. Try publishing again after ", PUBLISH_CONFIRMATION_TIMEOUT, " seconds");
|
||||
m_PublishConfirmationTimer.expires_from_now (boost::posix_time::seconds(PUBLISH_CONFIRMATION_TIMEOUT));
|
||||
LogPrint (eLogInfo, "Destination: Can't publish LeasetSet because destination is not ready. Try publishing again after ", PUBLISH_CONFIRMATION_TIMEOUT, " milliseconds");
|
||||
m_PublishConfirmationTimer.expires_from_now (boost::posix_time::milliseconds(PUBLISH_CONFIRMATION_TIMEOUT));
|
||||
m_PublishConfirmationTimer.async_wait (std::bind (&LeaseSetDestination::HandlePublishConfirmationTimer,
|
||||
shared_from_this (), std::placeholders::_1));
|
||||
return;
|
||||
@ -696,7 +697,7 @@ namespace client
|
||||
s->HandlePublishConfirmationTimer (boost::system::error_code());
|
||||
});
|
||||
};
|
||||
m_PublishConfirmationTimer.expires_from_now (boost::posix_time::seconds(PUBLISH_CONFIRMATION_TIMEOUT));
|
||||
m_PublishConfirmationTimer.expires_from_now (boost::posix_time::milliseconds(PUBLISH_CONFIRMATION_TIMEOUT));
|
||||
m_PublishConfirmationTimer.async_wait (std::bind (&LeaseSetDestination::HandlePublishConfirmationTimer,
|
||||
shared_from_this (), std::placeholders::_1));
|
||||
outbound->SendTunnelDataMsgTo (floodfill->GetIdentHash (), 0, msg);
|
||||
@ -712,15 +713,15 @@ namespace client
|
||||
m_PublishReplyToken = 0;
|
||||
if (GetIdentity ()->GetCryptoKeyType () == i2p::data::CRYPTO_KEY_TYPE_ELGAMAL)
|
||||
{
|
||||
LogPrint (eLogWarning, "Destination: Publish confirmation was not received in ", PUBLISH_CONFIRMATION_TIMEOUT, " seconds or failed. will try again");
|
||||
LogPrint (eLogWarning, "Destination: Publish confirmation was not received in ", PUBLISH_CONFIRMATION_TIMEOUT, " milliseconds or failed. will try again");
|
||||
Publish ();
|
||||
}
|
||||
else
|
||||
{
|
||||
LogPrint (eLogWarning, "Destination: Publish confirmation was not received in ", PUBLISH_CONFIRMATION_TIMEOUT, " seconds from Java floodfill for crypto type ", (int)GetIdentity ()->GetCryptoKeyType ());
|
||||
LogPrint (eLogWarning, "Destination: Publish confirmation was not received in ", PUBLISH_CONFIRMATION_TIMEOUT, " milliseconds from Java floodfill for crypto type ", (int)GetIdentity ()->GetCryptoKeyType ());
|
||||
// Java floodfill never sends confirmation back for unknown crypto type
|
||||
// assume it successive and try to verify
|
||||
m_PublishVerificationTimer.expires_from_now (boost::posix_time::seconds(PUBLISH_VERIFICATION_TIMEOUT));
|
||||
m_PublishVerificationTimer.expires_from_now (boost::posix_time::seconds(PUBLISH_VERIFICATION_TIMEOUT + PUBLISH_VERIFICATION_TIMEOUT_VARIANCE)); // always max
|
||||
m_PublishVerificationTimer.async_wait (std::bind (&LeaseSetDestination::HandlePublishVerificationTimer,
|
||||
shared_from_this (), std::placeholders::_1));
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2024, The PurpleI2P Project
|
||||
* Copyright (c) 2013-2025, The PurpleI2P Project
|
||||
*
|
||||
* This file is part of Purple i2pd project and licensed under BSD3
|
||||
*
|
||||
@ -36,8 +36,9 @@ namespace client
|
||||
const uint8_t PROTOCOL_TYPE_STREAMING = 6;
|
||||
const uint8_t PROTOCOL_TYPE_DATAGRAM = 17;
|
||||
const uint8_t PROTOCOL_TYPE_RAW = 18;
|
||||
const int PUBLISH_CONFIRMATION_TIMEOUT = 5; // in seconds
|
||||
const int PUBLISH_VERIFICATION_TIMEOUT = 10; // in seconds after successful publish
|
||||
const int PUBLISH_CONFIRMATION_TIMEOUT = 1800; // in milliseconds
|
||||
const int PUBLISH_VERIFICATION_TIMEOUT = 5; // in seconds after successful publish
|
||||
const int PUBLISH_VERIFICATION_TIMEOUT_VARIANCE = 3; // in seconds
|
||||
const int PUBLISH_MIN_INTERVAL = 20; // in seconds
|
||||
const int PUBLISH_REGULAR_VERIFICATION_INTERNAL = 100; // in seconds periodically
|
||||
const int LEASESET_REQUEST_TIMEOUT = 1600; // in milliseconds
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2024, The PurpleI2P Project
|
||||
* Copyright (c) 2013-2025, The PurpleI2P Project
|
||||
*
|
||||
* This file is part of Purple i2pd project and licensed under BSD3
|
||||
*
|
||||
@ -1434,7 +1434,7 @@ namespace i2p
|
||||
i2p::garlic::WrapECIESX25519MessageForRouter (msg, floodfill->GetIdentity ()->GetEncryptionPublicKey ()));
|
||||
}
|
||||
else
|
||||
LogPrint (eLogInfo, "Router: Can't publish our RouterInfo. No tunnles. Try again in ", ROUTER_INFO_CONFIRMATION_TIMEOUT, " seconds");
|
||||
LogPrint (eLogInfo, "Router: Can't publish our RouterInfo. No tunnels. Try again in ", ROUTER_INFO_CONFIRMATION_TIMEOUT, " milliseconds");
|
||||
}
|
||||
m_PublishExcluded.insert (floodfill->GetIdentHash ());
|
||||
m_PublishReplyToken = replyToken;
|
||||
@ -1448,7 +1448,7 @@ namespace i2p
|
||||
if (m_PublishTimer)
|
||||
{
|
||||
m_PublishTimer->cancel ();
|
||||
m_PublishTimer->expires_from_now (boost::posix_time::seconds(ROUTER_INFO_CONFIRMATION_TIMEOUT));
|
||||
m_PublishTimer->expires_from_now (boost::posix_time::milliseconds(ROUTER_INFO_CONFIRMATION_TIMEOUT));
|
||||
m_PublishTimer->async_wait (std::bind (&RouterContext::HandlePublishResendTimer,
|
||||
this, std::placeholders::_1));
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2024, The PurpleI2P Project
|
||||
* Copyright (c) 2013-2025, The PurpleI2P Project
|
||||
*
|
||||
* This file is part of Purple i2pd project and licensed under BSD3
|
||||
*
|
||||
@ -34,7 +34,7 @@ namespace garlic
|
||||
const int ROUTER_INFO_PUBLISH_INTERVAL = 39*60; // in seconds
|
||||
const int ROUTER_INFO_INITIAL_PUBLISH_INTERVAL = 10; // in seconds
|
||||
const int ROUTER_INFO_PUBLISH_INTERVAL_VARIANCE = 105;// in seconds
|
||||
const int ROUTER_INFO_CONFIRMATION_TIMEOUT = 5; // in seconds
|
||||
const int ROUTER_INFO_CONFIRMATION_TIMEOUT = 1600; // in milliseconds
|
||||
const int ROUTER_INFO_MAX_PUBLISH_EXCLUDED_FLOODFILLS = 15;
|
||||
const int ROUTER_INFO_CONGESTION_UPDATE_INTERVAL = 12*60; // in seconds
|
||||
const int ROUTER_INFO_CLEANUP_INTERVAL = 102; // in seconds
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2024, The PurpleI2P Project
|
||||
* Copyright (c) 2022-2025, The PurpleI2P Project
|
||||
*
|
||||
* This file is part of Purple i2pd project and licensed under BSD3
|
||||
*
|
||||
@ -92,7 +92,7 @@ namespace transport
|
||||
m_RTO (SSU2_INITIAL_RTO), m_RelayTag (0),m_ConnectTimer (server.GetService ()),
|
||||
m_TerminationReason (eSSU2TerminationReasonNormalClose),
|
||||
m_MaxPayloadSize (SSU2_MIN_PACKET_SIZE - IPV6_HEADER_SIZE - UDP_HEADER_SIZE - 32), // min size
|
||||
m_LastResendTime (0), m_LastResendAttemptTime (0)
|
||||
m_LastResendTime (0), m_LastResendAttemptTime (0), m_NumRanges (0)
|
||||
{
|
||||
if (noise)
|
||||
m_NoiseState.reset (new i2p::crypto::NoiseSymmetricState);
|
||||
@ -1744,6 +1744,7 @@ namespace transport
|
||||
HandleAckRange (firstPacketNum, ackThrough, i2p::util::GetMillisecondsSinceEpoch ()); // acnt
|
||||
// ranges
|
||||
len -= 5;
|
||||
if (!len || m_SentPackets.empty ()) return; // don't handle ranges if nothing to acknowledge
|
||||
const uint8_t * ranges = buf + 5;
|
||||
while (len > 0 && firstPacketNum && ackThrough - firstPacketNum < SSU2_MAX_NUM_ACK_PACKETS)
|
||||
{
|
||||
@ -2624,17 +2625,17 @@ namespace transport
|
||||
size_t SSU2Session::CreateAckBlock (uint8_t * buf, size_t len)
|
||||
{
|
||||
if (len < 8) return 0;
|
||||
int maxNumRanges = (len - 8) >> 1;
|
||||
if (maxNumRanges > SSU2_MAX_NUM_ACK_RANGES) maxNumRanges = SSU2_MAX_NUM_ACK_RANGES;
|
||||
buf[0] = eSSU2BlkAck;
|
||||
uint32_t ackThrough = m_OutOfSequencePackets.empty () ? m_ReceivePacketNum : *m_OutOfSequencePackets.rbegin ();
|
||||
htobe32buf (buf + 3, ackThrough); // Ack Through
|
||||
uint16_t acnt = 0;
|
||||
int numRanges = 0;
|
||||
if (ackThrough)
|
||||
{
|
||||
if (m_OutOfSequencePackets.empty ())
|
||||
{
|
||||
acnt = std::min ((int)ackThrough, SSU2_MAX_NUM_ACNT); // no gaps
|
||||
m_NumRanges = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto it = m_OutOfSequencePackets.rbegin (); it++; // prev packet num
|
||||
@ -2647,6 +2648,11 @@ namespace transport
|
||||
it++;
|
||||
}
|
||||
// ranges
|
||||
if (!m_NumRanges)
|
||||
{
|
||||
int maxNumRanges = (len - 8) >> 1;
|
||||
if (maxNumRanges > SSU2_MAX_NUM_ACK_RANGES) maxNumRanges = SSU2_MAX_NUM_ACK_RANGES;
|
||||
int numRanges = 0;
|
||||
uint32_t lastNum = ackThrough - acnt;
|
||||
if (acnt > SSU2_MAX_NUM_ACNT)
|
||||
{
|
||||
@ -2660,12 +2666,12 @@ namespace transport
|
||||
// Acks only ranges for acnt
|
||||
for (int i = 0; i < d.quot; i++)
|
||||
{
|
||||
buf[8 + numRanges*2] = 0; buf[8 + numRanges*2 + 1] = SSU2_MAX_NUM_ACNT; // NACKs 0, Acks 255
|
||||
m_Ranges[numRanges*2] = 0; m_Ranges[numRanges*2 + 1] = SSU2_MAX_NUM_ACNT; // NACKs 0, Acks 255
|
||||
numRanges++;
|
||||
}
|
||||
if (d.rem > 0)
|
||||
{
|
||||
buf[8 + numRanges*2] = 0; buf[8 + numRanges*2 + 1] = d.rem;
|
||||
m_Ranges[numRanges*2] = 0; m_Ranges[numRanges*2 + 1] = d.rem;
|
||||
numRanges++;
|
||||
}
|
||||
}
|
||||
@ -2679,15 +2685,15 @@ namespace transport
|
||||
if (lastNum > (*it) + SSU2_MAX_NUM_ACNT*(maxNumRanges - numRanges)) break; // too many NACKs
|
||||
while (lastNum - (*it) > SSU2_MAX_NUM_ACNT)
|
||||
{
|
||||
buf[8 + numRanges*2] = SSU2_MAX_NUM_ACNT; buf[8 + numRanges*2 + 1] = 0; // NACKs 255, Acks 0
|
||||
m_Ranges[numRanges*2] = SSU2_MAX_NUM_ACNT; m_Ranges[numRanges*2 + 1] = 0; // NACKs 255, Acks 0
|
||||
lastNum -= SSU2_MAX_NUM_ACNT;
|
||||
numRanges++;
|
||||
numPackets += SSU2_MAX_NUM_ACNT;
|
||||
}
|
||||
}
|
||||
// NACKs and Acks ranges
|
||||
buf[8 + numRanges*2] = lastNum - (*it) - 1; // NACKs
|
||||
numPackets += buf[8 + numRanges*2];
|
||||
m_Ranges[numRanges*2] = lastNum - (*it) - 1; // NACKs
|
||||
numPackets += m_Ranges[numRanges*2];
|
||||
lastNum = *it; it++;
|
||||
int numAcks = 1;
|
||||
while (it != m_OutOfSequencePackets.rend () && lastNum > 0 && *it == lastNum - 1)
|
||||
@ -2698,15 +2704,15 @@ namespace transport
|
||||
while (numAcks > SSU2_MAX_NUM_ACNT)
|
||||
{
|
||||
// Acks only ranges
|
||||
buf[8 + numRanges*2 + 1] = SSU2_MAX_NUM_ACNT; // Acks 255
|
||||
m_Ranges[numRanges*2 + 1] = SSU2_MAX_NUM_ACNT; // Acks 255
|
||||
numAcks -= SSU2_MAX_NUM_ACNT;
|
||||
numRanges++;
|
||||
numPackets += SSU2_MAX_NUM_ACNT;
|
||||
buf[8 + numRanges*2] = 0; // NACKs 0
|
||||
m_Ranges[numRanges*2] = 0; // NACKs 0
|
||||
if (numRanges >= maxNumRanges || numPackets >= SSU2_MAX_NUM_ACK_PACKETS) break;
|
||||
}
|
||||
if (numAcks > SSU2_MAX_NUM_ACNT) numAcks = SSU2_MAX_NUM_ACNT;
|
||||
buf[8 + numRanges*2 + 1] = (uint8_t)numAcks; // Acks
|
||||
m_Ranges[numRanges*2 + 1] = (uint8_t)numAcks; // Acks
|
||||
numPackets += numAcks;
|
||||
numRanges++;
|
||||
}
|
||||
@ -2718,16 +2724,20 @@ namespace transport
|
||||
if (nacks > 0)
|
||||
{
|
||||
if (nacks > SSU2_MAX_NUM_ACNT) nacks = SSU2_MAX_NUM_ACNT;
|
||||
buf[8 + numRanges*2] = nacks;
|
||||
buf[8 + numRanges*2 + 1] = std::min ((int)m_ReceivePacketNum + 1, SSU2_MAX_NUM_ACNT);
|
||||
m_Ranges[numRanges*2] = nacks;
|
||||
m_Ranges[numRanges*2 + 1] = std::min ((int)m_ReceivePacketNum + 1, SSU2_MAX_NUM_ACNT);
|
||||
numRanges++;
|
||||
}
|
||||
}
|
||||
m_NumRanges = numRanges;
|
||||
}
|
||||
if (m_NumRanges)
|
||||
memcpy (buf + 8, m_Ranges, m_NumRanges*2);
|
||||
}
|
||||
}
|
||||
buf[7] = (uint8_t)acnt; // acnt
|
||||
htobe16buf (buf + 1, 5 + numRanges*2);
|
||||
return 8 + numRanges*2;
|
||||
htobe16buf (buf + 1, 5 + m_NumRanges*2);
|
||||
return 8 + m_NumRanges*2;
|
||||
}
|
||||
|
||||
size_t SSU2Session::CreatePaddingBlock (uint8_t * buf, size_t len, size_t minSize)
|
||||
@ -2961,11 +2971,17 @@ namespace transport
|
||||
}
|
||||
m_OutOfSequencePackets.erase (m_OutOfSequencePackets.begin (), it);
|
||||
}
|
||||
m_NumRanges = 0; // recalculate ranges when create next Ack
|
||||
}
|
||||
m_ReceivePacketNum = packetNum;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_NumRanges && (m_OutOfSequencePackets.empty () ||
|
||||
packetNum != (*m_OutOfSequencePackets.rbegin ()) + 1))
|
||||
m_NumRanges = 0; // reset ranges if received packet is not next
|
||||
m_OutOfSequencePackets.insert (packetNum);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2024, The PurpleI2P Project
|
||||
* Copyright (c) 2022-2025, The PurpleI2P Project
|
||||
*
|
||||
* This file is part of Purple i2pd project and licensed under BSD3
|
||||
*
|
||||
@ -397,6 +397,8 @@ namespace transport
|
||||
std::unique_ptr<i2p::data::IdentHash> m_PathChallenge;
|
||||
std::unordered_map<uint32_t, uint32_t> m_ReceivedI2NPMsgIDs; // msgID -> timestamp in seconds
|
||||
uint64_t m_LastResendTime, m_LastResendAttemptTime; // in milliseconds
|
||||
int m_NumRanges;
|
||||
uint8_t m_Ranges[SSU2_MAX_NUM_ACK_RANGES*2]; // ranges sent with previous Ack if any
|
||||
};
|
||||
|
||||
inline uint64_t CreateHeaderMask (const uint8_t * kh, const uint8_t * nonce)
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2024, The PurpleI2P Project
|
||||
* Copyright (c) 2013-2025, The PurpleI2P Project
|
||||
*
|
||||
* This file is part of Purple i2pd project and licensed under BSD3
|
||||
*
|
||||
@ -416,15 +416,10 @@ namespace client
|
||||
|
||||
void ClientContext::CreateNewSharedLocalDestination ()
|
||||
{
|
||||
std::map<std::string, std::string> params
|
||||
{
|
||||
{ I2CP_PARAM_INBOUND_TUNNELS_QUANTITY, "3" },
|
||||
{ I2CP_PARAM_OUTBOUND_TUNNELS_QUANTITY, "3" },
|
||||
{ I2CP_PARAM_LEASESET_TYPE, "3" },
|
||||
{ I2CP_PARAM_LEASESET_ENCRYPTION_TYPE, "0,4" },
|
||||
{ I2CP_PARAM_OUTBOUND_NICKNAME, "SharedDest" },
|
||||
{ I2CP_PARAM_STREAMING_PROFILE, "2" }
|
||||
};
|
||||
std::map<std::string, std::string> params;
|
||||
ReadI2CPOptionsFromConfig ("shareddest.", params);
|
||||
params[I2CP_PARAM_OUTBOUND_NICKNAME] = "SharedDest";
|
||||
|
||||
m_SharedLocalDestination = CreateNewLocalDestination (false, i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519,
|
||||
i2p::data::CRYPTO_KEY_TYPE_ELGAMAL, ¶ms); // non-public, EDDSA
|
||||
m_SharedLocalDestination->Acquire ();
|
||||
|
@ -43,18 +43,20 @@ uint8_t encrypted[114] =
|
||||
int main ()
|
||||
{
|
||||
uint8_t buf[114+16];
|
||||
i2p::crypto::AEADChaCha20Poly1305Encryptor encryptor;
|
||||
// test encryption
|
||||
i2p::crypto::AEADChaCha20Poly1305 ((uint8_t *)text, 114, ad, 12, key, nonce, buf, 114 + 16, true);
|
||||
encryptor.Encrypt ((uint8_t *)text, 114, ad, 12, key, nonce, buf, 114 + 16);
|
||||
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));
|
||||
i2p::crypto::AEADChaCha20Poly1305Decryptor decryptor;
|
||||
assert (decryptor.Decrypt (buf, 114, ad, 12, key, nonce, buf1, 114));
|
||||
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);
|
||||
encryptor.Encrypt (bufs, key, nonce, buf + 114);
|
||||
decryptor.Decrypt (buf, 114, nullptr, 0, key, nonce, buf1, 114);
|
||||
assert (memcmp (buf1, text, 114) == 0);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user