상속: GeneralDigest
예제 #1
0
        /**
         * Copy constructor.  This will copy the state of the provided
         * message digest.
         */
        public RipeMD128Digest(RipeMD128Digest t) : base(t)
        {
            H0 = t.H0;
            H1 = t.H1;
            H2 = t.H2;
            H3 = t.H3;

            Array.Copy(t.X, 0, X, 0, t.X.Length);
            xOff = t.xOff;
        }
        /**
        * Copy constructor.  This will copy the state of the provided
        * message digest.
        */
        public RipeMD128Digest(RipeMD128Digest t) : base(t)
        {
            H0 = t.H0;
            H1 = t.H1;
            H2 = t.H2;
            H3 = t.H3;

            Array.Copy(t.X, 0, X, 0, t.X.Length);
            xOff = t.xOff;
        }
예제 #3
0
 private void CopyIn(RipeMD128Digest t)
 {
     base.CopyIn(t);
     this.H0 = t.H0;
     this.H1 = t.H1;
     this.H2 = t.H2;
     this.H3 = t.H3;
     Array.Copy(t.X, 0, this.X, 0, t.X.Length);
     this.xOff = t.xOff;
 }
예제 #4
0
 private void CopyIn(RipeMD128Digest t)
 {
     CopyIn((GeneralDigest)t);
     H0 = t.H0;
     H1 = t.H1;
     H2 = t.H2;
     H3 = t.H3;
     Array.Copy(t.X, 0, X, 0, t.X.Length);
     xOff = t.xOff;
 }
예제 #5
0
 private void CopyIn(RipeMD128Digest t)
 {
     CopyIn((GeneralDigest)t);
     H0 = t.H0;
     H1 = t.H1;
     H2 = t.H2;
     H3 = t.H3;
     global::System.Array.Copy((global::System.Array)t.X, 0, (global::System.Array)X, 0, t.X.Length);
     xOff = t.xOff;
 }
예제 #6
0
		private void CopyIn(RipeMD128Digest t)
		{
			base.CopyIn(t);

			H0 = t.H0;
            H1 = t.H1;
            H2 = t.H2;
            H3 = t.H3;

            Array.Copy(t.X, 0, X, 0, t.X.Length);
            xOff = t.xOff;
        }
예제 #7
0
        public override void Reset(IMemoable other)
        {
            RipeMD128Digest d = (RipeMD128Digest)other;

            CopyIn(d);
        }
예제 #8
0
 /**
  * Copy constructor.  This will copy the state of the provided
  * message digest.
  */
 public RipeMD128Digest(RipeMD128Digest t) : base(t)
 {
     CopyIn(t);
 }
예제 #9
0
        public ITestResult Perform()
        {
            IDigest digest = new RipeMD128Digest();
            byte[] resBuf = new byte[digest.GetDigestSize()];

            for (int i = 0; i < messages.Length; i++)
            {
                byte[] m = Encoding.ASCII.GetBytes(messages[i]);
                digest.BlockUpdate(m, 0, m.Length);
                digest.DoFinal(resBuf, 0);

                if (!Arrays.AreEqual(resBuf, Hex.Decode(digests[i])))
                {
                    return new SimpleTestResult(false, Name + ": Vector " + i + " failed");
                }
            }

            //
            // test 2
            //
            byte[] mm = Encoding.ASCII.GetBytes(messages[messages.Length-1]);

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

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

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

            if (!Arrays.AreEqual(resBuf, Hex.Decode(digests[digests.Length-1])))
            {
                return new SimpleTestResult(false,
                    "RipeMD128 failing clone test"
                    + SimpleTest.NewLine
                    + "    expected: " + digests[digests.Length-1]
                    + SimpleTest.NewLine
                    + "    got     : " + Hex.ToHexString(resBuf));
            }

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

            if (!Arrays.AreEqual(resBuf, Hex.Decode(digests[digests.Length-1])))
            {
                return new SimpleTestResult(false,
                    "RipeMD128 failing clone test - part 2"
                    + SimpleTest.NewLine
                    + "    expected: " +  digests[digests.Length-1]
                    + SimpleTest.NewLine
                    + "    got     : " + Hex.ToHexString(resBuf));
            }

            for (int i = 0; i < 1000000; i++)
            {
                digest.Update((byte)'a');
            }
            digest.DoFinal(resBuf, 0);

            if (!Arrays.AreEqual(resBuf, Hex.Decode(MillionADigest)))
            {
                return new SimpleTestResult(false, Name + ": Million a's failed");
            }

            return new SimpleTestResult(true, Name + ": Okay");
        }
예제 #10
0
        /**
        * Copy constructor.  This will copy the state of the provided
        * message digest.
        */
        public RipeMD128Digest(RipeMD128Digest t) : base(t)
		{
			CopyIn(t);
		}
예제 #11
0
        public override void Reset(IMemoable other)
        {
            RipeMD128Digest t = (RipeMD128Digest)other;

            this.CopyIn(t);
        }
예제 #12
0
 public RipeMD128Digest(RipeMD128Digest t) : base(t)
 {
     this.X = new int[0x10];
     this.CopyIn(t);
 }
예제 #13
0
 /// <summary>
 /// Note:  Clears pool contents before returning
 /// </summary>
 private void CreateNewPRNG(byte[] pool)
 {
     if (pool == null)
     {
         throw new CryptographicException("Refusing to reseed with null pool");
     }
     try
     {
         if (pool.Length != PoolSize)
         {
             throw new CryptographicException("Refusing to reseed with invalid pool");
         }
         // Now, pool has been seeded, file operations are all completed, it's time to create my internal PRNG
         IDigest digest;
         switch (this.myRNGAlgorithm)
         {
             case PrngAlgorithm.MD5_128bit:
                 digest = new MD5Digest();
                 break;
             case PrngAlgorithm.RIPEMD128_128bit:
                 digest = new RipeMD128Digest();
                 break;
             case PrngAlgorithm.RIPEMD160_160bit:
                 digest = new RipeMD160Digest();
                 break;
             case PrngAlgorithm.RIPEMD256_256bit:
                 digest = new RipeMD256Digest();
                 break;
             case PrngAlgorithm.RIPEMD320_320bit:
                 digest = new RipeMD320Digest();
                 break;
             case PrngAlgorithm.SHA1_160bit:
                 digest = new Sha1Digest();
                 break;
             case PrngAlgorithm.SHA256_256bit:
                 digest = new Sha256Digest();
                 break;
             case PrngAlgorithm.SHA512_512bit:
                 digest = new Sha512Digest();
                 break;
             case PrngAlgorithm.Tiger_192bit:
                 digest = new TigerDigest();
                 break;
             case PrngAlgorithm.Whirlpool_512bit:
                 digest = new WhirlpoolDigest();
                 break;
             default:
                 throw new CryptographicException("Unknown prngAlgorithm specified: " + this.myRNGAlgorithm.ToString());
         }
         var drng = new DigestRandomGenerator(digest);
         drng.AddSeedMaterial(pool);
         this.myRNG = drng;
     }
     finally
     {
         Array.Clear(pool, 0, pool.Length);
     }
 }