Add DES key parity calc utility

This commit is contained in:
Daniel Dugger 2019-09-14 17:03:04 -04:00
parent dde50bd6d7
commit 0d22c498df
6 changed files with 95 additions and 1 deletions

View File

@ -0,0 +1,16 @@
<UserControl x:Class="KFDtool.Gui.Control.UtilFixDesKeyParity"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:KFDtool.Gui.Control"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<Label Content="DES Key IN" HorizontalAlignment="Left" Margin="22,44,0,0" VerticalAlignment="Top"/>
<TextBox Name="txtDesKeyIn" MaxLength="16" HorizontalAlignment="Left" Height="23" Margin="109,47,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="150"/>
<Label Content="DES Key OUT" HorizontalAlignment="Left" Margin="22,78,0,0" VerticalAlignment="Top"/>
<TextBox Name="txtDesKeyOut" MaxLength="16" HorizontalAlignment="Left" Height="23" Margin="109,81,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="150"/>
<Button Content="Fix" Click="Fix_Button_Click" HorizontalAlignment="Left" Margin="109,119,0,0" VerticalAlignment="Top" Width="75"/>
</Grid>
</UserControl>

View File

@ -0,0 +1,65 @@
using KFDtool.P25.Generator;
using KFDtool.Shared;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace KFDtool.Gui.Control
{
/// <summary>
/// Interaction logic for UtilFixDesKeyParity.xaml
/// </summary>
public partial class UtilFixDesKeyParity : UserControl
{
public UtilFixDesKeyParity()
{
InitializeComponent();
}
private void Fix_Button_Click(object sender, RoutedEventArgs e)
{
if (txtDesKeyIn.Text.Length != 16)
{
MessageBox.Show("Invalid key length", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
List<byte> key = new List<byte>();
try
{
key = Utility.ByteStringToByteList(txtDesKeyIn.Text);
}
catch (Exception)
{
MessageBox.Show("Error Parsing Key", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
byte[] outArrKey = null;
try
{
outArrKey = KeyGenerator.FixupKeyParity(key.ToArray());
}
catch (Exception)
{
MessageBox.Show("Error Fixing Key", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
txtDesKeyOut.Text = BitConverter.ToString(outArrKey).Replace("-", string.Empty);
}
}
}

View File

@ -83,6 +83,9 @@
<Compile Include="Control\UtilAdapterSelfTest.xaml.cs">
<DependentUpon>UtilAdapterSelfTest.xaml</DependentUpon>
</Compile>
<Compile Include="Control\UtilFixDesKeyParity.xaml.cs">
<DependentUpon>UtilFixDesKeyParity.xaml</DependentUpon>
</Compile>
<Compile Include="Control\UtilInitAdapter.xaml.cs">
<DependentUpon>UtilInitAdapter.xaml</DependentUpon>
</Compile>
@ -111,6 +114,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Control\UtilFixDesKeyParity.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Control\UtilInitAdapter.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>

View File

@ -20,6 +20,7 @@
<MenuItem Name="NavigateP25ViewKeyInfo" Header="_View Key Info" IsCheckable="True" Click="Navigate_MenuItem_Click"/>
</MenuItem>
<MenuItem Name="UtilityMenu" Header="_Utility">
<MenuItem Name="NavigateUtilityFixDesKeyParity" Header="_Fix DES Key Parity" IsCheckable="True" Click="Navigate_MenuItem_Click" />
<MenuItem Name="NavigateUtilityUpdateAdapterFirmware" Header="_Update Adapter Firmware" IsCheckable="True" Click="Navigate_MenuItem_Click" />
<MenuItem Name="NavigateUtilityInitializeAdapter" Header="_Initialize Adapter" IsCheckable="True" Click="Navigate_MenuItem_Click" />
<MenuItem Name="NavigateUtilityAdapterSelfTest" Header="_Adapter Self Test" IsCheckable="True" Click="Navigate_MenuItem_Click" />

View File

@ -99,6 +99,11 @@ namespace KFDtool.Gui
AppView.Content = new Control.P25ViewKeyInfo();
UpdateTitle("P25 - View Key Info");
}
else if (mi.Name == "NavigateUtilityFixDesKeyParity")
{
AppView.Content = new Control.UtilFixDesKeyParity();
UpdateTitle("Utility - Fix DES Key Parity");
}
else if (mi.Name == "NavigateUtilityUpdateAdapterFirmware")
{
AppView.Content = new Control.UtilUpdateAdapterFw();

View File

@ -10,7 +10,7 @@ namespace KFDtool.P25.Generator
public class KeyGenerator
{
// internal method from .NET 4.8 refsrc system\security\cryptography\utils.cs FixupKeyParity()
private static byte[] FixupKeyParity(byte[] key)
public static byte[] FixupKeyParity(byte[] key)
{
byte[] oddParityKey = new byte[key.Length];
for (int index = 0; index < key.Length; index++)