コード例 #1
0
ファイル: AesXtsTests.cs プロジェクト: usnistgov/ACVP-Server
        public void ShouldComputeProperIValueFromInteger(int dataUnitSeqNumber, string hex)
        {
            var expectedBitString = new BitString(hex);

            var result = XtsHelper.GetIFromInteger(dataUnitSeqNumber);

            Assert.AreEqual(expectedBitString, result);
        }
コード例 #2
0
ファイル: AesXtsTests.cs プロジェクト: usnistgov/ACVP-Server
        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");
        }