* Moved encryption algorithms into a folder
* Sorted networking into separate files
Additions:
* Created Elliptic Curve encryption implementation
* Generalized the key exchange implementation
- Implemented Diffie-Hellman key exchange
- Implemented Elliptic Curve Diffie-Hellman key exchange
* Started implementing binary data compressor
Changes:
* Changed NetClient and NetServer to use IKeyExchange for initial AES key exchange instead of RSA (for optimization)
* Adapted TextView implementation to properly support optional borders
* Fed InputView issue caused due to border rendering change
* Fixed and simplified Rectangle computations
* Fixed errant naming in Session layout file
* Fixed errant i18n naming in Session layout file
* Fixed resize background rendering issue in ConsoleController
* Fully implemented ListView (needs testing)
* Updated BankInteractor and server to use ECDH-E with Curve25519
Removals:
* Removed identity verification from NetClient (identities checks should be performed as a layer on top of NetClient/NetServer, not as part of it)
35 lines
1.1 KiB
C#
35 lines
1.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Numerics;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Tofvesson.Crypto;
|
|
|
|
namespace Common.Cryptography.KeyExchange
|
|
{
|
|
public sealed class DiffieHellman : IKeyExchange
|
|
{
|
|
private static readonly BigInteger EPHEMERAL_MAX = BigInteger.One << 2048;
|
|
private static readonly RandomProvider provider = new CryptoRandomProvider();
|
|
private BigInteger priv, p, q;
|
|
private readonly BigInteger pub;
|
|
|
|
public DiffieHellman(BigInteger p, BigInteger q) : this(provider.GenerateRandom(EPHEMERAL_MAX), p, q) { }
|
|
public DiffieHellman(BigInteger priv, BigInteger p, BigInteger q)
|
|
{
|
|
this.priv = priv;
|
|
this.p = p;
|
|
this.q = q;
|
|
pub = Support.ModExp(p, priv, q);
|
|
}
|
|
|
|
public byte[] GetPublicKey() => pub.ToByteArray();
|
|
|
|
public byte[] GetSharedSecret(byte[] p) {
|
|
BigInteger pub = new BigInteger(p);
|
|
return (pub <= 0 ? (BigInteger) 0 : Support.ModExp(pub, priv, q)).ToByteArray();
|
|
}
|
|
}
|
|
}
|