/// <summary> /// Check if the master key of the specified generation is correct. /// </summary> /// <param name="s">The <see cref="KeySet"/> to test.</param> /// <param name="generation">The generation to test.</param> /// <returns><see langword="true"/> if the key is correct.</returns> private static bool TestKeyGeneration(KeySet s, int generation) { ReadOnlySpan <AesKey> keyVectors = MasterKeyVectors(s); // Decrypt the vector chain until we get Master Key 0 AesKey key = s.MasterKeys[generation]; for (int i = generation; i > 0; i--) { Aes.DecryptEcb128(keyVectors[i], key, key); } // Decrypt the zeros with Master Key 0 Aes.DecryptEcb128(keyVectors[0], key, key); // If we don't get zeros, MasterKeys[generation] is incorrect return(key.IsZeros()); }