Implementation of RipeMD256.

Note: this algorithm offers the same level of security as RipeMD128.

Inheritance: GeneralDigest
コード例 #1
0
        public virtual ITestResult Perform()
        {
            IDigest digest = new RipeMD256Digest();
            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" + "    expected: " + digests[i] + SimpleTest.NewLine + "    got     : " + Hex.ToHexString(resBuf));
                }
            }

            //
            // test 2
            //
            byte[] m2 = Encoding.ASCII.GetBytes(messages[messages.Length - 1]);
            digest.BlockUpdate(m2, 0, m2.Length / 2);

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

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

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

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

            if (!Arrays.AreEqual(resBuf, Hex.Decode(digests[digests.Length - 1])))
            {
                return new SimpleTestResult(false, "RipeMD256 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");
        }
コード例 #2
0
 private void CopyIn(RipeMD256Digest t)
 {
     CopyIn((GeneralDigest)t);
     H0 = t.H0;
     H1 = t.H1;
     H2 = t.H2;
     H3 = t.H3;
     H4 = t.H4;
     H5 = t.H5;
     H6 = t.H6;
     H7 = t.H7;
     global::System.Array.Copy((global::System.Array)t.X, 0, (global::System.Array)X, 0, t.X.Length);
     xOff = t.xOff;
 }
コード例 #3
0
 private void CopyIn(RipeMD256Digest t)
 {
     base.CopyIn(t);
     this.H0 = t.H0;
     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;
     Array.Copy(t.X, 0, this.X, 0, t.X.Length);
     this.xOff = t.xOff;
 }
コード例 #4
0
        /// <summary> Copy constructor.  This will copy the state of the provided
        /// message digest.
        /// </summary>
        public RipeMD256Digest(RipeMD256Digest t) : base(t)
        {
            H0 = t.H0;
            H1 = t.H1;
            H2 = t.H2;
            H3 = t.H3;
            H4 = t.H4;
            H5 = t.H5;
            H6 = t.H6;
            H7 = t.H7;

            Array.Copy(t.X, 0, X, 0, t.X.Length);
            xOff = t.xOff;
        }
コード例 #5
0
        /// <summary> Copy constructor.  This will copy the state of the provided
        /// message digest.
        /// </summary>
        public RipeMD256Digest(RipeMD256Digest t):base(t)
        {

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

            Array.Copy(t.X, 0, X, 0, t.X.Length);
            xOff = t.xOff;
        }
コード例 #6
0
        private void CopyIn(RipeMD256Digest t)
        {
            base.CopyIn(t);

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

            Array.Copy(t.X, 0, X, 0, t.X.Length);
            xOff = t.xOff;
        }
コード例 #7
0
		private void CopyIn(RipeMD256Digest t)
		{
			base.CopyIn(t);

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

            Array.Copy(t.X, 0, X, 0, t.X.Length);
            xOff = t.xOff;
        }
コード例 #8
0
 /// <summary> Copy constructor.  This will copy the state of the provided
 /// message digest.
 /// </summary>
 public RipeMD256Digest(RipeMD256Digest t) : base(t)
 {
     CopyIn(t);
 }
コード例 #9
0
        public override void Reset(IMemoable other)
        {
            RipeMD256Digest d = (RipeMD256Digest)other;

            CopyIn(d);
        }
コード例 #10
0
        public override void Reset(IMemoable other)
        {
            RipeMD256Digest t = (RipeMD256Digest)other;

            this.CopyIn(t);
        }
コード例 #11
0
 public RipeMD256Digest(RipeMD256Digest t) : base(t)
 {
     this.X = new int[0x10];
     this.CopyIn(t);
 }
コード例 #12
0
        /// <summary> Copy constructor.  This will copy the state of the provided
        /// message digest.
        /// </summary>
        public RipeMD256Digest(RipeMD256Digest t):base(t)
        {
			CopyIn(t);
		}
コード例 #13
0
ファイル: EntropyFileRNG.cs プロジェクト: Muraad/tinhat
 /// <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);
     }
 }