public static ExtraHashAlgorithm CreateRipeMD128()
        {
            var ha = new RipeMD128Digest();

            return(new ExtraHashAlgorithm(
                       ha.AlgorithmName, ha.GetDigestSize(),
                       ha.Reset, ha.BlockUpdate, ha.DoFinal
                       ));
        }
        public static byte[] Hash128(byte[] bytes)
        {
            var digest = new RipeMD128Digest();
            var output = new byte[digest.GetDigestSize()];

            digest.BlockUpdate(bytes, 0, bytes.Length);
            digest.DoFinal(output, 0);
            return(output);
        }
Beispiel #3
0
        public static byte[] Hash128(byte[] message)
        {
            var digest = new RipeMD128Digest();
            var output = new byte[digest.GetDigestSize()];

            byte[] msg = message ?? new byte[0];
            digest.BlockUpdate(msg, 0, msg.Length);
            digest.DoFinal(output, 0);
            return(output);
        }
 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;
 }
Beispiel #5
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"));
        }
        public static IDigest GetDigest(string algorithm)
        {
            string text  = Platform.ToUpperInvariant(algorithm);
            string text2 = (string)DigestUtilities.algorithms[text];

            if (text2 == null)
            {
                text2 = text;
            }
            try
            {
                switch ((DigestUtilities.DigestAlgorithm)Enums.GetEnumValue(typeof(DigestUtilities.DigestAlgorithm), text2))
                {
                case DigestUtilities.DigestAlgorithm.GOST3411:
                {
                    IDigest result = new Gost3411Digest();
                    return(result);
                }

                case DigestUtilities.DigestAlgorithm.MD2:
                {
                    IDigest result = new MD2Digest();
                    return(result);
                }

                case DigestUtilities.DigestAlgorithm.MD4:
                {
                    IDigest result = new MD4Digest();
                    return(result);
                }

                case DigestUtilities.DigestAlgorithm.MD5:
                {
                    IDigest result = new MD5Digest();
                    return(result);
                }

                case DigestUtilities.DigestAlgorithm.RIPEMD128:
                {
                    IDigest result = new RipeMD128Digest();
                    return(result);
                }

                case DigestUtilities.DigestAlgorithm.RIPEMD160:
                {
                    IDigest result = new RipeMD160Digest();
                    return(result);
                }

                case DigestUtilities.DigestAlgorithm.RIPEMD256:
                {
                    IDigest result = new RipeMD256Digest();
                    return(result);
                }

                case DigestUtilities.DigestAlgorithm.RIPEMD320:
                {
                    IDigest result = new RipeMD320Digest();
                    return(result);
                }

                case DigestUtilities.DigestAlgorithm.SHA_1:
                {
                    IDigest result = new Sha1Digest();
                    return(result);
                }

                case DigestUtilities.DigestAlgorithm.SHA_224:
                {
                    IDigest result = new Sha224Digest();
                    return(result);
                }

                case DigestUtilities.DigestAlgorithm.SHA_256:
                {
                    IDigest result = new Sha256Digest();
                    return(result);
                }

                case DigestUtilities.DigestAlgorithm.SHA_384:
                {
                    IDigest result = new Sha384Digest();
                    return(result);
                }

                case DigestUtilities.DigestAlgorithm.SHA_512:
                {
                    IDigest result = new Sha512Digest();
                    return(result);
                }

                case DigestUtilities.DigestAlgorithm.SHA_512_224:
                {
                    IDigest result = new Sha512tDigest(224);
                    return(result);
                }

                case DigestUtilities.DigestAlgorithm.SHA_512_256:
                {
                    IDigest result = new Sha512tDigest(256);
                    return(result);
                }

                case DigestUtilities.DigestAlgorithm.SHA3_224:
                {
                    IDigest result = new Sha3Digest(224);
                    return(result);
                }

                case DigestUtilities.DigestAlgorithm.SHA3_256:
                {
                    IDigest result = new Sha3Digest(256);
                    return(result);
                }

                case DigestUtilities.DigestAlgorithm.SHA3_384:
                {
                    IDigest result = new Sha3Digest(384);
                    return(result);
                }

                case DigestUtilities.DigestAlgorithm.SHA3_512:
                {
                    IDigest result = new Sha3Digest(512);
                    return(result);
                }

                case DigestUtilities.DigestAlgorithm.TIGER:
                {
                    IDigest result = new TigerDigest();
                    return(result);
                }

                case DigestUtilities.DigestAlgorithm.WHIRLPOOL:
                {
                    IDigest result = new WhirlpoolDigest();
                    return(result);
                }
                }
            }
            catch (ArgumentException)
            {
            }
            throw new SecurityUtilityException("Digest " + text2 + " not recognised.");
        }
    public override void Reset(IMemoable other)
    {
        RipeMD128Digest t = (RipeMD128Digest)other;

        CopyIn(t);
    }
 public RipeMD128Digest(RipeMD128Digest t)
     : base(t)
 {
     CopyIn(t);
 }