Beispiel #1
0
        private void doFinalTest()
        {
            KMac kmac = new KMac(128, Encoding.ASCII.GetBytes("My Tagged Application"));

            kmac.Init(new KeyParameter(Hex.Decode(
                                           "404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F")));

            kmac.BlockUpdate(Hex.Decode("00010203"), 0, 4);

            byte[] res = new byte[32];

            kmac.DoOutput(res, 0, res.Length);

            Assert.IsTrue(Arrays.AreEqual(Hex.Decode("31a44527b4ed9f5c6101d11de6d26f0620aa5c341def41299657fe9df1a3b16c"), res), Hex.ToHexString(res));

            kmac.DoOutput(res, 0, res.Length);

            Assert.IsTrue(!Arrays.AreEqual(Hex.Decode("31a44527b4ed9f5c6101d11de6d26f0620aa5c341def41299657fe9df1a3b16c"), res));

            kmac.DoFinal(res, 0, res.Length);

            kmac.BlockUpdate(Hex.Decode("00010203"), 0, 4);

            kmac.DoFinal(res, 0, res.Length);

            Assert.IsTrue(Arrays.AreEqual(Hex.Decode("3B1FBA963CD8B0B59E8C1A6D71888B7143651AF8BA0A7070C0979E2811324AA5"), res));

            kmac.BlockUpdate(Hex.Decode("00010203"), 0, 4);

            kmac.DoOutput(res, 0, res.Length);

            Assert.IsTrue(Arrays.AreEqual(Hex.Decode("31a44527b4ed9f5c6101d11de6d26f0620aa5c341def41299657fe9df1a3b16c"), res));

            kmac.DoFinal(res, 0, res.Length);

            Assert.IsTrue(Arrays.AreEqual(Hex.Decode("ffcb48c7620ccd67d1c83224186892cef2f2a99278d5cfdde10e48bdc89718c2"), res), Hex.ToHexString(res));
        }
Beispiel #2
0
        private void paddingCheckTest()
        {
            byte[] data = Hex.Decode("01880204187B3E43EDA8D51EC181D37DDE5B17ECCDD8BE84C268DC6C9500700857");
            byte[] out_ = new byte[32];

            KMac k128 = new KMac(128, new byte[0]);

            k128.Init(new KeyParameter(new byte[163]));
            k128.BlockUpdate(data, 0, data.Length);
            k128.DoOutput(out_, 0, out_.Length);

            Assert.IsTrue(Arrays.AreEqual(out_, Hex.Decode("6e6ab56468c7445f81c679f89f45c90a95a9c01afbaab5f7065b7e2e96f7d2bb")), "128 failed");

            KMac k256 = new KMac(256, new byte[0]);

            k256.Init(new KeyParameter(new byte[131]));
            k256.BlockUpdate(data, 0, data.Length);
            k256.DoOutput(out_, 0, out_.Length);

            Assert.IsTrue(Arrays.AreEqual(out_, Hex.Decode("f6302d4f854b4872e811b37993b6bfe027258089b6a9fbb26a755b1ebfc0d830")), "256 failed");
        }