コード例 #1
0
        public ITestResult Perform()
        {
            // test1
            IMac         mac = new Gost28147Mac();
            KeyParameter key = new KeyParameter(gkeyBytes1);

            mac.Init(key);

            mac.BlockUpdate(input3, 0, input3.Length);

            byte[] outBytes = new byte[4];

            mac.DoFinal(outBytes, 0);

            if (!Arrays.AreEqual(outBytes, output7))
            {
                return(new SimpleTestResult(false, Name + ": Failed test 1 - expected "
                                            + Hex.ToHexString(output7)
                                            + " got " + Hex.ToHexString(outBytes)));
            }

            // test2
            key = new KeyParameter(gkeyBytes2);

            ParametersWithSBox gparam = new ParametersWithSBox(key, Gost28147Engine.GetSBox("E-A"));

            mac.Init(gparam);

            mac.BlockUpdate(input4, 0, input4.Length);

            outBytes = new byte[4];

            mac.DoFinal(outBytes, 0);

            if (!Arrays.AreEqual(outBytes, output8))
            {
                return(new SimpleTestResult(false, Name + ": Failed test 2 - expected "
                                            + Hex.ToHexString(output8)
                                            + " got " + Hex.ToHexString(outBytes)));
            }

            return(new SimpleTestResult(true, Name + ": Okay"));
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: jvinkovic/SSH-simulator
        /// <summary>
        /// IMPLEMENTACIJA JE TAKVA DA VRATI 4 bajta
        /// </summary>
        /// <param name="paket"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static byte[] Compute_gost28147(byte[] paket, byte[] key)
        {
            Gost28147Mac gost  = new Gost28147Mac();
            KeyParameter param = new KeyParameter(key, 0, key.Length);

            gost.Init(param);

            gost.BlockUpdate(key, 0, key.Length);

            var macS = gost.GetMacSize();

            byte[] output = new byte[macS];
            int    b      = gost.DoFinal(output, 0);

            return(output);
        }
コード例 #3
0
        private static void CheckMac(byte[] key, byte[] cek, byte[] data, byte[] mac)
        {
            var m      = new Gost28147Mac();
            var keyPrm = ParameterUtilities.CreateKeyParameter("GOST", key);

            m.Init(keyPrm);

            var cekmac = new byte[4];

            m.BlockUpdate(data, 0, data.Length);
            m.DoFinal(cekmac, 0);

            if (!mac.SequenceEqual(cekmac))
            {
                throw new CryptographicException("Неверный ПИН-код");
            }
        }
コード例 #4
0
        private void CheckMac(byte[] cekDecrypted, byte[] kek)
        {
            var cekmac = new byte[4];
            var mac    = new Gost28147Mac();
            var key    = ParameterUtilities.CreateKeyParameter("GOST", kek);
            var prms   = new ParametersWithIV(key, UKM);

            mac.Init(prms);
            SetSBox(mac, Gost28147_SBox);

            mac.BlockUpdate(cekDecrypted, 0, cekDecrypted.Length);
            mac.DoFinal(cekmac, 0);

            for (int i = 0; i < 4; ++i)
            {
                if (cekmac[i] != MAC[i])
                {
                    throw new CryptographicException("CEK decryption error, MAC values do not match.");
                }
            }
        }