private void GenerateKey( int bitlen, DHKeyGeneration keygen, out BigInteger p, out BigInteger g) { if (keygen == DHKeyGeneration.Static) { switch (bitlen) { case 768: p = new BigInteger(DiffieHellmanManaged.m_OAKLEY768); break; case 1024: p = new BigInteger(DiffieHellmanManaged.m_OAKLEY1024); break; case 1536: p = new BigInteger(DiffieHellmanManaged.m_OAKLEY1536); break; default: throw new ArgumentException("Invalid bit size."); } g = new BigInteger(22U); } else { p = BigInteger.GeneratePseudoPrime(bitlen); g = new BigInteger(3U); } }
/// <summary> /// Initializes a new <see cref="DiffieHellmanManaged"/> instance. /// </summary> /// <param name="bitlen">The length, in bits, of the public P parameter.</param> /// <param name="l">The length, in bits, of the secret value X. This parameter can be set to 0 to use the default size.</param> /// <param name="keygen">One of the <see cref="DHKeyGeneration"/> values.</param> /// <remarks>The larger the bit length, the more secure the algorithm is. The default is 1024 bits. The minimum bit length is 128 bits.<br/>The size of the private value will be one fourth of the bit length specified.</remarks> /// <exception cref="ArgumentException">The specified bit length is invalid.</exception> public DiffieHellmanManaged(int bitlen, int l, DHKeyGeneration keygen) { if (bitlen < 256 || l < 0) throw new ArgumentException(); BigInteger p, g; GenerateKey(bitlen, keygen, out p, out g); Initialize(p, g, null, l, false); }
/// <summary> /// Initializes a new <see cref="DiffieHellmanManaged"/> instance. /// </summary> /// <param name="bitLength">The length, in bits, of the public P parameter.</param> /// <param name="l">The length, in bits, of the secret value X. This parameter can be set to 0 to use the default size.</param> /// <param name="method">One of the <see cref="DHKeyGeneration"/> values.</param> /// <remarks>The larger the bit length, the more secure the algorithm is. The default is 1024 bits. The minimum bit length is 128 bits.<br/>The size of the private value will be one fourth of the bit length specified.</remarks> /// <exception cref="ArgumentException">The specified bit length is invalid.</exception> public DiffieHellmanManaged(int bitLength, int l, DHKeyGeneration method) { if (bitLength < 256 || l < 0) throw new ArgumentException(); BigInteger p, g; GenerateKey (bitLength, method, out p, out g); Initialize(p, g, null, l, false); }
private void GenerateKey(int bitlen, DHKeyGeneration keygen, out BigInteger p, out BigInteger g) { if (keygen == DHKeyGeneration.Static) { if (bitlen == 768) { p = new BigInteger(DiffieHellmanManaged.m_OAKLEY768); } else if (bitlen == 1024) { p = new BigInteger(DiffieHellmanManaged.m_OAKLEY1024); } else { if (bitlen != 1536) { throw new ArgumentException("Invalid bit size."); } p = new BigInteger(DiffieHellmanManaged.m_OAKLEY1536); } g = new BigInteger(22u); } else { p = BigInteger.GeneratePseudoPrime(bitlen); g = new BigInteger(3u); } }
public DiffieHellmanManaged(int bitLength, int l, DHKeyGeneration method) { if (bitLength < 256 || l < 0) { throw new ArgumentException(); } GenerateKey(bitLength, method, out BigInteger p, out BigInteger g); Initialize(p, g, null, l, checkInput: false); }
public DiffieHellmanManaged(int bitlen, int l, DHKeyGeneration keygen) { if (bitlen < 256 || l < 0) { throw new ArgumentException(); } GenerateKey(bitlen, keygen, out BigInteger p, out BigInteger g); Initialize(p, g, null, l, checkInput: false); }
public DiffieHellmanManaged(int bitLength, int l, DHKeyGeneration method) { if (bitLength < 256 || l < 0) { throw new ArgumentException(); } BigInteger p; BigInteger g; this.GenerateKey(bitLength, method, out p, out g); this.Initialize(p, g, (BigInteger)null, l, false); }
/// <summary> /// Initializes a new <see cref="DiffieHellmanManaged"/> instance. /// </summary> /// <param name="bitlen">The length, in bits, of the public P parameter.</param> /// <param name="l">The length, in bits, of the secret value X. This parameter can be set to 0 to use the default size.</param> /// <param name="keygen">One of the <see cref="DHKeyGeneration"/> values.</param> /// <remarks>The larger the bit length, the more secure the algorithm is. The default is 1024 bits. The minimum bit length is 128 bits.<br/>The size of the private value will be one fourth of the bit length specified.</remarks> /// <exception cref="ArgumentException">The specified bit length is invalid.</exception> public DiffieHellmanManaged(int bitlen, int l, DHKeyGeneration keygen) { //GladNet modification. This is gutsy. To modify an underlying encryption algorithm. //However, we don't want 256 bit AES. We want 128 bit. if (bitlen < 256 || l < 0) { throw new ArgumentException(); } BigInteger p, g; GenerateKey(bitlen, keygen, out p, out g); Initialize(p, g, null, l, false); }
//TODO: implement DH key generation methods private void GenerateKey(int bitlen, DHKeyGeneration keygen, out BigInteger p, out BigInteger g) { if (keygen == DHKeyGeneration.Static) { if (bitlen == 768) { p = new BigInteger(m_OAKLEY768); } else if (bitlen == 1024) { p = new BigInteger(m_OAKLEY1024); } else if (bitlen == 1536) { p = new BigInteger(m_OAKLEY1536); } else { throw new ArgumentException("Invalid bit size."); } g = new BigInteger(22); // all OAKLEY keys use 22 as generator //} else if (keygen == DHKeyGeneration.SophieGermain) { // throw new NotSupportedException(); //TODO //} else if (keygen == DHKeyGeneration.DSA) { // 1. Let j = (p - 1)/q. // 2. Set h = any integer, where 1 < h < p - 1 // 3. Set g = h^j mod p // 4. If g = 1 go to step 2 // BigInteger j = (p - 1) / q; } else { // random p = BigInteger.GeneratePseudoPrime(bitlen); g = new BigInteger(3); // always use 3 as a generator } }
//TODO: implement DH key generation methods private void GenerateKey(int bitlen, DHKeyGeneration keygen, out BigInteger p, out BigInteger g) { if (keygen == DHKeyGeneration.Static) { if (bitlen == 768) p = new BigInteger(m_OAKLEY768); else if (bitlen == 1024) p = new BigInteger(m_OAKLEY1024); else if (bitlen == 1536) p = new BigInteger(m_OAKLEY1536); else throw new ArgumentException("Invalid bit size."); g = new BigInteger(22); // all OAKLEY keys use 22 as generator //} else if (keygen == DHKeyGeneration.SophieGermain) { // throw new NotSupportedException(); //TODO //} else if (keygen == DHKeyGeneration.DSA) { // 1. Let j = (p - 1)/q. // 2. Set h = any integer, where 1 < h < p - 1 // 3. Set g = h^j mod p // 4. If g = 1 go to step 2 // BigInteger j = (p - 1) / q; } else { // random p = BigInteger.genPseudoPrime(bitlen); g = new BigInteger(3); // always use 3 as a generator } }
//ctor: public DiffieHellmanManaged(int bitLength, int l, DHKeyGeneration method) { }