i2pd-sys 0.0.4

Raw FFI bindings to a minimal C shim over libi2pd (PurpleI2P/i2pd).
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
/*
* Copyright (c) 2025-2026, The PurpleI2P Project
*
* This file is part of Purple i2pd project and licensed under BSD3
*
* See full license text in LICENSE file at top of project tree
*/

#include "Log.h"
#include "PostQuantum.h"

#if OPENSSL_PQ

// tachyon-web: AWS-LC's ML-KEM support is reached through the classic EVP_PKEY_CTX_new_id-style
// API (see the OPENSSL_IS_AWSLC branches below), not OpenSSL 3.5's "provider" API -- so this
// doesn't need (and, since AWS-LC doesn't ship these headers itself, must not pull in) either
// <openssl/param_build.h>/<openssl/core_names.h> (which would otherwise resolve to the system's
// real OpenSSL headers and conflict with AWS-LC's differently-shaped types) or LibreSSL's
// <openssl/mlkem.h>.
#if defined(OPENSSL_IS_AWSLC)
// (no extra includes -- PostQuantum.h already pulled in bytestring.h/obj.h/asn1.h for this path)
#elif !defined(LIBRESSL_VERSION_NUMBER)
#include <openssl/param_build.h>
#include <openssl/core_names.h>
#else
#include<openssl/mlkem.h>
#endif

namespace i2p
{
namespace crypto
{
#ifdef OPENSSL_IS_AWSLC
	// tachyon-web: maps this file's ML-KEM name strings to AWS-LC's NID_MLKEM* constants, needed
	// by EVP_PKEY_CTX_kem_set_params (keygen) and OBJ_nid2obj (SetPublicKey's SPKI wrapper).
	static int MLKEMNidFromName (const std::string& name)
	{
		if (name == "ML-KEM-512") return NID_MLKEM512;
		if (name == "ML-KEM-768") return NID_MLKEM768;
		if (name == "ML-KEM-1024") return NID_MLKEM1024;
		return NID_undef;
	}
#endif

	MLKEMKeys::MLKEMKeys (MLKEMTypes type):
#ifndef LIBRESSL_VERSION_NUMBER
		m_Name (std::get<0>(MLKEMS[type])), m_KeyLen (std::get<1>(MLKEMS[type])),
		m_CTLen (std::get<2>(MLKEMS[type])),
#else
		m_Name (std::get<0>(MLKEMS[eMLKEM768])), m_KeyLen (std::get<1>(MLKEMS[eMLKEM768])),
		m_CTLen (std::get<2>(MLKEMS[eMLKEM768])),
#endif
		m_Pkey (nullptr)
	{
	}

	MLKEMKeys::~MLKEMKeys ()
	{
		FreeKeys();
	}

	void MLKEMKeys::FreeKeys ()
	{
#ifndef LIBRESSL_VERSION_NUMBER
		if (m_Pkey) EVP_PKEY_free (m_Pkey);
#else
	    if (m_Pkey) MLKEM_private_key_free (m_Pkey);
#endif
		if (m_Pkey) m_Pkey = nullptr;
	}

