Inheritance: GeneralDigest
Exemplo n.º 1
0
 private void CopyIn(Sha224Digest t)
 {
     CopyIn((GeneralDigest)t);
     H1 = t.H1;
     H2 = t.H2;
     H3 = t.H3;
     H4 = t.H4;
     H5 = t.H5;
     H6 = t.H6;
     H7 = t.H7;
     H8 = t.H8;
     Array.Copy(t.X, 0, X, 0, t.X.Length);
     xOff = t.xOff;
 }
Exemplo n.º 2
0
 private void CopyIn(Sha224Digest t)
 {
     base.CopyIn(t);
     this.H1 = t.H1;
     this.H2 = t.H2;
     this.H3 = t.H3;
     this.H4 = t.H4;
     this.H5 = t.H5;
     this.H6 = t.H6;
     this.H7 = t.H7;
     this.H8 = t.H8;
     Array.Copy(t.X, 0, this.X, 0, t.X.Length);
     this.xOff = t.xOff;
 }
Exemplo n.º 3
0
 private void CopyIn(Sha224Digest t)
 {
     CopyIn((GeneralDigest)t);
     H1 = t.H1;
     H2 = t.H2;
     H3 = t.H3;
     H4 = t.H4;
     H5 = t.H5;
     H6 = t.H6;
     H7 = t.H7;
     H8 = t.H8;
     global::System.Array.Copy((global::System.Array)t.X, 0, (global::System.Array)X, 0, t.X.Length);
     xOff = t.xOff;
 }
Exemplo n.º 4
0
        /**
         * Copy constructor.  This will copy the state of the provided
         * message digest.
         */
        public Sha224Digest(
            Sha224Digest t)
            : base(t)
        {
            H1 = t.H1;
            H2 = t.H2;
            H3 = t.H3;
            H4 = t.H4;
            H5 = t.H5;
            H6 = t.H6;
            H7 = t.H7;
            H8 = t.H8;

            Array.Copy(t.X, 0, X, 0, t.X.Length);
            xOff = t.xOff;
        }
Exemplo n.º 5
0
		private void CopyIn(Sha224Digest t)
		{
			base.CopyIn(t);

            H1 = t.H1;
            H2 = t.H2;
            H3 = t.H3;
            H4 = t.H4;
            H5 = t.H5;
            H6 = t.H6;
            H7 = t.H7;
            H8 = t.H8;

            Array.Copy(t.X, 0, X, 0, t.X.Length);
            xOff = t.xOff;
        }
Exemplo n.º 6
0
		/**
         * Copy constructor.  This will copy the state of the provided
         * message digest.
         */
         public Sha224Digest(
			 Sha224Digest t)
			 : base(t)
        {
            H1 = t.H1;
            H2 = t.H2;
            H3 = t.H3;
            H4 = t.H4;
            H5 = t.H5;
            H6 = t.H6;
            H7 = t.H7;
            H8 = t.H8;

            Array.Copy(t.X, 0, X, 0, t.X.Length);
            xOff = t.xOff;
        }
Exemplo n.º 7
0
		/**
         * Copy constructor.  This will copy the state of the provided
         * message digest.
         */
         public Sha224Digest(
			 Sha224Digest t)
			 : base(t)
        {
			CopyIn(t);
		}
 /**
  * Copy constructor.  This will copy the state of the provided
  * message digest.
  */
 public Sha224Digest(
     Sha224Digest t)
     : base(t)
 {
     CopyIn(t);
 }
        public override void Reset(IMemoable other)
        {
            Sha224Digest d = (Sha224Digest)other;

            CopyIn(d);
        }
Exemplo n.º 10
0
        public override void Reset(IMemoable other)
        {
            Sha224Digest t = (Sha224Digest)other;

            this.CopyIn(t);
        }
