Switch to X25519 + ML-KEM-768 encryption
This commit is contained in:
parent
9183651c4f
commit
79af6fcddf
5 changed files with 62 additions and 85 deletions
|
|
@ -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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue