Ejemplo n.º 1
0
        public void ShouldComputeProperIValueFromInteger(int dataUnitSeqNumber, string hex)
        {
            var expectedBitString = new BitString(hex);

            var result = XtsHelper.GetIFromInteger(dataUnitSeqNumber);

            Assert.AreEqual(expectedBitString, result);
        }
Ejemplo n.º 2
0
        public void ShouldGetCAVSFileRight(int length, string ptHex, string keyHex, int seqNum, string ctHex)
        {
            var key   = new BitString(keyHex);
            var tweak = XtsHelper.GetIFromInteger(seqNum);
            var pt    = new BitString(ptHex, length);
            var ct    = new BitString(ctHex, length);

            var subject = new XtsBlockCipher(new AesEngine());

            var encryptResult = subject.ProcessPayload(new XtsModeBlockCipherParameters(BlockCipherDirections.Encrypt, tweak, key, pt, pt.BitLength));

            Assert.IsTrue(encryptResult.Success, $"encryption failed, {encryptResult.ErrorMessage}");
            Assert.AreEqual(ct.ToHex(), encryptResult.Result.ToHex(), "encrypt comparison");

            var decryptResult = subject.ProcessPayload(new XtsModeBlockCipherParameters(BlockCipherDirections.Decrypt, tweak, key, ct, ct.BitLength));

            Assert.IsTrue(decryptResult.Success, $"decryption failed, {decryptResult.ErrorMessage}");
            Assert.AreEqual(pt.ToHex(), decryptResult.Result.ToHex(), "decrypt comparison");
        }