	void MLKEMKeys::GenerateKeys ()
	{
		FreeKeys();
#ifdef OPENSSL_IS_AWSLC
		auto ctx = EVP_PKEY_CTX_new_id (EVP_PKEY_KEM, NULL);
		if (ctx)
		{
			if (EVP_PKEY_CTX_kem_set_params (ctx, MLKEMNidFromName (m_Name)) &&
			    EVP_PKEY_keygen_init (ctx) && EVP_PKEY_keygen (ctx, &m_Pkey))
				LogPrint (eLogDebug, "MLKEM: GenerateKeys [ aws-lc ]");
			else
				LogPrint (eLogError, "MLKEM: GenerateKeys [ aws-lc ] failed");
			EVP_PKEY_CTX_free (ctx);
		}
		else
			LogPrint (eLogError, "MLKEM: can't create PKEY context [ aws-lc ]");
#elif !defined(LIBRESSL_VERSION_NUMBER)
		m_Pkey = EVP_PKEY_Q_keygen(NULL, NULL, m_Name.c_str ());
		LogPrint(eLogDebug, "MLKEM: GenerateKeys [ openssl ]");
#else
		m_Pkey = MLKEM_private_key_new( MLKEM768_RANK);

		uint8_t * pub_key = nullptr;
		size_t pub_key_len = 0;
		uint8_t * seed = nullptr;
		size_t seed_len = 0;

		if (MLKEM_generate_key(m_Pkey, &pub_key, &pub_key_len, &seed, &seed_len) == 1)
		{
			LogPrint(eLogDebug, "MLKEM: GenerateKeys [ libressl ] success");
			if (pub_key_len <= sizeof(m_CachedPub))
			{
				memcpy(m_CachedPub, pub_key, pub_key_len);
				m_IsPubCached = true;
				LogPrint(eLogDebug, "MLKEM [libressl] cache the pub succes");
			} else
			{
				 LogPrint(eLogError, "MLKEM: can't cache private key [libressl]");
			}
			OPENSSL_free(pub_key);
			if (seed) OPENSSL_free(seed);
		} else
		{
			LogPrint(eLogError, "MLKEM: GenerateKeys [ libressl ] failed");
			MLKEM_private_key_free(m_Pkey);
			m_Pkey = nullptr;
		}
#endif
	} // end method

	void MLKEMKeys::GetPublicKey (uint8_t * pub) const
	{
		if (m_Pkey)
		{
#ifdef OPENSSL_IS_AWSLC
			size_t len = m_KeyLen;
			if (!EVP_PKEY_get_raw_public_key (m_Pkey, pub, &len))
				LogPrint (eLogError, "MLKEM: GetPublicKey [ aws-lc ] failed");
#elif !defined(LIBRESSL_VERSION_NUMBER)
			size_t len = m_KeyLen;
			EVP_PKEY_get_octet_string_param (m_Pkey, OSSL_PKEY_PARAM_PUB_KEY, pub, m_KeyLen, &len);
#else
			if (!m_Pkey) return;

			LogPrint(eLogDebug, "MLKEM: GetPublicKey [ libressl ]");

			if (m_IsPubCached)
			{
				memcpy(pub, m_CachedPub, MLKEM768_KEY_LENGTH);
				LogPrint(eLogDebug,"MLKEM [libressl]: copy pubkey");
			}
			else
				LogPrint(eLogError, "MLKEM: Public key not cached!");
#endif
		}
	}


