| 325 | } |
| 326 | |
| 327 | bool NTCP2Establisher::ProcessSessionRequestMessage (uint16_t& paddingLen, bool& clockSkew, bool& pq, bool decryptX) |
| 328 | { |
| 329 | clockSkew = false; |
| 330 | pq = false; |
| 331 | size_t offset = 0; |
| 332 | if (decryptX) |
| 333 | { |
| 334 | // decrypt X |
| 335 | auto x = GetRemotePub (); |
| 336 | i2p::crypto::CBCDecryption decryption; |
| 337 | decryption.SetKey (i2p::context.GetIdentHash ()); |
| 338 | decryption.Decrypt (m_Buffer, 32, i2p::context.GetNTCP2IV (), x); |
| 339 | memcpy (m_IV, m_Buffer + 16, 16); // save last block as IV for SessionCreated |
| 340 | if (x[31] & 0x80) |
| 341 | { |
| 342 | #if OPENSSL_PQ |
| 343 | if (m_CryptoType > i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD) |
| 344 | { |
| 345 | pq = true; |
| 346 | x[31] &= 0x7F; |
| 347 | } |
| 348 | #endif |
| 349 | if (!pq) |
| 350 | { |
| 351 | LogPrint (eLogWarning, "NTCP2: SessionRequest ML-KEM requested but not supported"); |
| 352 | return false; |
| 353 | } |
| 354 | } |
| 355 | else |
| 356 | SetVersion (2); // regular x25519 requested |
| 357 | // decryption key for next block |
| 358 | if (!KDF1Bob ()) |
| 359 | { |
| 360 | LogPrint (eLogWarning, "NTCP2: SessionRequest KDF failed"); |
| 361 | return false; |
| 362 | } |
| 363 | } |
| 364 | offset += 32; |
| 365 | #if OPENSSL_PQ |
| 366 | if (pq) return true; // we need to read extra ML-KEM block first |
| 367 | if (m_CryptoType > i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD) |
| 368 | { |
| 369 | auto keyLen = i2p::crypto::GetMLKEMPublicKeyLen (m_CryptoType); |
| 370 | std::vector<uint8_t> encapsKey(keyLen); |
| 371 | if (Decrypt (m_Buffer + offset, encapsKey.data (), keyLen)) |
| 372 | { |
| 373 | MixHash (m_Buffer + offset, keyLen + 16); |
| 374 | offset += keyLen + 16; |
| 375 | m_PQKeys = i2p::crypto::CreateMLKEMKeys (m_CryptoType); |
| 376 | m_PQKeys->SetPublicKey (encapsKey.data ()); |
| 377 | } |
| 378 | } |
| 379 | #endif |
| 380 | // verify MAC and decrypt options block (32 bytes) |
| 381 | uint8_t options[16]; |
| 382 | if (Decrypt (m_Buffer + offset, options, 16)) |
| 383 | { |
| 384 | MixHash (m_Buffer + offset, 32); |
no test coverage detected