| 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 | { |
nothing calls this directly
no test coverage detected