Condense crypto and compress wrapper libraries into foundation.

This commit is contained in:
jakcron 2018-08-07 16:35:03 +08:00
parent ebbdbcd364
commit 99420f28bf
84 changed files with 402 additions and 882 deletions

View file

@ -28,10 +28,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libpolarssl", "lib\libpolar
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "liblz4", "lib\liblz4\liblz4.vcxproj", "{AB0C3362-63AB-480A-ADBC-2EF7D859778B}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libcrypto", "lib\libcrypto\libcrypto.vcxproj", "{6ADBB60D-DBA0-411D-BD2D-A355EF8E0FE1}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libcompress", "lib\libcompress\libcompress.vcxproj", "{CF01B5B7-730A-447F-9BB2-5EDA9B082177}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libpki", "lib\libpki\libpki.vcxproj", "{B9113734-6E84-44FF-8CF7-58199AA815C5}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libes", "lib\libes\libes.vcxproj", "{7BE99936-0D40-410D-944B-4513C2EFF8DC}"
@ -74,14 +70,6 @@ Global
{AB0C3362-63AB-480A-ADBC-2EF7D859778B}.Release|x64.Build.0 = Release|x64
{AB0C3362-63AB-480A-ADBC-2EF7D859778B}.Release|x86.ActiveCfg = Release|Win32
{AB0C3362-63AB-480A-ADBC-2EF7D859778B}.Release|x86.Build.0 = Release|Win32
{6ADBB60D-DBA0-411D-BD2D-A355EF8E0FE1}.Debug|x64.ActiveCfg = Debug|x64
{6ADBB60D-DBA0-411D-BD2D-A355EF8E0FE1}.Debug|x64.Build.0 = Debug|x64
{6ADBB60D-DBA0-411D-BD2D-A355EF8E0FE1}.Debug|x86.ActiveCfg = Debug|Win32
{6ADBB60D-DBA0-411D-BD2D-A355EF8E0FE1}.Debug|x86.Build.0 = Debug|Win32
{6ADBB60D-DBA0-411D-BD2D-A355EF8E0FE1}.Release|x64.ActiveCfg = Release|x64
{6ADBB60D-DBA0-411D-BD2D-A355EF8E0FE1}.Release|x64.Build.0 = Release|x64
{6ADBB60D-DBA0-411D-BD2D-A355EF8E0FE1}.Release|x86.ActiveCfg = Release|Win32
{6ADBB60D-DBA0-411D-BD2D-A355EF8E0FE1}.Release|x86.Build.0 = Release|Win32
{91BA9E79-8242-4F7D-B997-0DFEC95EA22B}.Debug|x64.ActiveCfg = Debug|x64
{91BA9E79-8242-4F7D-B997-0DFEC95EA22B}.Debug|x64.Build.0 = Debug|x64
{91BA9E79-8242-4F7D-B997-0DFEC95EA22B}.Debug|x86.ActiveCfg = Debug|Win32
@ -98,14 +86,6 @@ Global
{7BE99936-0D40-410D-944B-4513C2EFF8DC}.Release|x64.Build.0 = Release|x64
{7BE99936-0D40-410D-944B-4513C2EFF8DC}.Release|x86.ActiveCfg = Release|Win32
{7BE99936-0D40-410D-944B-4513C2EFF8DC}.Release|x86.Build.0 = Release|Win32
{CF01B5B7-730A-447F-9BB2-5EDA9B082177}.Debug|x64.ActiveCfg = Debug|x64
{CF01B5B7-730A-447F-9BB2-5EDA9B082177}.Debug|x64.Build.0 = Debug|x64
{CF01B5B7-730A-447F-9BB2-5EDA9B082177}.Debug|x86.ActiveCfg = Debug|Win32
{CF01B5B7-730A-447F-9BB2-5EDA9B082177}.Debug|x86.Build.0 = Debug|Win32
{CF01B5B7-730A-447F-9BB2-5EDA9B082177}.Release|x64.ActiveCfg = Release|x64
{CF01B5B7-730A-447F-9BB2-5EDA9B082177}.Release|x64.Build.0 = Release|x64
{CF01B5B7-730A-447F-9BB2-5EDA9B082177}.Release|x86.ActiveCfg = Release|Win32
{CF01B5B7-730A-447F-9BB2-5EDA9B082177}.Release|x86.Build.0 = Release|Win32
{738CB4FC-CD9E-4B81-A04B-DEADBFA71C63}.Debug|x64.ActiveCfg = Debug|x64
{738CB4FC-CD9E-4B81-A04B-DEADBFA71C63}.Debug|x64.Build.0 = Debug|x64
{738CB4FC-CD9E-4B81-A04B-DEADBFA71C63}.Debug|x86.ActiveCfg = Debug|Win32
@ -138,10 +118,8 @@ Global
{4D27EDB9-5110-44FE-8CE2-D46C5AD3C55B} = {170B4A09-1B67-4A62-93AB-116EBCFF4A8C}
{394EFC16-BD3A-4538-B33D-7BA1EDB8DAC1} = {170B4A09-1B67-4A62-93AB-116EBCFF4A8C}
{AB0C3362-63AB-480A-ADBC-2EF7D859778B} = {170B4A09-1B67-4A62-93AB-116EBCFF4A8C}
{6ADBB60D-DBA0-411D-BD2D-A355EF8E0FE1} = {170B4A09-1B67-4A62-93AB-116EBCFF4A8C}
{91BA9E79-8242-4F7D-B997-0DFEC95EA22B} = {170B4A09-1B67-4A62-93AB-116EBCFF4A8C}
{7BE99936-0D40-410D-944B-4513C2EFF8DC} = {170B4A09-1B67-4A62-93AB-116EBCFF4A8C}
{CF01B5B7-730A-447F-9BB2-5EDA9B082177} = {170B4A09-1B67-4A62-93AB-116EBCFF4A8C}
{738CB4FC-CD9E-4B81-A04B-DEADBFA71C63} = {170B4A09-1B67-4A62-93AB-116EBCFF4A8C}
{B9113734-6E84-44FF-8CF7-58199AA815C5} = {170B4A09-1B67-4A62-93AB-116EBCFF4A8C}
{AF09FA96-4463-417D-8FE6-526063F41349} = {E0863FCC-8E72-490D-BE1B-458F12CA8298}

View file

@ -1,133 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>15.0</VCProjectVersion>
<ProjectGuid>{CF01B5B7-730A-447F-9BB2-5EDA9B082177}</ProjectGuid>
<RootNamespace>libcompress</RootNamespace>
<WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>..\libcompress\include;..\liblz4\include;</AdditionalIncludeDirectories>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>..\libcompress\include;..\liblz4\include;</AdditionalIncludeDirectories>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>..\libcompress\include;..\liblz4\include;</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>..\libcompress\include;..\liblz4\include;</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="include\compress\lz4.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="source\lz4_wrapper.cpp" />
</ItemGroup>
<ItemGroup>
<None Include="makefile" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View file

@ -1,30 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="include\compress\lz4.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="source\lz4_wrapper.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="makefile" />
</ItemGroup>
</Project>

View file

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>

View file

