示例#1
0
        public static void GetCiphertextLengthCfb_NoPaddingAndPlaintextSizeNotFeedbackAligned()
        {
            AnySizeAlgorithm alg = new AnySizeAlgorithm();

            Assert.Throws <ArgumentException>("plaintextLength", () =>
                                              alg.GetCiphertextLengthCfb(17, PaddingMode.None, feedbackSizeInBits: 128));
        }
示例#2
0
        public static void GetCiphertextLengthCfb_ThrowsForNonByteFeedbackSize(PaddingMode mode)
        {
            AnySizeAlgorithm alg = new AnySizeAlgorithm();

            AssertExtensions.Throws <ArgumentException>("feedbackSizeInBits", () =>
                                                        alg.GetCiphertextLengthCfb(16, mode, 7));
        }
示例#3
0
        public static void GetCiphertextLengthCfb_ThrowsForOverflow(PaddingMode mode)
        {
            AnySizeAlgorithm alg = new AnySizeAlgorithm();

            AssertExtensions.Throws <ArgumentOutOfRangeException>("plaintextLength", () =>
                                                                  alg.GetCiphertextLengthCfb(0x7FFFFFFF, mode, feedbackSizeInBits: 128));
        }
示例#4
0
        public static void GetCiphertextLengthBlock_ThrowsForNonByteBlockSize(PaddingMode mode)
        {
            AnySizeAlgorithm alg = new AnySizeAlgorithm {
                BlockSize = 5
            };

            Assert.Throws <InvalidOperationException>(() => alg.GetCiphertextLengthCbc(16, mode));
            Assert.Throws <InvalidOperationException>(() => alg.GetCiphertextLengthEcb(16, mode));
        }
示例#5
0
        public static void GetCiphertextLengthBlock_ThrowsForOverflow(PaddingMode mode)
        {
            AnySizeAlgorithm alg = new AnySizeAlgorithm {
                BlockSize = 128
            };

            AssertExtensions.Throws <ArgumentOutOfRangeException>("plaintextLength", () => alg.GetCiphertextLengthCbc(0x7FFFFFF1, mode));
            AssertExtensions.Throws <ArgumentOutOfRangeException>("plaintextLength", () => alg.GetCiphertextLengthEcb(0x7FFFFFF1, mode));
        }
示例#6
0
        public static void DecryptEcb_NotSupportedInDerived()
        {
            AnySizeAlgorithm alg = new AnySizeAlgorithm {
                BlockSize = 128
            };

            Assert.Throws <NotSupportedException>(() =>
                                                  alg.DecryptEcb(Array.Empty <byte>(), PaddingMode.None));
        }
示例#7
0
        public static void GetCiphertextLengthBlock_NoPaddingAndPlaintextSizeNotBlockAligned()
        {
            AnySizeAlgorithm alg = new AnySizeAlgorithm {
                BlockSize = 128
            };

            Assert.Throws <ArgumentException>("plaintextLength", () => alg.GetCiphertextLengthCbc(17, PaddingMode.None));
            Assert.Throws <ArgumentException>("plaintextLength", () => alg.GetCiphertextLengthEcb(17, PaddingMode.None));
        }
示例#8
0
        public static void GetCiphertextLength_ThrowsForNegativeInput(PaddingMode mode)
        {
            AnySizeAlgorithm alg = new AnySizeAlgorithm {
                BlockSize = 128
            };

            AssertExtensions.Throws <ArgumentOutOfRangeException>("plaintextLength", () => alg.GetCiphertextLengthCbc(-1, mode));
            AssertExtensions.Throws <ArgumentOutOfRangeException>("plaintextLength", () => alg.GetCiphertextLengthEcb(-1, mode));
            AssertExtensions.Throws <ArgumentOutOfRangeException>("plaintextLength", () => alg.GetCiphertextLengthCfb(-1, mode));
        }
示例#9
0
        public static void GetCiphertextLengthCfb_ValidInputs(
            PaddingMode mode,
            int plaintextSize,
            int expectedCiphertextSize,
            int alignmentSizeInBits)
        {
            AnySizeAlgorithm alg  = new AnySizeAlgorithm();
            int ciphertextSizeCfb = alg.GetCiphertextLengthCfb(plaintextSize, mode, alignmentSizeInBits);

            Assert.Equal(expectedCiphertextSize, ciphertextSizeCfb);
        }
示例#10
0
        public static void GetCiphertextLength_ThrowsForInvalidPaddingMode()
        {
            AnySizeAlgorithm alg = new AnySizeAlgorithm {
                BlockSize = 128
            };
            PaddingMode mode = (PaddingMode)(-1);

            Assert.Throws <ArgumentOutOfRangeException>("paddingMode", () => alg.GetCiphertextLengthCbc(16, mode));
            Assert.Throws <ArgumentOutOfRangeException>("paddingMode", () => alg.GetCiphertextLengthEcb(16, mode));
            Assert.Throws <ArgumentOutOfRangeException>("paddingMode", () => alg.GetCiphertextLengthCfb(16, mode));
        }
示例#11
0
        public static void GetCiphertextLengthBlock_ValidInputs(
            PaddingMode mode,
            int plaintextSize,
            int expectedCiphertextSize,
            int alignmentSizeInBits)
        {
            AnySizeAlgorithm alg = new AnySizeAlgorithm {
                BlockSize = alignmentSizeInBits
            };
            int ciphertextSizeCbc = alg.GetCiphertextLengthCbc(plaintextSize, mode);
            int ciphertextSizeEcb = alg.GetCiphertextLengthEcb(plaintextSize, mode);

            Assert.Equal(expectedCiphertextSize, ciphertextSizeCbc);
            Assert.Equal(expectedCiphertextSize, ciphertextSizeEcb);
        }