diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2011-07-20 07:01:58 -0600 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2011-07-20 07:01:58 -0600 |
commit | 1328f88a36187d8aa5890a46e35af59c4df04d3f (patch) | |
tree | c42a3aad4aa21d39b91dcc87a912f8cb96c22c11 /src/Org.Mentalis.Security.Cryptography | |
parent | d15895e626b73b6f96f561786b4b5c941c0a4bb1 (diff) | |
download | DotNetOpenAuth-1328f88a36187d8aa5890a46e35af59c4df04d3f.zip DotNetOpenAuth-1328f88a36187d8aa5890a46e35af59c4df04d3f.tar.gz DotNetOpenAuth-1328f88a36187d8aa5890a46e35af59c4df04d3f.tar.bz2 |
Splitting up the OpenID profile into OpenID RP and OP. The core OpenID DLL compiles, but the RP and OP ones do not.
Diffstat (limited to 'src/Org.Mentalis.Security.Cryptography')
6 files changed, 552 insertions, 0 deletions
diff --git a/src/Org.Mentalis.Security.Cryptography/DHKeyGeneration.cs b/src/Org.Mentalis.Security.Cryptography/DHKeyGeneration.cs new file mode 100644 index 0000000..6eca6a0 --- /dev/null +++ b/src/Org.Mentalis.Security.Cryptography/DHKeyGeneration.cs @@ -0,0 +1,56 @@ +// <auto-generated /> + +// +// DHKeyGeneration.cs: Defines the different key generation methods. +// +// Author: +// Pieter Philippaerts (Pieter@mentalis.org) +// +// (C) 2003 The Mentalis.org Team (http://www.mentalis.org/) +// +// Source Code License +// Copyright © 2002-2007, The Mentalis.org Team +// All rights reserved. +// http://www.mentalis.org/ +// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: +// - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. +// - Neither the name of the Mentalis.org Team, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +namespace Org.Mentalis.Security.Cryptography { + /// <summary> + /// Defines the different Diffie-Hellman key generation methods. + /// </summary> + internal enum DHKeyGeneration { + /* + /// <summary> + /// [TODO] you first randomly select a prime Q of size 160 bits, then choose P randomly among numbers like + /// Q*R+1 with R random. Then you go along with finding a generator G which has order exactly Q. The private + /// key X is then a number modulo Q. + /// [FIPS 186-2-Change1 -- http://csrc.nist.gov/publications/fips/] + /// </summary> + // see RFC2631 [http://www.faqs.org/rfcs/rfc2631.html] + DSA,*/ + /// <summary> + /// Returns dynamically generated values for P and G. Unlike the Sophie Germain or DSA key generation methods, + /// this method does not ensure that the selected prime offers an adequate security level. + /// </summary> + Random, + /* + /// <summary> + /// Returns dynamically generated values for P and G. P is a Sophie Germain prime, which has some interesting + /// security features when used with Diffie Hellman. + /// </summary> + SophieGermain,*/ + /// <summary> + /// Returns values for P and G that are hard coded in this library. Contrary to what your intuition may tell you, + /// using these hard coded values is perfectly safe. + /// The values of the P and G parameters are taken from 'The OAKLEY Key Determination Protocol' [RFC2412]. + /// This is the prefered key generation method, because it is very fast and very safe. + /// Because this method uses fixed values for the P and G parameters, not all bit sizes are supported. + /// The current implementation supports bit sizes of 768, 1024 and 1536. + /// </summary> + Static + } +}
\ No newline at end of file diff --git a/src/Org.Mentalis.Security.Cryptography/DHParameters.cs b/src/Org.Mentalis.Security.Cryptography/DHParameters.cs new file mode 100644 index 0000000..8105125 --- /dev/null +++ b/src/Org.Mentalis.Security.Cryptography/DHParameters.cs @@ -0,0 +1,38 @@ +// <auto-generated /> + +// +// DHParameters.cs: Defines a structure that holds the parameters of the Diffie-Hellman algorithm +// +// Author: +// Pieter Philippaerts (Pieter@mentalis.org) +// +// (C) 2003 The Mentalis.org Team (http://www.mentalis.org/) +// +// Source Code License +// Copyright © 2002-2007, The Mentalis.org Team +// All rights reserved. +// http://www.mentalis.org/ +// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: +// - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. +// - Neither the name of the Mentalis.org Team, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +namespace Org.Mentalis.Security.Cryptography { + /// <summary> + /// Represents the parameters of the Diffie-Hellman algorithm. + /// </summary> + internal struct DHParameters { + /// <summary> + /// Represents the public <b>P</b> parameter of the Diffie-Hellman algorithm. + /// </summary> + public byte[] P; + /// <summary> + /// Represents the public <b>G</b> parameter of the Diffie-Hellman algorithm. + /// </summary> + public byte[] G; + /// <summary> + /// Represents the private <b>X</b> parameter of the Diffie-Hellman algorithm. + /// </summary> + public byte[] X; + } +}
\ No newline at end of file diff --git a/src/Org.Mentalis.Security.Cryptography/DiffieHellman.cs b/src/Org.Mentalis.Security.Cryptography/DiffieHellman.cs new file mode 100644 index 0000000..5019f70 --- /dev/null +++ b/src/Org.Mentalis.Security.Cryptography/DiffieHellman.cs @@ -0,0 +1,101 @@ +// <auto-generated /> + +// +// DiffieHellman.cs: Defines a base class from which all Diffie-Hellman implementations inherit +// +// Author: +// Pieter Philippaerts (Pieter@mentalis.org) +// +// (C) 2003 The Mentalis.org Team (http://www.mentalis.org/) +// +// +// Source Code License +// Copyright © 2002-2007, The Mentalis.org Team +// All rights reserved. +// http://www.mentalis.org/ +// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: +// - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. +// - Neither the name of the Mentalis.org Team, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +using System; +using System.Security.Cryptography; + +namespace Org.Mentalis.Security.Cryptography { + /// <summary> + /// Defines a base class from which all Diffie-Hellman implementations inherit. + /// </summary> + internal abstract class DiffieHellman : AsymmetricAlgorithm { + /// <summary> + /// Creates an instance of the default implementation of the <see cref="DiffieHellman"/> algorithm. + /// </summary> + /// <returns>A new instance of the default implementation of DiffieHellman.</returns> + public static new DiffieHellman Create () { + return Create ("Mono.Security.Cryptography.DiffieHellman"); + } + /// <summary> + /// Creates an instance of the specified implementation of <see cref="DiffieHellman"/>. + /// </summary> + /// <param name="algName">The name of the implementation of DiffieHellman to use.</param> + /// <returns>A new instance of the specified implementation of DiffieHellman.</returns> + public static new DiffieHellman Create (string algName) { + return (DiffieHellman) CryptoConfig.CreateFromName (algName); + } + + /// <summary> + /// Initializes a new <see cref="DiffieHellman"/> instance. + /// </summary> + public DiffieHellman() {} + + /// <summary> + /// When overridden in a derived class, creates the key exchange data. + /// </summary> + /// <returns>The key exchange data to be sent to the intended recipient.</returns> + public abstract byte[] CreateKeyExchange(); + /// <summary> + /// When overridden in a derived class, extracts secret information from the key exchange data. + /// </summary> + /// <param name="keyEx">The key exchange data within which the secret information is hidden.</param> + /// <returns>The secret information derived from the key exchange data.</returns> + public abstract byte[] DecryptKeyExchange(byte[] keyEx); + + /// <summary> + /// When overridden in a derived class, exports the <see cref="DHParameters"/>. + /// </summary> + /// <param name="includePrivate"><b>true</b> to include private parameters; otherwise, <b>false</b>.</param> + /// <returns>The parameters for Diffie-Hellman.</returns> + public abstract DHParameters ExportParameters (bool includePrivate); + /// <summary> + /// When overridden in a derived class, imports the specified <see cref="DHParameters"/>. + /// </summary> + /// <param name="parameters">The parameters for Diffie-Hellman.</param> + public abstract void ImportParameters (DHParameters parameters); + +#if UNUSED + private byte[] GetNamedParam(SecurityElement se, string param) { + SecurityElement sep = se.SearchForChildByTag(param); + if (sep == null) + return null; + return Convert.FromBase64String(sep.Text); + } +#endif + /// <summary> + /// Reconstructs a <see cref="DiffieHellman"/> object from an XML string. + /// </summary> + /// <param name="xmlString">The XML string to use to reconstruct the DiffieHellman object.</param> + /// <exception cref="CryptographicException">One of the values in the XML string is invalid.</exception> + public override void FromXmlString (string xmlString) { + if (xmlString == null) + throw new ArgumentNullException (); + throw new NotImplementedException(); + } + /// <summary> + /// Creates and returns an XML string representation of the current <see cref="DiffieHellman"/> object. + /// </summary> + /// <param name="includePrivateParameters"><b>true</b> to include private parameters; otherwise, <b>false</b>.</param> + /// <returns>An XML string encoding of the current DiffieHellman object.</returns> + public override string ToXmlString (bool includePrivateParameters) { + throw new NotImplementedException(); + } + } +}
\ No newline at end of file diff --git a/src/Org.Mentalis.Security.Cryptography/DiffieHellmanManaged.cs b/src/Org.Mentalis.Security.Cryptography/DiffieHellmanManaged.cs new file mode 100644 index 0000000..6ac28df --- /dev/null +++ b/src/Org.Mentalis.Security.Cryptography/DiffieHellmanManaged.cs @@ -0,0 +1,267 @@ +// <auto-generated /> + +// +// DiffieHellmanManaged.cs: Implements the Diffie-Hellman key agreement algorithm +// +// Author: +// Pieter Philippaerts (Pieter@mentalis.org) +// +// (C) 2003 The Mentalis.org Team (http://www.mentalis.org/) +// +// References: +// - PKCS#3 [http://www.rsasecurity.com/rsalabs/pkcs/pkcs-3/] +// +// +// Source Code License +// Copyright © 2002-2007, The Mentalis.org Team +// All rights reserved. +// http://www.mentalis.org/ +// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: +// - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. +// - Neither the name of the Mentalis.org Team, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +using System; +using System.Security.Cryptography; +using Mono.Math; + +namespace Org.Mentalis.Security.Cryptography { + /// <summary> + /// Implements the Diffie-Hellman algorithm. + /// </summary> + internal sealed class DiffieHellmanManaged : DiffieHellman { + /// <summary> + /// Initializes a new <see cref="DiffieHellmanManaged"/> instance. + /// </summary> + /// <remarks>The default length of the shared secret is 1024 bits.</remarks> + public DiffieHellmanManaged() : this(1024, 160, DHKeyGeneration.Static) {} + /// <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="p">The P parameter of the Diffie-Hellman algorithm. This is a public parameter.</param> + /// <param name="g">The G parameter of the Diffie-Hellman algorithm. This is a public parameter.</param> + /// <param name="x">The X parameter of the Diffie-Hellman algorithm. This is a private parameter. If this parameters is a null reference (<b>Nothing</b> in Visual Basic), a secret value of the default size will be generated.</param> + /// <exception cref="ArgumentNullException"><paramref name="p"/> or <paramref name="g"/> is a null reference (<b>Nothing</b> in Visual Basic).</exception> + /// <exception cref="CryptographicException"><paramref name="p"/> or <paramref name="g"/> is invalid.</exception> + public DiffieHellmanManaged(byte[] p, byte[] g, byte[] x) { + if (p == null || g == null) + throw new ArgumentNullException(); + if (x == null) + Initialize(new BigInteger(p), new BigInteger(g), null, 0, true); + else + Initialize(new BigInteger(p), new BigInteger(g), new BigInteger(x), 0, true); + } + /// <summary> + /// Initializes a new <see cref="DiffieHellmanManaged"/> instance. + /// </summary> + /// <param name="p">The P parameter of the Diffie-Hellman algorithm.</param> + /// <param name="g">The G parameter of the Diffie-Hellman algorithm.</param> + /// <param name="l">The length, in bits, of the private value. If 0 is specified, the default value will be used.</param> + /// <exception cref="ArgumentNullException"><paramref name="p"/> or <paramref name="g"/> is a null reference (<b>Nothing</b> in Visual Basic).</exception> + /// <exception cref="ArgumentException"><paramref name="l"/> is invalid.</exception> + /// <exception cref="CryptographicException"><paramref name="p"/> or <paramref name="g"/> is invalid.</exception> + public DiffieHellmanManaged(byte[] p, byte[] g, int l) { + if (p == null || g == null) + throw new ArgumentNullException(); + if (l < 0) + throw new ArgumentException(); + Initialize(new BigInteger(p), new BigInteger(g), null, l, true); + } + + // initializes the private variables (throws CryptographicException) + private void Initialize(BigInteger p, BigInteger g, BigInteger x, int secretLen, bool checkInput) { + if (!p.isProbablePrime() || g <= 0 || g >= p || (x != null && (x <= 0 || x > p - 2))) + throw new CryptographicException(); + // default is to generate a number as large as the prime this + // is usually overkill, but it's the most secure thing we can + // do if the user doesn't specify a desired secret length ... + if (secretLen == 0) + secretLen = p.bitCount(); + m_P = p; + m_G = g; + if (x == null) { + BigInteger pm1 = m_P - 1; + for(m_X = BigInteger.genRandom(secretLen); m_X >= pm1 || m_X == 0; m_X = BigInteger.genRandom(secretLen)) {} + } else { + m_X = x; + } + } + /// <summary> + /// Creates the key exchange data. + /// </summary> + /// <returns>The key exchange data to be sent to the intended recipient.</returns> + public override byte[] CreateKeyExchange() { + BigInteger y = m_G.modPow(m_X, m_P); + byte[] ret = y.getBytes(); + y.Clear(); + return ret; + } + /// <summary> + /// Extracts secret information from the key exchange data. + /// </summary> + /// <param name="keyEx">The key exchange data within which the shared key is hidden.</param> + /// <returns>The shared key derived from the key exchange data.</returns> + public override byte[] DecryptKeyExchange(byte[] keyEx) { + BigInteger pvr = new BigInteger(keyEx); + BigInteger z = pvr.modPow(m_X, m_P); + byte[] ret = z.getBytes(); + z.Clear(); + return ret; + } + /// <summary> + /// Gets the name of the key exchange algorithm. + /// </summary> + /// <value>The name of the key exchange algorithm.</value> + public override string KeyExchangeAlgorithm { + get { + return "1.2.840.113549.1.3"; // PKCS#3 OID + } + } + /// <summary> + /// Gets the name of the signature algorithm. + /// </summary> + /// <value>The name of the signature algorithm.</value> + public override string SignatureAlgorithm { + get { + return null; + } + } + /// <summary> + /// Releases the unmanaged resources used by the SymmetricAlgorithm and optionally releases the managed resources. + /// </summary> + /// <param name="disposing"><b>true</b> to release both managed and unmanaged resources; <b>false</b> to release only unmanaged resources.</param> + protected override void Dispose(bool disposing) { + if (!m_Disposed) { + m_P.Clear(); + m_G.Clear(); + m_X.Clear(); + } + m_Disposed = true; + } + /// <summary> + /// Exports the <see cref="DHParameters"/>. + /// </summary> + /// <param name="includePrivateParameters"><b>true</b> to include private parameters; otherwise, <b>false</b>.</param> + /// <returns>The parameters for <see cref="DiffieHellman"/>.</returns> + public override DHParameters ExportParameters(bool includePrivateParameters) { + DHParameters ret = new DHParameters(); + ret.P = m_P.getBytes(); + ret.G = m_G.getBytes(); + if (includePrivateParameters) { + ret.X = m_X.getBytes(); + } + return ret; + } + /// <summary> + /// Imports the specified <see cref="DHParameters"/>. + /// </summary> + /// <param name="parameters">The parameters for <see cref="DiffieHellman"/>.</param> + /// <exception cref="CryptographicException"><see cref="DHParameters.P">parameters.P</see> or <see cref="DHParameters.G">parameters.G</see> is a null reference (<b>Nothing</b> in Visual Basic) -or- <see cref="DHParameters.P">parameters.P</see> is not a prime number.</exception> + public override void ImportParameters(DHParameters parameters) { + if (parameters.P == null) + throw new CryptographicException("Missing P value."); + if (parameters.G == null) + throw new CryptographicException("Missing G value."); + + BigInteger p = new BigInteger(parameters.P), g = new BigInteger(parameters.G), x = null; + if (parameters.X != null) { + x = new BigInteger(parameters.X); + } + Initialize(p, g, x, 0, true); + } + /// <summary> + /// Releases the unmanaged resources used by the SymmetricAlgorithm. + /// </summary> + ~DiffieHellmanManaged() { + Dispose(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.genPseudoPrime(bitlen); + g = new BigInteger(3); // always use 3 as a generator + } + } + + private BigInteger m_P; + private BigInteger m_G; + private BigInteger m_X; + private bool m_Disposed; + + private byte[] m_OAKLEY768 = new byte[] { + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2, + 0x21, 0x68, 0xC2, 0x34, 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1, + 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74, 0x02, 0x0B, 0xBE, 0xA6, + 0x3B, 0x13, 0x9B, 0x22, 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD, + 0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B, 0x30, 0x2B, 0x0A, 0x6D, + 0xF2, 0x5F, 0x14, 0x37, 0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45, + 0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6, 0xF4, 0x4C, 0x42, 0xE9, + 0xA6, 0x3A, 0x36, 0x20, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF + }; + private byte[] m_OAKLEY1024 = new byte[] { + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2, + 0x21, 0x68, 0xC2, 0x34, 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1, + 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74, 0x02, 0x0B, 0xBE, 0xA6, + 0x3B, 0x13, 0x9B, 0x22, 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD, + 0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B, 0x30, 0x2B, 0x0A, 0x6D, + 0xF2, 0x5F, 0x14, 0x37, 0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45, + 0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6, 0xF4, 0x4C, 0x42, 0xE9, + 0xA6, 0x37, 0xED, 0x6B, 0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED, + 0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5, 0xAE, 0x9F, 0x24, 0x11, + 0x7C, 0x4B, 0x1F, 0xE6, 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE6, 0x53, 0x81, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF + }; + private byte[] m_OAKLEY1536 = new byte[] { + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2, + 0x21, 0x68, 0xC2, 0x34, 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1, + 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74, 0x02, 0x0B, 0xBE, 0xA6, + 0x3B, 0x13, 0x9B, 0x22, 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD, + 0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B, 0x30, 0x2B, 0x0A, 0x6D, + 0xF2, 0x5F, 0x14, 0x37, 0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45, + 0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6, 0xF4, 0x4C, 0x42, 0xE9, + 0xA6, 0x37, 0xED, 0x6B, 0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED, + 0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5, 0xAE, 0x9F, 0x24, 0x11, + 0x7C, 0x4B, 0x1F, 0xE6, 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE4, 0x5B, 0x3D, + 0xC2, 0x00, 0x7C, 0xB8, 0xA1, 0x63, 0xBF, 0x05, 0x98, 0xDA, 0x48, 0x36, + 0x1C, 0x55, 0xD3, 0x9A, 0x69, 0x16, 0x3F, 0xA8, 0xFD, 0x24, 0xCF, 0x5F, + 0x83, 0x65, 0x5D, 0x23, 0xDC, 0xA3, 0xAD, 0x96, 0x1C, 0x62, 0xF3, 0x56, + 0x20, 0x85, 0x52, 0xBB, 0x9E, 0xD5, 0x29, 0x07, 0x70, 0x96, 0x96, 0x6D, + 0x67, 0x0C, 0x35, 0x4E, 0x4A, 0xBC, 0x98, 0x04, 0xF1, 0x74, 0x6C, 0x08, + 0xCA, 0x23, 0x73, 0x27, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF + }; + } +}
\ No newline at end of file diff --git a/src/Org.Mentalis.Security.Cryptography/Org.Mentalis.Security.Cryptography.csproj b/src/Org.Mentalis.Security.Cryptography/Org.Mentalis.Security.Cryptography.csproj new file mode 100644 index 0000000..c2b1055 --- /dev/null +++ b/src/Org.Mentalis.Security.Cryptography/Org.Mentalis.Security.Cryptography.csproj @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), EnlistmentInfo.props))\EnlistmentInfo.props" Condition=" '$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), EnlistmentInfo.props))' != '' " /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + </PropertyGroup> + <Import Project="$(ProjectRoot)tools\DotNetOpenAuth.props" /> + <PropertyGroup> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{26DC877F-5987-48DD-9DDB-E62F2DE0E150}</ProjectGuid> + <OutputType>Library</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <RootNamespace>Org.Mentalis.Security.Cryptography</RootNamespace> + <AssemblyName>Org.Mentalis.Security.Cryptography</AssemblyName> + </PropertyGroup> + <Import Project="$(ProjectRoot)tools\DotNetOpenAuth.Product.props" /> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + </PropertyGroup> + <ItemGroup> + <Compile Include="DHKeyGeneration.cs" /> + <Compile Include="DHParameters.cs" /> + <Compile Include="DiffieHellman.cs" /> + <Compile Include="DiffieHellmanManaged.cs" /> + <Compile Include="Properties\AssemblyInfo.cs" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\Mono.Math\Mono.Math.csproj"> + <Project>{F4CD3C04-6037-4946-B7A5-34BFC96A75D2}</Project> + <Name>Mono.Math</Name> + </ProjectReference> + </ItemGroup> + <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> + <Import Project="$(ProjectRoot)tools\DotNetOpenAuth.targets" /> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), EnlistmentInfo.targets))\EnlistmentInfo.targets" Condition=" '$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), EnlistmentInfo.targets))' != '' " /> +</Project>
\ No newline at end of file diff --git a/src/Org.Mentalis.Security.Cryptography/Properties/AssemblyInfo.cs b/src/Org.Mentalis.Security.Cryptography/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..064d991 --- /dev/null +++ b/src/Org.Mentalis.Security.Cryptography/Properties/AssemblyInfo.cs @@ -0,0 +1,52 @@ +//----------------------------------------------------------------------- +// <copyright file="AssemblyInfo.cs" company="Andrew Arnott"> +// Copyright (c) Andrew Arnott. All rights reserved. +// </copyright> +//----------------------------------------------------------------------- + +// We DON'T put an AssemblyVersionAttribute in here because it is generated in the build. + +using System; +using System.Diagnostics.Contracts; +using System.Net; +using System.Reflection; +using System.Resources; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Security; +using System.Security.Permissions; +using System.Web.UI; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Org.Mentalis.Security.Cryptography")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("DotNetOpenAuth")] +[assembly: AssemblyCopyright("Copyright © 2008")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] +[assembly: NeutralResourcesLanguage("en-US")] +[assembly: CLSCompliant(true)] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("7d73990c-47c0-4256-9f20-a893add9e289")] + +[assembly: ContractVerification(true)] + +#if StrongNameSigned +// See comment at top of this file. We need this so that strong-naming doesn't +// keep this assembly from being useful to shared host (medium trust) web sites. +[assembly: AllowPartiallyTrustedCallers] + +[assembly: InternalsVisibleTo("DotNetOpenAuth.OpenId, PublicKey=0024000004800000940000000602000000240000525341310004000001000100AD093C3765257C89A7010E853F2C7C741FF92FA8ACE06D7B8254702CAD5CF99104447F63AB05F8BB6F51CE0D81C8C93D2FCE8C20AAFF7042E721CBA16EAAE98778611DED11C0ABC8900DC5667F99B50A9DADEC24DBD8F2C91E3E8AD300EF64F1B4B9536CEB16FB440AF939F57624A9B486F867807C649AE4830EAB88C6C03998")] +#else +[assembly: InternalsVisibleTo("DotNetOpenAuth.OpenId")] +#endif |