Exemplo n.º 1
0
        /// <summary>
        /// Reset the seed <see cref="VTDev.Libraries.CEXEngine.Crypto.Enumeration.SeedGenerators">Seed Generator</see> and the <see cref="VTDev.Libraries.CEXEngine.Crypto.Enumeration.Digests">Digest</see> engines
        /// </summary>
        public void Reset()
        {
            if (m_seedEngine != null)
            {
                m_seedEngine.Dispose();
                m_seedEngine = null;
            }
            m_seedEngine = SeedGeneratorFromName.GetInstance(SeedEngine);

            // reset hash engine
            if (m_hashEngine != null)
            {
                m_hashEngine.Dispose();
                m_hashEngine = null;
            }
            m_hashEngine = DigestFromName.GetInstance(HashEngine);

            // if absent, generate the initial counter
            if (m_ctrLength == 0)
            {
                if (m_hashEngine.BlockSize < 72)
                {
                    m_ctrLength = CTRDEF_SIZE;
                }
                else
                {
                    m_ctrLength = CTRMAX_SIZE;
                }

                m_ctrVector = new byte[m_ctrLength];

                using (CSPRsg pool = new CSPRsg())
                    m_ctrVector = pool.GetBytes(m_ctrLength);
            }
        }
Exemplo n.º 2
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!");
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Get the digest engine
 /// </summary>
 ///
 /// <param name="DigestType">Engine type</param>
 ///
 /// <returns>Instance of digest</returns>
 private IDigest GetDigest(Digests DigestType)
 {
     try
     {
         return(DigestFromName.GetInstance(DigestType));
     }
     catch
     {
         throw new CryptoAsymmetricException("RLWESign:GetDigest", "The digest type is not unsupported!", new ArgumentException());
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Get the digest engine
 /// </summary>
 ///
 /// <param name="DigestType">Engine type</param>
 ///
 /// <returns>Instance of digest</returns>
 private IDigest GetDigest(Digests DigestType)
 {
     try
     {
         return(DigestFromName.GetInstance(DigestType));
     }
     catch
     {
         throw new CryptoRandomException("GMSSKeyGenerator:GetDigest", "The digest type is not recognized!", new ArgumentException());
     }
 }
Exemplo n.º 5
0
 private IDigest LoadDigest(Digests KeyEngine)
 {
     try
     {
         return(DigestFromName.GetInstance(KeyEngine));
     }
     catch
     {
         throw new CryptoSymmetricException("RHX:GetKeyEngine", "The digest type is not supported!", new ArgumentException());
     }
 }
Exemplo n.º 6
0
 private IDigest GetDigest(Digests DigestType)
 {
     try
     {
         return(DigestFromName.GetInstance(DigestType));
     }
     catch
     {
         throw new CryptoProcessingException("DigestStream:GetDigest", "The digest type is not unsupported!", new ArgumentException());
     }
 }
Exemplo n.º 7
0
 /// <summary>
 /// Get the digest engine
 /// </summary>
 ///
 /// <param name="DigestType">Engine type</param>
 ///
 /// <returns>Instance of digest</returns>
 ///
 /// <exception cref="CryptoAsymmetricException">Thrown if the digest is unrecognized or unsupported</exception>
 private IDigest GetDigest(Digests DigestType)
 {
     try
     {
         return(DigestFromName.GetInstance(DigestType));
     }
     catch
     {
         throw new CryptoAsymmetricException("MPKCSign:GetDigest", "The digest is unrecognized or unsupported!", new ArgumentException());
     }
 }
Exemplo n.º 8
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;
            }
        }