Exemplo n.º 11
0
        internal override void ProcessBlock()
        {
            for (int i = 16; i <= 63; i++)
            {
                this.X[i] = Sha224Digest.Theta1(this.X[i - 2]) + this.X[i - 7] + Sha224Digest.Theta0(this.X[i - 15]) + this.X[i - 16];
            }
            uint num  = this.H1;
            uint num2 = this.H2;
            uint num3 = this.H3;
            uint num4 = this.H4;
            uint num5 = this.H5;
            uint num6 = this.H6;
            uint num7 = this.H7;
            uint num8 = this.H8;
            int  num9 = 0;

            for (int j = 0; j < 8; j++)
            {
                num8 += Sha224Digest.Sum1(num5) + Sha224Digest.Ch(num5, num6, num7) + Sha224Digest.K[num9] + this.X[num9];
                num4 += num8;
                num8 += Sha224Digest.Sum0(num) + Sha224Digest.Maj(num, num2, num3);
                num9++;
                num7 += Sha224Digest.Sum1(num4) + Sha224Digest.Ch(num4, num5, num6) + Sha224Digest.K[num9] + this.X[num9];
                num3 += num7;
                num7 += Sha224Digest.Sum0(num8) + Sha224Digest.Maj(num8, num, num2);
                num9++;
                num6 += Sha224Digest.Sum1(num3) + Sha224Digest.Ch(num3, num4, num5) + Sha224Digest.K[num9] + this.X[num9];
                num2 += num6;
                num6 += Sha224Digest.Sum0(num7) + Sha224Digest.Maj(num7, num8, num);
                num9++;
                num5 += Sha224Digest.Sum1(num2) + Sha224Digest.Ch(num2, num3, num4) + Sha224Digest.K[num9] + this.X[num9];
                num  += num5;
                num5 += Sha224Digest.Sum0(num6) + Sha224Digest.Maj(num6, num7, num8);
                num9++;
                num4 += Sha224Digest.Sum1(num) + Sha224Digest.Ch(num, num2, num3) + Sha224Digest.K[num9] + this.X[num9];
                num8 += num4;
                num4 += Sha224Digest.Sum0(num5) + Sha224Digest.Maj(num5, num6, num7);
                num9++;
                num3 += Sha224Digest.Sum1(num8) + Sha224Digest.Ch(num8, num, num2) + Sha224Digest.K[num9] + this.X[num9];
                num7 += num3;
                num3 += Sha224Digest.Sum0(num4) + Sha224Digest.Maj(num4, num5, num6);
                num9++;
                num2 += Sha224Digest.Sum1(num7) + Sha224Digest.Ch(num7, num8, num) + Sha224Digest.K[num9] + this.X[num9];
                num6 += num2;
                num2 += Sha224Digest.Sum0(num3) + Sha224Digest.Maj(num3, num4, num5);
                num9++;
                num  += Sha224Digest.Sum1(num6) + Sha224Digest.Ch(num6, num7, num8) + Sha224Digest.K[num9] + this.X[num9];
                num5 += num;
                num  += Sha224Digest.Sum0(num2) + Sha224Digest.Maj(num2, num3, num4);
                num9++;
            }
            this.H1  += num;
            this.H2  += num2;
            this.H3  += num3;
            this.H4  += num4;
            this.H5  += num5;
            this.H6  += num6;
            this.H7  += num7;
            this.H8  += num8;
            this.xOff = 0;
            Array.Clear(this.X, 0, 16);
        }
