コード例 #1
0
        internal static byte[] Digest(byte[] data)
        {
            Sha512tDigest digest = new Sha512tDigest(256);

            digest.BlockUpdate(data, 0, data.Length);
            byte[] output = new byte[32];
            digest.DoFinal(output, 0);
            return(output);
        }
コード例 #2
0
    public override void Reset(IMemoable other)
    {
        Sha512tDigest sha512tDigest = (Sha512tDigest)other;

        if (digestLength != sha512tDigest.digestLength)
        {
            throw new MemoableResetException("digestLength inappropriate in other");
        }
        CopyIn(sha512tDigest);
        H1t = sha512tDigest.H1t;
        H2t = sha512tDigest.H2t;
        H3t = sha512tDigest.H3t;
        H4t = sha512tDigest.H4t;
        H5t = sha512tDigest.H5t;
        H6t = sha512tDigest.H6t;
        H7t = sha512tDigest.H7t;
        H8t = sha512tDigest.H8t;
    }
コード例 #3
0
        /// <summary>
        /// Hashes a list of byte arrays, prefixing each one with its length.
        /// </summary>
        public byte[] Sum(byte[] domain, params byte[][] datas)
        {
            using (var stream = new MemoryStream())
            {
                byte[] ulongBytes;

                foreach (var data in datas)
                {
                    ulongBytes = this.UInt64ToBytes((ulong)data.Length);

                    stream.Write(ulongBytes, 0, ulongBytes.Length);
                    stream.Write(data, 0, data.Length);
                }

                ulongBytes = this.UInt64ToBytes((ulong)domain.Length);

                stream.Write(ulongBytes, 0, ulongBytes.Length);
                stream.Write(domain, 0, domain.Length);

                var result = stream.ToArray();

                byte[] hash;
                var    sha = new Sha512tDigest(256);

                try
                {
                    sha.BlockUpdate(result, 0, result.Length);
                    hash = new byte[sha.GetDigestSize()];
                    sha.DoFinal(hash, 0);
                }
                finally
                {
                    sha.Finish();
                }

                return(hash);
            }
        }
コード例 #4
0
ファイル: SwuTests.cs プロジェクト: BuddahLD/sdk-net
        public void Should_GeneratePointOnCurve_When_RandomHashesArePassed()
        {
            var curveParams = NistNamedCurves.GetByName("P-256");

            var swu    = new Swu(((FpCurve)curveParams.Curve).Q, curveParams.Curve.B.ToBigInteger());
            var rng    = new SecureRandom();
            var sha    = new Sha512tDigest(256);
            var random = new byte[32];

            for (int i = 0; i <= 10000; i++)
            {
                var hash = new byte[32];

                rng.NextBytes(random);
                sha.BlockUpdate(random, 0, random.Length);
                sha.DoFinal(hash, 0);

                var(x, y) = swu.HashToPoint(hash);
                Assert.True(curveParams.Curve.CreatePoint(x, y).IsValid());

                sha.Reset();
            }
        }
コード例 #5
0
        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.");
        }
コード例 #6
0
 public Sha512tDigest(Sha512tDigest t)
     : base(t)
 {
     digestLength = t.digestLength;
     Reset(t);
 }
コード例 #7
0
 public SHA512tCryptoServiceProvider(int hashSize)
 {
     _hashSize = hashSize;
     _digest   = new Sha512tDigest(hashSize);
 }