Просмотр исходного кода

* Initial versions of several classes, including
DSA base classes and CSP base classes

svn path=/trunk/mcs/; revision=1141

Thomas Neidhart 24 лет назад
Родитель
Сommit
f0b7d41fb9

+ 12 - 0
mcs/class/corlib/System.Security.Cryptography/ChangeLog

@@ -1,3 +1,15 @@
+2001-10-11  Thomas Neidhart <[email protected]>
+
+	* CryptoAPITransform.cs: Initial version
+	* CryptoStream.cs: Initial version
+	* CspParameter.cs: Initial version
+	* CspProviderFlags.cs: Initial version
+	* DSA.cs: Initial version
+	* DSAParameters.cs: Initial version
+	* DSASignatureDeformatter.cs: Initial version
+	* DSASignatureFormatter.cs: Initial version
+	* DeriveBytes.cs: Initial version
+
 2001-10-06  Thomas Neidhart <[email protected]>
 
     * AsymmetricAlgorithm.cs: Inital version

+ 71 - 0
mcs/class/corlib/System.Security.Cryptography/CryptoAPITransform.cs

@@ -0,0 +1,71 @@
+//
+// System.Security.Cryptography CryptoAPITransform.cs
+//
+// Author:
+//   Thomas Neidhart ([email protected])
+//
+
+using System;
+using System.IO;
+
+namespace System.Security.Cryptography
+{
+
+	public sealed class CryptoAPITransform : ICryptoTransform
+	{
+		public CryptoAPITransform() 
+		{
+		}
+		
+		/// <summary>
+		/// Indicates if the Transform object can transform multiple blocks
+		/// </summary>
+		public bool CanTransformMultipleBlocks
+		{
+			get 
+			{
+				// FIXME: should not be always true
+				return true;
+			}
+		}
+
+		public int InputBlockSize
+		{
+			get {
+				// TODO: implement
+				return 0;
+			}
+		}
+		
+		public IntPtr KeyHandle 
+		{
+			get {
+				// TODO: implement
+				return IntPtr.Zero;
+			}
+		}
+		
+		public int OutputBlockSize 
+		{
+			get {
+				// TODO: implement
+				return 0;
+			}
+		}
+		
+		public int TransformBlock(byte[] inputBuffer, int inputOffset, 
+		                          int inputCount, byte[] outputBuffer, int outputOffset)
+		{
+			// TODO: implement
+			return 0;
+		}
+		
+		public byte[] TransformFinalBlock(byte[] inputBuffer, int inputOffset, int inputCount)
+		{
+			// TODO: implement
+			return null;
+		}
+		
+	} // CryptoAPITransform
+	
+} // System.Security.Cryptography

+ 116 - 0
mcs/class/corlib/System.Security.Cryptography/CryptoStream.cs

@@ -0,0 +1,116 @@
+//
+// System.Security.Cryptography CryptoStream.cs
+//
+// Author:
+//   Thomas Neidhart ([email protected])
+//
+
+using System;
+using System.IO;
+
+namespace System.Security.Cryptography
+{
+
+	public class CryptoStream : Stream
+	{
+		private CryptoStreamMode _mode;
+		
+		public CryptoStream(Stream stream, ICryptoTransform transform, CryptoStreamMode mode) 
+		{
+			_mode = mode;
+		}
+		
+		public override bool CanRead
+		{
+			get {
+				switch (_mode) {
+					case CryptoStreamMode.Read:
+						return true;
+					
+					case CryptoStreamMode.Write:
+						return false;
+					
+					default:
+						return false;
+				}
+			}
+		}
+
+		public override bool CanSeek
+		{
+			get {
+				return false;
+			}
+		}
+
+		public override bool CanWrite
+		{
+			get {
+				switch (_mode) {
+					case CryptoStreamMode.Read:
+						return false;
+					
+					case CryptoStreamMode.Write:
+						return true;
+					
+					default:
+						return false;
+				}
+			}
+		}
+		
+		public override long Length
+		{
+			get {
+				throw new NotSupportedException("Length property not supported by CryptoStream");
+			}
+		}
+
+		public override long Position
+		{
+			get {
+				throw new NotSupportedException("Position property not supported by CryptoStream");
+			}
+			set {
+				throw new NotSupportedException("Position property not supported by CryptoStream");
+			}
+		}
+
+		public override int Read(byte[] buffer, int offset, int count)
+		{
+			// TODO: implement
+			return 0;
+		}
+		
+		public override void Write(byte[] buffer, int offset, int count)
+		{
+			// TODO: implement
+		}
+		
+		public override void Flush()
+		{
+			// TODO: implement
+		}
+		
+		public void FlushFinalBlock()
+		{
+			if (_mode != CryptoStreamMode.Write)
+				throw new NotSupportedException("cannot flush a non-writeable CryptoStream");
+			
+			// TODO: implement
+		}
+		
+		public override long Seek(long offset, SeekOrigin origin)
+		{
+			throw new NotSupportedException("cannot seek a CryptoStream");
+		}
+		
+		public override void SetLength(long value)
+		{
+			// LAMESPEC: should throw NotSupportedException like Seek??
+			return;
+		}
+		
+	} // CryptoStream
+	
+} // System.Security.Cryptography