	void MLKEMKeys::SetPublicKey (const uint8_t * pub)
	{
#ifdef OPENSSL_IS_AWSLC
		if (m_Pkey)
		{
			EVP_PKEY_free (m_Pkey);
			m_Pkey = nullptr;
		}
		// tachyon-web: AWS-LC's kem_asn1_meth has no set_pub_raw (EVP_PKEY_new_raw_public_key
		// doesn't accept EVP_PKEY_KEM), but its ASN.1 pub_decode path -- reached via d2i_PUBKEY --
		// does call KEM_KEY_set_raw_public_key internally. So build the minimal DER
		// SubjectPublicKeyInfo that kem_pub_encode would itself produce (see p_kem_asn1.c:
		// SEQUENCE { SEQUENCE { OID }, BIT STRING { 0x00 padding, raw key } }, no parameters
		// per RFC 9935 section 4) and hand it to d2i_PUBKEY instead.
		ASN1_OBJECT *obj = OBJ_nid2obj (MLKEMNidFromName (m_Name));
		uint8_t *oidDer = nullptr;
		int oidDerLen = obj ? i2d_ASN1_OBJECT (obj, &oidDer) : -1;
		if (oidDerLen > 0)
		{
			CBB cbb;
			CBB_zero (&cbb);
			if (CBB_init (&cbb, 32 + m_KeyLen))
			{
				CBB spki, algorithm, keyBitstring;
				uint8_t *der = nullptr;
				size_t derLen = 0;
				if (CBB_add_asn1 (&cbb, &spki, CBS_ASN1_SEQUENCE) &&
				    CBB_add_asn1 (&spki, &algorithm, CBS_ASN1_SEQUENCE) &&
				    CBB_add_bytes (&algorithm, oidDer, (size_t)oidDerLen) &&
				    CBB_add_asn1 (&spki, &keyBitstring, CBS_ASN1_BITSTRING) &&
				    CBB_add_u8 (&keyBitstring, 0) &&
				    CBB_add_bytes (&keyBitstring, pub, m_KeyLen) &&
				    CBB_finish (&cbb, &der, &derLen))
				{
					const uint8_t *p = der;
					m_Pkey = d2i_PUBKEY (nullptr, &p, (long)derLen);
					if (!m_Pkey)
						LogPrint (eLogError, "MLKEM: failed to parse public key [ aws-lc ]");
					OPENSSL_free (der);
				}
				else
				{
					LogPrint (eLogError, "MLKEM: failed to build SPKI [ aws-lc ]");
					CBB_cleanup (&cbb);
				}
			}
			OPENSSL_free (oidDer);
		}
		else
			LogPrint (eLogError, "MLKEM: unknown NID for public key [ aws-lc ]");
#elif !defined(LIBRESSL_VERSION_NUMBER)
		if (m_Pkey)
		{
			EVP_PKEY_free (m_Pkey);
			m_Pkey = nullptr;
		}
		OSSL_PARAM params[] =
		{
			OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_PUB_KEY, (void*)pub, m_KeyLen),
			OSSL_PARAM_END
		};

		EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new_from_name(NULL, m_Name.c_str(), NULL);
		if (ctx)
		{
			EVP_PKEY_fromdata_init(ctx);
			if (EVP_PKEY_fromdata(ctx, &m_Pkey, OSSL_KEYMGMT_SELECT_PUBLIC_KEY, params) <= 0)
				LogPrint(eLogError, "MLKEM: Failed to set public key data");
			EVP_PKEY_CTX_free(ctx);
		}
		else
			LogPrint(eLogError, "MLKEM: can't create PKEY context");
#else
		MLKEM_public_key * pub_key = MLKEM_public_key_new(MLKEM768_RANK);
		if (MLKEM_parse_public_key(pub_key, pub, m_KeyLen))
		{
			memcpy(m_CachedPub, pub, m_KeyLen);
			m_IsPubCached = true;
			LogPrint(eLogDebug, "MLKEM: SetPublicKey [ libressl ] success");
		}
		else
			LogPrint(eLogError, "MLKEM: failed to parse public key");
		if (pub_key) MLKEM_public_key_free(pub_key);
#endif
	}

