Ejemplo n.º 1
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));
        }
Ejemplo n.º 2
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));
        }
Ejemplo n.º 3
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));
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 6
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));
        }