+ 57 - 0
mcs/class/corlib/System.Security.Cryptography/CspParameters.cs

@@ -0,0 +1,57 @@
+//
+// System.Security.Cryptography CspParameters.cs
+//
+// Author:
+//   Thomas Neidhart ([email protected])
+//
+
+using System;
+
+namespace System.Security.Cryptography
+{
+
+	/// <summary>
+	/// Contains information passed to Crypto Service Providers (CSP)
+	/// </summary>
+	public sealed class CspParameters
+	{
+		private CspProviderFlags _Flags;
+	
+		public CspParameters() : this(1) {}
+		
+		public CspParameters(int dwTypeIn) : this(dwTypeIn, null) {}
+		
+		public CspParameters(int dwTypeIn, string strProviderNameIn) : this(dwTypeIn, null, null) {}
+		
+		public CspParameters(int dwTypeIn, string strProviderNameIn, string strContainerNameIn)
+		{
+			ProviderType = dwTypeIn;
+			ProviderName = strProviderNameIn;
+			KeyContainerName = strContainerNameIn;
+			
+			// not defined in specs, only tested from M$ impl
+			KeyNumber = -1;
+		}
+		
+		public string KeyContainerName;
+		
+		public int KeyNumber;
+		
+		public string ProviderName;
+		
+		public int ProviderType;
+		
+		public CspProviderFlags Flags 
+		{
+			get {
+				return _Flags;
+			}
+			
+			set {
+				_Flags = value;
+			}
+		}
+		
+	} // CspParameters
+	
+} // System.Security.Cryptography

+ 19 - 0
mcs/class/corlib/System.Security.Cryptography/CspProviderFlags.cs

@@ -0,0 +1,19 @@
+//
+// System.Security.Cryptography CspProviderFlags enumeration
+//
+// Authors:
+//   Thomas Neidhart <[email protected]>
+//
+
+
+namespace System.Security.Cryptography {
+
+	/// <summary>
+	/// CSP Provider Flags
+	/// </summary>
+	public enum CspProviderFlags {
+		UseDefaultKeyContainer,
+		UseMachineKeyStore
+	}
+}
+

+ 98 - 0
mcs/class/corlib/System.Security.Cryptography/DSA.cs

@@ -0,0 +1,98 @@
+//
+// System.Security.Cryptography DSA.cs
+//
+// Author:
+//   Thomas Neidhart ([email protected])
+//
+
+using System;
+using System.Text;
+
+namespace System.Security.Cryptography
+{
+
+	/// <summary>
+	/// Abstract base class for all implementations of the DSA algorithm
+	/// </summary>
+	public abstract class DSA : AsymmetricAlgorithm
+	{
+	
+		public static new DSA Create()
+		{
+			return new DSACryptoServiceProvider();
+		}
+		
+		public static new DSA Create(string algName)
+		{
+			// TODO: implement
+			return null;
+		}
+		
+		public abstract byte[] CreateSignature(byte[] rgbHash);
+		
+		public abstract DSAParameters ExportParameters(bool includePrivateParameters);
+		
+		public override void FromXmlString(string xmlString) 
+		{
+			if (xmlString == null)
+				throw new ArgumentNullException();
+			
+			// TODO: implement
+		}
+		
+		public abstract void ImportParameters(DSAParameters parameters);
+
+		public override string ToXmlString(bool includePrivateParameters)
+		{
+			DSAParameters dsaParams = ExportParameters(includePrivateParameters);
+			
+			StringBuilder sb = new StringBuilder();
+			
+			sb.Append("<DSAKeyValue>");
+			
+			sb.Append("<P>");
+			sb.Append(Convert.ToBase64String(dsaParams.P));
+			sb.Append("</P>");
+			
+			sb.Append("<Q>");
+			sb.Append(Convert.ToBase64String(dsaParams.Q));
+			sb.Append("</Q>");
+
+			sb.Append("<G>");
+			sb.Append(Convert.ToBase64String(dsaParams.G));
+			sb.Append("</G>");
+
+			sb.Append("<Y>");
+			sb.Append(Convert.ToBase64String(dsaParams.Y));
+			sb.Append("</Y>");
+
+			sb.Append("<J>");
+			sb.Append(Convert.ToBase64String(dsaParams.J));
+			sb.Append("</J>");
+			
+			sb.Append("<Seed>");
+			sb.Append(Convert.ToBase64String(dsaParams.Seed));
+			sb.Append("</Seed>");
+			
+			sb.Append("<PgenCounter>");
+			string cnt = Convert.ToString(dsaParams.Counter);
+			byte[] inArr = new ASCIIEncoding().GetBytes(cnt);
+			sb.Append(Convert.ToBase64String(inArr));
+			sb.Append("</PgenCounter>");
+
+			if (dsaParams.X != null)  {
+				sb.Append("<X>");
+				sb.Append(Convert.ToBase64String(dsaParams.X));
+				sb.Append("</X>");
+			}
+
+			sb.Append("</DSAKeyValue>");
+			
+			return sb.ToString();
+		}
+		
+		public abstract bool VerifySignature(byte[] rgbHash, byte[] rgbSignature);
+		
+	} // DSA
+	
+} // System.Security.Cryptography

