Beispiel #1
0
        private void DigestTest(Digests DigestType, string Path, bool Parallel = false)
        {
            int hashSize = DigestFromName.GetDigestSize(DigestType);

            using (StreamReader r = new StreamReader(Path))
            {
                string line;
                while ((line = r.ReadLine()) != null)
                {
                    if (line.Contains(DMK_INP))
                    {
                        byte[] input  = new byte[0];
                        byte[] expect = new byte[hashSize];
                        byte[] key    = new byte[0];
                        byte[] hash   = new byte[hashSize];

                        int sze = DMK_INP.Length;
                        if (line.Length - sze > 0)
                        {
                            input = HexConverter.Decode(line.Substring(sze, line.Length - sze));
                        }

                        line = r.ReadLine();
                        sze  = DMK_KEY.Length;
                        if (line.Length - sze > 0)
                        {
                            key = HexConverter.Decode(line.Substring(sze, line.Length - sze));
                        }

                        line = r.ReadLine();
                        sze  = DMK_HSH.Length;
                        if (line.Length - sze > 0)
                        {
                            expect = HexConverter.Decode(line.Substring(sze, line.Length - sze));
                        }

                        IDigest dgt = DigestFromName.GetInstance(DigestType, Parallel);

                        if (dgt.Enumeral == Digests.Blake2B512)
                        {
                            ((Blake2B512)dgt).LoadMacKey(new MacParams(key));
                        }
                        else
                        {
                            ((Blake2S256)dgt).LoadMacKey(new MacParams(key));
                        }

                        hash = dgt.ComputeHash(input);
                        //16,235
                        if (Evaluate.AreEqual(hash, expect) == false)
                        {
                            throw new Exception("Blake2: Expected hash is not equal!");
                        }
                    }
                }
            }
        }
Beispiel #2
0
        private void LoadState(Digests ExtractorType)
        {
            m_kdfExtractorType = ExtractorType;

            if (m_kdfExtractorType == Digests.None)
            {
                m_legalRounds   = new int[] { 32, 40 };
                m_legalKeySizes = new int[] { 16, 24, 32, 64 };
            }
            else
            {
                m_legalRounds = new int[] { 32, 40, 48, 56, 64 };
                m_kdfKeySize  = DigestFromName.GetBlockSize(m_kdfExtractorType);
                // calculate max saturation of entropy when distribution code is used as key extension; subtract hash finalizer padding + 1 byte kdf counter
                m_kdfInfoMax       = m_kdfKeySize - (DigestFromName.GetPaddingSize(m_kdfExtractorType) + 1);
                m_legalKeySizes    = new int[3];
                m_legalKeySizes[0] = DigestFromName.GetDigestSize(m_kdfExtractorType);
                m_legalKeySizes[1] = m_kdfKeySize;
                m_legalKeySizes[2] = m_kdfKeySize * 2;
            }
        }