@ -1,46 +0,0 @@
# Sources
SRC_DIR = source
OBJS = $(foreach dir,$(SRC_DIR),$(subst .cpp,.o,$(wildcard $(dir)/*.cpp))) $(foreach dir,$(SRC_DIR),$(subst .c,.o,$(wildcard $(dir)/*.c)))
# External dependencies
DEPENDS = lz4
LIB_DIR = ..
INCS = -I"include" $(foreach dep,$(DEPENDS), -I"$(LIB_DIR)/lib$(dep)/include")
# Compiler Settings
CXXFLAGS = -std=c++11 $(INCS) -D__STDC_FORMAT_MACROS -Wall -Wno-unused-value
CFLAGS = -std=c11 $(INCS) -Wall -Wno-unused-value
ARFLAGS = cr -o
ifeq ($(OS),Windows_NT)
# Windows Only Flags/Libs
CC = x86_64-w64-mingw32-gcc
CXX = x86_64-w64-mingw32-g++
CFLAGS += -Wno-unused-but-set-variable
CXXFLAGS += -Wno-unused-but-set-variable
else
UNAME = $(shell uname -s)
ifeq ($(UNAME), Darwin)
# MacOS Only Flags/Libs
CFLAGS += -Wno-unused-private-field
CXXFLAGS += -Wno-unused-private-field
ARFLAGS = rc
else
# *nix Only Flags/Libs
CFLAGS += -Wno-unused-but-set-variable
CXXFLAGS += -Wno-unused-but-set-variable
endif
endif
# Output
OUTPUT = $(shell basename $(CURDIR)).a
main: build
rebuild: clean build
build: $(OBJS)
ar $(ARFLAGS) $(OUTPUT) $(OBJS)
clean:
rm -rf $(OUTPUT) $(OBJS)

View file

@ -1,14 +0,0 @@
#include <compress/lz4.h>
#include <lz4.h>
void compress::lz4::compressData(const uint8_t* src, uint32_t src_len, uint8_t* dst, uint32_t dst_capacity, uint32_t& compressed_size)
{
compressed_size = LZ4_compress_default((const char*)src, (char*)dst, (int)src_len, (int)dst_capacity);
}
void compress::lz4::decompressData(const uint8_t* src, uint32_t src_len, uint8_t* dst, uint32_t dst_capacity, uint32_t& decompressed_size)
{
decompressed_size = LZ4_decompress_safe((const char*)src, (char*)dst, (int)src_len, (int)dst_capacity);
}

View file

@ -1,139 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>15.0</VCProjectVersion>
<ProjectGuid>{6ADBB60D-DBA0-411D-BD2D-A355EF8E0FE1}</ProjectGuid>
<WindowsTargetPlatformVersion>10.0.15063.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>..\libfnd\include;..\libcrypto\include;..\libpolarssl\include;</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_MBCS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>..\libfnd\include;..\libcrypto\include;..\libpolarssl\include;</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_MBCS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>..\libfnd\include;..\libcrypto\include;..\libpolarssl\include;</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_MBCS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>..\libfnd\include;..\libcrypto\include;..\libpolarssl\include;</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_MBCS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="include\crypto\aes.h" />
<ClInclude Include="include\crypto\base64.h" />
<ClInclude Include="include\crypto\ecdsa.h" />
<ClInclude Include="include\crypto\rsa.h" />
<ClInclude Include="include\crypto\sha.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="source\aes_wrapper.cpp" />
<ClCompile Include="source\base64_wrapper.cpp" />
<ClCompile Include="source\rsa_wrapper.cpp" />
<ClCompile Include="source\sha_wrapper.cpp" />
</ItemGroup>
<ItemGroup>
<None Include="makefile" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View file

@ -1,51 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="include\crypto\aes.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\crypto\rsa.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\crypto\sha.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\crypto\ecdsa.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\crypto\base64.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="source\aes_wrapper.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="source\rsa_wrapper.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="source\sha_wrapper.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="source\base64_wrapper.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="makefile" />
</ItemGroup>
</Project>

View file

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>

View file

@ -1,45 +0,0 @@
# Sources
SRC_DIR = source
OBJS = $(foreach dir,$(SRC_DIR),$(subst .cpp,.o,$(wildcard $(dir)/*.cpp))) $(foreach dir,$(SRC_DIR),$(subst .c,.o,$(wildcard $(dir)/*.c)))
# External dependencies
DEPENDS = fnd polarssl
LIB_DIR = ..
INCS = -I"include" $(foreach dep,$(DEPENDS), -I"$(LIB_DIR)/lib$(dep)/include")
# Compiler Settings
CXXFLAGS = -std=c++11 $(INCS) -D__STDC_FORMAT_MACROS -Wall -Wno-unused-value
CFLAGS = -std=c11 $(INCS) -Wall -Wno-unused-value
ARFLAGS = cr -o
ifeq ($(OS),Windows_NT)
# Windows Only Flags/Libs
CC = x86_64-w64-mingw32-gcc
CXX = x86_64-w64-mingw32-g++
CFLAGS += -Wno-unused-but-set-variable
CXXFLAGS += -Wno-unused-but-set-variable
else
UNAME = $(shell uname -s)
ifeq ($(UNAME), Darwin)
# MacOS Only Flags/Libs
CFLAGS += -arch x86_64 -Wno-unused-private-field
CXXFLAGS += -arch x86_64 -Wno-unused-private-field
ARFLAGS = rc
else
# *nix Only Flags/Libs
CFLAGS += -Wno-unused-but-set-variable
CXXFLAGS += -Wno-unused-but-set-variable
endif
endif
# Output
OUTPUT = $(shell basename $(CURDIR)).a
main: build
rebuild: clean build
build: $(OBJS)
ar $(ARFLAGS) $(OUTPUT) $(OBJS)
clean:
rm -rf $(OUTPUT) $(OBJS)

View file

@ -1,30 +0,0 @@
#include <crypto/base64.h>
#include <polarssl/base64.h>
size_t crypto::base64::B64_GetEncodeLen(const uint8_t* src, size_t slen)
{
size_t dlen = 0;
base64_encode(nullptr, &dlen, src, slen);
return dlen;
}
void crypto::base64::B64_Encode(const uint8_t* src, size_t slen, uint8_t* dst, size_t dlen)
{
base64_encode(dst, &dlen, src, slen);
}
size_t crypto::base64::B64_GetDecodeLen(const uint8_t* src, size_t slen)
{
size_t dlen = 0;
base64_decode(nullptr, &dlen, src, slen);
return dlen;
}
void crypto::base64::B64_Decode(const uint8_t* src, size_t slen, uint8_t* dst, size_t dlen)
{
base64_decode(dst, &dlen, src, slen);
}

View file

@ -1,15 +0,0 @@
#include <crypto/sha.h>
#include <polarssl/sha1.h>
#include <polarssl/sha2.h>
using namespace crypto::sha;
void crypto::sha::Sha1(const uint8_t* in, uint64_t size, uint8_t hash[kSha1HashLen])
{
sha1(in, size, hash);
}
void crypto::sha::Sha256(const uint8_t* in, uint64_t size, uint8_t hash[kSha256HashLen])
{
sha2(in, size, hash, false);
}

View file

@ -1,7 +1,7 @@
#pragma once
#include <string>
#include <fnd/types.h>
#include <crypto/rsa.h>
#include <fnd/rsa.h>
namespace nn
{
@ -44,7 +44,7 @@ namespace es
static const size_t kIssuerSize = 0x40;
static const byte_t kFormatVersion = 2;
static const size_t kEncTitleKeySize = crypto::rsa::kRsa2048Size;
static const size_t kEncTitleKeySize = fnd::rsa::kRsa2048Size;
static const size_t kReservedRegionSize = 8;
static const size_t kRightsIdSize = 16;
}

View file

@ -73,7 +73,7 @@
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>..\libfnd\include;..\libcrypto\include;..\libes\include;</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\libfnd\include;..\libes\include;</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_MBCS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>
@ -82,7 +82,7 @@
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>..\libfnd\include;..\libcrypto\include;..\libes\include;</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\libfnd\include;..\libes\include;</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_MBCS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>
@ -93,7 +93,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>..\libfnd\include;..\libcrypto\include;..\libes\include;</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\libfnd\include;..\libes\include;</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_MBCS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
@ -108,7 +108,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>..\libfnd\include;..\libcrypto\include;..\libes\include;</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\libfnd\include;..\libes\include;</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_MBCS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>

View file

@ -2,7 +2,7 @@
#include <cstdint>
#include <cstring>
namespace crypto
namespace fnd
{
namespace aes
{

View file

@ -2,7 +2,7 @@
#include <cstdint>
#include <cstring>
namespace crypto
namespace fnd
{
namespace base64
{

View file

@ -2,7 +2,7 @@
#include <cstdint>
#include <cstring>
namespace crypto
namespace fnd
{
namespace ecdsa
{

View file

@ -1,7 +1,7 @@
#pragma once
#include <string>
namespace compress
namespace fnd
{
namespace lz4
{

View file

@ -1,9 +1,9 @@
#pragma once
#include <cstdint>
#include <cstring>
#include <crypto/sha.h>
#include <fnd/sha.h>
namespace crypto
namespace fnd
{
namespace rsa
{

View file

@ -2,7 +2,7 @@
#include <cstdint>
#include <cstring>
namespace crypto
namespace fnd
{
namespace sha
{

View file

@ -3,7 +3,7 @@ SRC_DIR = source
OBJS = $(foreach dir,$(SRC_DIR),$(subst .cpp,.o,$(wildcard $(dir)/*.cpp))) $(foreach dir,$(SRC_DIR),$(subst .c,.o,$(wildcard $(dir)/*.c)))
# External dependencies
DEPENDS =
DEPENDS = polarssl lz4
LIB_DIR = ..
INCS = -I"include" $(foreach dep,$(DEPENDS), -I"$(LIB_DIR)/lib$(dep)/include")

View file

@ -1,7 +1,7 @@
#include <crypto/aes.h>
#include <fnd/aes.h>
#include <polarssl/aes.h>
using namespace crypto::aes;
using namespace fnd::aes;
inline void XorBlock(const uint8_t a[kAesBlockSize], const uint8_t b[kAesBlockSize], uint8_t out[kAesBlockSize])
{
@ -16,7 +16,7 @@ inline void putbe32(uint8_t* data, uint32_t val) { data[0] = val >> 24; data[1]
void crypto::aes::AesEcbDecrypt(const uint8_t * in, uint64_t size, const uint8_t key[kAes128KeySize], uint8_t * out)
void fnd::aes::AesEcbDecrypt(const uint8_t * in, uint64_t size, const uint8_t key[kAes128KeySize], uint8_t * out)
{
aes_context ctx;
aes_setkey_dec(&ctx, key, 128);
@ -28,7 +28,7 @@ void crypto::aes::AesEcbDecrypt(const uint8_t * in, uint64_t size, const uint8_t
}
void crypto::aes::AesEcbEncrypt(const uint8_t * in, uint64_t size, const uint8_t key[kAes128KeySize], uint8_t * out)
void fnd::aes::AesEcbEncrypt(const uint8_t * in, uint64_t size, const uint8_t key[kAes128KeySize], uint8_t * out)
{
aes_context ctx;
aes_setkey_enc(&ctx, key, 128);
@ -38,7 +38,7 @@ void crypto::aes::AesEcbEncrypt(const uint8_t * in, uint64_t size, const uint8_t
}
}
void crypto::aes::AesCtr(const uint8_t* in, uint64_t size, const uint8_t key[kAes128KeySize], uint8_t ctr[kAesBlockSize], uint8_t* out)
void fnd::aes::AesCtr(const uint8_t* in, uint64_t size, const uint8_t key[kAes128KeySize], uint8_t ctr[kAesBlockSize], uint8_t* out)
{
aes_context ctx;
uint8_t block[kAesBlockSize] = { 0 };
@ -48,7 +48,7 @@ void crypto::aes::AesCtr(const uint8_t* in, uint64_t size, const uint8_t key[kAe
aes_crypt_ctr(&ctx, size, &counterOffset, ctr, block, in, out);
}
void crypto::aes::AesIncrementCounter(const uint8_t in[kAesBlockSize], size_t block_num, uint8_t out[kAesBlockSize])
void fnd::aes::AesIncrementCounter(const uint8_t in[kAesBlockSize], size_t block_num, uint8_t out[kAesBlockSize])
{
memcpy(out, in, kAesBlockSize);
@ -78,21 +78,21 @@ void crypto::aes::AesIncrementCounter(const uint8_t in[kAesBlockSize], size_t bl
putbe32(&out[12], ctr[0]);
}
void crypto::aes::AesCbcDecrypt(const uint8_t* in, uint64_t size, const uint8_t key[kAes128KeySize], uint8_t iv[kAesBlockSize], uint8_t* out)
void fnd::aes::AesCbcDecrypt(const uint8_t* in, uint64_t size, const uint8_t key[kAes128KeySize], uint8_t iv[kAesBlockSize], uint8_t* out)
{
aes_context ctx;
aes_setkey_dec(&ctx, key, 128);
aes_crypt_cbc(&ctx, AES_DECRYPT, size, iv, in, out);
}
void crypto::aes::AesCbcEncrypt(const uint8_t* in, uint64_t size, const uint8_t key[kAes128KeySize], uint8_t iv[kAesBlockSize], uint8_t* out)
void fnd::aes::AesCbcEncrypt(const uint8_t* in, uint64_t size, const uint8_t key[kAes128KeySize], uint8_t iv[kAesBlockSize], uint8_t* out)
{
aes_context ctx;
aes_setkey_enc(&ctx, key, 128);
aes_crypt_cbc(&ctx, AES_ENCRYPT, size, iv, in, out);
}
void crypto::aes::AesXtsDecryptSector(const uint8_t * in, uint64_t sector_size, const uint8_t key1[kAes128KeySize], const uint8_t key2[kAes128KeySize], uint8_t tweak[kAesBlockSize], uint8_t * out)
void fnd::aes::AesXtsDecryptSector(const uint8_t * in, uint64_t sector_size, const uint8_t key1[kAes128KeySize], const uint8_t key2[kAes128KeySize], uint8_t tweak[kAesBlockSize], uint8_t * out)
{
aes_context data_ctx;
aes_setkey_dec(&data_ctx, key1, 128);
@ -116,7 +116,7 @@ void crypto::aes::AesXtsDecryptSector(const uint8_t * in, uint64_t sector_size,
}
}
void crypto::aes::AesXtsEncryptSector(const uint8_t * in, uint64_t sector_size, const uint8_t key1[kAes128KeySize], const uint8_t key2[kAes128KeySize], uint8_t tweak[kAesBlockSize], uint8_t * out)
void fnd::aes::AesXtsEncryptSector(const uint8_t * in, uint64_t sector_size, const uint8_t key1[kAes128KeySize], const uint8_t key2[kAes128KeySize], uint8_t tweak[kAesBlockSize], uint8_t * out)
{
aes_context data_ctx;
aes_setkey_enc(&data_ctx, key1, 128);
@ -140,13 +140,13 @@ void crypto::aes::AesXtsEncryptSector(const uint8_t * in, uint64_t sector_size,
}
}
void crypto::aes::AesXtsMakeTweak(uint8_t tweak[kAesBlockSize], size_t block_index)
void fnd::aes::AesXtsMakeTweak(uint8_t tweak[kAesBlockSize], size_t block_index)
{
memset(tweak, 0, kAesBlockSize);
AesIncrementCounter(tweak, block_index, tweak);
}
void crypto::aes::GaloisFunc(uint8_t x[kAesBlockSize])
void fnd::aes::GaloisFunc(uint8_t x[kAesBlockSize])
{
uint8_t t = x[15];

View file

@ -0,0 +1,30 @@
#include <fnd/base64.h>
#include <polarssl/base64.h>
size_t fnd::base64::B64_GetEncodeLen(const uint8_t* src, size_t slen)
{
size_t dlen = 0;
base64_encode(nullptr, &dlen, src, slen);
return dlen;
}
void fnd::base64::B64_Encode(const uint8_t* src, size_t slen, uint8_t* dst, size_t dlen)
{
base64_encode(dst, &dlen, src, slen);
}
size_t fnd::base64::B64_GetDecodeLen(const uint8_t* src, size_t slen)
{
size_t dlen = 0;
base64_decode(nullptr, &dlen, src, slen);
return dlen;
}
void fnd::base64::B64_Decode(const uint8_t* src, size_t slen, uint8_t* dst, size_t dlen)
{
base64_decode(dst, &dlen, src, slen);
}

View file

@ -0,0 +1,14 @@
#include <fnd/lz4.h>
#include <lz4.h>
void fnd::lz4::compressData(const uint8_t* src, uint32_t src_len, uint8_t* dst, uint32_t dst_capacity, uint32_t& compressed_size)
{
compressed_size = LZ4_compress_default((const char*)src, (char*)dst, (int)src_len, (int)dst_capacity);
}
void fnd::lz4::decompressData(const uint8_t* src, uint32_t src_len, uint8_t* dst, uint32_t dst_capacity, uint32_t& decompressed_size)
{
decompressed_size = LZ4_decompress_safe((const char*)src, (char*)dst, (int)src_len, (int)dst_capacity);
}

View file

@ -1,9 +1,9 @@
#include <crypto/rsa.h>
#include <fnd/rsa.h>
#include <polarssl/rsa.h>
#include <polarssl/md.h>
using namespace crypto::rsa;
using namespace crypto::sha;
using namespace fnd::rsa;
using namespace fnd::sha;
int getWrappedHashType(HashType type)
{
@ -57,7 +57,7 @@ uint32_t getWrappedHashSize(HashType type)
return size;
}
int crypto::rsa::pkcs::rsaSign(const sRsa1024Key & key, HashType hash_type, const uint8_t * hash, uint8_t signature[kRsa1024Size])
int fnd::rsa::pkcs::rsaSign(const sRsa1024Key & key, HashType hash_type, const uint8_t * hash, uint8_t signature[kRsa1024Size])
{
int ret;
rsa_context ctx;
@ -74,7 +74,7 @@ int crypto::rsa::pkcs::rsaSign(const sRsa1024Key & key, HashType hash_type, cons
return ret;
}
int crypto::rsa::pkcs::rsaVerify(const sRsa1024Key & key, HashType hash_type, const uint8_t * hash, const uint8_t signature[kRsa1024Size])
int fnd::rsa::pkcs::rsaVerify(const sRsa1024Key & key, HashType hash_type, const uint8_t * hash, const uint8_t signature[kRsa1024Size])
{
static const uint8_t public_exponent[3] = { 0x01, 0x00, 0x01 };
@ -93,7 +93,7 @@ int crypto::rsa::pkcs::rsaVerify(const sRsa1024Key & key, HashType hash_type, co
return ret;
}
int crypto::rsa::pkcs::rsaSign(const sRsa2048Key & key, HashType hash_type, const uint8_t * hash, uint8_t signature[kRsa2048Size])
int fnd::rsa::pkcs::rsaSign(const sRsa2048Key & key, HashType hash_type, const uint8_t * hash, uint8_t signature[kRsa2048Size])
{
int ret;
rsa_context ctx;
@ -110,7 +110,7 @@ int crypto::rsa::pkcs::rsaSign(const sRsa2048Key & key, HashType hash_type, cons
return ret;
}
int crypto::rsa::pkcs::rsaVerify(const sRsa2048Key & key, HashType hash_type, const uint8_t * hash, const uint8_t signature[kRsa2048Size])
int fnd::rsa::pkcs::rsaVerify(const sRsa2048Key & key, HashType hash_type, const uint8_t * hash, const uint8_t signature[kRsa2048Size])
{
static const uint8_t public_exponent[3] = { 0x01, 0x00, 0x01 };
@ -129,7 +129,7 @@ int crypto::rsa::pkcs::rsaVerify(const sRsa2048Key & key, HashType hash_type, co
return ret;
}
int crypto::rsa::pkcs::rsaSign(const sRsa4096Key & key, HashType hash_type, const uint8_t * hash, uint8_t signature[kRsa4096Size])
int fnd::rsa::pkcs::rsaSign(const sRsa4096Key & key, HashType hash_type, const uint8_t * hash, uint8_t signature[kRsa4096Size])
{
int ret;
rsa_context ctx;
@ -146,7 +146,7 @@ int crypto::rsa::pkcs::rsaSign(const sRsa4096Key & key, HashType hash_type, cons
return ret;
}
int crypto::rsa::pkcs::rsaVerify(const sRsa4096Key & key, HashType hash_type, const uint8_t * hash, const uint8_t signature[kRsa4096Size])
int fnd::rsa::pkcs::rsaVerify(const sRsa4096Key & key, HashType hash_type, const uint8_t * hash, const uint8_t signature[kRsa4096Size])
{
static const uint8_t public_exponent[3] = { 0x01, 0x00, 0x01 };
@ -165,7 +165,7 @@ int crypto::rsa::pkcs::rsaVerify(const sRsa4096Key & key, HashType hash_type, co
return ret;
}
int crypto::rsa::pss::rsaVerify(const sRsa2048Key & key, HashType hash_type, const uint8_t * hash, const uint8_t signature[kRsa2048Size])
int fnd::rsa::pss::rsaVerify(const sRsa2048Key & key, HashType hash_type, const uint8_t * hash, const uint8_t signature[kRsa2048Size])
{
static const uint8_t public_exponent[3] = { 0x01, 0x00, 0x01 };

View file

@ -0,0 +1,15 @@
#include <fnd/sha.h>
#include <polarssl/sha1.h>
#include <polarssl/sha2.h>
using namespace fnd::sha;
void fnd::sha::Sha1(const uint8_t* in, uint64_t size, uint8_t hash[kSha1HashLen])
{
sha1(in, size, hash);
}
void fnd::sha::Sha256(const uint8_t* in, uint64_t size, uint8_t hash[kSha256HashLen])
{
sha2(in, size, hash, false);
}

View file

@ -77,7 +77,7 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>..\libfnd\include;..\libcrypto\include;..\libhac\include;..\libhac-hb\include;</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\libfnd\include;..\libhac\include;..\libhac-hb\include;</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
@ -90,7 +90,7 @@
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>..\libfnd\include;..\libcrypto\include;..\libhac\include;..\libhac-hb\include;</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\libfnd\include;..\libhac\include;..\libhac-hb\include;</AdditionalIncludeDirectories>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@ -99,7 +99,7 @@
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>..\libfnd\include;..\libcrypto\include;..\libhac\include;..\libhac-hb\include;</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\libfnd\include;..\libhac\include;..\libhac-hb\include;</AdditionalIncludeDirectories>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@ -110,7 +110,7 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>..\libfnd\include;..\libcrypto\include;..\libhac\include;..\libhac-hb\include;</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\libfnd\include;..\libhac\include;..\libhac-hb\include;</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>

View file

@ -50,14 +50,14 @@ namespace hac
void fromBytes(const byte_t* data, size_t len);
const fnd::Vec<byte_t>& getBytes() const;
void generateSignature(const crypto::rsa::sRsa2048Key& key);
void validateSignature(const crypto::rsa::sRsa2048Key& key) const;
void generateSignature(const fnd::rsa::sRsa2048Key& key);
void validateSignature(const fnd::rsa::sRsa2048Key& key) const;
// variables
void clear();
const crypto::rsa::sRsa2048Key& getNcaHeaderSignature2Key() const;
void setNcaHeaderSignature2Key(const crypto::rsa::sRsa2048Key& key);
const fnd::rsa::sRsa2048Key& getNcaHeaderSignature2Key() const;
void setNcaHeaderSignature2Key(const fnd::rsa::sRsa2048Key& key);
const fnd::List<aci::Flag>& getFlagList() const;
void setFlagList(const fnd::List<aci::Flag>& flags);
@ -80,7 +80,7 @@ namespace hac
fnd::Vec<byte_t> mRawBinary;
// variables
crypto::rsa::sRsa2048Key mNcaHeaderSignature2Key;
fnd::rsa::sRsa2048Key mNcaHeaderSignature2Key;
fnd::List<aci::Flag> mFlags;
sProgramIdRestrict mProgramIdRestrict;
nn::hac::FileSystemAccessControlBinary mFileSystemAccessControl;

View file

@ -1,7 +1,7 @@
#pragma once
#include <string>
#include <fnd/types.h>
#include <crypto/aes.h>
#include <fnd/aes.h>
namespace nn
{

View file

@ -14,7 +14,7 @@ namespace hac
public:
struct ContentInfo
{
crypto::sha::sSha256Hash hash;
fnd::sha::sSha256Hash hash;
byte_t nca_id[cnmt::kContentIdLen];
size_t size;
cnmt::ContentType type;

View file

@ -2,7 +2,7 @@
#include <nn/hac/hierarchicalintegrity.h>
#include <fnd/ISerialisable.h>
#include <fnd/List.h>
#include <crypto/sha.h>
#include <fnd/sha.h>
namespace nn
{
@ -54,8 +54,8 @@ namespace hac
const fnd::List<sLayer>& getLayerInfo() const;
void setLayerInfo(const fnd::List<sLayer>& layer_info);
const fnd::List<crypto::sha::sSha256Hash>& getMasterHashList() const;
void setMasterHashList(const fnd::List<crypto::sha::sSha256Hash>& master_hash_list);
const fnd::List<fnd::sha::sSha256Hash>& getMasterHashList() const;
void setMasterHashList(const fnd::List<fnd::sha::sSha256Hash>& master_hash_list);
private:
const std::string kModuleName = "HIERARCHICAL_INTEGRITY_HEADER";
@ -64,7 +64,7 @@ namespace hac
// data
fnd::List<sLayer> mLayerInfo;
fnd::List<crypto::sha::sSha256Hash> mMasterHashList;
fnd::List<fnd::sha::sSha256Hash> mMasterHashList;
};
}
}

View file

@ -48,8 +48,8 @@ namespace hac
// variables
void clear();
const crypto::sha::sSha256Hash& getMasterHash() const;
void setMasterHash(const crypto::sha::sSha256Hash& master_hash);
const fnd::sha::sSha256Hash& getMasterHash() const;
void setMasterHash(const fnd::sha::sSha256Hash& master_hash);
size_t getHashBlockSize() const;
void setHashBlockSize(size_t hash_block_size);
@ -63,7 +63,7 @@ namespace hac
fnd::Vec<byte_t> mRawBinary;
// data
crypto::sha::sSha256Hash mMasterHash;
fnd::sha::sSha256Hash mMasterHash;
size_t mHashBlockSize;
fnd::List<sLayer> mLayerInfo;
};

View file

@ -22,7 +22,7 @@ namespace hac
byte_t index;
uint64_t offset;
uint64_t size;
crypto::sha::sSha256Hash hash;
fnd::sha::sSha256Hash hash;
const sPartition& operator=(const sPartition& other)
{
@ -88,8 +88,8 @@ namespace hac
void setRightsId(const byte_t* rights_id);
const fnd::List<sPartition>& getPartitions() const;
void setPartitions(const fnd::List<sPartition>& partitions);
const fnd::List<crypto::aes::sAes128Key>& getEncAesKeys() const;
void setEncAesKeys(const fnd::List<crypto::aes::sAes128Key>& keys);
const fnd::List<fnd::aes::sAes128Key>& getEncAesKeys() const;
void setEncAesKeys(const fnd::List<fnd::aes::sAes128Key>& keys);
private:
const std::string kModuleName = "NCA_HEADER";
@ -109,7 +109,7 @@ namespace hac
uint32_t mSdkAddonVersion;
byte_t mRightsId[nca::kRightsIdLen];
fnd::List<sPartition> mPartitions;
fnd::List<crypto::aes::sAes128Key> mEncAesKeys;
fnd::List<fnd::aes::sAes128Key> mEncAesKeys;
uint64_t blockNumToSize(uint32_t block_num) const;
uint32_t sizeToBlockNum(uint64_t real_size) const;

View file

@ -9,7 +9,7 @@ namespace hac
{
public:
static inline size_t sectorToOffset(size_t sector_index) { return sector_index * nn::hac::nca::kSectorSize; }
static void decryptNcaHeader(const byte_t* src, byte_t* dst, const crypto::aes::sAesXts128Key& key);
static void decryptNcaHeader(const byte_t* src, byte_t* dst, const fnd::aes::sAesXts128Key& key);
static byte_t getMasterKeyRevisionFromKeyGeneration(byte_t key_generation);
static void getNcaPartitionAesCtr(const nn::hac::sNcaFsHeader* hdr, byte_t* ctr);
};

View file

@ -60,7 +60,7 @@ namespace hac
sLayout memory_layout;
bool is_compressed;
bool is_hashed;
crypto::sha::sSha256Hash hash;
fnd::sha::sSha256Hash hash;
void operator=(const sCodeSegment& other)
{

View file

@ -25,7 +25,7 @@ namespace hac
size_t offset;
size_t size;
size_t hash_protected_size;
crypto::sha::sSha256Hash hash;
fnd::sha::sSha256Hash hash;
sFile& operator=(const sFile& other)
{
@ -84,7 +84,7 @@ namespace hac
void setFsType(FsType type);
const fnd::List<sFile>& getFileList() const;
void addFile(const std::string& name, size_t size);
void addFile(const std::string& name, size_t size, size_t hash_protected_size, const crypto::sha::sSha256Hash& hash);
void addFile(const std::string& name, size_t size, size_t hash_protected_size, const fnd::sha::sSha256Hash& hash);
private:
const std::string kModuleName = "PFS_HEADER";

View file

@ -43,16 +43,16 @@ namespace hac
void setPackageId(uint64_t id);
uint32_t getValidDataEndPage() const;
void setValidDataEndPage(uint32_t page);
const crypto::aes::sAesIvCtr& getAesCbcIv() const;
void setAesCbcIv(const crypto::aes::sAesIvCtr& iv);
const fnd::aes::sAesIvCtr& getAesCbcIv() const;
void setAesCbcIv(const fnd::aes::sAesIvCtr& iv);
uint64_t getPartitionFsAddress() const;
void setPartitionFsAddress(uint64_t address);
uint64_t getPartitionFsSize() const;
void setPartitionFsSize(uint64_t size);
const crypto::sha::sSha256Hash& getPartitionFsHash() const;
void setPartitionFsHash(const crypto::sha::sSha256Hash& hash);
const crypto::sha::sSha256Hash& getInitialDataHash() const;
void setInitialDataHash(const crypto::sha::sSha256Hash& hash);
const fnd::sha::sSha256Hash& getPartitionFsHash() const;
void setPartitionFsHash(const fnd::sha::sSha256Hash& hash);
const fnd::sha::sSha256Hash& getInitialDataHash() const;
void setInitialDataHash(const fnd::sha::sSha256Hash& hash);
uint32_t getSelSec() const;
void setSelSec(uint32_t sel_sec);
uint32_t getSelT1Key() const;
@ -101,11 +101,11 @@ namespace hac
byte_t mFlags;
uint64_t mPackageId;
uint32_t mValidDataEndPage;
crypto::aes::sAesIvCtr mAesCbcIv;
fnd::aes::sAesIvCtr mAesCbcIv;
uint64_t mPartitionFsHeaderAddress;
uint64_t mPartitionFsHeaderSize;
crypto::sha::sSha256Hash mPartitionFsHeaderHash;
crypto::sha::sSha256Hash mInitialDataHash;
fnd::sha::sSha256Hash mPartitionFsHeaderHash;
fnd::sha::sSha256Hash mInitialDataHash;
uint32_t mSelSec;
uint32_t mSelT1Key;
uint32_t mSelKey;

View file

@ -1,6 +1,6 @@
#pragma once
#include <fnd/types.h>
#include <crypto/rsa.h>
#include <fnd/rsa.h>
#include <nn/hac/macro.h>
namespace nn
@ -39,8 +39,8 @@ namespace hac
struct sAciDescHeader
{
byte_t signature[crypto::rsa::kRsa2048Size];
byte_t nca_rsa_signature2_modulus[crypto::rsa::kRsa2048Size];
byte_t signature[fnd::rsa::kRsa2048Size];
byte_t nca_rsa_signature2_modulus[fnd::rsa::kRsa2048Size];
le_uint32_t st_magic;
le_uint32_t signed_size;
byte_t reserved_00[0x4];

View file

@ -1,6 +1,6 @@
#pragma once
#include <fnd/types.h>
#include <crypto/sha.h>
#include <fnd/sha.h>
namespace nn
{
@ -83,7 +83,7 @@ namespace hac
struct sContentInfo
{
crypto::sha::sSha256Hash content_hash;
fnd::sha::sSha256Hash content_hash;
byte_t content_id[cnmt::kContentIdLen];
le_uint32_t size_lower;
le_uint16_t size_higher;

View file

@ -1,6 +1,6 @@
#pragma once
#include <fnd/types.h>
#include <crypto/sha.h>
#include <fnd/sha.h>
namespace nn
{
@ -15,7 +15,7 @@ namespace hac
#pragma pack(push,1)
struct sHierarchicalSha256Header
{
crypto::sha::sSha256Hash master_hash;
fnd::sha::sSha256Hash master_hash;
le_uint32_t hash_block_size;
le_uint32_t layer_num;
struct sLayer

View file

@ -1,6 +1,6 @@
#pragma once
#include <fnd/types.h>
#include <crypto/rsa.h>
#include <fnd/rsa.h>
#include <nn/hac/macro.h>
namespace nn

View file

@ -1,8 +1,8 @@
#pragma once
#include <fnd/types.h>
#include <crypto/aes.h>
#include <crypto/sha.h>
#include <crypto/rsa.h>
#include <fnd/aes.h>
#include <fnd/sha.h>
#include <fnd/rsa.h>
#include <nn/hac/macro.h>
namespace nn
@ -108,8 +108,8 @@ namespace hac
byte_t enabled;
byte_t reserved[7];
} partition[nca::kPartitionNum];
crypto::sha::sSha256Hash partition_hash[nca::kPartitionNum];
crypto::aes::sAes128Key enc_aes_key[nca::kAesKeyNum];
fnd::sha::sSha256Hash partition_hash[nca::kPartitionNum];
fnd::aes::sAes128Key enc_aes_key[nca::kAesKeyNum];
};
struct sNcaFsHeader
@ -126,8 +126,8 @@ namespace hac
struct sNcaHeaderBlock
{
byte_t signature_main[crypto::rsa::kRsa2048Size];
byte_t signature_acid[crypto::rsa::kRsa2048Size];
byte_t signature_main[fnd::rsa::kRsa2048Size];
byte_t signature_acid[fnd::rsa::kRsa2048Size];
sNcaHeader header;
sNcaFsHeader fs_header[nn::hac::nca::kPartitionNum];
};

View file

@ -1,6 +1,6 @@
#pragma once
#include <fnd/types.h>
#include <crypto/rsa.h>
#include <fnd/rsa.h>
#include <nn/hac/macro.h>
namespace nn
@ -17,8 +17,8 @@ namespace hac
{
le_uint64_t application_id_mask;
le_uint64_t application_id_pattern;
byte_t nrr_body_modulus[crypto::rsa::kRsa2048Size];
byte_t nrr_cert_signature[crypto::rsa::kRsa2048Size];
byte_t nrr_body_modulus[fnd::rsa::kRsa2048Size];
byte_t nrr_cert_signature[fnd::rsa::kRsa2048Size];
};
struct sNrrHeader
@ -26,7 +26,7 @@ namespace hac
le_uint32_t st_magic;
byte_t reserved_0[28];
sNrrCertificate certificate;
byte_t nrr_body_signature[crypto::rsa::kRsa2048Size];
byte_t nrr_body_signature[fnd::rsa::kRsa2048Size];
le_uint64_t application_id;
le_uint32_t size;
byte_t reserved_1[4];

View file

@ -1,6 +1,6 @@
#pragma once
#include <fnd/types.h>
#include <crypto/sha.h>
#include <fnd/sha.h>
#include <nn/hac/macro.h>
namespace nn
@ -58,9 +58,9 @@ namespace hac
sNsoSection embedded;
sNsoSection dyn_str;
sNsoSection dyn_sym;
crypto::sha::sSha256Hash text_hash;
crypto::sha::sSha256Hash ro_hash;
crypto::sha::sSha256Hash data_hash;
fnd::sha::sSha256Hash text_hash;
fnd::sha::sSha256Hash ro_hash;
fnd::sha::sSha256Hash data_hash;
};
#pragma pack(pop)

View file

@ -1,5 +1,5 @@
#include <fnd/types.h>
#include <crypto/sha.h>
#include <fnd/sha.h>
#include <nn/hac/macro.h>
namespace nn
@ -37,7 +37,7 @@ namespace hac
le_uint32_t name_offset;
le_uint32_t hash_protected_size;
byte_t padding[8];
crypto::sha::sSha256Hash hash;
fnd::sha::sSha256Hash hash;
}; // sizeof(0x40)
#pragma pack(pop)
}

View file

@ -1,9 +1,9 @@
#pragma once
#include <fnd/types.h>
#include <fnd/List.h>
#include <crypto/aes.h>
#include <crypto/sha.h>
#include <crypto/rsa.h>
#include <fnd/aes.h>
#include <fnd/sha.h>
#include <fnd/rsa.h>
#include <nn/hac/macro.h>
namespace nn
@ -80,11 +80,11 @@ namespace hac
le_uint64_t package_id;
le_uint32_t valid_data_end_page;
byte_t reserved_00[4];
crypto::aes::sAesIvCtr aescbc_iv;
fnd::aes::sAesIvCtr aescbc_iv;
le_uint64_t partition_fs_header_address;
le_uint64_t partition_fs_header_size;
crypto::sha::sSha256Hash partition_fs_header_hash;
crypto::sha::sSha256Hash initial_data_hash;
fnd::sha::sSha256Hash partition_fs_header_hash;
fnd::sha::sSha256Hash initial_data_hash;
le_uint32_t sel_sec;
le_uint32_t sel_t1_key;
le_uint32_t sel_key;
@ -107,7 +107,7 @@ namespace hac
struct sXciHeaderPage
{
byte_t signature[crypto::rsa::kRsa2048Size];
byte_t signature[fnd::rsa::kRsa2048Size];
sXciHeader header;
}; // sizeof() = 512 (1 page)
@ -124,8 +124,8 @@ namespace hac
{
sInitialData initial_data; // AES128-CCM encrypted {titlekey[16]}
byte_t encrypted_00[xci::kPageSize * 6]; // AES128-CTR encrypted {titlekey[16]}
byte_t encrypted_00_aesctr_data[crypto::rsa::kRsa2048Size]; // RSA2048-OAEP-SHA256 encrypted AES-CTR data used for encrypted_00 {key[16],iv[16]}
byte_t reserved[xci::kPageSize - crypto::rsa::kRsa2048Size];
byte_t encrypted_00_aesctr_data[fnd::rsa::kRsa2048Size]; // RSA2048-OAEP-SHA256 encrypted AES-CTR data used for encrypted_00 {key[16],iv[16]}
byte_t reserved[xci::kPageSize - fnd::rsa::kRsa2048Size];
}; // sizeof() = 512*8 (8 pages)
#pragma pack(pop)

View file

@ -175,7 +175,7 @@
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>..\libfnd\include;..\libcrypto\include;..\libhac\include;</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\libfnd\include;..\libhac\include;</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_MBCS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>
@ -184,7 +184,7 @@
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>..\libfnd\include;..\libcrypto\include;..\libhac\include;</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\libfnd\include;..\libhac\include;</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_MBCS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>
@ -195,7 +195,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>..\libfnd\include;..\libcrypto\include;..\libhac\include;</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\libfnd\include;..\libhac\include;</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_MBCS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
@ -210,7 +210,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>..\libfnd\include;..\libcrypto\include;..\libhac\include;</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\libfnd\include;..\libhac\include;</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_MBCS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>

View file

@ -66,13 +66,13 @@ void nn::hac::AccessControlInfoDescBinary::toBytes()
sAciDescHeader* hdr = (sAciDescHeader*)mRawBinary.data();
// set rsa modulus
memcpy(hdr->nca_rsa_signature2_modulus, mNcaHeaderSignature2Key.modulus, crypto::rsa::kRsa2048Size);
memcpy(hdr->nca_rsa_signature2_modulus, mNcaHeaderSignature2Key.modulus, fnd::rsa::kRsa2048Size);
// set type
hdr->st_magic = aci::kAciDescStructMagic;
// set "acid size"
hdr->signed_size = (uint32_t)(total_size - crypto::rsa::kRsa2048Size);
hdr->signed_size = (uint32_t)(total_size - fnd::rsa::kRsa2048Size);
// set flags
uint32_t flags = 0;
@ -128,7 +128,7 @@ void nn::hac::AccessControlInfoDescBinary::fromBytes(const byte_t* data, size_t
memcpy(mRawBinary.data(), data, mRawBinary.size());
// save variables
memcpy(mNcaHeaderSignature2Key.modulus, hdr.nca_rsa_signature2_modulus, crypto::rsa::kRsa2048Size);
memcpy(mNcaHeaderSignature2Key.modulus, hdr.nca_rsa_signature2_modulus, fnd::rsa::kRsa2048Size);
for (size_t i = 0; i < 32; i++)
{
@ -149,29 +149,29 @@ const fnd::Vec<byte_t>& nn::hac::AccessControlInfoDescBinary::getBytes() const
return mRawBinary;
}
void nn::hac::AccessControlInfoDescBinary::generateSignature(const crypto::rsa::sRsa2048Key& key)
void nn::hac::AccessControlInfoDescBinary::generateSignature(const fnd::rsa::sRsa2048Key& key)
{
if (mRawBinary.size() == 0)
toBytes();
byte_t hash[crypto::sha::kSha256HashLen];
crypto::sha::Sha256(mRawBinary.data() + crypto::rsa::kRsa2048Size, mRawBinary.size() - crypto::rsa::kRsa2048Size, hash);
byte_t hash[fnd::sha::kSha256HashLen];
fnd::sha::Sha256(mRawBinary.data() + fnd::rsa::kRsa2048Size, mRawBinary.size() - fnd::rsa::kRsa2048Size, hash);
if (crypto::rsa::pkcs::rsaSign(key, crypto::sha::HASH_SHA256, hash, mRawBinary.data()) != 0)
if (fnd::rsa::pkcs::rsaSign(key, fnd::sha::HASH_SHA256, hash, mRawBinary.data()) != 0)
{
throw fnd::Exception(kModuleName, "Failed to sign Access Control Info Desc");
}
}
void nn::hac::AccessControlInfoDescBinary::validateSignature(const crypto::rsa::sRsa2048Key& key) const
void nn::hac::AccessControlInfoDescBinary::validateSignature(const fnd::rsa::sRsa2048Key& key) const
{
if (mRawBinary.size() == 0)
throw fnd::Exception(kModuleName, "No Access Control Info Desc binary exists to verify");
byte_t hash[crypto::sha::kSha256HashLen];
crypto::sha::Sha256(mRawBinary.data() + crypto::rsa::kRsa2048Size, mRawBinary.size() - crypto::rsa::kRsa2048Size, hash);
byte_t hash[fnd::sha::kSha256HashLen];
fnd::sha::Sha256(mRawBinary.data() + fnd::rsa::kRsa2048Size, mRawBinary.size() - fnd::rsa::kRsa2048Size, hash);
if (crypto::rsa::pss::rsaVerify(key, crypto::sha::HASH_SHA256, hash, mRawBinary.data()) != 0)
if (fnd::rsa::pss::rsaVerify(key, fnd::sha::HASH_SHA256, hash, mRawBinary.data()) != 0)
{
throw fnd::Exception(kModuleName, "Failed to verify Access Control Info Desc");
}
@ -189,12 +189,12 @@ void nn::hac::AccessControlInfoDescBinary::clear()
mKernelCapabilities.clear();
}
const crypto::rsa::sRsa2048Key& nn::hac::AccessControlInfoDescBinary::getNcaHeaderSignature2Key() const
const fnd::rsa::sRsa2048Key& nn::hac::AccessControlInfoDescBinary::getNcaHeaderSignature2Key() const
{
return mNcaHeaderSignature2Key;
}
void nn::hac::AccessControlInfoDescBinary::setNcaHeaderSignature2Key(const crypto::rsa::sRsa2048Key& key)
void nn::hac::AccessControlInfoDescBinary::setNcaHeaderSignature2Key(const fnd::rsa::sRsa2048Key& key)
{
mNcaHeaderSignature2Key = key;
}

View file

@ -2,18 +2,18 @@
void nn::hac::AesKeygen::generateKey(byte_t* dst, const byte_t* src, const byte_t* src_key)
{
crypto::aes::AesEcbDecrypt(src, sizeof(crypto::aes::sAes128Key), src_key, dst);
fnd::aes::AesEcbDecrypt(src, sizeof(fnd::aes::sAes128Key), src_key, dst);
}
void nn::hac::AesKeygen::generateKey(byte_t* dst, const byte_t* src1, const byte_t* src2, const byte_t* src1_key)
{
crypto::aes::sAes128Key src2_key;
fnd::aes::sAes128Key src2_key;
generateKey(src2_key.key, src1, src1_key);
generateKey(dst, src2, src2_key.key);
}
void nn::hac::AesKeygen::generateKey(byte_t* dst, const byte_t* src1, const byte_t* src2, const byte_t* src3, const byte_t* src1_key)
{
crypto::aes::sAes128Key src3_key;
fnd::aes::sAes128Key src3_key;
generateKey(src3_key.key, src1, src2, src1_key);
generateKey(dst, src3, src3_key.key);
}

View file

@ -98,8 +98,8 @@ void nn::hac::HierarchicalIntegrityHeader::fromBytes(const byte_t* data, size_t
}
// save hash list
const crypto::sha::sSha256Hash* hash_list = (const crypto::sha::sSha256Hash*)(mRawBinary.data() + master_hash_offset);
for (size_t i = 0; i < hdr->master_hash_size.get()/sizeof(crypto::sha::sSha256Hash); i++)
const fnd::sha::sSha256Hash* hash_list = (const fnd::sha::sSha256Hash*)(mRawBinary.data() + master_hash_offset);
for (size_t i = 0; i < hdr->master_hash_size.get()/sizeof(fnd::sha::sSha256Hash); i++)
{
mMasterHashList.addElement(hash_list[i]);
}
@ -126,12 +126,12 @@ void nn::hac::HierarchicalIntegrityHeader::setLayerInfo(const fnd::List<sLayer>&
mLayerInfo = layer_info;
}
const fnd::List<crypto::sha::sSha256Hash>& nn::hac::HierarchicalIntegrityHeader::getMasterHashList() const
const fnd::List<fnd::sha::sSha256Hash>& nn::hac::HierarchicalIntegrityHeader::getMasterHashList() const
{
return mMasterHashList;
}
void nn::hac::HierarchicalIntegrityHeader::setMasterHashList(const fnd::List<crypto::sha::sSha256Hash>& master_hash_list)
void nn::hac::HierarchicalIntegrityHeader::setMasterHashList(const fnd::List<fnd::sha::sSha256Hash>& master_hash_list)
{
mMasterHashList = master_hash_list;
}

View file

@ -76,17 +76,17 @@ const fnd::Vec<byte_t>& nn::hac::HierarchicalSha256Header::getBytes() const
void nn::hac::HierarchicalSha256Header::clear()
{
memset(mMasterHash.bytes, 0, sizeof(crypto::sha::sSha256Hash));
memset(mMasterHash.bytes, 0, sizeof(fnd::sha::sSha256Hash));
mHashBlockSize = 0;
mLayerInfo.clear();
}
const crypto::sha::sSha256Hash & nn::hac::HierarchicalSha256Header::getMasterHash() const
const fnd::sha::sSha256Hash & nn::hac::HierarchicalSha256Header::getMasterHash() const
{
return mMasterHash;
}
void nn::hac::HierarchicalSha256Header::setMasterHash(const crypto::sha::sSha256Hash & master_hash)
void nn::hac::HierarchicalSha256Header::setMasterHash(const fnd::sha::sSha256Hash & master_hash)
{
mMasterHash = master_hash;
}

View file

@ -306,12 +306,12 @@ void nn::hac::NcaHeader::setPartitions(const fnd::List<nn::hac::NcaHeader::sPart
}
}
const fnd::List<crypto::aes::sAes128Key>& nn::hac::NcaHeader::getEncAesKeys() const
const fnd::List<fnd::aes::sAes128Key>& nn::hac::NcaHeader::getEncAesKeys() const
{
return mEncAesKeys;
}
void nn::hac::NcaHeader::setEncAesKeys(const fnd::List<crypto::aes::sAes128Key>& keys)
void nn::hac::NcaHeader::setEncAesKeys(const fnd::List<fnd::aes::sAes128Key>& keys)
{
mEncAesKeys = keys;
}

View file

@ -1,21 +1,21 @@
#include <nn/hac/NcaUtils.h>
void nn::hac::NcaUtils::decryptNcaHeader(const byte_t* src, byte_t* dst, const crypto::aes::sAesXts128Key& key)
void nn::hac::NcaUtils::decryptNcaHeader(const byte_t* src, byte_t* dst, const fnd::aes::sAesXts128Key& key)
{
byte_t tweak[crypto::aes::kAesBlockSize];
byte_t tweak[fnd::aes::kAesBlockSize];
// decrypt main header
byte_t raw_hdr[nn::hac::nca::kSectorSize];
crypto::aes::AesXtsMakeTweak(tweak, 1);
crypto::aes::AesXtsDecryptSector(src + sectorToOffset(1), nn::hac::nca::kSectorSize, key.key[0], key.key[1], tweak, raw_hdr);
fnd::aes::AesXtsMakeTweak(tweak, 1);
fnd::aes::AesXtsDecryptSector(src + sectorToOffset(1), nn::hac::nca::kSectorSize, key.key[0], key.key[1], tweak, raw_hdr);
bool useNca2SectorIndex = ((nn::hac::sNcaHeader*)(raw_hdr))->st_magic.get() == nn::hac::nca::kNca2StructMagic;
// decrypt whole header
for (size_t i = 0; i < nn::hac::nca::kHeaderSectorNum; i++)
{
crypto::aes::AesXtsMakeTweak(tweak, (i > 1 && useNca2SectorIndex)? 0 : i);
crypto::aes::AesXtsDecryptSector(src + sectorToOffset(i), nn::hac::nca::kSectorSize, key.key[0], key.key[1], tweak, dst + sectorToOffset(i));
fnd::aes::AesXtsMakeTweak(tweak, (i > 1 && useNca2SectorIndex)? 0 : i);
fnd::aes::AesXtsDecryptSector(src + sectorToOffset(i), nn::hac::nca::kSectorSize, key.key[0], key.key[1], tweak, dst + sectorToOffset(i));
}
}

View file

@ -222,7 +222,7 @@ void nn::hac::PfsHeader::addFile(const std::string & name, size_t size)
mFileList.addElement({ name, 0, size, 0 });
}
void nn::hac::PfsHeader::addFile(const std::string & name, size_t size, size_t hash_protected_size, const crypto::sha::sSha256Hash& hash)
void nn::hac::PfsHeader::addFile(const std::string & name, size_t size, size_t hash_protected_size, const fnd::sha::sSha256Hash& hash)
{
mFileList.addElement({ name, 0, size, hash_protected_size, hash });
}

View file

@ -119,7 +119,7 @@ void nn::hac::XciHeader::fromBytes(const byte_t* data, size_t len)
mFlags = hdr->flags;
mPackageId = hdr->package_id.get();
mValidDataEndPage = hdr->valid_data_end_page.get();
for (size_t i = 0; i < crypto::aes::kAesBlockSize; i++)
for (size_t i = 0; i < fnd::aes::kAesBlockSize; i++)
mAesCbcIv.iv[i] = hdr->aescbc_iv.iv[15-i];
mPartitionFsHeaderAddress = hdr->partition_fs_header_address.get();
mPartitionFsHeaderSize = hdr->partition_fs_header_size.get();
@ -277,12 +277,12 @@ void nn::hac::XciHeader::setValidDataEndPage(uint32_t page)
mValidDataEndPage = page;
}
const crypto::aes::sAesIvCtr& nn::hac::XciHeader::getAesCbcIv() const
const fnd::aes::sAesIvCtr& nn::hac::XciHeader::getAesCbcIv() const
{
return mAesCbcIv;
}
void nn::hac::XciHeader::setAesCbcIv(const crypto::aes::sAesIvCtr& iv)
void nn::hac::XciHeader::setAesCbcIv(const fnd::aes::sAesIvCtr& iv)
{
mAesCbcIv = iv;
}
@ -307,22 +307,22 @@ void nn::hac::XciHeader::setPartitionFsSize(uint64_t size)
mPartitionFsHeaderSize = size;
}
const crypto::sha::sSha256Hash& nn::hac::XciHeader::getPartitionFsHash() const
const fnd::sha::sSha256Hash& nn::hac::XciHeader::getPartitionFsHash() const
{
return mPartitionFsHeaderHash;
}
void nn::hac::XciHeader::setPartitionFsHash(const crypto::sha::sSha256Hash& hash)
void nn::hac::XciHeader::setPartitionFsHash(const fnd::sha::sSha256Hash& hash)
{
mPartitionFsHeaderHash = hash;
}
const crypto::sha::sSha256Hash& nn::hac::XciHeader::getInitialDataHash() const
const fnd::sha::sSha256Hash& nn::hac::XciHeader::getInitialDataHash() const
{
return mInitialDataHash;
}
void nn::hac::XciHeader::setInitialDataHash(const crypto::sha::sSha256Hash& hash)
void nn::hac::XciHeader::setInitialDataHash(const fnd::sha::sSha256Hash& hash)
{
mInitialDataHash = hash;
}

View file

@ -10,7 +10,7 @@ void nn::hac::XciUtils::getXciHeaderAesIv(const nn::hac::sXciHeader* hdr, byte_t
void nn::hac::XciUtils::decryptXciHeader(const byte_t* src, byte_t* dst, const byte_t* key)
{
byte_t iv[crypto::aes::kAesBlockSize];
byte_t iv[fnd::aes::kAesBlockSize];
getXciHeaderAesIv((const nn::hac::sXciHeader*)src, iv);
@ -18,5 +18,5 @@ void nn::hac::XciUtils::decryptXciHeader(const byte_t* src, byte_t* dst, const b
memcpy(dst, src, nn::hac::xci::kHeaderEncOffset);
// decrypt encrypted data
crypto::aes::AesCbcDecrypt(src + nn::hac::xci::kHeaderEncOffset, nn::hac::xci::kHeaderEncSize, key, iv, dst + nn::hac::xci::kHeaderEncOffset);
fnd::aes::AesCbcDecrypt(src + nn::hac::xci::kHeaderEncOffset, nn::hac::xci::kHeaderEncSize, key, iv, dst + nn::hac::xci::kHeaderEncOffset);
}

View file

@ -38,14 +38,14 @@ namespace pki
uint32_t getCertId() const;
void setCertId(uint32_t id);
const crypto::rsa::sRsa4096Key& getRsa4098PublicKey() const;
void setRsa4098PublicKey(const crypto::rsa::sRsa4096Key& key);
const fnd::rsa::sRsa4096Key& getRsa4098PublicKey() const;
void setRsa4098PublicKey(const fnd::rsa::sRsa4096Key& key);
const crypto::rsa::sRsa2048Key& getRsa2048PublicKey() const;
void setRsa2048PublicKey(const crypto::rsa::sRsa2048Key& key);
const fnd::rsa::sRsa2048Key& getRsa2048PublicKey() const;
void setRsa2048PublicKey(const fnd::rsa::sRsa2048Key& key);
const crypto::ecdsa::sEcdsa240Point& getEcdsa240PublicKey() const;
void setEcdsa240PublicKey(const crypto::ecdsa::sEcdsa240Point& key);
const fnd::ecdsa::sEcdsa240Point& getEcdsa240PublicKey() const;
void setEcdsa240PublicKey(const fnd::ecdsa::sEcdsa240Point& key);
private:
const std::string kModuleName = "CERTIFICATE_BODY";
@ -59,9 +59,9 @@ namespace pki
uint32_t mCertId;
cert::PublicKeyType mPublicKeyType;
crypto::rsa::sRsa4096Key mRsa4096PublicKey;
crypto::rsa::sRsa2048Key mRsa2048PublicKey;
crypto::ecdsa::sEcdsa240Point mEcdsa240PublicKey;
fnd::rsa::sRsa4096Key mRsa4096PublicKey;
fnd::rsa::sRsa2048Key mRsa2048PublicKey;
fnd::ecdsa::sEcdsa240Point mEcdsa240PublicKey;
};
}
}

View file

@ -1,6 +1,6 @@
#pragma once
#include <nn/pki/sign.h>
#include <crypto/sha.h>
#include <fnd/sha.h>
namespace nn
{

View file

@ -1,9 +1,9 @@
#pragma once
#include <string>
#include <fnd/types.h>
#include <crypto/aes.h>
#include <crypto/rsa.h>
#include <crypto/ecdsa.h>
#include <fnd/aes.h>
#include <fnd/rsa.h>
#include <fnd/ecdsa.h>
namespace nn
{
@ -32,21 +32,21 @@ namespace pki
struct sRsa4096PublicKeyBlock
{
byte_t modulus[crypto::rsa::kRsa4096Size];
byte_t public_exponent[crypto::rsa::kRsaPublicExponentSize];
byte_t modulus[fnd::rsa::kRsa4096Size];
byte_t public_exponent[fnd::rsa::kRsaPublicExponentSize];
byte_t padding[0x34];
};
struct sRsa2048PublicKeyBlock
{
byte_t modulus[crypto::rsa::kRsa2048Size];
byte_t public_exponent[crypto::rsa::kRsaPublicExponentSize];
byte_t modulus[fnd::rsa::kRsa2048Size];
byte_t public_exponent[fnd::rsa::kRsaPublicExponentSize];
byte_t padding[0x34];
};
struct sEcdsa240PublicKeyBlock
{
crypto::ecdsa::sEcdsa240Point public_key;
fnd::ecdsa::sEcdsa240Point public_key;
byte_t padding[0x3C];
};
#pragma pack(pop)

View file

@ -1,9 +1,9 @@
#pragma once
#include <string>
#include <fnd/types.h>
#include <crypto/aes.h>
#include <crypto/rsa.h>
#include <crypto/ecdsa.h>
#include <fnd/aes.h>
#include <fnd/rsa.h>
#include <fnd/ecdsa.h>
namespace nn
{
@ -43,14 +43,14 @@ namespace pki
struct sRsa4096SignBlock
{
be_uint32_t sign_type;
byte_t signature[crypto::rsa::kRsa4096Size];
byte_t signature[fnd::rsa::kRsa4096Size];
byte_t padding[0x3C];
};
struct sRsa2048SignBlock
{
be_uint32_t sign_type;
byte_t signature[crypto::rsa::kRsa2048Size];
byte_t signature[fnd::rsa::kRsa2048Size];
byte_t padding[0x3C];
};

View file

@ -77,7 +77,7 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>..\libfnd\include;..\libcrypto\include;..\libpki\include;</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\libfnd\include;..\libpki\include;</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
@ -91,7 +91,7 @@
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>..\libfnd\include;..\libcrypto\include;..\libpki\include;</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\libfnd\include;..\libpki\include;</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>
@ -101,7 +101,7 @@
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>..\libfnd\include;..\libcrypto\include;..\libpki\include;</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\libfnd\include;..\libpki\include;</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>
@ -113,7 +113,7 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>..\libfnd\include;..\libcrypto\include;..\libpki\include;</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\libfnd\include;..\libpki\include;</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>

View file

@ -168,9 +168,9 @@ void nn::pki::CertificateBody::clear()
mCertId = 0;
mPublicKeyType = cert::RSA2048;
memset(&mRsa4096PublicKey, 0, sizeof(crypto::rsa::sRsa4096Key));
memset(&mRsa2048PublicKey, 0, sizeof(crypto::rsa::sRsa2048Key));
memset(&mEcdsa240PublicKey, 0, sizeof(crypto::ecdsa::sEcdsa240Point));
memset(&mRsa4096PublicKey, 0, sizeof(fnd::rsa::sRsa4096Key));
memset(&mRsa2048PublicKey, 0, sizeof(fnd::rsa::sRsa2048Key));
memset(&mEcdsa240PublicKey, 0, sizeof(fnd::ecdsa::sEcdsa240Point));
}
const std::string& nn::pki::CertificateBody::getIssuer() const
@ -223,32 +223,32 @@ void nn::pki::CertificateBody::setCertId(uint32_t id)
mCertId = id;
}
const crypto::rsa::sRsa4096Key& nn::pki::CertificateBody::getRsa4098PublicKey() const
const fnd::rsa::sRsa4096Key& nn::pki::CertificateBody::getRsa4098PublicKey() const
{
return mRsa4096PublicKey;
}
void nn::pki::CertificateBody::setRsa4098PublicKey(const crypto::rsa::sRsa4096Key& key)
void nn::pki::CertificateBody::setRsa4098PublicKey(const fnd::rsa::sRsa4096Key& key)
{
mRsa4096PublicKey = key;
}
const crypto::rsa::sRsa2048Key& nn::pki::CertificateBody::getRsa2048PublicKey() const
const fnd::rsa::sRsa2048Key& nn::pki::CertificateBody::getRsa2048PublicKey() const
{
return mRsa2048PublicKey;
}
void nn::pki::CertificateBody::setRsa2048PublicKey(const crypto::rsa::sRsa2048Key& key)
void nn::pki::CertificateBody::setRsa2048PublicKey(const fnd::rsa::sRsa2048Key& key)
{
mRsa2048PublicKey = key;
}
const crypto::ecdsa::sEcdsa240Point& nn::pki::CertificateBody::getEcdsa240PublicKey() const
const fnd::ecdsa::sEcdsa240Point& nn::pki::CertificateBody::getEcdsa240PublicKey() const
{
return mEcdsa240PublicKey;
}
void nn::pki::CertificateBody::setEcdsa240PublicKey(const crypto::ecdsa::sEcdsa240Point& key)
void nn::pki::CertificateBody::setEcdsa240PublicKey(const fnd::ecdsa::sEcdsa240Point& key)
{
mEcdsa240PublicKey = key;
}

View file

@ -40,12 +40,12 @@ void nn::pki::SignatureBlock::toBytes()
case (sign::SIGN_ID_RSA4096_SHA1):
case (sign::SIGN_ID_RSA4096_SHA256):
totalSize = sizeof(sRsa4096SignBlock);
sigSize = crypto::rsa::kRsa4096Size;
sigSize = fnd::rsa::kRsa4096Size;
break;
case (sign::SIGN_ID_RSA2048_SHA1):
case (sign::SIGN_ID_RSA2048_SHA256):
totalSize = sizeof(sRsa2048SignBlock);
sigSize = crypto::rsa::kRsa2048Size;
sigSize = fnd::rsa::kRsa2048Size;
break;
case (sign::SIGN_ID_ECDSA240_SHA1):
case (sign::SIGN_ID_ECDSA240_SHA256):
@ -83,12 +83,12 @@ void nn::pki::SignatureBlock::fromBytes(const byte_t* src, size_t size)
case (sign::SIGN_ID_RSA4096_SHA1):
case (sign::SIGN_ID_RSA4096_SHA256):
totalSize = sizeof(sRsa4096SignBlock);
sigSize = crypto::rsa::kRsa4096Size;
sigSize = fnd::rsa::kRsa4096Size;
break;
case (sign::SIGN_ID_RSA2048_SHA1):
case (sign::SIGN_ID_RSA2048_SHA256):
totalSize = sizeof(sRsa2048SignBlock);
sigSize = crypto::rsa::kRsa2048Size;
sigSize = fnd::rsa::kRsa2048Size;
break;
case (sign::SIGN_ID_ECDSA240_SHA1):
case (sign::SIGN_ID_ECDSA240_SHA256):
@ -106,12 +106,12 @@ void nn::pki::SignatureBlock::fromBytes(const byte_t* src, size_t size)
case (sign::SIGN_ID_RSA4096_SHA1):
case (sign::SIGN_ID_RSA4096_SHA256):
totalSize = sizeof(sRsa4096SignBlock);
sigSize = crypto::rsa::kRsa4096Size;
sigSize = fnd::rsa::kRsa4096Size;
break;
case (sign::SIGN_ID_RSA2048_SHA1):
case (sign::SIGN_ID_RSA2048_SHA256):
totalSize = sizeof(sRsa2048SignBlock);
sigSize = crypto::rsa::kRsa2048Size;
sigSize = fnd::rsa::kRsa2048Size;
break;
case (sign::SIGN_ID_ECDSA240_SHA1):
case (sign::SIGN_ID_ECDSA240_SHA256):

View file

@ -3,7 +3,7 @@ LIB_DIR = $(PROJECT_DIR)/lib
PROGRAM_DIR = $(PROJECT_DIR)/programs
BIN_DIR = $(PROJECT_DIR)/bin
LIBS = libpolarssl liblz4 libfnd libcrypto libcompress libes libpki libhac libhac-hb
LIBS = libpolarssl liblz4 libfnd libes libpki libhac libhac-hb
PROGS = nstool
main: build

View file

@ -3,7 +3,7 @@ SRC_DIR = source
OBJS = $(foreach dir,$(SRC_DIR),$(subst .cpp,.o,$(wildcard $(dir)/*.cpp))) $(foreach dir,$(SRC_DIR),$(subst .c,.o,$(wildcard $(dir)/*.c)))
# External dependencies
DEPENDS = hac-hb hac es pki crypto compress fnd polarssl lz4
DEPENDS = hac-hb hac es pki fnd polarssl lz4
LIB_DIR = ../../lib
LIBS = $(foreach dep,$(DEPENDS), -L"$(LIB_DIR)/lib$(dep)" -l$(dep))
INCS = $(foreach dep,$(DEPENDS), -I"$(LIB_DIR)/lib$(dep)/include")

View file

@ -90,7 +90,7 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>..\..\lib\libpki\include;..\..\lib\libes\include;..\..\lib\libfnd\include;..\..\lib\libcompress\include;..\..\lib\libcrypto\include;..\..\lib\libhac\include;..\..\lib\libhac-hb\include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\..\lib\libpki\include;..\..\lib\libes\include;..\..\lib\libfnd\include;..\..\lib\libhac\include;..\..\lib\libhac-hb\include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@ -105,7 +105,7 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>..\..\lib\libpki\include;..\..\lib\libes\include;..\..\lib\libfnd\include;..\..\lib\libcompress\include;..\..\lib\libcrypto\include;..\..\lib\libhac\include;..\..\lib\libhac-hb\include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\..\lib\libpki\include;..\..\lib\libes\include;..\..\lib\libfnd\include;..\..\lib\libhac\include;..\..\lib\libhac-hb\include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@ -122,7 +122,7 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>..\..\lib\libpki\include;..\..\lib\libes\include;..\..\lib\libfnd\include;..\..\lib\libcompress\include;..\..\lib\libcrypto\include;..\..\lib\libhac\include;..\..\lib\libhac-hb\include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\..\lib\libpki\include;..\..\lib\libes\include;..\..\lib\libfnd\include;..\..\lib\libhac\include;..\..\lib\libhac-hb\include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@ -141,7 +141,7 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>..\..\lib\libpki\include;..\..\lib\libes\include;..\..\lib\libfnd\include;..\..\lib\libcompress\include;..\..\lib\libcrypto\include;..\..\lib\libhac\include;..\..\lib\libhac-hb\include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\..\lib\libpki\include;..\..\lib\libes\include;..\..\lib\libfnd\include;..\..\lib\libhac\include;..\..\lib\libhac-hb\include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@ -157,12 +157,6 @@
<ProjectReference Include="..\..\lib\liblz4\liblz4.vcxproj">
<Project>{AB0C3362-63AB-480A-ADBC-2EF7D859778B}</Project>
</ProjectReference>
<ProjectReference Include="..\..\lib\libcompress\libcompress.vcxproj">
<Project>{cf01b5b7-730a-447f-9bb2-5eda9b082177}</Project>
</ProjectReference>
<ProjectReference Include="..\..\lib\libcrypto\libcrypto.vcxproj">
<Project>{6adbb60d-dba0-411d-bd2d-a355ef8e0fe1}</Project>
</ProjectReference>
<ProjectReference Include="..\..\lib\libes\libes.vcxproj">
<Project>{7be99936-0d40-410d-944b-4513c2eff8dc}</Project>
</ProjectReference>

View file

@ -1,6 +1,6 @@
#include "AesCtrWrappedIFile.h"
AesCtrWrappedIFile::AesCtrWrappedIFile(fnd::IFile* file, bool ownIfile, const crypto::aes::sAes128Key& key, const crypto::aes::sAesIvCtr& ctr) :
AesCtrWrappedIFile::AesCtrWrappedIFile(fnd::IFile* file, bool ownIfile, const fnd::aes::sAes128Key& key, const fnd::aes::sAesIvCtr& ctr) :
mOwnIFile(ownIfile),
mFile(file),
mKey(key),
@ -47,8 +47,8 @@ void AesCtrWrappedIFile::read(byte_t* out, size_t len)
mFile->seek(read_pos);
mFile->read(mCache.data(), kCacheSizeAllocSize);
crypto::aes::AesIncrementCounter(mBaseCtr.iv, read_pos>>4, mCurrentCtr.iv);
crypto::aes::AesCtr(mCache.data(), kCacheSizeAllocSize, mKey.key, mCurrentCtr.iv, mCache.data());
fnd::aes::AesIncrementCounter(mBaseCtr.iv, read_pos>>4, mCurrentCtr.iv);
fnd::aes::AesCtr(mCache.data(), kCacheSizeAllocSize, mKey.key, mCurrentCtr.iv, mCache.data());
memcpy(out + (i * kCacheSize), mCache.data() + (mFileOffset & 0xf), read_len);
}
@ -78,8 +78,8 @@ void AesCtrWrappedIFile::write(const byte_t* in, size_t len)
memcpy(mCache.data() + (mFileOffset & 0xf), in + (i * kCacheSize), write_len);
crypto::aes::AesIncrementCounter(mBaseCtr.iv, write_pos>>4, mCurrentCtr.iv);
crypto::aes::AesCtr(mCache.data(), kCacheSizeAllocSize, mKey.key, mCurrentCtr.iv, mCache.data());
fnd::aes::AesIncrementCounter(mBaseCtr.iv, write_pos>>4, mCurrentCtr.iv);
fnd::aes::AesCtr(mCache.data(), kCacheSizeAllocSize, mKey.key, mCurrentCtr.iv, mCache.data());
mFile->seek(write_pos);
mFile->write(mCache.data(), kCacheSizeAllocSize);
@ -91,7 +91,7 @@ void AesCtrWrappedIFile::write(const byte_t* in, size_t len)
for (size_t i = 0; i < (len / kAesCtrScratchSize); i++)
{
memcpy(mScratch.data() + mBlockOffset, out + (i * kAesCtrScratchSize), kAesCtrScratchSize);
crypto::aes::AesCtr(mScratch.data(), kAesCtrScratchAllocSize, mKey.key, mCurrentCtr.iv, mScratch.data());
fnd::aes::AesCtr(mScratch.data(), kAesCtrScratchAllocSize, mKey.key, mCurrentCtr.iv, mScratch.data());
mFile->write(mScratch.data() + mBlockOffset, kAesCtrScratchSize);
}
@ -100,7 +100,7 @@ void AesCtrWrappedIFile::write(const byte_t* in, size_t len)
size_t write_len = len % kAesCtrScratchSize;
size_t write_pos = ((len / kAesCtrScratchSize) * kAesCtrScratchSize);
memcpy(mScratch.data() + mBlockOffset, out + write_pos, write_len);
crypto::aes::AesCtr(mScratch.data(), kAesCtrScratchAllocSize, mKey.key, mCurrentCtr.iv, mScratch.data());
fnd::aes::AesCtr(mScratch.data(), kAesCtrScratchAllocSize, mKey.key, mCurrentCtr.iv, mScratch.data());
mFile->write(mScratch.data() + mBlockOffset, write_len);
}
*/

View file

@ -1,11 +1,11 @@
#include <fnd/IFile.h>
#include <fnd/Vec.h>
#include <crypto/aes.h>
#include <fnd/aes.h>
class AesCtrWrappedIFile : public fnd::IFile
{
public:
AesCtrWrappedIFile(fnd::IFile* file, bool ownIfile, const crypto::aes::sAes128Key& key, const crypto::aes::sAesIvCtr& ctr);
AesCtrWrappedIFile(fnd::IFile* file, bool ownIfile, const fnd::aes::sAes128Key& key, const fnd::aes::sAesIvCtr& ctr);
~AesCtrWrappedIFile();
size_t size();
@ -17,12 +17,12 @@ public:
private:
const std::string kModuleName = "AesCtrWrappedIFile";
static const size_t kCacheSize = 0x10000;
static const size_t kCacheSizeAllocSize = kCacheSize + crypto::aes::kAesBlockSize;
static const size_t kCacheSizeAllocSize = kCacheSize + fnd::aes::kAesBlockSize;
bool mOwnIFile;
fnd::IFile* mFile;
crypto::aes::sAes128Key mKey;
crypto::aes::sAesIvCtr mBaseCtr, mCurrentCtr;
fnd::aes::sAes128Key mKey;
fnd::aes::sAesIvCtr mBaseCtr, mCurrentCtr;
size_t mFileOffset;
fnd::Vec<byte_t> mCache;

View file

@ -83,12 +83,12 @@ void EsTikProcess::verifyTicket()
switch (nn::pki::sign::getHashAlgo(mTik.getSignature().getSignType()))
{
case (nn::pki::sign::HASH_ALGO_SHA1):
tik_hash.alloc(crypto::sha::kSha1HashLen);
crypto::sha::Sha1(mTik.getBody().getBytes().data(), mTik.getBody().getBytes().size(), tik_hash.data());
tik_hash.alloc(fnd::sha::kSha1HashLen);
fnd::sha::Sha1(mTik.getBody().getBytes().data(), mTik.getBody().getBytes().size(), tik_hash.data());
break;
case (nn::pki::sign::HASH_ALGO_SHA256):
tik_hash.alloc(crypto::sha::kSha256HashLen);
crypto::sha::Sha256(mTik.getBody().getBytes().data(), mTik.getBody().getBytes().size(), tik_hash.data());
tik_hash.alloc(fnd::sha::kSha256HashLen);
fnd::sha::Sha256(mTik.getBody().getBytes().data(), mTik.getBody().getBytes().size(), tik_hash.data());
break;
}
@ -124,7 +124,7 @@ void EsTikProcess::displayTicket()
std::cout << " EncMode: " << getTitleKeyPersonalisationStr(body.getTitleKeyEncType()) << std::endl;
std::cout << " KeyGeneration: " << std::dec << (uint32_t)body.getCommonKeyId() << std::endl;
std::cout << " Data:" << std::endl;
size_t size = body.getTitleKeyEncType() == nn::es::ticket::RSA2048 ? crypto::rsa::kRsa2048Size : crypto::aes::kAes128KeySize;
size_t size = body.getTitleKeyEncType() == nn::es::ticket::RSA2048 ? fnd::rsa::kRsa2048Size : fnd::aes::kAes128KeySize;
fnd::SimpleTextOutput::hexDump(body.getEncTitleKey(), size, 0x10, 6);
printf(" Version: v%d.%d.%d", _SPLIT_VER(body.getTicketVersion()));

View file

@ -72,12 +72,12 @@ void HashTreeMeta::setDataLayer(const sLayer& data_info)
mDataLayer = data_info;
}
const fnd::List<crypto::sha::sSha256Hash>& HashTreeMeta::getMasterHashList() const
const fnd::List<fnd::sha::sSha256Hash>& HashTreeMeta::getMasterHashList() const
{
return mMasterHashList;
}
void HashTreeMeta::setMasterHashList(const fnd::List<crypto::sha::sSha256Hash>& master_hash_list)
void HashTreeMeta::setMasterHashList(const fnd::List<fnd::sha::sSha256Hash>& master_hash_list)
{
mMasterHashList = master_hash_list;
}

View file

@ -50,8 +50,8 @@ public:
const sLayer& getDataLayer() const;
void setDataLayer(const sLayer& data_info);
const fnd::List<crypto::sha::sSha256Hash>& getMasterHashList() const;
void setMasterHashList(const fnd::List<crypto::sha::sSha256Hash>& master_hash_list);
const fnd::List<fnd::sha::sSha256Hash>& getMasterHashList() const;
void setMasterHashList(const fnd::List<fnd::sha::sSha256Hash>& master_hash_list);
bool getAlignHashToBlock() const;
void setAlignHashToBlock(bool doAlign);
@ -60,7 +60,7 @@ private:
// data
fnd::List<sLayer> mLayerInfo;
sLayer mDataLayer;
fnd::List<crypto::sha::sSha256Hash> mMasterHashList;
fnd::List<fnd::sha::sSha256Hash> mMasterHashList;
bool mDoAlignHashToBlock;
void importHierarchicalIntergityHeader(const nn::hac::HierarchicalIntegrityHeader& hdr);

View file

@ -96,16 +96,16 @@ void HashTreeWrappedIFile::write(const byte_t* out, size_t offset, size_t len)
void HashTreeWrappedIFile::initialiseDataLayer(const HashTreeMeta& hdr)
{
crypto::sha::sSha256Hash hash;
fnd::sha::sSha256Hash hash;
fnd::Vec<byte_t> cur, prev;
mAlignHashCalcToBlock = hdr.getAlignHashToBlock();
// copy master hash into prev
prev.alloc(sizeof(crypto::sha::sSha256Hash) * hdr.getMasterHashList().size());
prev.alloc(sizeof(fnd::sha::sSha256Hash) * hdr.getMasterHashList().size());
for (size_t i = 0; i < hdr.getMasterHashList().size(); i++)
{
((crypto::sha::sSha256Hash*)prev.data())[i] = hdr.getMasterHashList()[i];
((fnd::sha::sSha256Hash*)prev.data())[i] = hdr.getMasterHashList()[i];
}
// check each hash layer
@ -125,8 +125,8 @@ void HashTreeWrappedIFile::initialiseDataLayer(const HashTreeMeta& hdr)
for (size_t j = 0; j < cur.size() / layer.block_size; j++)
{
validate_size = mAlignHashCalcToBlock? layer.block_size : _MIN(layer.size - (j * layer.block_size), layer.block_size);
crypto::sha::Sha256(cur.data() + (j * layer.block_size), validate_size, hash.bytes);
if (hash.compare(prev.data() + j * sizeof(crypto::sha::sSha256Hash)) == false)
fnd::sha::Sha256(cur.data() + (j * layer.block_size), validate_size, hash.bytes);
if (hash.compare(prev.data() + j * sizeof(fnd::sha::sSha256Hash)) == false)
{
mErrorSs << "Hash tree layer verification failed (layer: " << i << ", block: " << j << ")";
throw fnd::Exception(kModuleName, mErrorSs.str());
@ -138,8 +138,8 @@ void HashTreeWrappedIFile::initialiseDataLayer(const HashTreeMeta& hdr)
}
// save last layer as hash table for data layer
crypto::sha::sSha256Hash* hash_list = (crypto::sha::sSha256Hash*)prev.data();
for (size_t i = 0; i < prev.size() / sizeof(crypto::sha::sSha256Hash); i++)
fnd::sha::sSha256Hash* hash_list = (fnd::sha::sSha256Hash*)prev.data();
for (size_t i = 0; i < prev.size() / sizeof(fnd::sha::sSha256Hash); i++)
{
mDataHashLayer.addElement(hash_list[i]);
}
@ -161,7 +161,7 @@ void HashTreeWrappedIFile::initialiseDataLayer(const HashTreeMeta& hdr)
void HashTreeWrappedIFile::readData(size_t block_offset, size_t block_num)
{
mData->seek(block_offset * mDataBlockSize);
crypto::sha::sSha256Hash hash;
fnd::sha::sSha256Hash hash;
// determine read size
size_t read_len = 0;
@ -194,7 +194,7 @@ void HashTreeWrappedIFile::readData(size_t block_offset, size_t block_num)
for (size_t i = 0; i < block_num; i++)
{
validate_size = mAlignHashCalcToBlock? mDataBlockSize : _MIN(read_len - (i * mDataBlockSize), mDataBlockSize);
crypto::sha::Sha256(mCache.data() + (i * mDataBlockSize), validate_size, hash.bytes);
fnd::sha::Sha256(mCache.data() + (i * mDataBlockSize), validate_size, hash.bytes);
if (hash != mDataHashLayer[block_offset + i])
{
mErrorSs << "Hash tree layer verification failed (layer: data, block: " << (block_offset + i) << " ( " << i << "/" << block_num-1 << " ), offset: 0x" << std::hex << ((block_offset + i) * mDataBlockSize) << ", size: 0x" << std::hex << validate_size <<")";

View file

@ -2,7 +2,7 @@
#include <sstream>
#include <fnd/IFile.h>
#include <fnd/Vec.h>
#include <crypto/sha.h>
#include <fnd/sha.h>
#include "HashTreeMeta.h"
@ -30,7 +30,7 @@ private:
fnd::IFile* mData;
size_t mDataOffset;
size_t mDataBlockSize;
fnd::List<crypto::sha::sSha256Hash> mDataHashLayer;
fnd::List<fnd::sha::sSha256Hash> mDataHashLayer;
bool mAlignHashCalcToBlock;
fnd::Vec<byte_t> mCache;

View file

@ -265,7 +265,7 @@ void NcaProcess::process()
nn::hac::NcaUtils::decryptNcaHeader((byte_t*)&mHdrBlock, (byte_t*)&mHdrBlock, mKeyset->nca.header_key);
// generate header hash
crypto::sha::Sha256((byte_t*)&mHdrBlock.header, sizeof(nn::hac::sNcaHeader), mHdrHash.bytes);
fnd::sha::Sha256((byte_t*)&mHdrBlock.header, sizeof(nn::hac::sNcaHeader), mHdrHash.bytes);
// proccess main header
mHdr.fromBytes((byte_t*)&mHdrBlock.header, sizeof(nn::hac::sNcaHeader));
@ -341,9 +341,9 @@ void NcaProcess::setListFs(bool list_fs)
void NcaProcess::generateNcaBodyEncryptionKeys()
{
// create zeros key
crypto::aes::sAes128Key zero_aesctr_key;
fnd::aes::sAes128Key zero_aesctr_key;
memset(zero_aesctr_key.key, 0, sizeof(zero_aesctr_key));
crypto::aes::sAesXts128Key zero_aesxts_key;
fnd::aes::sAesXts128Key zero_aesxts_key;
memset(zero_aesxts_key.key, 0, sizeof(zero_aesxts_key));
// get key data from header
@ -398,8 +398,8 @@ void NcaProcess::generateNcaBodyEncryptionKeys()
// otherwise decrypt key area
else
{
crypto::aes::sAes128Key keak_aesctr_key = zero_aesctr_key;
crypto::aes::sAesXts128Key keak_aesxts_key = zero_aesxts_key;
fnd::aes::sAes128Key keak_aesctr_key = zero_aesctr_key;
fnd::aes::sAesXts128Key keak_aesxts_key = zero_aesxts_key;
for (size_t i = 0; i < mBodyKeys.keak_list.size(); i++)
{
if (mBodyKeys.keak_list[i].index == nn::hac::nca::KEY_AESCTR && mBodyKeys.keak_list[i].decrypted)
@ -408,11 +408,11 @@ void NcaProcess::generateNcaBodyEncryptionKeys()
}
else if (mBodyKeys.keak_list[i].index == nn::hac::nca::KEY_AESXTS_0 && mBodyKeys.keak_list[i].decrypted)
{
memcpy(keak_aesxts_key.key[0], mBodyKeys.keak_list[i].dec.key, sizeof(crypto::aes::sAes128Key));
memcpy(keak_aesxts_key.key[0], mBodyKeys.keak_list[i].dec.key, sizeof(fnd::aes::sAes128Key));
}
else if (mBodyKeys.keak_list[i].index == nn::hac::nca::KEY_AESXTS_1 && mBodyKeys.keak_list[i].decrypted)
{
memcpy(keak_aesxts_key.key[1], mBodyKeys.keak_list[i].dec.key, sizeof(crypto::aes::sAes128Key));
memcpy(keak_aesxts_key.key[1], mBodyKeys.keak_list[i].dec.key, sizeof(fnd::aes::sAes128Key));
}
}
@ -472,8 +472,8 @@ void NcaProcess::generatePartitionConfiguration()
sPartitionInfo& info = mPartitions[partition.index];
// validate header hash
crypto::sha::sSha256Hash calc_hash;
crypto::sha::Sha256((const byte_t*)&mHdrBlock.fs_header[partition.index], sizeof(nn::hac::sNcaFsHeader), calc_hash.bytes);
fnd::sha::sSha256Hash calc_hash;
fnd::sha::Sha256((const byte_t*)&mHdrBlock.fs_header[partition.index], sizeof(nn::hac::sNcaFsHeader), calc_hash.bytes);
if (calc_hash.compare(partition.hash) == false)
{
error.clear();
@ -570,7 +570,7 @@ void NcaProcess::generatePartitionConfiguration()
void NcaProcess::validateNcaSignatures()
{
// validate signature[0]
if (crypto::rsa::pss::rsaVerify(mKeyset->nca.header_sign_key, crypto::sha::HASH_SHA256, mHdrHash.bytes, mHdrBlock.signature_main) != 0)
if (fnd::rsa::pss::rsaVerify(mKeyset->nca.header_sign_key, fnd::sha::HASH_SHA256, mHdrHash.bytes, mHdrBlock.signature_main) != 0)
{
printf("[WARNING] NCA Header Main Signature: FAIL \n");
}
@ -597,7 +597,7 @@ void NcaProcess::validateNcaSignatures()
npdm.setCliOutputMode(0);
npdm.process();
if (crypto::rsa::pss::rsaVerify(npdm.getNpdmBinary().getAcid().getNcaHeaderSignature2Key(), crypto::sha::HASH_SHA256, mHdrHash.bytes, mHdrBlock.signature_acid) != 0)
if (fnd::rsa::pss::rsaVerify(npdm.getNpdmBinary().getAcid().getNcaHeaderSignature2Key(), fnd::sha::HASH_SHA256, mHdrHash.bytes, mHdrBlock.signature_acid) != 0)
{
printf("[WARNING] NCA Header ACID Signature: FAIL \n");
}
@ -686,9 +686,9 @@ void NcaProcess::displayHeader()
if (info.enc_type == nn::hac::nca::CRYPT_AESCTR)
{
printf(" AES-CTR: ");
crypto::aes::sAesIvCtr ctr;
crypto::aes::AesIncrementCounter(info.aes_ctr.iv, info.offset>>4, ctr.iv);
fnd::SimpleTextOutput::hexDump(ctr.iv, sizeof(crypto::aes::sAesIvCtr));
fnd::aes::sAesIvCtr ctr;
fnd::aes::AesIncrementCounter(info.aes_ctr.iv, info.offset>>4, ctr.iv);
fnd::SimpleTextOutput::hexDump(ctr.iv, sizeof(fnd::aes::sAesIvCtr));
}
if (info.hash_type == nn::hac::nca::HASH_HIERARCHICAL_INTERGRITY)
{
@ -712,7 +712,7 @@ void NcaProcess::displayHeader()
for (size_t j = 0; j < hash_hdr.getMasterHashList().size(); j++)
{
printf(" Master Hash %d: ", (int)j);
fnd::SimpleTextOutput::hexDump(hash_hdr.getMasterHashList()[j].bytes, sizeof(crypto::sha::sSha256Hash));
fnd::SimpleTextOutput::hexDump(hash_hdr.getMasterHashList()[j].bytes, sizeof(fnd::sha::sSha256Hash));
}
}
else if (info.hash_type == nn::hac::nca::HASH_HIERARCHICAL_SHA256)
@ -720,7 +720,7 @@ void NcaProcess::displayHeader()
HashTreeMeta& hash_hdr = info.hash_tree_meta;
printf(" HierarchicalSha256 Header:\n");
printf(" Master Hash: ");
fnd::SimpleTextOutput::hexDump(hash_hdr.getMasterHashList()[0].bytes, sizeof(crypto::sha::sSha256Hash));
fnd::SimpleTextOutput::hexDump(hash_hdr.getMasterHashList()[0].bytes, sizeof(fnd::sha::sSha256Hash));
printf(" HashBlockSize: 0x%" PRIx32 "\n", (uint32_t)hash_hdr.getDataLayer().block_size);
//printf(" LayerNum: %d\n", hash_hdr.getLayerInfo().size());
printf(" Hash Layer:\n");

View file

@ -50,7 +50,7 @@ private:
// data
nn::hac::sNcaHeaderBlock mHdrBlock;
crypto::sha::sSha256Hash mHdrHash;
fnd::sha::sSha256Hash mHdrHash;
nn::hac::NcaHeader mHdr;
// crypto
@ -60,8 +60,8 @@ private:
{
byte_t index;
bool decrypted;
crypto::aes::sAes128Key enc;
crypto::aes::sAes128Key dec;
fnd::aes::sAes128Key enc;
fnd::aes::sAes128Key dec;
void operator=(const sKeyAreaKey& other)
{
@ -86,8 +86,8 @@ private:
};
fnd::List<sKeyAreaKey> keak_list;
sOptional<crypto::aes::sAes128Key> aes_ctr;
sOptional<crypto::aes::sAesXts128Key> aes_xts;
sOptional<fnd::aes::sAes128Key> aes_ctr;
sOptional<fnd::aes::sAesXts128Key> aes_xts;
} mBodyKeys;
struct sPartitionInfo
@ -102,7 +102,7 @@ private:
nn::hac::nca::HashType hash_type;
nn::hac::nca::EncryptionType enc_type;
HashTreeMeta hash_tree_meta;
crypto::aes::sAesIvCtr aes_ctr;
fnd::aes::sAesIvCtr aes_ctr;
} mPartitions[nn::hac::nca::kPartitionNum];
void generateNcaBodyEncryptionKeys();

View file

@ -1,6 +1,6 @@
#include <fnd/SimpleTextOutput.h>
#include <fnd/Vec.h>
#include <compress/lz4.h>
#include <fnd/lz4.h>
#include <nn/hac/nro-hb.h>
#include "OffsetAdjustedIFile.h"
#include "NroProcess.h"

View file

@ -1,6 +1,6 @@
#include <fnd/SimpleTextOutput.h>
#include <fnd/Vec.h>
#include <compress/lz4.h>
#include <fnd/lz4.h>
#include "OffsetAdjustedIFile.h"
#include "NsoProcess.h"
@ -89,7 +89,7 @@ void NsoProcess::importCodeSegments()
{
fnd::Vec<byte_t> scratch;
uint32_t decompressed_len;
crypto::sha::sSha256Hash calc_hash;
fnd::sha::sSha256Hash calc_hash;
// process text segment
if (mHdr.getTextSegmentInfo().is_compressed)
@ -97,7 +97,7 @@ void NsoProcess::importCodeSegments()
scratch.alloc(mHdr.getTextSegmentInfo().file_layout.size);
mFile->read(scratch.data(), mHdr.getTextSegmentInfo().file_layout.offset, scratch.size());
mTextBlob.alloc(mHdr.getTextSegmentInfo().memory_layout.size);
compress::lz4::decompressData(scratch.data(), (uint32_t)scratch.size(), mTextBlob.data(), (uint32_t)mTextBlob.size(), decompressed_len);
fnd::lz4::decompressData(scratch.data(), (uint32_t)scratch.size(), mTextBlob.data(), (uint32_t)mTextBlob.size(), decompressed_len);
if (decompressed_len != mTextBlob.size())
{
throw fnd::Exception(kModuleName, "NSO text segment failed to decompress");
@ -110,7 +110,7 @@ void NsoProcess::importCodeSegments()
}
if (mHdr.getTextSegmentInfo().is_hashed)
{
crypto::sha::Sha256(mTextBlob.data(), mTextBlob.size(), calc_hash.bytes);
fnd::sha::Sha256(mTextBlob.data(), mTextBlob.size(), calc_hash.bytes);
if (calc_hash != mHdr.getTextSegmentInfo().hash)
{
throw fnd::Exception(kModuleName, "NSO text segment failed SHA256 verification");
@ -123,7 +123,7 @@ void NsoProcess::importCodeSegments()
scratch.alloc(mHdr.getRoSegmentInfo().file_layout.size);
mFile->read(scratch.data(), mHdr.getRoSegmentInfo().file_layout.offset, scratch.size());
mRoBlob.alloc(mHdr.getRoSegmentInfo().memory_layout.size);
compress::lz4::decompressData(scratch.data(), (uint32_t)scratch.size(), mRoBlob.data(), (uint32_t)mRoBlob.size(), decompressed_len);
fnd::lz4::decompressData(scratch.data(), (uint32_t)scratch.size(), mRoBlob.data(), (uint32_t)mRoBlob.size(), decompressed_len);
if (decompressed_len != mRoBlob.size())
{
throw fnd::Exception(kModuleName, "NSO ro segment failed to decompress");
@ -136,7 +136,7 @@ void NsoProcess::importCodeSegments()
}
if (mHdr.getRoSegmentInfo().is_hashed)
{
crypto::sha::Sha256(mRoBlob.data(), mRoBlob.size(), calc_hash.bytes);
fnd::sha::Sha256(mRoBlob.data(), mRoBlob.size(), calc_hash.bytes);
if (calc_hash != mHdr.getRoSegmentInfo().hash)
{
throw fnd::Exception(kModuleName, "NSO ro segment failed SHA256 verification");
@ -149,7 +149,7 @@ void NsoProcess::importCodeSegments()
scratch.alloc(mHdr.getDataSegmentInfo().file_layout.size);
mFile->read(scratch.data(), mHdr.getDataSegmentInfo().file_layout.offset, scratch.size());
mDataBlob.alloc(mHdr.getDataSegmentInfo().memory_layout.size);
compress::lz4::decompressData(scratch.data(), (uint32_t)scratch.size(), mDataBlob.data(), (uint32_t)mDataBlob.size(), decompressed_len);
fnd::lz4::decompressData(scratch.data(), (uint32_t)scratch.size(), mDataBlob.data(), (uint32_t)mDataBlob.size(), decompressed_len);
if (decompressed_len != mDataBlob.size())
{
throw fnd::Exception(kModuleName, "NSO data segment failed to decompress");
@ -162,7 +162,7 @@ void NsoProcess::importCodeSegments()
}
if (mHdr.getDataSegmentInfo().is_hashed)
{
crypto::sha::Sha256(mDataBlob.data(), mDataBlob.size(), calc_hash.bytes);
fnd::sha::Sha256(mDataBlob.data(), mDataBlob.size(), calc_hash.bytes);
if (calc_hash != mHdr.getDataSegmentInfo().hash)
{
throw fnd::Exception(kModuleName, "NSO data segment failed SHA256 verification");

View file

@ -142,13 +142,13 @@ bool PfsProcess::validateHeaderMagic(const nn::hac::sPfsHeader* hdr)
void PfsProcess::validateHfs()
{
crypto::sha::sSha256Hash hash;
fnd::sha::sSha256Hash hash;
const fnd::List<nn::hac::PfsHeader::sFile>& file = mPfs.getFileList();
for (size_t i = 0; i < file.size(); i++)
{
mCache.alloc(file[i].hash_protected_size);
mFile->read(mCache.data(), file[i].offset, file[i].hash_protected_size);
crypto::sha::Sha256(mCache.data(), file[i].hash_protected_size, hash.bytes);
fnd::sha::Sha256(mCache.data(), file[i].hash_protected_size, hash.bytes);
if (hash != file[i].hash)
{
printf("[WARNING] HFS0 %s%s%s: FAIL (bad hash)\n", !mMountName.empty()? mMountName.c_str() : "", (!mMountName.empty() && mMountName.at(mMountName.length()-1) != '/' )? "/" : "", file[i].name.c_str());

View file

@ -123,25 +123,25 @@ void PkiCertProcess::displayCert(const nn::pki::SignedData<nn::pki::CertificateB
{
std::cout << " PublicKey:" << std::endl;
std::cout << " Modulus:" << std::endl;
fnd::SimpleTextOutput::hexDump(cert.getBody().getRsa4098PublicKey().modulus, getHexDumpLen(crypto::rsa::kRsa4096Size), 0x10, 6);
fnd::SimpleTextOutput::hexDump(cert.getBody().getRsa4098PublicKey().modulus, getHexDumpLen(fnd::rsa::kRsa4096Size), 0x10, 6);
std::cout << " Public Exponent:" << std::endl;
fnd::SimpleTextOutput::hexDump(cert.getBody().getRsa4098PublicKey().public_exponent, crypto::rsa::kRsaPublicExponentSize, 0x10, 6);
fnd::SimpleTextOutput::hexDump(cert.getBody().getRsa4098PublicKey().public_exponent, fnd::rsa::kRsaPublicExponentSize, 0x10, 6);
}
else if (cert.getBody().getPublicKeyType() == nn::pki::cert::RSA2048)
{
std::cout << " PublicKey:" << std::endl;
std::cout << " Public Exponent:" << std::endl;
fnd::SimpleTextOutput::hexDump(cert.getBody().getRsa2048PublicKey().modulus, getHexDumpLen(crypto::rsa::kRsa2048Size), 0x10, 6);
fnd::SimpleTextOutput::hexDump(cert.getBody().getRsa2048PublicKey().modulus, getHexDumpLen(fnd::rsa::kRsa2048Size), 0x10, 6);
std::cout << " Modulus:" << std::endl;
fnd::SimpleTextOutput::hexDump(cert.getBody().getRsa2048PublicKey().public_exponent, crypto::rsa::kRsaPublicExponentSize, 0x10, 6);
fnd::SimpleTextOutput::hexDump(cert.getBody().getRsa2048PublicKey().public_exponent, fnd::rsa::kRsaPublicExponentSize, 0x10, 6);
}
else if (cert.getBody().getPublicKeyType() == nn::pki::cert::ECDSA240)
{
std::cout << " PublicKey:" << std::endl;
std::cout << " R:" << std::endl;
fnd::SimpleTextOutput::hexDump(cert.getBody().getEcdsa240PublicKey().r, getHexDumpLen(crypto::ecdsa::kEcdsa240Size), 0x10, 6);
fnd::SimpleTextOutput::hexDump(cert.getBody().getEcdsa240PublicKey().r, getHexDumpLen(fnd::ecdsa::kEcdsa240Size), 0x10, 6);
std::cout << " S:" << std::endl;
fnd::SimpleTextOutput::hexDump(cert.getBody().getEcdsa240PublicKey().s, getHexDumpLen(crypto::ecdsa::kEcdsa240Size), 0x10, 6);
fnd::SimpleTextOutput::hexDump(cert.getBody().getEcdsa240PublicKey().s, getHexDumpLen(fnd::ecdsa::kEcdsa240Size), 0x10, 6);
}

View file

@ -9,7 +9,7 @@ PkiValidator::PkiValidator()
clearCertificates();
}
void PkiValidator::setRootKey(const crypto::rsa::sRsa4096Key& root_key)
void PkiValidator::setRootKey(const fnd::rsa::sRsa4096Key& root_key)
{
// save a copy of the certificate bank
fnd::List<nn::pki::SignedData<nn::pki::CertificateBody>> old_certs = mCertificateBank;
@ -58,12 +58,12 @@ void PkiValidator::addCertificate(const nn::pki::SignedData<nn::pki::Certificate
switch (cert_hash_algo)
{
case (nn::pki::sign::HASH_ALGO_SHA1):
cert_hash.alloc(crypto::sha::kSha1HashLen);
crypto::sha::Sha1(cert.getBody().getBytes().data(), cert.getBody().getBytes().size(), cert_hash.data());
cert_hash.alloc(fnd::sha::kSha1HashLen);
fnd::sha::Sha1(cert.getBody().getBytes().data(), cert.getBody().getBytes().size(), cert_hash.data());
break;
case (nn::pki::sign::HASH_ALGO_SHA256):
cert_hash.alloc(crypto::sha::kSha256HashLen);
crypto::sha::Sha256(cert.getBody().getBytes().data(), cert.getBody().getBytes().size(), cert_hash.data());
cert_hash.alloc(fnd::sha::kSha256HashLen);
fnd::sha::Sha256(cert.getBody().getBytes().data(), cert.getBody().getBytes().size(), cert_hash.data());
break;
default:
throw fnd::Exception(kModuleName, "Unrecognised hash type");
@ -102,7 +102,7 @@ void PkiValidator::validateSignature(const std::string& issuer, nn::pki::sign::S
{
throw fnd::Exception(kModuleName, "Issued by Root, but does not have a RSA4096 signature");
}
sig_validate_res = crypto::rsa::pkcs::rsaVerify(mRootKey, getCryptoHashAlgoFromEsSignHashAlgo(hash_algo), hash.data(), signature.data());
sig_validate_res = fnd::rsa::pkcs::rsaVerify(mRootKey, getCryptoHashAlgoFromEsSignHashAlgo(hash_algo), hash.data(), signature.data());
}
else
{
@ -112,11 +112,11 @@ void PkiValidator::validateSignature(const std::string& issuer, nn::pki::sign::S
if (issuer_pubk_type == nn::pki::cert::RSA4096 && sign_algo == nn::pki::sign::SIGN_ALGO_RSA4096)
{
sig_validate_res = crypto::rsa::pkcs::rsaVerify(issuer_cert.getRsa4098PublicKey(), getCryptoHashAlgoFromEsSignHashAlgo(hash_algo), hash.data(), signature.data());
sig_validate_res = fnd::rsa::pkcs::rsaVerify(issuer_cert.getRsa4098PublicKey(), getCryptoHashAlgoFromEsSignHashAlgo(hash_algo), hash.data(), signature.data());
}
else if (issuer_pubk_type == nn::pki::cert::RSA2048 && sign_algo == nn::pki::sign::SIGN_ALGO_RSA2048)
{
sig_validate_res = crypto::rsa::pkcs::rsaVerify(issuer_cert.getRsa2048PublicKey(), getCryptoHashAlgoFromEsSignHashAlgo(hash_algo), hash.data(), signature.data());
sig_validate_res = fnd::rsa::pkcs::rsaVerify(issuer_cert.getRsa2048PublicKey(), getCryptoHashAlgoFromEsSignHashAlgo(hash_algo), hash.data(), signature.data());
}
else if (issuer_pubk_type == nn::pki::cert::ECDSA240 && sign_algo == nn::pki::sign::SIGN_ALGO_ECDSA240)
{
@ -179,17 +179,17 @@ const nn::pki::SignedData<nn::pki::CertificateBody>& PkiValidator::getCert(const
throw fnd::Exception(kModuleName, "Issuer certificate does not exist");
}
crypto::sha::HashType PkiValidator::getCryptoHashAlgoFromEsSignHashAlgo(nn::pki::sign::HashAlgo hash_algo) const
fnd::sha::HashType PkiValidator::getCryptoHashAlgoFromEsSignHashAlgo(nn::pki::sign::HashAlgo hash_algo) const
{
crypto::sha::HashType hash_type = crypto::sha::HASH_SHA1;
fnd::sha::HashType hash_type = fnd::sha::HASH_SHA1;
switch (hash_algo)
{
case (nn::pki::sign::HASH_ALGO_SHA1):
hash_type = crypto::sha::HASH_SHA1;
hash_type = fnd::sha::HASH_SHA1;
break;
case (nn::pki::sign::HASH_ALGO_SHA256):
hash_type = crypto::sha::HASH_SHA256;
hash_type = fnd::sha::HASH_SHA256;
break;
};

View file

@ -2,7 +2,7 @@
#include <fnd/types.h>
#include <fnd/List.h>
#include <fnd/Vec.h>
#include <crypto/rsa.h>
#include <fnd/rsa.h>
#include <nn/pki/SignedData.h>
#include <nn/pki/CertificateBody.h>
#include <string>
@ -12,7 +12,7 @@ class PkiValidator
public:
PkiValidator();
void setRootKey(const crypto::rsa::sRsa4096Key& root_key);
void setRootKey(const fnd::rsa::sRsa4096Key& root_key);
void addCertificates(const fnd::List<nn::pki::SignedData<nn::pki::CertificateBody>>& certs);
void addCertificate(const nn::pki::SignedData<nn::pki::CertificateBody>& cert);
void clearCertificates();
@ -23,12 +23,12 @@ private:
const std::string kModuleName = "NNPkiValidator";
crypto::rsa::sRsa4096Key mRootKey;
fnd::rsa::sRsa4096Key mRootKey;
fnd::List<nn::pki::SignedData<nn::pki::CertificateBody>> mCertificateBank;
void makeCertIdent(const nn::pki::SignedData<nn::pki::CertificateBody>& cert, std::string& ident) const;
void makeCertIdent(const std::string& issuer, const std::string& subject, std::string& ident) const;
bool doesCertExist(const std::string& ident) const;
const nn::pki::SignedData<nn::pki::CertificateBody>& getCert(const std::string& ident) const;
crypto::sha::HashType getCryptoHashAlgoFromEsSignHashAlgo(nn::pki::sign::HashAlgo hash_algo) const;
fnd::sha::HashType getCryptoHashAlgoFromEsSignHashAlgo(nn::pki::sign::HashAlgo hash_algo) const;
};

View file

@ -385,10 +385,10 @@ void UserSettings::populateCmdArgs(const std::vector<std::string>& arg_list, sCm
void UserSettings::populateKeyset(sCmdArgs& args)
{
crypto::aes::sAes128Key zeros_aes_key;
crypto::aes::sAesXts128Key zeros_aes_xts_key;
memset((void*)&zeros_aes_key, 0, sizeof(crypto::aes::sAes128Key));
memset((void*)&zeros_aes_xts_key, 0, sizeof(crypto::aes::sAesXts128Key));
fnd::aes::sAes128Key zeros_aes_key;
fnd::aes::sAesXts128Key zeros_aes_xts_key;
memset((void*)&zeros_aes_key, 0, sizeof(fnd::aes::sAes128Key));
memset((void*)&zeros_aes_xts_key, 0, sizeof(fnd::aes::sAesXts128Key));
memset((void*)&mKeyset, 0, sizeof(sKeyset));
fnd::ResourceFileReader res;
@ -446,14 +446,14 @@ void UserSettings::populateKeyset(sCmdArgs& args)
// sources
crypto::aes::sAes128Key master_key[kMasterKeyNum] = { zeros_aes_key };
crypto::aes::sAes128Key package2_key_source = zeros_aes_key;
crypto::aes::sAes128Key ticket_titlekek_source = zeros_aes_key;
crypto::aes::sAes128Key key_area_key_source[3] = { zeros_aes_key, zeros_aes_key, zeros_aes_key };
crypto::aes::sAes128Key aes_kek_generation_source = zeros_aes_key;
crypto::aes::sAes128Key aes_key_generation_source = zeros_aes_key;
crypto::aes::sAes128Key nca_header_kek_source = zeros_aes_key;
crypto::aes::sAesXts128Key nca_header_key_source = zeros_aes_xts_key;
fnd::aes::sAes128Key master_key[kMasterKeyNum] = { zeros_aes_key };
fnd::aes::sAes128Key package2_key_source = zeros_aes_key;
fnd::aes::sAes128Key ticket_titlekek_source = zeros_aes_key;
fnd::aes::sAes128Key key_area_key_source[3] = { zeros_aes_key, zeros_aes_key, zeros_aes_key };
fnd::aes::sAes128Key aes_kek_generation_source = zeros_aes_key;
fnd::aes::sAes128Key aes_key_generation_source = zeros_aes_key;
fnd::aes::sAes128Key nca_header_kek_source = zeros_aes_key;
fnd::aes::sAesXts128Key nca_header_key_source = zeros_aes_xts_key;
#define _CONCAT_2_STRINGS(str1, str2) ((str1) + "_" + (str2))
@ -509,44 +509,44 @@ void UserSettings::populateKeyset(sCmdArgs& args)
_SAVE_KEYDATA(_CONCAT_2_STRINGS(kXciHeaderBase, kKeyStr), mKeyset.xci.header_key.key, 0x10);
// store rsa keys
_SAVE_KEYDATA(_CONCAT_2_STRINGS(kNcaHeaderBase[1], kRsaKeySuffix[0]), mKeyset.nca.header_sign_key.priv_exponent, crypto::rsa::kRsa2048Size);
_SAVE_KEYDATA(_CONCAT_2_STRINGS(kNcaHeaderBase[1], kRsaKeySuffix[1]), mKeyset.nca.header_sign_key.modulus, crypto::rsa::kRsa2048Size);
_SAVE_KEYDATA(_CONCAT_2_STRINGS(kNcaHeaderBase[1], kRsaKeySuffix[0]), mKeyset.nca.header_sign_key.priv_exponent, fnd::rsa::kRsa2048Size);
_SAVE_KEYDATA(_CONCAT_2_STRINGS(kNcaHeaderBase[1], kRsaKeySuffix[1]), mKeyset.nca.header_sign_key.modulus, fnd::rsa::kRsa2048Size);
_SAVE_KEYDATA(_CONCAT_2_STRINGS(kXciHeaderBase, kRsaKeySuffix[0]), mKeyset.xci.header_sign_key.priv_exponent, crypto::rsa::kRsa2048Size);
_SAVE_KEYDATA(_CONCAT_2_STRINGS(kXciHeaderBase, kRsaKeySuffix[1]), mKeyset.xci.header_sign_key.modulus, crypto::rsa::kRsa2048Size);
_SAVE_KEYDATA(_CONCAT_2_STRINGS(kXciHeaderBase, kRsaKeySuffix[0]), mKeyset.xci.header_sign_key.priv_exponent, fnd::rsa::kRsa2048Size);
_SAVE_KEYDATA(_CONCAT_2_STRINGS(kXciHeaderBase, kRsaKeySuffix[1]), mKeyset.xci.header_sign_key.modulus, fnd::rsa::kRsa2048Size);
_SAVE_KEYDATA(_CONCAT_2_STRINGS(kAcidBase, kRsaKeySuffix[0]), mKeyset.acid_sign_key.priv_exponent, crypto::rsa::kRsa2048Size);
_SAVE_KEYDATA(_CONCAT_2_STRINGS(kAcidBase, kRsaKeySuffix[1]), mKeyset.acid_sign_key.modulus, crypto::rsa::kRsa2048Size);
_SAVE_KEYDATA(_CONCAT_2_STRINGS(kAcidBase, kRsaKeySuffix[0]), mKeyset.acid_sign_key.priv_exponent, fnd::rsa::kRsa2048Size);
_SAVE_KEYDATA(_CONCAT_2_STRINGS(kAcidBase, kRsaKeySuffix[1]), mKeyset.acid_sign_key.modulus, fnd::rsa::kRsa2048Size);
_SAVE_KEYDATA(_CONCAT_2_STRINGS(kPackage2Base, kRsaKeySuffix[0]), mKeyset.package2_sign_key.priv_exponent, crypto::rsa::kRsa2048Size);
_SAVE_KEYDATA(_CONCAT_2_STRINGS(kPackage2Base, kRsaKeySuffix[1]), mKeyset.package2_sign_key.modulus, crypto::rsa::kRsa2048Size);
_SAVE_KEYDATA(_CONCAT_2_STRINGS(kPackage2Base, kRsaKeySuffix[0]), mKeyset.package2_sign_key.priv_exponent, fnd::rsa::kRsa2048Size);
_SAVE_KEYDATA(_CONCAT_2_STRINGS(kPackage2Base, kRsaKeySuffix[1]), mKeyset.package2_sign_key.modulus, fnd::rsa::kRsa2048Size);
_SAVE_KEYDATA(_CONCAT_2_STRINGS(kPkiRootBase, kRsaKeySuffix[0]), mKeyset.pki.root_sign_key.priv_exponent, crypto::rsa::kRsa4096Size);
_SAVE_KEYDATA(_CONCAT_2_STRINGS(kPkiRootBase, kRsaKeySuffix[1]), mKeyset.pki.root_sign_key.modulus, crypto::rsa::kRsa4096Size);
_SAVE_KEYDATA(_CONCAT_2_STRINGS(kPkiRootBase, kRsaKeySuffix[0]), mKeyset.pki.root_sign_key.priv_exponent, fnd::rsa::kRsa4096Size);
_SAVE_KEYDATA(_CONCAT_2_STRINGS(kPkiRootBase, kRsaKeySuffix[1]), mKeyset.pki.root_sign_key.modulus, fnd::rsa::kRsa4096Size);
// save keydata from input args
if (args.nca_bodykey.isSet)
{
if (args.nca_bodykey.var.length() == (sizeof(crypto::aes::sAes128Key)*2))
if (args.nca_bodykey.var.length() == (sizeof(fnd::aes::sAes128Key)*2))
{
decodeHexStringToBytes("--bodykey", args.nca_bodykey.var, mKeyset.nca.manual_body_key_aesctr.key, sizeof(crypto::aes::sAes128Key));
decodeHexStringToBytes("--bodykey", args.nca_bodykey.var, mKeyset.nca.manual_body_key_aesctr.key, sizeof(fnd::aes::sAes128Key));
}
else
{
decodeHexStringToBytes("--bodykey", args.nca_bodykey.var, mKeyset.nca.manual_body_key_aesxts.key[0], sizeof(crypto::aes::sAesXts128Key));
decodeHexStringToBytes("--bodykey", args.nca_bodykey.var, mKeyset.nca.manual_body_key_aesxts.key[0], sizeof(fnd::aes::sAesXts128Key));
}
}
if (args.nca_titlekey.isSet)
{
if (args.nca_titlekey.var.length() == (sizeof(crypto::aes::sAes128Key)*2))
if (args.nca_titlekey.var.length() == (sizeof(fnd::aes::sAes128Key)*2))
{
decodeHexStringToBytes("--titlekey", args.nca_titlekey.var, mKeyset.nca.manual_title_key_aesctr.key, sizeof(crypto::aes::sAes128Key));
decodeHexStringToBytes("--titlekey", args.nca_titlekey.var, mKeyset.nca.manual_title_key_aesctr.key, sizeof(fnd::aes::sAes128Key));
}
else
{
decodeHexStringToBytes("--titlekey", args.nca_titlekey.var, mKeyset.nca.manual_title_key_aesxts.key[0], sizeof(crypto::aes::sAesXts128Key));
decodeHexStringToBytes("--titlekey", args.nca_titlekey.var, mKeyset.nca.manual_title_key_aesxts.key[0], sizeof(fnd::aes::sAesXts128Key));
}
}
@ -590,12 +590,12 @@ void UserSettings::populateKeyset(sCmdArgs& args)
switch (nn::pki::sign::getHashAlgo(tik.getSignature().getSignType()))
{
case (nn::pki::sign::HASH_ALGO_SHA1):
tik_hash.alloc(crypto::sha::kSha1HashLen);
crypto::sha::Sha1(tik.getBody().getBytes().data(), tik.getBody().getBytes().size(), tik_hash.data());
tik_hash.alloc(fnd::sha::kSha1HashLen);
fnd::sha::Sha1(tik.getBody().getBytes().data(), tik.getBody().getBytes().size(), tik_hash.data());
break;
case (nn::pki::sign::HASH_ALGO_SHA256):
tik_hash.alloc(crypto::sha::kSha256HashLen);
crypto::sha::Sha256(tik.getBody().getBytes().data(), tik.getBody().getBytes().size(), tik_hash.data());
tik_hash.alloc(fnd::sha::kSha256HashLen);
fnd::sha::Sha256(tik.getBody().getBytes().data(), tik.getBody().getBytes().size(), tik_hash.data());
break;
}
@ -615,7 +615,7 @@ void UserSettings::populateKeyset(sCmdArgs& args)
// extract title key
if (tik.getBody().getTitleKeyEncType() == nn::es::ticket::AES128_CBC)
{
memcpy(mKeyset.nca.manual_title_key_aesctr.key, tik.getBody().getEncTitleKey(), crypto::aes::kAes128KeySize);
memcpy(mKeyset.nca.manual_title_key_aesctr.key, tik.getBody().getEncTitleKey(), fnd::aes::kAes128KeySize);
}
else
{
@ -638,7 +638,7 @@ void UserSettings::populateKeyset(sCmdArgs& args)
{
if (mKeyset.nca.header_key == zeros_aes_xts_key)
{
crypto::aes::sAes128Key nca_header_kek;
fnd::aes::sAes128Key nca_header_kek;
nn::hac::AesKeygen::generateKey(nca_header_kek.key, aes_kek_generation_source.key, nca_header_kek_source.key, aes_key_generation_source.key, master_key[i].key);
nn::hac::AesKeygen::generateKey(mKeyset.nca.header_key.key[0], nca_header_key_source.key[0], nca_header_kek.key);
nn::hac::AesKeygen::generateKey(mKeyset.nca.header_key.key[1], nca_header_key_source.key[1], nca_header_kek.key);

View file

@ -183,18 +183,18 @@ void XciProcess::displayHeader()
bool XciProcess::validateRegionOfFile(size_t offset, size_t len, const byte_t* test_hash)
{
fnd::Vec<byte_t> scratch;
crypto::sha::sSha256Hash calc_hash;
fnd::sha::sSha256Hash calc_hash;
scratch.alloc(len);
mFile->read(scratch.data(), offset, scratch.size());
crypto::sha::Sha256(scratch.data(), scratch.size(), calc_hash.bytes);
fnd::sha::Sha256(scratch.data(), scratch.size(), calc_hash.bytes);
return calc_hash.compare(test_hash);
}
void XciProcess::validateXciSignature()
{
crypto::sha::sSha256Hash calc_hash;
crypto::sha::Sha256((byte_t*)&mHdrPage.header, sizeof(nn::hac::sXciHeader), calc_hash.bytes);
if (crypto::rsa::pkcs::rsaVerify(mKeyset->xci.header_sign_key, crypto::sha::HASH_SHA256, calc_hash.bytes, mHdrPage.signature) != 0)
fnd::sha::sSha256Hash calc_hash;
fnd::sha::Sha256((byte_t*)&mHdrPage.header, sizeof(nn::hac::sXciHeader), calc_hash.bytes);
if (fnd::rsa::pkcs::rsaVerify(mKeyset->xci.header_sign_key, fnd::sha::HASH_SHA256, calc_hash.bytes, mHdrPage.signature) != 0)
{
printf("[WARNING] XCI Header Signature: FAIL \n");
}

View file

@ -2,8 +2,8 @@
#pragma once
#include <string>
#include <fnd/types.h>
#include <crypto/aes.h>
#include <crypto/rsa.h>
#include <fnd/aes.h>
#include <fnd/rsa.h>
#include <nn/hac/nca.h>
static const size_t kMasterKeyNum = 0x20;
@ -63,38 +63,38 @@ struct sOptional
struct sKeyset
{
crypto::rsa::sRsa2048Key acid_sign_key;
crypto::aes::sAes128Key package1_key[kMasterKeyNum];
crypto::rsa::sRsa2048Key package2_sign_key;
crypto::aes::sAes128Key package2_key[kMasterKeyNum];
fnd::rsa::sRsa2048Key acid_sign_key;
fnd::aes::sAes128Key package1_key[kMasterKeyNum];
fnd::rsa::sRsa2048Key package2_sign_key;
fnd::aes::sAes128Key package2_key[kMasterKeyNum];
struct sNcaData
{
crypto::rsa::sRsa2048Key header_sign_key;
crypto::aes::sAesXts128Key header_key;
crypto::aes::sAes128Key key_area_key[kNcaKeakNum][kMasterKeyNum];
fnd::rsa::sRsa2048Key header_sign_key;
fnd::aes::sAesXts128Key header_key;
fnd::aes::sAes128Key key_area_key[kNcaKeakNum][kMasterKeyNum];
crypto::aes::sAes128Key manual_title_key_aesctr;
crypto::aes::sAesXts128Key manual_title_key_aesxts;
crypto::aes::sAes128Key manual_body_key_aesctr;
crypto::aes::sAesXts128Key manual_body_key_aesxts;
fnd::aes::sAes128Key manual_title_key_aesctr;
fnd::aes::sAesXts128Key manual_title_key_aesxts;
fnd::aes::sAes128Key manual_body_key_aesctr;
fnd::aes::sAesXts128Key manual_body_key_aesxts;
} nca;
struct sXciData
{
crypto::rsa::sRsa2048Key header_sign_key;
crypto::aes::sAes128Key header_key;
fnd::rsa::sRsa2048Key header_sign_key;
fnd::aes::sAes128Key header_key;
} xci;
struct sTicketData
{
crypto::rsa::sRsa2048Key sign_key;
crypto::aes::sAes128Key titlekey_kek[kMasterKeyNum];
fnd::rsa::sRsa2048Key sign_key;
fnd::aes::sAes128Key titlekey_kek[kMasterKeyNum];
} ticket;
struct sPkiData
{
crypto::rsa::sRsa4096Key root_sign_key;
fnd::rsa::sRsa4096Key root_sign_key;
} pki;
};