	void MLKEMKeys::Encaps (uint8_t * ciphertext, uint8_t * shared)
	{
#ifdef OPENSSL_IS_AWSLC
		if (!m_Pkey)
		{
			LogPrint(eLogError, "MLKEM: No public key for Encaps");
			return;
		}
		auto ctx = EVP_PKEY_CTX_new (m_Pkey, NULL);
		if (ctx)
		{
			// tachyon-web: unlike the OpenSSL-3.5 provider API below, AWS-LC's
			// EVP_PKEY_encapsulate needs no separate _init call.
			size_t len = m_CTLen, sharedLen = 32;
			if (!EVP_PKEY_encapsulate (ctx, ciphertext, &len, shared, &sharedLen))
				LogPrint (eLogError, "MLKEM: Encaps [ aws-lc ] failed");
			EVP_PKEY_CTX_free (ctx);
		}
		else
			LogPrint (eLogError, "MLKEM can't create PKEY context [ aws-lc ]");
#elif !defined(LIBRESSL_VERSION_NUMBER)
		if (!m_Pkey)
		{
			LogPrint(eLogError, "MLKEM: No public key for Encaps");
			return;
        }
		auto ctx = EVP_PKEY_CTX_new_from_pkey (NULL, m_Pkey, NULL);
		if (ctx)
		{
			EVP_PKEY_encapsulate_init (ctx, NULL);
			size_t len = m_CTLen, sharedLen = 32;
			EVP_PKEY_encapsulate (ctx, ciphertext, &len, shared, &sharedLen);
			EVP_PKEY_CTX_free (ctx);
		}
		else
			LogPrint (eLogError, "MLKEM can't create PKEY context");
#else
		if (!m_IsPubCached)
		{
			LogPrint(eLogError, "MLKEM: No public key for Encaps");
			return;
		}
		auto pub_key = MLKEM_public_key_new(MLKEM768_RANK);
		if (MLKEM_parse_public_key (pub_key, m_CachedPub, m_KeyLen) != 1)
		{
			LogPrint(eLogError, "MLKEM can't parse cached public key");
			return;
		}
		uint8_t * out_ct = nullptr;
		size_t out_ct_len = 0;
		uint8_t * out_ss = nullptr;
		size_t out_ss_len = 0;
		if (MLKEM_encap(pub_key, &out_ct, &out_ct_len, &out_ss, &out_ss_len) == 1)
		{
			memcpy(ciphertext, out_ct, out_ct_len);
			memcpy(shared, out_ss, out_ss_len);
			OPENSSL_cleanse(out_ct, out_ct_len);
			OPENSSL_cleanse(out_ss, out_ss_len);
			OPENSSL_free(out_ct);
			OPENSSL_free(out_ss);
			LogPrint(eLogDebug, "MLKEM [libressl] succesfully encaps");
		}
		else
			LogPrint(eLogError, "MLKEM [libressl]: encapsulation failed");
		MLKEM_public_key_free(pub_key);
#endif
	}

	void MLKEMKeys::Decaps (const uint8_t * ciphertext, uint8_t * shared)
	{
		if (!m_Pkey) return;
#ifdef OPENSSL_IS_AWSLC
		auto ctx = EVP_PKEY_CTX_new (m_Pkey, NULL);
		if (ctx)
		{
			// tachyon-web: no separate _init call needed, same as Encaps above.
			size_t sharedLen = 32;
			if (!EVP_PKEY_decapsulate (ctx, shared, &sharedLen, ciphertext, m_CTLen))
				LogPrint (eLogError, "MLKEM: Decaps [ aws-lc ] failed");
			EVP_PKEY_CTX_free (ctx);
		}
		else
			LogPrint (eLogError, "MLKEM can't create PKEY context [ aws-lc ]");
#elif !defined(LIBRESSL_VERSION_NUMBER)
		auto ctx = EVP_PKEY_CTX_new_from_pkey (NULL, m_Pkey, NULL);
		if (ctx)
		{
			EVP_PKEY_decapsulate_init (ctx, NULL);
			size_t sharedLen = 32;
			EVP_PKEY_decapsulate (ctx, shared, &sharedLen, ciphertext, m_CTLen);
			EVP_PKEY_CTX_free (ctx);
		}
		else
			LogPrint (eLogError, "MLKEM can't create PKEY context");
#else
			uint8_t * out_shared_secret = nullptr;
			size_t out_shared_secret_len = 0;
			if (MLKEM_decap(m_Pkey, ciphertext, m_CTLen, &out_shared_secret, &out_shared_secret_len) == 1)
			{
				memcpy(shared, out_shared_secret, out_shared_secret_len);

				OPENSSL_cleanse(out_shared_secret, out_shared_secret_len);

				OPENSSL_free(out_shared_secret);
				LogPrint(eLogDebug, "MLKEM [libressl] succesfully decrypt");
			}
			else
			{
				LogPrint(eLogError, "MLKEM [libressl]: decapsulation failed");
			}
#endif
	}