+ 37 - 0
mcs/class/corlib/System.Security.Cryptography/DSAParameters.cs

@@ -0,0 +1,37 @@
+//
+// System.Security.Cryptography DSAParameters.cs
+//
+// Author:
+//   Thomas Neidhart ([email protected])
+//
+
+using System;
+
+namespace System.Security.Cryptography
+{
+
+	/// <summary>
+	/// DSA Parameters
+	/// </summary>
+	public struct DSAParameters
+	{
+		public int Counter;
+		
+		public byte[] G;
+		
+		public byte[] J;
+		
+		public byte[] P;
+		
+		public byte[] Q;
+		
+		public byte[] Seed;
+		
+		[NonSerialized]
+		public byte[] X;
+		
+		public byte[] Y;
+		
+	} // DSAParameters
+	
+} // System.Security.Cryptography

+ 47 - 0
mcs/class/corlib/System.Security.Cryptography/DSASignatureDeformatter.cs

@@ -0,0 +1,47 @@
+//
+// System.Security.Cryptography DSASignatureDeformatter.cs
+//
+// Author:
+//   Thomas Neidhart ([email protected])
+//
+
+using System;
+
+namespace System.Security.Cryptography
+{
+
+	/// <summary>
+	/// DSA Signature Deformatter
+	/// </summary>
+	public class DSASignatureDeformatter : AsymmetricSignatureDeformatter
+	{
+		
+		public DSASignatureDeformatter()
+		{
+			// TODO: implement
+		}
+		
+		public DSASignatureDeformatter(AsymmetricAlgorithm key)
+		{
+			// TODO: implement
+		}
+		
+		public override void SetHashAlgorithm(string strName)
+		{
+			throw new CryptographicException("This method is not used");
+		}
+		
+		public override void SetKey(AsymmetricAlgorithm key)
+		{
+			// TODO: implement
+		}
+		
+		public override bool VerifySignature(byte[] rgbHash, byte[] rgbSignature)
+		{
+			// TODO: implement
+			return false;
+		}
+		
+	} // DSASignatureDeformatter
+	
+} // System.Security.Cryptography

+ 47 - 0
mcs/class/corlib/System.Security.Cryptography/DSASignatureFormatter.cs

@@ -0,0 +1,47 @@
+//
+// System.Security.Cryptography DSASignatureFormatter.cs
+//
+// Author:
+//   Thomas Neidhart ([email protected])
+//
+
+using System;
+
+namespace System.Security.Cryptography
+{
+
+	/// <summary>
+	/// DSA Signature Formatter
+	/// </summary>
+	public class DSASignatureFormatter : AsymmetricSignatureFormatter
+	{
+		
+		public DSASignatureFormatter() 
+		{
+			// TODO: implement
+		}
+		
+		public DSASignatureFormatter(AsymmetricAlgorithm key)
+		{
+			// TODO: implement
+		}
+		
+		public override byte[] CreateSignature(byte[] rgbHash)
+		{
+			// TODO: implement
+			return null;
+		}
+		
+		public override void SetHashAlgorithm(string strName)
+		{
+			// TODO: implement
+		}
+		
+		public override void SetKey(AsymmetricAlgorithm key)
+		{
+			// TODO: implement
+		}
+		
+	} // DSASignatureFormatter
+	
+} // System.Security.Cryptography

+ 27 - 0
mcs/class/corlib/System.Security.Cryptography/DeriveBytes.cs

@@ -0,0 +1,27 @@
+//
+// System.Security.Cryptography DeriveBytes.cs
+//
+// Author:
+//   Thomas Neidhart ([email protected])
+//
+
+using System;
+
+namespace System.Security.Cryptography
+{
+
+	/// <summary>
+	/// Abstract base class for all classes that derive byte information from an integer
+	/// </summary>
+	public abstract class DeriveBytes
+	{
+	
+		protected DeriveBytes() {}
+		
+		public abstract byte[] GetBytes(int cb);
+
+		public abstract void Reset();
+		
+	} // DeriveBytes
+	
+} // System.Security.Cryptography