public NistKnownAnswerTestVector(NistKnownAnswerTestOperation operation, CipherMode cipherMode, int count, byte[] key, byte[] iv, int bitLength, byte[] plaintext, byte[] ciphertext) { Operation = operation; CipherMode = cipherMode; Count = count; Key = key; IV = iv; BitLength = bitLength; Plaintext = plaintext; Ciphertext = ciphertext; }
private static NistKnownAnswerTestVector ReadVector(NistKnownAnswerTestOperation operation, CipherMode cipherMode, string firstLine, StreamReader reader) { string[] countInfo = ParseNameValuePair(firstLine); if (!"COUNT".Equals(countInfo[0], StringComparison.OrdinalIgnoreCase)) { throw new InvalidDataException("Expected COUNT as first item"); } int count = Int32.Parse(countInfo[1], CultureInfo.InvariantCulture); string name; byte[] bytes; int bitLength; ParseNamedBytes(reader.ReadLine(), out name, out bytes, out bitLength); if (!"KEY".Equals(name, StringComparison.OrdinalIgnoreCase)) { throw new InvalidDataException("Expected KEY"); } byte[] key = bytes; ParseNamedBytes(reader.ReadLine(), out name, out bytes, out bitLength); byte[] iv = null; // IV is optional since ECB doesn't need it if ("IV".Equals(name, StringComparison.OrdinalIgnoreCase)) { iv = bytes; ParseNamedBytes(reader.ReadLine(), out name, out bytes, out bitLength); } byte[] plaintext; byte[] ciphertext; if (operation == NistKnownAnswerTestOperation.Encrypt) { if (!"PLAINTEXT".Equals(name, StringComparison.OrdinalIgnoreCase)) { throw new InvalidDataException("Expected PLAINTEXT"); } plaintext = bytes; ParseNamedBytes(reader.ReadLine(), out name, out bytes, out bitLength); if (!"CIPHERTEXT".Equals(name, StringComparison.OrdinalIgnoreCase)) { throw new InvalidDataException("Expected CIPHERTEXT"); } ciphertext = bytes; } else { if (!"CIPHERTEXT".Equals(name, StringComparison.OrdinalIgnoreCase)) { throw new InvalidDataException("Expected CIPHERTEXT"); } ciphertext = bytes; ParseNamedBytes(reader.ReadLine(), out name, out bytes, out bitLength); if (!"PLAINTEXT".Equals(name, StringComparison.OrdinalIgnoreCase)) { throw new InvalidDataException("Expected PLAINTEXT"); } plaintext = bytes; } return new NistKnownAnswerTestVector(operation, cipherMode, count, key, iv, bitLength, plaintext, ciphertext); }
private static NistKnownAnswerTestVector ReadVector(NistKnownAnswerTestOperation operation, CipherMode cipherMode, string firstLine, StreamReader reader) { string[] countInfo = ParseNameValuePair(firstLine); if (!"COUNT".Equals(countInfo[0], StringComparison.OrdinalIgnoreCase)) { throw new InvalidDataException("Expected COUNT as first item"); } int count = Int32.Parse(countInfo[1], CultureInfo.InvariantCulture); string name; byte[] bytes; int bitLength; ParseNamedBytes(reader.ReadLine(), out name, out bytes, out bitLength); if (!"KEY".Equals(name, StringComparison.OrdinalIgnoreCase)) { throw new InvalidDataException("Expected KEY"); } byte[] key = bytes; ParseNamedBytes(reader.ReadLine(), out name, out bytes, out bitLength); byte[] iv = null; // IV is optional since ECB doesn't need it if ("IV".Equals(name, StringComparison.OrdinalIgnoreCase)) { iv = bytes; ParseNamedBytes(reader.ReadLine(), out name, out bytes, out bitLength); } byte[] plaintext; byte[] ciphertext; if (operation == NistKnownAnswerTestOperation.Encrypt) { if (!"PLAINTEXT".Equals(name, StringComparison.OrdinalIgnoreCase)) { throw new InvalidDataException("Expected PLAINTEXT"); } plaintext = bytes; ParseNamedBytes(reader.ReadLine(), out name, out bytes, out bitLength); if (!"CIPHERTEXT".Equals(name, StringComparison.OrdinalIgnoreCase)) { throw new InvalidDataException("Expected CIPHERTEXT"); } ciphertext = bytes; } else { if (!"CIPHERTEXT".Equals(name, StringComparison.OrdinalIgnoreCase)) { throw new InvalidDataException("Expected CIPHERTEXT"); } ciphertext = bytes; ParseNamedBytes(reader.ReadLine(), out name, out bytes, out bitLength); if (!"PLAINTEXT".Equals(name, StringComparison.OrdinalIgnoreCase)) { throw new InvalidDataException("Expected PLAINTEXT"); } plaintext = bytes; } return(new NistKnownAnswerTestVector(operation, cipherMode, count, key, iv, bitLength, plaintext, ciphertext)); }