Skip to content

Commit

Permalink
Add functionality to permutate hashes to determine PCR value
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronald Aigner committed Jun 3, 2018
1 parent de805ba commit 0f48f17
Show file tree
Hide file tree
Showing 10 changed files with 471 additions and 8 deletions.
6 changes: 6 additions & 0 deletions HashCalculator/AppShell.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ public sealed partial class AppShell : Page
DestPage = typeof(CalculateHMACHash)
},
new NavMenuItem()
{
Symbol = Symbol.Sort,
Label = "Hash Permutater",
DestPage = typeof(PermutateHash)
},
new NavMenuItem()
{
Symbol = Symbol.Setting,
Label = "Settings",
Expand Down
22 changes: 22 additions & 0 deletions HashCalculator/PermutationHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Collections.Generic;
using System.Linq;

namespace TPMPCRCalculator
{
static class PermutationHelper
{
static public IEnumerable<IEnumerable<T>> GetPermutations<T>(IEnumerable<T> list, int length)
{
if (length == 1) return list.Select(t => new T[] { t });

return GetPermutations(list, length - 1)
.SelectMany(t => list.Where(e => !t.Contains(e)),
(t1, t2) => t1.Concat(new T[] { t2 }));
}

static public IEnumerable<IEnumerable<T>> Split<T>(this IEnumerable<T> source, int chunkSize)
{
return source.Where((x, i) => i % chunkSize == 0).Select((x, i) => source.Skip(i * chunkSize).Take(chunkSize));
}
}
}
10 changes: 9 additions & 1 deletion HashCalculator/TPMPCRCalculator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
<Compile Include="AppShell.xaml.cs">
<DependentUpon>AppShell.xaml</DependentUpon>
</Compile>
<Compile Include="PermutationHelper.cs" />
<Compile Include="Views\CalculateHMACHash.xaml.cs">
<DependentUpon>CalculateHMACHash.xaml</DependentUpon>
</Compile>
Expand All @@ -131,6 +132,9 @@
<DependentUpon>TpmPcrs.xaml</DependentUpon>
</Compile>
<Compile Include="Worker.cs" />
<Compile Include="Views\PermutateHash.xaml.cs">
<DependentUpon>PermutateHash.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<AppxManifest Include="Package.appxmanifest">
Expand Down Expand Up @@ -180,6 +184,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\PermutateHash.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights">
Expand All @@ -199,7 +207,7 @@
<VisualStudioVersion>14.0</VisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
Expand Down
3 changes: 3 additions & 0 deletions HashCalculator/Views/LandingPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
<TextBlock Style="{StaticResource SubtitleTextBlockStyle}">HMAC Hash Calculator Tool</TextBlock>
<TextBlock Style="{StaticResource BodyTextBlockStyle}" Margin="0,4">This tool allows to perform different kinds of hash calculations using HMAC keys.</TextBlock>

<TextBlock Style="{StaticResource SubtitleTextBlockStyle}">Hash Permutation Tool</TextBlock>
<TextBlock Style="{StaticResource BodyTextBlockStyle}" Margin="0,4">Given a list of hashes and an expected rsult hash, this tool permutates through all hashes with all possible initial PCR values to determine which sequence results in the expected hash value. This is useful to validate if a hash has been measured or the order of hashes has been changed.</TextBlock>

<TextBlock Style="{StaticResource SubtitleTextBlockStyle}" Margin="0,12,0,4">Overview</TextBlock>
<TextBlock Style="{StaticResource BodyTextBlockStyle}" Margin="0,4">
A "hash" or "hash function" is a computation that maps variable sized input data to
Expand Down
87 changes: 87 additions & 0 deletions HashCalculator/Views/PermutateHash.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<Page
x:Class="TPMPCRCalculator.Views.PermutateHash"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TPMPCRCalculator"
xmlns:ctl="using:TPMPCRCalculator.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
KeyDown="MainPage_KeyDown"
mc:Ignorable="d">

<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState>
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="{StaticResource MediumWindowSnapPoint}" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="Layoutroot.Margin" Value="12,0,0,0"/>
<Setter Target="title.Style" Value="{StaticResource PageTitleTextBlockStyle}"/>
</VisualState.Setters>
</VisualState>
<VisualState>
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="{StaticResource MinWindowSnapPoint}" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="LayoutRoot.Margin" Value="0"/>
<Setter Target="title.Style" Value="{StaticResource NarrowPageTitleTextBlockStyle}"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>

<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>

<ctl:PageHeader>
<ctl:PageHeader.HeaderContent>
<TextBlock x:Name="title" Style="{StaticResource PageTitleTextBlockStyle}" Text="Hash Permutater"/>
</ctl:PageHeader.HeaderContent>
</ctl:PageHeader>

<ScrollViewer x:Name="LayoutRoot"
Grid.Row="1"
Margin="24,0,0,0">
<StackPanel>
<Grid Margin="0,0,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>

<TextBlock Grid.Row="0" Grid.ColumnSpan="2" HorizontalAlignment="Left" Margin="20,10" Text="Insert the text or data you want to hash into the first text box." Style="{StaticResource BodyTextBlockStyle}" VerticalAlignment="Top"/>
<ComboBox Grid.Row="1" Grid.Column="0" x:Name="ListOfAlgorithms" Margin="20,10,10,10" HorizontalAlignment="Stretch" VerticalAlignment="Top" SelectionChanged="ListOfAlgorithms_SelectionChanged" />
<Button Grid.Row="1" Grid.Column="1" x:Name="Reset" Content="Clear List" HorizontalAlignment="Stretch" Margin="10,10,20,10" VerticalAlignment="Top" Click="Reset_Click" />
<TextBox Grid.Row="2" Grid.Column="0" x:Name="HashToAdd" Margin="20,10,10,10" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" PlaceholderText="Insert hash to add to list" FontFamily="Consolas" />
<Button Grid.Row="2" Grid.Column="1" x:Name="AddHash" Content="Add Hash" HorizontalAlignment="Stretch" Margin="10,10,20,10" VerticalAlignment="Top" Click="AddHash_Click" />
<TextBox Grid.Row="3" Grid.Column="0" x:Name="ExpectedResultHash" Margin="20,10,10,10" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" PlaceholderText="Insert expected result hash" FontFamily="Consolas" />
<Button Grid.Row="3" Grid.Column="1" x:Name="PermutateHashes" Content="Permutate" Margin="10,10,20,10" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Click="PermutateHashes_Click" />
<CheckBox Grid.Row="4" Grid.Column="0" x:Name="DontChangeHashOrder" Content="Do not change order of hashes" HorizontalAlignment="Left" VerticalAlignment="Top" Style="{StaticResource BodyTextBlockStyle}" Margin="20,10" ToolTipService.ToolTip="Select this checkbox to only test different initialization values of a PCR."/>
<Button Grid.Row="4" Grid.Column="1" x:Name="Cancel" Content="Cancel" Margin="20,10" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Click="Cancel_Click" />
<TextBlock Grid.Row="5" Grid.ColumnSpan="2" HorizontalAlignment="Left" Margin="20,10" Text="List of hashes to test with:" Style="{StaticResource BodyTextBlockStyle}" VerticalAlignment="Top" />
<ListView Grid.Row="6" Grid.ColumnSpan="2" x:Name="Hashes" Margin="20,10" HorizontalAlignment="Stretch" VerticalAlignment="Top" FontFamily="Consolas" BorderBrush="{StaticResource ListBoxBorderThemeBrush}"/>
<TextBlock Grid.Row="7" Grid.ColumnSpan="2" HorizontalAlignment="Left" Margin="20,10" Text="Order of hashes used to compute expected value" VerticalAlignment="Top" Style="{StaticResource BodyTextBlockStyle}" />
<ListView Grid.Row="8" Grid.ColumnSpan="2" x:Name="ResultHashes" Margin="20,10" HorizontalAlignment="Stretch" VerticalAlignment="Top" FontFamily="Consolas" BorderBrush="{StaticResource ListBoxBorderThemeBrush}"/>
<ProgressBar Grid.Row="8" Grid.Column="2" x:Name="PercentComputed" Margin="20,10" Visibility="Collapsed" HorizontalAlignment="Stretch" VerticalAlignment="Top" />
</Grid>
</StackPanel>
</ScrollViewer>
</Grid>
</Page>
Loading

0 comments on commit 0f48f17

Please sign in to comment.