	std::unique_ptr<MLKEMKeys> CreateMLKEMKeys (i2p::data::CryptoKeyType type)
	{
		if (type <= i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD ||
		    type - i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD > (int)MLKEMS.size ()) return nullptr;
		return std::make_unique<MLKEMKeys>((MLKEMTypes)(type - i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD - 1));
	}

	static constexpr std::array NoiseIKInitMLKEMKeys =
	{
		std::make_pair
		(
			std::array<uint8_t, 32>
		 	{
				0xb0, 0x8f, 0xb1, 0x73, 0x92, 0x66, 0xc9, 0x90, 0x45, 0x7f, 0xdd, 0xc6, 0x4e, 0x55, 0x40, 0xd8,
				0x0a, 0x37, 0x99, 0x06, 0x92, 0x2a, 0x78, 0xc4, 0xb1, 0xef, 0x86, 0x06, 0xd0, 0x15, 0x9f, 0x4d
			}, // SHA256("Noise_IKhfselg2_25519+MLKEM512_ChaChaPoly_SHA256")
			std::array<uint8_t, 32>
		 	{
				0x95, 0x8d, 0xf6, 0x6c, 0x95, 0xce, 0xa9, 0xf7, 0x42, 0xfc, 0xfa, 0x62, 0x71, 0x36, 0x1e, 0xa7,
				0xdc, 0x7a, 0xc0, 0x75, 0x01, 0xcf, 0xf9, 0xfc, 0x9f, 0xdb, 0x4c, 0x68, 0x3a, 0x53, 0x49, 0xeb
			} // SHA256 (first)
		),
		std::make_pair
		(
			std::array<uint8_t, 32>
		 	{
				0x36, 0x03, 0x90, 0x2d, 0xf9, 0xa2, 0x2a, 0x5e, 0xc9, 0x3d, 0xdb, 0x8f, 0xa8, 0x1b, 0xdb, 0x4b,
				0xae, 0x9d, 0x93, 0x9c, 0xdf, 0xaf, 0xde, 0x55, 0x49, 0x13, 0xfe, 0x98, 0xf8, 0x4a, 0xd4, 0xbd
			}, // SHA256("Noise_IKhfselg2_25519+MLKEM768_ChaChaPoly_SHA256")
		 	std::array<uint8_t, 32>
		 	{
				0x15, 0x44, 0x89, 0xbf, 0x30, 0xf0, 0xc9, 0x77, 0x66, 0x10, 0xcb, 0xb1, 0x57, 0x3f, 0xab, 0x68,
				0x79, 0x57, 0x39, 0x57, 0x0a, 0xe7, 0xc0, 0x31, 0x8a, 0xa2, 0x96, 0xef, 0xbf, 0xa9, 0x6a, 0xbb
			} // SHA256 (first)
		),
		std::make_pair
		(
			std::array<uint8_t, 32>
		 	{
				0x86, 0xa5, 0x36, 0x44, 0xc6, 0x12, 0xd5, 0x71, 0xa1, 0x2d, 0xd8, 0xb6, 0x0a, 0x00, 0x9f, 0x2c,
				0x1a, 0xa8, 0x7d, 0x22, 0xa4, 0xff, 0x2b, 0xcd, 0x61, 0x34, 0x97, 0x6d, 0xa1, 0x49, 0xeb, 0x4a
			}, // SHA256("Noise_IKhfselg2_25519+MLKEM1024_ChaChaPoly_SHA256")
		 	std::array<uint8_t, 32>
		 	{
				0x42, 0x0d, 0xc2, 0x1c, 0x7b, 0x18, 0x61, 0xb7, 0x4a, 0x04, 0x3d, 0xae, 0x0f, 0xdc, 0xf2, 0x71,
				0xb9, 0xba, 0x19, 0xbb, 0xbd, 0x5f, 0xd4, 0x9c, 0x3f, 0x4b, 0x01, 0xed, 0x6d, 0x13, 0x1d, 0xa2
			} // SHA256 (first)
		)
	};

