Add src code
This commit is contained in:
parent
27b0a7f08e
commit
6c3e10033c
|
@ -1,4 +1,4 @@
|
||||||
# gen-act-nvs
|
# gen-act-nvs
|
||||||
|
|
||||||
Generates "act-nvs.dat" from "act.dat"
|
Generates "act-nvs.dat" from "act.dat"
|
||||||
(for testkit/devkit activation)
|
(for testkit/devkit activation)
|
|
@ -0,0 +1,22 @@
|
||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio 15
|
||||||
|
VisualStudioVersion = 15.0.26228.76
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "gen-act-nvs", "gen-act-nvs\gen-act-nvs.csproj", "{B57FBE6F-2457-4487-9092-5901AC4ECFF2}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{B57FBE6F-2457-4487-9092-5901AC4ECFF2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{B57FBE6F-2457-4487-9092-5901AC4ECFF2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{B57FBE6F-2457-4487-9092-5901AC4ECFF2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{B57FBE6F-2457-4487-9092-5901AC4ECFF2}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<configuration>
|
||||||
|
<startup>
|
||||||
|
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
|
||||||
|
</startup>
|
||||||
|
</configuration>
|
|
@ -0,0 +1,108 @@
|
||||||
|
using Org.BouncyCastle.Crypto;
|
||||||
|
using Org.BouncyCastle.Crypto.Engines;
|
||||||
|
using Org.BouncyCastle.Crypto.Macs;
|
||||||
|
using Org.BouncyCastle.Crypto.Parameters;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace gen_act_nvs
|
||||||
|
{
|
||||||
|
class Program
|
||||||
|
{
|
||||||
|
static byte[] ACT_NVS_KEY = new byte[] { 0x5A, 0x91, 0xFC, 0x74, 0xA8, 0x2B, 0xE3, 0xF2, 0xB8, 0xF4, 0xDB, 0x60, 0x70, 0xA0, 0x99, 0xA2, 0xBD, 0xF0, 0x0E, 0x7B, 0xF0, 0x0E, 0x7B, 0xF0, 0x8B, 0x68, 0x55, 0x34, 0xA0, 0x64, 0x6D, 0x87 };
|
||||||
|
static void WriteString(Stream stream, string str)
|
||||||
|
{
|
||||||
|
byte[] strBytes = Encoding.UTF8.GetBytes(str);
|
||||||
|
stream.Write(strBytes, 0x00, strBytes.Length);
|
||||||
|
stream.WriteByte(0x00);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void WriteInt32(Stream stream, Int32 numb)
|
||||||
|
{
|
||||||
|
byte[] intBytes = BitConverter.GetBytes(numb);
|
||||||
|
stream.Write(intBytes, 0x00, intBytes.Length);
|
||||||
|
}
|
||||||
|
static Int32 ReadInt32(Stream stream)
|
||||||
|
{
|
||||||
|
byte[] intBytes = new byte[0x4];
|
||||||
|
stream.Read(intBytes, 0x00, intBytes.Length);
|
||||||
|
return BitConverter.ToInt32(intBytes, 0x00);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Main(string[] args)
|
||||||
|
{
|
||||||
|
if (args.Length >= 1)
|
||||||
|
{
|
||||||
|
string actPath = args[0];
|
||||||
|
string actNvsPath = "";
|
||||||
|
if (args.Length >= 2)
|
||||||
|
{
|
||||||
|
actNvsPath = args[1];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
actNvsPath = Path.Combine(Path.GetDirectoryName(actPath), "act-nvs.dat");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (File.Exists(actNvsPath))
|
||||||
|
{
|
||||||
|
Console.WriteLine(actNvsPath + " Allready exists!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
FileStream act = new FileStream(actPath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
|
||||||
|
FileStream nvsAct = new FileStream(actNvsPath, FileMode.CreateNew, FileAccess.ReadWrite);
|
||||||
|
|
||||||
|
act.Seek(0x8, SeekOrigin.Begin);
|
||||||
|
int IssueNo = ReadInt32(act);
|
||||||
|
int StartDate = ReadInt32(act);
|
||||||
|
int EndDate = ReadInt32(act);
|
||||||
|
|
||||||
|
|
||||||
|
WriteString(nvsAct, "act");
|
||||||
|
WriteInt32(nvsAct, IssueNo);
|
||||||
|
WriteInt32(nvsAct, EndDate);
|
||||||
|
WriteInt32(nvsAct, StartDate);
|
||||||
|
|
||||||
|
Console.WriteLine("Writing nvs-act.dat\n");
|
||||||
|
Console.WriteLine("Issue No. " + IssueNo.ToString());
|
||||||
|
Console.WriteLine("End Date " + EndDate.ToString());
|
||||||
|
Console.WriteLine("Start Date " + StartDate.ToString());
|
||||||
|
Console.WriteLine("\nCaclulating CMAC");
|
||||||
|
|
||||||
|
//Calculate CMAC
|
||||||
|
nvsAct.Seek(0x00, SeekOrigin.Begin);
|
||||||
|
byte[] actBuffer = new byte[0x10];
|
||||||
|
nvsAct.Read(actBuffer, 0x00, actBuffer.Length);
|
||||||
|
|
||||||
|
IBlockCipher cipher = new AesEngine();
|
||||||
|
IMac mac = new CMac(cipher, 128);
|
||||||
|
KeyParameter key = new KeyParameter(ACT_NVS_KEY);
|
||||||
|
mac.Init(key);
|
||||||
|
mac.BlockUpdate(actBuffer, 0, actBuffer.Length);
|
||||||
|
byte[] outBytes = new byte[16];
|
||||||
|
mac.DoFinal(outBytes, 0);
|
||||||
|
|
||||||
|
nvsAct.Seek(0x10, SeekOrigin.Begin);
|
||||||
|
nvsAct.Write(outBytes,0x00,outBytes.Length);
|
||||||
|
|
||||||
|
foreach(byte b in outBytes)
|
||||||
|
{
|
||||||
|
Console.Write(b.ToString("X") + " ");
|
||||||
|
}
|
||||||
|
Console.WriteLine("\nDone!");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine("gen-act-nvs <input act> [output act]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
// General Information about an assembly is controlled through the following
|
||||||
|
// set of attributes. Change these attribute values to modify the information
|
||||||
|
// associated with an assembly.
|
||||||
|
[assembly: AssemblyTitle("gen-act-nvs")]
|
||||||
|
[assembly: AssemblyDescription("")]
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("")]
|
||||||
|
[assembly: AssemblyProduct("gen-act-nvs")]
|
||||||
|
[assembly: AssemblyCopyright("Copyright © 2019")]
|
||||||
|
[assembly: AssemblyTrademark("")]
|
||||||
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
|
// Setting ComVisible to false makes the types in this assembly not visible
|
||||||
|
// to COM components. If you need to access a type in this assembly from
|
||||||
|
// COM, set the ComVisible attribute to true on that type.
|
||||||
|
[assembly: ComVisible(false)]
|
||||||
|
|
||||||
|
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||||
|
[assembly: Guid("b57fbe6f-2457-4487-9092-5901ac4ecff2")]
|
||||||
|
|
||||||
|
// Version information for an assembly consists of the following four values:
|
||||||
|
//
|
||||||
|
// Major Version
|
||||||
|
// Minor Version
|
||||||
|
// Build Number
|
||||||
|
// Revision
|
||||||
|
//
|
||||||
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
|
// by using the '*' as shown below:
|
||||||
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
|
[assembly: AssemblyVersion("1.0.0.0")]
|
||||||
|
[assembly: AssemblyFileVersion("1.0.0.0")]
|
|
@ -0,0 +1,56 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
|
<ProjectGuid>{B57FBE6F-2457-4487-9092-5901AC4ECFF2}</ProjectGuid>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<RootNamespace>gen_act_nvs</RootNamespace>
|
||||||
|
<AssemblyName>gen-act-nvs</AssemblyName>
|
||||||
|
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||||
|
<FileAlignment>512</FileAlignment>
|
||||||
|
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
<OutputPath>bin\Debug\</OutputPath>
|
||||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="BouncyCastle.Crypto, Version=1.8.5.0, Culture=neutral, PublicKeyToken=0e99375e54769942">
|
||||||
|
<HintPath>..\packages\BouncyCastle.1.8.5\lib\BouncyCastle.Crypto.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.Core" />
|
||||||
|
<Reference Include="System.Xml.Linq" />
|
||||||
|
<Reference Include="System.Data.DataSetExtensions" />
|
||||||
|
<Reference Include="Microsoft.CSharp" />
|
||||||
|
<Reference Include="System.Data" />
|
||||||
|
<Reference Include="System.Net.Http" />
|
||||||
|
<Reference Include="System.Xml" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="Program.cs" />
|
||||||
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="App.config" />
|
||||||
|
<None Include="packages.config" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
</Project>
|
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<packages>
|
||||||
|
<package id="BouncyCastle" version="1.8.5" targetFramework="net452" />
|
||||||
|
</packages>
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,30 @@
|
||||||
|
# The Bouncy Castle Crypto Package For C Sharp
|
||||||
|
|
||||||
|
The Bouncy Castle Crypto package is a C\# implementation of cryptographic algorithms and protocols, it was developed by the Legion of the Bouncy Castle, a registered Australian Charity, with a little help! The Legion, and the latest goings on with this package, can be found at [http://www.bouncycastle.org](http://www.bouncycastle.org). In addition to providing basic cryptography algorithms, the package also provides support for CMS, TSP, X.509 certificate generation and a variety of other standards such as OpenPGP.
|
||||||
|
|
||||||
|
The Legion also gratefully acknowledges the contributions made to this package by others (see [here](http://www.bouncycastle.org/csharp/contributors.html) for the current list). If you would like to contribute to our efforts please feel free to get in touch with us or visit our [donations page](https://www.bouncycastle.org/donate), sponsor some specific work, or purchase a support contract through [Crypto Workshop](http://www.cryptoworkshop.com).
|
||||||
|
|
||||||
|
Except where otherwise stated, this software is distributed under a license based on the MIT X Consortium license. To view the license, [see here](http://www.bouncycastle.org/licence.html). The OpenPGP library also includes a modified BZIP2 library which is licensed under the [Apache Software License, Version 2.0](http://www.apache.org/licenses/).
|
||||||
|
|
||||||
|
**Note**: this source tree is not the FIPS version of the APIs - if you are interested in our FIPS version please contact us directly at [office@bouncycastle.org](mailto:office@bouncycastle.org).
|
||||||
|
|
||||||
|
## Mailing Lists
|
||||||
|
|
||||||
|
For those who are interested, there are 2 mailing lists for participation in this project. To subscribe use the links below and include the word subscribe in the message body. (To unsubscribe, replace **subscribe** with **unsubscribe** in the message body)
|
||||||
|
|
||||||
|
* [announce-crypto-csharp-request@bouncycastle.org](mailto:announce-crypto-csharp-request@bouncycastle.org)
|
||||||
|
This mailing list is for new release announcements only, general subscribers cannot post to it.
|
||||||
|
* [dev-crypto-csharp-request@bouncycastle.org](mailto:dev-crypto-csharp-request@bouncycastle.org)
|
||||||
|
This mailing list is for discussion of development of the package. This includes bugs, comments, requests for enhancements, questions about use or operation.
|
||||||
|
|
||||||
|
**NOTE:**You need to be subscribed to send mail to the above mailing list.
|
||||||
|
|
||||||
|
## Feedback
|
||||||
|
|
||||||
|
If you want to provide feedback directly to the members of **The Legion** then please use [feedback-crypto@bouncycastle.org](mailto:feedback-crypto@bouncycastle.org), if you want to help this project survive please consider [donating](https://www.bouncycastle.org/donate).
|
||||||
|
|
||||||
|
For bug reporting/requests you can report issues here on github, via feedback-crypto if required, and we also have a [Jira issue tracker](http://www.bouncycastle.org/jira). We will accept pull requests based on this repository as well.
|
||||||
|
|
||||||
|
## Finally
|
||||||
|
|
||||||
|
Enjoy!
|
Binary file not shown.
Loading…
Reference in New Issue