Beispiel #1
0
        public static void TestCmacTestVectors(TestData data)
        {
            var actual = new byte[0x10];

            CryptoOld.CalculateAesCmac(data.Key, data.Message, data.Start, actual, 0, data.Length);

            Assert.Equal(data.Expected, actual);
        }
Beispiel #2
0
        private Validity ValidateSignature(Keyset keyset)
        {
            var calculatedCmac = new byte[0x10];

            CryptoOld.CalculateAesCmac(keyset.SaveMacKey, Data, 0x100, calculatedCmac, 0, 0x200);

            return(Utilities.ArraysEqual(calculatedCmac, Cmac) ? Validity.Valid : Validity.Invalid);
        }
        public Result Commit(Keyset keyset)
        {
            CoreDataIvfcStorage.Flush();
            FatIvfcStorage?.Flush();

            Stream headerStream = BaseStorage.AsStream();

            var hashData = new byte[0x3d00];

            headerStream.Position = 0x300;
            headerStream.Read(hashData, 0, hashData.Length);

            var hash = new byte[Sha256.DigestSize];

            Sha256.GenerateSha256Hash(hashData, hash);

            headerStream.Position = 0x108;
            headerStream.Write(hash, 0, hash.Length);

            if (keyset == null || keyset.SaveMacKey.IsEmpty())
            {
                return(ResultFs.PreconditionViolation);
            }

            var cmacData = new byte[0x200];
            var cmac     = new byte[0x10];

            headerStream.Position = 0x100;
            headerStream.Read(cmacData, 0, 0x200);

            CryptoOld.CalculateAesCmac(keyset.SaveMacKey, cmacData, 0, cmac, 0, 0x200);

            headerStream.Position = 0;
            headerStream.Write(cmac, 0, 0x10);
            headerStream.Flush();

            return(Result.Success);
        }