diff --git a/protocol.md b/protocol.md index fc5c60a..7181155 100644 --- a/protocol.md +++ b/protocol.md @@ -34,10 +34,14 @@ All numbers, unless otherwise specified, are the string representation of a base #### Server to Client -0. Login/registration request. +0. Diffie-Hellman key exchange +| Region | | | Length | +| ------ | --- | --- | ------ | +| test | a | b | c | #### Client to Server +0. Diffie-Hellman key exchange ## Sockstamps diff --git a/server/Encryption/Cipher.cs b/server/Encryption/Cipher.cs index 38c26d1..dafabea 100644 --- a/server/Encryption/Cipher.cs +++ b/server/Encryption/Cipher.cs @@ -32,7 +32,5 @@ namespace CircleScape.Encryption { cipher[x] = state[(state[i] + state[j]) % 256]; } } - - // http://bradconte.com/rc4_c } } diff --git a/server/Encryption/KeyExchange.cs b/server/Encryption/KeyExchange.cs index a116eab..e4033a6 100644 --- a/server/Encryption/KeyExchange.cs +++ b/server/Encryption/KeyExchange.cs @@ -4,14 +4,18 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Numerics; +using Square; namespace CircleScape.Encryption { class KeyExchange { private BigInteger Secret; - public BigInteger Generator { get; private set; } + public BigInteger Generator { get; private set; } = 2; public BigInteger Modulus { get; private set; } - public BigInteger PrivateKey { get; private set; } + public BigInteger PrivateKey { get; private set; } = BigInteger.MinusOne; - // https://security.stackexchange.com/questions/45963/diffie-hellman-key-exchange-in-plain-english/45971#45971 + public KeyExchange() { + Secret = RNG.NextPrime(512 / 8); + Modulus = RNG.NextPrime(512 / 8); + } } } diff --git a/server/Entrypoint.cs b/server/Entrypoint.cs index e5d3f71..5af27a1 100644 --- a/server/Entrypoint.cs +++ b/server/Entrypoint.cs @@ -11,7 +11,7 @@ using Square; namespace CircleScape { class Entrypoint { static void Main(string[] args) { - var a = Square.Random.NextPrime(512 / 8); + var a = Square.RNG.NextPrime(512 / 8); Console.WriteLine(a.ToString("X")); var server = new Kneesocks.Server(6770, PoolManager.Pending); diff --git a/server/Libraries/Square/NumericExtensions.cs b/server/Libraries/Square/NumericExtensions.cs index 4a25822..3277e95 100644 --- a/server/Libraries/Square/NumericExtensions.cs +++ b/server/Libraries/Square/NumericExtensions.cs @@ -56,7 +56,7 @@ namespace Square { if(absValue < 25) return true; for(var i = 0; i < iterations; ++i) { - var rand = Random.NextBigInt(2, absValue - 2); + var rand = RNG.NextBigInt(2, absValue - 2); if(!BigInteger.ModPow(rand, absValue - 1, absValue).IsOne) return false; } diff --git a/server/Libraries/Square/RandomContext.cs b/server/Libraries/Square/RandomContext.cs index e2a0bc2..7015229 100644 --- a/server/Libraries/Square/RandomContext.cs +++ b/server/Libraries/Square/RandomContext.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; using System.Numerics; namespace Square { - public static class Random { + public static class RNG { private static System.Random RandCtx = new System.Random(); public static int Next() {