	void InitNoiseIKStateMLKEM (NoiseSymmetricState& state, i2p::data::CryptoKeyType type, const uint8_t * pub)
	{
		if (type <= i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD ||
		    type - i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD > (int)NoiseIKInitMLKEMKeys.size ()) return;
		auto ind = type - i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD - 1;
		state.Init (NoiseIKInitMLKEMKeys[ind].first.data(), NoiseIKInitMLKEMKeys[ind].second.data(), pub);
	}

	static constexpr std::array NoiseXKInitMLKEMKeys =
	{
		std::make_pair
		(
			std::array<uint8_t, 32>
		 	{
				0xf9, 0x9f, 0x6c, 0x60, 0xea, 0x06, 0x78, 0x7f, 0x8d, 0xc2, 0x3f, 0xa3, 0xe9, 0xf7, 0xc0, 0xa5,
				0x34, 0x77, 0x10, 0xc1, 0x1d, 0x99, 0xe0, 0xe9, 0x9c, 0xe3, 0x90, 0x2b, 0x92, 0x32, 0x07, 0x20
			}, // SHA256("Noise_XKhfsaesobfse+hs2+hs3_25519+MLKEM512_ChaChaPoly_SHA256")
			std::array<uint8_t, 32>
		 	{
				0x6a, 0xc4, 0x2c, 0xd8, 0x31, 0xeb, 0xd3, 0x0c, 0xdf, 0x90, 0x2e, 0x67, 0xf4, 0x66, 0x39, 0xab,
				0x85, 0xcf, 0xac, 0x0f, 0x77, 0xba, 0x79, 0x58, 0x61, 0xe9, 0x56, 0x97, 0x44, 0x99, 0xad, 0xe1
			} // SHA256 (first)
		),
		std::make_pair
		(
			std::array<uint8_t, 32>
		 	{
				0xb9, 0xc3, 0x44, 0x56, 0x11, 0xcc, 0x80, 0xec, 0xca, 0x15, 0xde, 0x37, 0xa4, 0x1a, 0xb6, 0xc6,
				0xfb, 0x59, 0xdb, 0x83, 0xeb, 0x1e, 0x9d, 0x7e, 0x27, 0x63, 0xa8, 0xa5, 0x34, 0xec, 0x53, 0xd1
			}, // SHA256("Noise_XKhfsaesobfse+hs2+hs3_25519+MLKEM768_ChaChaPoly_SHA256")
			std::array<uint8_t, 32>
		 	{
				0x0b, 0xcd, 0x38, 0xaf, 0xcf, 0xb7, 0xaa, 0xeb, 0x25, 0x73, 0xb8, 0x4f, 0x74, 0x83, 0x02, 0x94,
				0x8b, 0x53, 0xf5, 0x42, 0xce, 0x3f, 0x23, 0xdc, 0xcc, 0x9a, 0xe9, 0xb0, 0x21, 0xab, 0x48, 0xff
			} // SHA256 (first)
		),
		std::make_pair
		(
			std::array<uint8_t, 32>
		 	{
				0x97, 0xe6, 0x8d, 0x27, 0x49, 0x41, 0x50, 0xea, 0x80, 0x54, 0x8e, 0x73, 0x04, 0x45, 0x3f, 0x61,
				0x29, 0xbc, 0x07, 0x8b, 0x14, 0x05, 0x13, 0xbe, 0x9a, 0x55, 0xb2, 0x07, 0xa2, 0xda, 0x37, 0x0c
			}, // SHA256("Noise_XKhfsaesobfse+hs2+hs3_25519+MLKEM1024_ChaChaPoly_SHA256")
			std::array<uint8_t, 32>
		 	{
				0x59, 0x50, 0x1a, 0x59, 0x87, 0x82, 0x65, 0x55, 0x58, 0x09, 0x9b, 0xec, 0xab, 0x2a, 0x64, 0x1d,
				0xf1, 0x7b, 0xca, 0xe7, 0xb3, 0x5d, 0x6d, 0xa7, 0x8c, 0x6e, 0x79, 0x7e, 0xab, 0xf3, 0x57, 0x3f
			} // SHA256 (first)
		)
	};

