Example #1
0
        /// <summary>
        /// Compare this object instance with another
        /// </summary>
        ///
        /// <param name="Obj">Object to compare</param>
        ///
        /// <returns>True if equal, otherwise false</returns>
        public override bool Equals(Object Obj)
        {
            if (!(Obj is DtmSessionStruct))
            {
                return(false);
            }

            DtmSessionStruct other = (DtmSessionStruct)Obj;

            if (EngineType != other.EngineType)
            {
                return(false);
            }
            if (KeySize != other.KeySize)
            {
                return(false);
            }
            if (IvSize != other.IvSize)
            {
                return(false);
            }
            if (RoundCount != other.RoundCount)
            {
                return(false);
            }
            if (KdfEngine != other.KdfEngine)
            {
                return(false);
            }

            return(true);
        }
Example #2
0
 /// <summary>
 /// The DtmForwardKeyStruct primary constructor
 /// </summary>
 ///
 /// <param name="Key">The forward symmetric cipher key</param>
 /// <param name="SessionParams">The forward symmetric cipher description</param>
 /// <param name="LifeSpan">The time (in seconds, milliseconds, or ticks) that this key is to be considered valid</param>
 /// <param name="Instruction">A flag indicating a special handling instruction</param>
 /// <param name="OptionsFlag">Can be additonal information; like a 'valid from' UTC time stamp</param>
 public DtmForwardKeyStruct(KeyParams Key, DtmSessionStruct SessionParams, long LifeSpan = 0, short Instruction = 0, long OptionsFlag = 0)
 {
     this.Key           = Key;
     this.SessionParams = SessionParams;
     this.LifeSpan      = LifeSpan;
     this.Instruction   = Instruction;
     this.OptionsFlag   = OptionsFlag;
 }
Example #3
0
 /// <summary>
 /// DtmIdentityStruct partial constructor; used for the <c>Init</c> exchange and contains an empty Secret Id
 /// </summary>
 ///
 /// <param name="Identity">The active Identity field; used to first identify a host during the <c>Init</c> stage of a key exchange</param>
 /// <param name="PkeId">The Asymmetric parameters Id; can be the Asymmetric cipher parameters OId, or a serialized Asymmetric Parameters class</param>
 /// <param name="Session">The Symmetric sessions cipher parameters; contains a complete description of the Symmetric cipher</param>
 /// <param name="OptionFlag">This flag can be used as a time stamp indicating the expiry time of the corresponding session key</param>
 public DtmIdentityStruct(byte[] Identity, byte[] PkeId, DtmSessionStruct Session, long OptionFlag)
 {
     this.Identity = new byte[Identity.Length];
     Array.Copy(Identity, this.Identity, Identity.Length);
     this.PkeId = new byte[PkeId.Length];
     Array.Copy(PkeId, this.PkeId, PkeId.Length);
     this.Session    = Session;
     this.OptionFlag = OptionFlag;
 }
Example #4
0
        /// <summary>
        /// Constructs a DtmForwardKeyStruct from a stream
        /// </summary>
        ///
        /// <param name="SessionStream">Stream containing a serialized DtmForwardKeyStruct</param>
        ///
        /// <returns>A populated DtmForwardKeyStruct</returns>
        public DtmForwardKeyStruct(Stream SessionStream)
        {
            BinaryReader reader = new BinaryReader(SessionStream);

            Key           = KeyParams.DeSerialize(SessionStream);
            SessionParams = new DtmSessionStruct(SessionStream);
            LifeSpan      = reader.ReadInt64();
            Instruction   = reader.ReadInt16();
            OptionsFlag   = reader.ReadInt64();
        }
Example #5
0
        /// <summary>
        /// Get the key data from the key stream
        /// </summary>
        ///
        /// <param name="KeyStream">The stream containing a session key</param>
        ///
        /// <returns>KeyParams structure</returns>
        public static KeyParams GetKey(Stream KeyStream)
        {
            DtmSessionStruct session = new DtmSessionStruct(KeyStream);

            byte[] key = new byte[session.KeySize];
            byte[] iv  = new byte[session.IvSize];

            KeyStream.Seek(HDR_SIZE, SeekOrigin.Begin);
            KeyStream.Read(key, 0, key.Length);
            KeyStream.Read(iv, 0, iv.Length);

            return(new KeyParams(key, iv));
        }
Example #6
0
        /// <summary>
        /// Extracts a DtmIdentityStruct from a Stream
        /// </summary>
        ///
        /// <param name="IdentityStream">The Stream containing the DtmIdentityStruct structure</param>
        public DtmIdentityStruct(Stream IdentityStream)
        {
            BinaryReader reader = new BinaryReader(IdentityStream);
            int          len;

            byte[] data;

            len        = reader.ReadInt32();
            Identity   = reader.ReadBytes(len);
            len        = reader.ReadInt32();
            PkeId      = reader.ReadBytes(len);
            len        = reader.ReadInt32();
            data       = reader.ReadBytes(len);
            Session    = new DtmSessionStruct(data);
            OptionFlag = reader.ReadInt64();
        }
Example #7
0
 /// <summary>
 /// Get this is a valid header file
 /// </summary>
 ///
 /// <param name="Key">The stream containing a key header</param>
 ///
 /// <returns>Valid</returns>
 public static bool IsValid(DtmSessionStruct Key)
 {
     // not guaranteed, but should be ok
     return(Key.EngineType < Enum.GetValues(typeof(SymmetricEngines)).Length);
 }