Exemplo n.º 12
0
		public ITestResult Perform()
        {
            IDigest digest = new Sha224Digest();
            byte[] resBuf = new byte[digest.GetDigestSize()];
            string resStr;

			//
            // test 1
            //
            digest.DoFinal(resBuf, 0);

            resStr = Hex.ToHexString(resBuf);
            if (!resVec1.Equals(resStr))
            {
                return new SimpleTestResult(false,
                    "SHA-224 failing standard vector test 1"
                    + SimpleTest.NewLine
                    + "    expected: " + resVec1
                    + SimpleTest.NewLine
                    + "    got     : " + resStr);
            }

            //
            // test 2
            //
            byte[]  bytes = Hex.Decode(testVec2);

            digest.BlockUpdate(bytes, 0, bytes.Length);

            digest.DoFinal(resBuf, 0);

            resStr = Hex.ToHexString(resBuf);
            if (!resVec2.Equals(resStr))
            {
                return new SimpleTestResult(false,
                    "SHA-224 failing standard vector test 2"
                    + SimpleTest.NewLine
                    + "    expected: " + resVec2
                    + SimpleTest.NewLine
                    + "    got     : " + resStr);
            }

            //
            // test 3
            //
            bytes = Hex.Decode(testVec3);

            digest.BlockUpdate(bytes, 0, bytes.Length);

            digest.DoFinal(resBuf, 0);

            resStr = Hex.ToHexString(resBuf);
            if (!resVec3.Equals(resStr))
            {
                return new SimpleTestResult(false,
                    "SHA-224 failing standard vector test 3"
                    + SimpleTest.NewLine
                    + "    expected: " + resVec3
                    + SimpleTest.NewLine
                    + "    got     : " + resStr);
            }

            //
            // test 4
            //
            bytes = Hex.Decode(testVec4);

            digest.BlockUpdate(bytes, 0, bytes.Length);

            digest.DoFinal(resBuf, 0);

            resStr = Hex.ToHexString(resBuf);
            if (!resVec4.Equals(resStr))
            {
                return new SimpleTestResult(false,
                    "SHA-224 failing standard vector test 4"
                    + SimpleTest.NewLine
                    + "    expected: " + resVec4
                    + SimpleTest.NewLine
                    + "    got     : " + resStr);
            }

            //
            // test 5
            //
            bytes = Hex.Decode(testVec4);

            digest.BlockUpdate(bytes, 0, bytes.Length/2);

            // clone the IDigest
            IDigest d = new Sha224Digest((Sha224Digest)digest);

            digest.BlockUpdate(bytes, bytes.Length/2, bytes.Length - bytes.Length/2);
            digest.DoFinal(resBuf, 0);

            resStr = Hex.ToHexString(resBuf);
            if (!resVec4.Equals(resStr))
            {
                return new SimpleTestResult(false,
                    "SHA-224 failing standard vector test 5"
                    + SimpleTest.NewLine
                    + "    expected: " + resVec4
                    + SimpleTest.NewLine
                    + "    got     : " + resStr);
            }

            d.BlockUpdate(bytes, bytes.Length/2, bytes.Length - bytes.Length/2);
            d.DoFinal(resBuf, 0);

            resStr = Hex.ToHexString(resBuf);
            if (!resVec4.Equals(resStr))
            {
                return new SimpleTestResult(false,
                    "SHA-224 failing standard vector test 5"
                    + SimpleTest.NewLine
                    + "    expected: " + resVec4
                    + SimpleTest.NewLine
                    + "    got     : " + resStr);
            }

            // test 6
            bytes = Hex.Decode(testVec5);
            for ( int i = 0; i < 100000; i++ )
            {
                digest.BlockUpdate(bytes, 0, bytes.Length);
            }
            digest.DoFinal(resBuf, 0);

            resStr = Hex.ToHexString(resBuf);
            if (!resVec5.Equals(resStr))
            {
                return new SimpleTestResult(false,
                    "SHA-224 failing standard vector test 6"
                    + SimpleTest.NewLine
                    + "    expected: " + resVec5
                    + SimpleTest.NewLine
                    + "    got     : " + resStr);
            }

			return new SimpleTestResult(true, Name + ": Okay");
        }
Exemplo n.º 13
0
		private IDigest GetDigest(THashAlgorithm hashAlgorithm)
		{
			IDigest result = null;
			switch (hashAlgorithm)
			{
				case THashAlgorithm.None:
					result = new NullDigest();
					break;
				case THashAlgorithm.MD5:
					result = new MD5Digest();
					break;
				case THashAlgorithm.SHA1:
					result = new Sha1Digest();
					break;
				case THashAlgorithm.SHA224:
					result = new Sha224Digest();
					break;
				case THashAlgorithm.SHA256:
					result = new Sha256Digest();
					break;
				case THashAlgorithm.SHA384:
					result = new Sha384Digest();
					break;
				case THashAlgorithm.SHA512:
					result = new Sha512Digest();
					break;
				default:
					break;
			}
			return result;
		}
Exemplo n.º 14
0
 public Sha224Digest(Sha224Digest t) : base(t)
 {
     this.X = new uint[0x40];
     this.CopyIn(t);
 }