	void InitNoiseXKStateMLKEM (NoiseSymmetricState& state, i2p::data::CryptoKeyType type, const uint8_t * pub)
	{
		if (type <= i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD ||
		    type - i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD > (int)NoiseXKInitMLKEMKeys.size ()) return;
		auto ind = type - i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD - 1;
		state.Init (NoiseXKInitMLKEMKeys[ind].first.data(), NoiseXKInitMLKEMKeys[ind].second.data(), pub);
	}

	static constexpr std::array NoiseXKInitMLKEMKeys1 =
	{
		std::make_pair
		(
			std::array<uint8_t, 32>
		 	{
				0x16, 0x22, 0x45, 0x4d, 0xbe, 0xa3, 0xf7, 0x7b, 0xcf, 0x5a, 0x0b, 0x60, 0xf8, 0x56, 0xe0, 0x54,
				0xa6, 0x79, 0x72, 0x74, 0x2a, 0xb7, 0x1a, 0xdf, 0x39, 0x38, 0x7d, 0x35, 0xf8, 0x90, 0x41, 0x68
			}, // SHA256("Noise_XKhfschaobfse+hs1+hs2+hs3_25519+MLKEM512_ChaChaPoly_SHA256")
			std::array<uint8_t, 32>
		 	{
				0xb1, 0x84, 0xaf, 0x89, 0xb5, 0xd2, 0x7f, 0xbd, 0xa4, 0x62, 0xbe, 0x35, 0xa4, 0xc0, 0x17, 0x77,
				0xfb, 0x70, 0xc7, 0x39, 0x28, 0x72, 0xcf, 0x74, 0x4a, 0xbf, 0x3c, 0xc5, 0xb8, 0x6c, 0xaf, 0xcf
			} // SHA256 (first)
		),
		std::make_pair
		(
			std::array<uint8_t, 32>
		 	{
				0x06, 0x45, 0x8d, 0x7f, 0x4a, 0x0e, 0x53, 0xd3, 0x7b, 0xdb, 0xbb, 0x74, 0x77, 0x99, 0xa1, 0x04,
				0xc7, 0x52, 0x00, 0x0b, 0xe0, 0xd1, 0x2a, 0x83, 0x03, 0x7b, 0xe3, 0xd1, 0xdb, 0x77, 0xf2, 0x90
			}, // SHA256("Noise_XKhfschaobfse+hs1+hs2+hs3_25519+MLKEM768_ChaChaPoly_SHA256")
			std::array<uint8_t, 32>
		 	{
				0xd6, 0xae, 0x20, 0x15, 0x44, 0x5f, 0x61, 0xa5, 0xa7, 0xe2, 0x87, 0xcf, 0x64, 0xe0, 0x0c, 0xcc,
				0x97, 0xeb, 0xea, 0x1c, 0x5d, 0xd0, 0x8c, 0x26, 0x34, 0x32, 0x06, 0xf5, 0x5e, 0x28, 0xad, 0x12
			} // SHA256 (first)
		)
		// no ML-KEM-1024
	};

	void InitNoiseXKStateMLKEM1 (NoiseSymmetricState& state, i2p::data::CryptoKeyType type, const uint8_t * pub)
	{
		if (type <= i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD ||
		    type - i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD > (int)NoiseXKInitMLKEMKeys1.size ()) return;
		auto ind = type - i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD - 1;
		state.Init (NoiseXKInitMLKEMKeys1[ind].first.data(), NoiseXKInitMLKEMKeys1[ind].second.data(), pub);
	}
}
}
#endif