Switch to X25519 + ML-KEM-768 encryption
All checks were successful
Server Build / publish (push) Successful in 29s
Voice Build / publish (push) Successful in 26s

This commit is contained in:
olcxja 2026-05-27 20:39:40 +02:00
commit 79af6fcddf
5 changed files with 62 additions and 85 deletions

View file

@ -6,6 +6,7 @@ using LarpixServer.Filesystem;
using LarpixServer.Utils;
using LarpixServer.Utils.Jsons;
using static LarpixServer.Utils.Utils;
using Org.BouncyCastle.Crypto.Parameters;
namespace LarpixServer.Account;
@ -81,12 +82,10 @@ public class Requests
context.Response.ContentType = mimeTypes["json"];
(BigInteger p, BigInteger g, BigInteger pubServer, BigInteger secretServer) serverInfo =
Encryption.Encryption.Init();
var serverInfo = Encryption.Encryption.InitHybridKEM();
KeyExchangePayload payload = new KeyExchangePayload();
payload.p = serverInfo.p.ToString();
payload.g = serverInfo.g.ToString();
payload.pubServer = serverInfo.pubServer.ToString();
payload.pubX25519 = Convert.ToBase64String(serverInfo.pubX25519);
payload.pubMlKem = Convert.ToBase64String(serverInfo.pubMlKem);
payload.idKey = DateTimeOffset.UtcNow.ToUnixTimeSeconds() + "\n";
while (createHolder.ContainsKey(payload.idKey))
@ -96,7 +95,8 @@ public class Requests
CreateHolder dataHolder = new();
dataHolder.date = DateTimeOffset.UtcNow;
dataHolder.serverInfo = serverInfo;
dataHolder.privX25519Server = serverInfo.privX25519;
dataHolder.privMlKemServer = serverInfo.privMlKem;
createHolder.TryAdd(payload.idKey, dataHolder);
@ -123,9 +123,12 @@ public class Requests
}
entry.date = DateTimeOffset.UtcNow;
entry.pubClient = BigInteger.Parse(serializedBody.pubClient);
byte[] sharedKey = Encryption.Encryption.CalcCommunicationKey(entry.pubClient,
entry.serverInfo.secretServer, entry.serverInfo.p);
byte[] pubX25519Client = Convert.FromBase64String(serializedBody.pubX25519);
byte[] ciphertextMlKem = Convert.FromBase64String(serializedBody.ciphertextMlKem);
byte[] sharedKey = Encryption.Encryption.CalcHybridSharedKey(
pubX25519Client, entry.privX25519Server, ciphertextMlKem, entry.privMlKemServer);
entry.name = Encryption.Encryption.Decrypt(serializedBody.username, sharedKey);
@ -649,6 +652,6 @@ public class CreateHolder
public string name;
public string pass;
public string captcha;
public (BigInteger p, BigInteger g, BigInteger pubServer, BigInteger secretServer) serverInfo;
public BigInteger pubClient;
public X25519PrivateKeyParameters privX25519Server;
public MLKemPrivateKeyParameters privMlKemServer;
}