Ejemplo n.º 1
0
        public IEnumerable <HashTestVector> GetHashTestVectors()
        {
            string line;

            var  testVector      = new HashTestVector();
            bool canOutputVector = false;

            while ((line = Reader.ReadLine()?.Trim()) != null)
            {
                if (line.Length == 0)
                {
                    if (canOutputVector)
                    {
                        yield return(testVector);

                        testVector      = new HashTestVector();
                        canOutputVector = false;
                    }

                    continue;
                }

                if (line[0] == '#')
                {
                    continue;
                }
                if (line[0] == '[')
                {
                    continue;
                }

                string[] kvp = line.Split(new[] { " = " }, StringSplitOptions.None);
                if (kvp.Length != 2)
                {
                    throw new InvalidDataException();
                }

                canOutputVector = true;

                switch (kvp[0].ToUpperInvariant())
                {
                case "LEN":
                    testVector.LengthBits  = int.Parse(kvp[1]);
                    testVector.LengthBytes = testVector.LengthBits / 8;
                    break;

                case "MSG":
                    testVector.Message = kvp[1].ToBytes();
                    break;

                case "MD":
                    testVector.Digest = kvp[1].ToBytes();
                    break;
                }
            }
        }
Ejemplo n.º 2
0
 public static void Encrypt(HashTestVector tv)
 {
     Common.HashTestCore(tv.Message.AsSpan(0, tv.LengthBytes), tv.Digest, Sha256.CreateSha256Generator());
 }