public void ShouldFindIVsDecrypt(string keyHex, string ctHex, string ptHex, string iv) { var key = new BitString(keyHex); var pt = new BitString(ptHex); var ct = new BitString(ctHex); string[] ivsarray = { "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC0", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC1", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC2", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC3", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC4", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC5", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC6", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC7", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC8", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC9", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFCA", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFCB", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFCC", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFCD", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFCE", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFCF", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD0", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD1", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD2", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD3", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD4", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD5", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD6", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD7", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD8", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD9", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFDA", "FFFFFFFFFFFFFF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FFFFFFFFFFFF9", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFB", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", "00000000000000000000000000000000", "00000000000000000000000000000001", "00000000000000000000000000000002", "00000000000000000000000000000003", "00000000000000000000000000000004", "00000000000000000000000000000005", "00000000000000000000000000000006", "00000000000000000000000000000007", "00000000000000000000000000000008", "00000000000000000000000000000009", "0000000000000000000000000000000A", "0000000000000000000000000000000B", "0000000000000000000000000000000C", "0000000000000000000000000000000D", "0000000000000000000000000000000E", "0000000000000000000000000000000F", "00000000000000000000000000000010", "00000000000000000000000000000011", "00000000000000000000000000000012", "00000000000000000000000000000013", "00000000000000000000000000000014", "00000000000000000000000000000015", "00000000000000000000000000000016", "00000000000000000000000000000017", "00000000000000000000000000000018", "00000000000000000000000000000019", "0000000000000000000000000000001A", "0000000000000000000000000000001B", "0000000000000000000000000000001C", "0000000000000000000000000000001D", "0000000000000000000000000000001E", "0000000000000000000000000000001F", "00000000000000000000000000000020", "00000000000000000000000000000021", "00000000000000000000000000000022", "00000000000000000000000000000023" }; var ivsCorrect = new List <BitString>(); foreach (var ivgiven in ivsarray) { ivsCorrect.Add(new BitString(ivgiven)); } _subject = new CtrBlockCipher(new AesEngine(), new TestableCounter(new AesEngine(), ivsCorrect)); var param = new CounterModeBlockCipherParameters(BlockCipherDirections.Encrypt, key, pt, ct); var result = _subject.ExtractIvs(param); Assert.AreEqual(ivsCorrect, result.IVs); }
public void ShouldFindIVsEncrypt(string keyHex, string ptHex, string ctHex, string iv) { var key = new BitString(keyHex); var pt = new BitString(ptHex); var ct = new BitString(ctHex); string[] ivsarray = { "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF1", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF2", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF4", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF6", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF8", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFB", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", "00000000000000000000000000000000", "00000000000000000000000000000001", "00000000000000000000000000000002", "00000000000000000000000000000003", "00000000000000000000000000000004", "00000000000000000000000000000005", "00000000000000000000000000000006", "00000000000000000000000000000007", "00000000000000000000000000000008", "00000000000000000000000000000009", "0000000000000000000000000000000A", "0000000000000000000000000000000B", "0000000000000000000000000000000C", "0000000000000000000000000000000D", "0000000000000000000000000000000E", "0000000000000000000000000000000F", "00000000000000000000000000000010", "00000000000000000000000000000011", "00000000000000000000000000000012", "00000000000000000000000000000013", "00000000000000000000000000000014", "00000000000000000000000000000015", "00000000000000000000000000000016", "00000000000000000000000000000017", "00000000000000000000000000000018", "00000000000000000000000000000019", "0000000000000000000000000000001A", "0000000000000000000000000000001B", "0000000000000000000000000000001C", "0000000000000000000000000000001D", "0000000000000000000000000000001E", "0000000000000000000000000000001F", "00000000000000000000000000000020", "00000000000000000000000000000021", "00000000000000000000000000000022", "00000000000000000000000000000023", "00000000000000000000000000000024", "00000000000000000000000000000025", "00000000000000000000000000000026", "00000000000000000000000000000027", "00000000000000000000000000000028", "00000000000000000000000000000029", "0000000000000000000000000000002A", "0000000000000000000000000000002B", "0000000000000000000000000000002C", "0000000000000000000000000000002D", "0000000000000000000000000000002E", "0000000000000000000000000000002F", "00000000000000000000000000000030", "00000000000000000000000000000031", "00000000000000000000000000000032", "00000000000000000000000000000033", "00000000000000000000000000000034", "00000000000000000000000000000035", "00000000000000000000000000000036", "00000000000000000000000000000037", "00000000000000000000000000000038", "00000000000000000000000000000039", "0000000000000000000000000000003A", "0000000000000000000000000000003B", "0000000000000000000000000000003C", "0000000000000000000000000000003D", "0000000000000000000000000000003E", "0000000000000000000000000000003F", "00000000000000000000000000000040", "00000000000000000000000000000041", "00000000000000000000000000000042", "00000000000000000000000000000043", "00000000000000000000000000000044", "00000000000000000000000000000045", "00000000000000000000000000000046", "00000000000000000000000000000047", "00000000000000000000000000000048", "00000000000000000000000000000049", "0000000000000000000000000000004A", "0000000000000000000000000000004B", "0000000000000000000000000000004C", "0000000000000000000000000000004D", "0000000000000000000000000000004E", "0000000000000000000000000000004F", "00000000000000000000000000000050", "00000000000000000000000000000051", "00000000000000000000000000000052", "00000000000000000000000000000053" }; var ivsCorrect = new List <BitString>(); foreach (var ivgiven in ivsarray) { ivsCorrect.Add(new BitString(ivgiven)); } _subject = new CtrBlockCipher(new AesEngine(), new TestableCounter(new AesEngine(), ivsCorrect)); var param = new CounterModeBlockCipherParameters(BlockCipherDirections.Encrypt, key, pt, ct); var result = _subject.ExtractIvs(param); Assert.AreEqual(ivsCorrect, result.IVs); }