Beispiel #1
0
        public byte[] Generate(byte[] agreed)
        {
            IMac prfMac;

            if (prfAlgorithm == FipsPrfAlgorithm.AesCMac)
            {
                Internal.IBlockCipher aesEng = FipsAes.ENGINE_PROVIDER.CreateEngine(EngineUsage.GENERAL);
                aesEng.Init(true, new KeyParameter(salt ?? new byte[16]));

                prfMac = new CMac(aesEng);
                prfMac.Init(null);
            }
            else
            {
                prfMac = FipsShs.CreateHmac((DigestAlgorithm)prfAlgorithm.BaseAlgorithm);
                prfMac.Init(new KeyParameter(salt ?? new byte[((HMac)prfMac).GetUnderlyingDigest().GetByteLength()]));
            }

            byte[] mac = Macs.DoFinal(prfMac, agreed, 0, agreed.Length);

            // ZEROIZE
            Arrays.Fill(agreed, (byte)0);

            return(mac);
        }
Beispiel #2
0
            public bool HasTestPassed(EngineProvider provider)
            {
                byte[] input16         = Hex.Decode("6bc1bee22e409f96e93d7e117393172a");
                byte[] output_k128_m16 = Hex.Decode("c0b9bbee139722ab");

                IMac mac = new CMac(provider.CreateEngine(EngineUsage.GENERAL), 64);

                //128 bytes key

                KeyParameter key = new KeyParameter(Hex.Decode("0102020404070708080b0b0d0d0e0e101013131515161619"));

                byte[] output = Macs.DoFinal(mac, key, input16, 0, input16.Length);

                return(Arrays.AreEqual(FipsKats.Values[FipsKats.Vec.TripleDesCMacTag], output));
            }
Beispiel #3
0
            public bool HasTestPassed(EngineProvider provider)
            {
                byte[] keyBytes128     = Hex.Decode("2b7e151628aed2a6abf7158809cf4f3c");
                byte[] input16         = Hex.Decode("6bc1bee22e409f96e93d7e117393172a");
                byte[] output_k128_m16 = Hex.Decode("070a16b46b4d4144f79bdd9dd04a287c");

                IMac mac = new CMac(provider.CreateEngine(EngineUsage.GENERAL), 128);

                //128 bits key
                KeyParameter key = new KeyParameter(keyBytes128);

                byte[] output = Macs.DoFinal(mac, key, input16, 0, input16.Length);

                return(Arrays.AreEqual(FipsKats.Values[FipsKats.Vec.AesCMacTag], output));
            }
Beispiel #4
0
        private static byte[] CalculateAssemblyHMac()
        {
            Assembly assembly = Assembly.GetExecutingAssembly();

            Check(assembly.GetModules().Length == 1);

            string path = assembly.ManifestModule.FullyQualifiedName;

            byte[] data = File.ReadAllBytes(path);

            IMac mac = new HMac(new Sha512Digest());

            mac.Init(new KeyParameter(MacKey));

            int macPos;
            var ranges = AnalyzePEData(data, out macPos);

            Check(macPos >= 0);

            int pos = 0;

            foreach (var range in ranges)
            {
                if (pos < range.Start)
                {
                    mac.BlockUpdate(data, pos, range.Start - pos);
                }
                if (range.Data != null)
                {
                    mac.BlockUpdate(range.Data, 0, range.Data.Length);
                }
                int rangeEnd = range.Start + range.Length;
                if (pos < rangeEnd)
                {
                    pos = rangeEnd;
                }
            }

            if (pos < data.Length)
            {
                mac.BlockUpdate(data, pos, data.Length - pos);
            }

            return(Macs.DoFinal(mac));
        }
Beispiel #5
0
 public byte[] Collect()
 {
     return(Macs.DoFinal(mac));
 }
Beispiel #6
0
            public bool HasTestPassed(IMac hMac)
            {
                byte[] result = Macs.DoFinal(hMac, new KeyParameter(key), stdHMacVector, 0, stdHMacVector.Length);

                return(Arrays.AreEqual(result, kat));
            }