MCPcopy Create free account
hub / github.com/PurpleI2P/i2pd / EncryptECIES

Method EncryptECIES

libi2pd/TunnelConfig.cpp:85–104  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

83 }
84
85 void ECIESTunnelHopConfig::EncryptECIES (const uint8_t * plainText, size_t len, uint8_t * encrypted)
86 {
87 if (!ident) return;
88 i2p::crypto::InitNoiseNState (*this, ident->GetEncryptionPublicKey ());
89 auto ephemeralKeys = i2p::transport::transports.GetNextX25519KeysPair ();
90 memcpy (encrypted, ephemeralKeys->GetPublicKey (), 32);
91 MixHash (encrypted, 32); // h = SHA256(h || sepk)
92 encrypted += 32;
93 uint8_t sharedSecret[32];
94 ephemeralKeys->Agree (ident->GetEncryptionPublicKey (), sharedSecret); // x25519(sesk, hepk)
95 MixKey (sharedSecret);
96 uint8_t nonce[12];
97 memset (nonce, 0, 12);
98 if (!i2p::crypto::AEADChaCha20Poly1305 (plainText, len, m_H, 32, m_CK + 32, nonce, encrypted, len + 16, true)) // encrypt
99 {
100 LogPrint (eLogWarning, "Tunnel: Plaintext AEAD encryption failed");
101 return;
102 }
103 MixHash (encrypted, len + 16); // h = SHA256(h || ciphertext)
104 }
105
106 bool ECIESTunnelHopConfig::DecryptECIES (const uint8_t * key, const uint8_t * nonce, const uint8_t * encrypted, size_t len, uint8_t * clearText) const
107 {

Callers

nothing calls this directly

Calls 7

InitNoiseNStateFunction · 0.85
AEADChaCha20Poly1305Function · 0.85
LogPrintFunction · 0.85
GetNextX25519KeysPairMethod · 0.80
AgreeMethod · 0.80
GetPublicKeyMethod · 0.45

Tested by

no test coverage detected