Zach Hilman
1d2f86949b
crypto: Various crypto fixes for quickstart guide
2018-10-14 21:57:52 -04:00
Lioncash
18db0f1107
partition_data_manager: Reserve and insert data within output vector in DecryptPackage2()
...
We can just reserve the memory then perform successive insertions
instead of needing to use memcpy. This also avoids the need to zero out
the output vector's memory before performing the insertions.
We can also std::move the output std::vector into the destination so
that we don't need to make a completely new copy of the vector, getting
rid of an unnecessary allocation.
Additionally, we can use iterators to determine the beginning and end
ranges of the std::vector instances that comprise the output vector, as
the end of one range just becomes the beginning for the next successive
range, and since std::vector's iterator constructor copies data within
the range [begin, end), this is more straightforward and gets rid of the
need to have an offset variable that keeps getting incremented to
determine where to do the next std::memcpy.
2018-10-13 09:50:08 -04:00
Lioncash
20a95f7e90
partition_data_manager: Remove unused std::map instance within DecryptPackage2()
...
Aside from emplacing elements into the map, the map itself is never
actually queried for contained data.
2018-10-13 09:27:12 -04:00
Lioncash
283f111f7d
partition_data_manager: Take package2_keys by const reference
...
These are only ever read from, so we don't need to make a copy of all
the keys here.
2018-10-13 09:24:41 -04:00
Lioncash
461cd4b81c
partition_data_manager: Move IV data to where it's needed in DecryptPackage2()
...
Given it's only used in one spot and has a fairly generic name, we can
just specify it directly in the function call. This also the benefit of
automatically moving it.
2018-10-13 09:20:21 -04:00
Lioncash
7095c2fa42
partition_data_manager: Remove commented out code
...
Commented out code shouldn't be left in without a reason indicating why
in a comment.
2018-10-13 09:17:02 -04:00
Lioncash
e21cda8767
key_manager/partition_data_manager: Silence truncation compiler warnings
2018-10-13 09:13:19 -04:00
Lioncash
8e8fbbc19b
partition_data_manager: Dehardcode array bounds
...
Instead, we can make it part of the type and make named variables for
them, so they only require one definition (and if they ever change for
whatever reason, they only need to be changed in one spot).
2018-10-13 08:52:37 -04:00
Lioncash
49f255e0b5
partition_data_manager: Take VirtualFile by const reference in constructor
...
Given the VirtualFile instance isn't stored into the class as a data
member, or written to, this can just be turned into a const reference,
as the constructor doesn't need to make a copy of it.
2018-10-13 08:39:05 -04:00
Lioncash
0581db975a
partition_data_manager: Amend constructor initializer list order
...
Orders the members in the exact order they would be initialized. This
also prevents compiler warnings about this sort of thing.
2018-10-13 08:36:26 -04:00
Lioncash
1b48e3ec08
partition_data_manager: Remove unused includes
...
Gets unused includes out of the headers and moves them into the cpp file
if they're used there instead.
2018-10-13 08:33:49 -04:00
Lioncash
f50401aa7f
key_manager: Use std::vector's insert() instead of std::copy with a back_inserter
...
If the data is unconditionally being appended to the back of a
std::vector, we can just directly insert it there without the need to
insert all of the elements one-by-one with a std::back_inserter.
2018-10-13 08:29:35 -04:00
Lioncash
5323ae4af4
key_manager: Brace long conditional body
...
If a conditional (or it's body) travels more than one line, it should be
braced.
2018-10-13 08:24:21 -04:00
Lioncash
214d206020
key_manager: Don't assume file seeks and reads will always succeed
...
Given the filesystem should always be assumed to be volatile, we should
check and bail out if a seek operation isn't successful. This'll prevent
potentially writing/returning garbage data from the function in rare
cases.
This also allows removing a check to see if an offset is within the
bounds of a file before perfoming a seek operation. If a seek is
attempted beyond the end of a file, it will fail, so this essentially
combines two checks into one in one place.
2018-10-13 08:24:18 -04:00
Lioncash
b7c947fed3
key_manager: Remove unnecessary seek in DeriveSDSeed()
...
Given the file is opened a few lines above and no operations are done,
other than check if the file is in a valid state, the read/write pointer
will always be at the beginning of the file.
2018-10-13 08:08:44 -04:00
Zach Hilman
cb3ebb0b8f
partition_data_manager: Rename system files for hekate
...
x
2018-10-07 13:16:23 -04:00
Zach Hilman
c137dca0fd
crypto: Add PartitionDataManager
...
Keeps track of system files for key derivation
2018-10-07 13:15:11 -04:00
Zach Hilman
877dd19cae
key_manager: Add support for loading keys from partition data
2018-10-07 13:15:11 -04:00
Zach Hilman
facd1d42a6
key_manager: Add ETicket key derivation
...
Derives titlekeys
2018-10-07 13:15:11 -04:00
Zach Hilman
30b8dd7c50
key_manager: Add base key derivation
...
Derives master keys, game encryption keys, and package1/2 keys
2018-10-07 13:15:11 -04:00
Zach Hilman
3048dad94a
key_manager: Add BIS key getter
2018-10-07 13:15:11 -04:00
Zach Hilman
509b916817
key_manager: Add support for more keys
...
TSEC, SBK, BIS, and other Sources for proper derivation
2018-10-07 13:15:11 -04:00
Zach Hilman
306f4c3c7b
key_manager: Add keyblob support
2018-10-07 13:15:11 -04:00
Zach Hilman
7a3faf4ced
key_manager: Add support for crypto revisions past 04
2018-10-07 13:15:11 -04:00
Zach Hilman
659b8150aa
key_manager: Add support for comments in keyfiles
2018-10-07 13:15:11 -04:00
Zach Hilman
01843d244e
key_manager: Add support for console-specific keyfile
2018-10-07 13:15:11 -04:00
Zach Hilman
0b4eb661a9
key_manager: Rename KEK to Kek
2018-10-07 13:15:11 -04:00
fearlessTobi
1190ea6ddb
Port #4182 from Citra: "Prefix all size_t with std::"
2018-09-15 15:21:06 +02:00
Zach Hilman
bf86700873
game_list: Use RegisteredCacheUnion for installed
...
Reduces code
2018-09-04 16:21:40 -04:00
Zach Hilman
7b95f295b6
aes_util: Fix error involving reads of less than 0x10
...
Issues with block size are fixed by making all reads minimum length of 0x10
2018-09-04 16:21:40 -04:00
Zach Hilman
887ffb2512
nsp: Comply with style and performance guidelines
2018-09-04 14:29:19 -04:00
Zach Hilman
57769f8d0d
card_image: Parse XCI secure partition with NSP
...
Eliminated duplicate code and adds support for Rev1+ carts
2018-09-04 14:27:33 -04:00
Zach Hilman
8e787e5ec2
key_manager: Avoid autogeneration if key exists
2018-09-04 14:25:54 -04:00
Lioncash
a9f4e31cc0
file_sys: Replace includes with forward declarations where applicable
...
Cuts down on include dependencies, resulting in less files that need to
be rebuilt when certain things are changed.
2018-09-03 22:52:24 -04:00
Zach Hilman
89422004c3
file_sys/crypto: Fix missing/unnecessary includes
2018-08-24 22:15:32 -04:00
Zach Hilman
8f6ef9d395
key_manager: Eliminate indexed for loop
2018-08-23 11:53:30 -04:00
Zach Hilman
8b989b2e11
key_manager: Create keys dir if it dosen't exist
...
On call to WriteKeyToFile, so that the autogenerated file can be written.
2018-08-23 11:53:30 -04:00
Zach Hilman
d867928e90
file_sys: Cut down on includes and copies
2018-08-23 11:53:30 -04:00
Zach Hilman
d3225fdae9
crypto: Eliminate magic constants
2018-08-23 11:53:30 -04:00
Zach Hilman
5b8fdc94e2
key_manager: Add support for autogenerated keys
...
Stored in a separate file than manual keys.
2018-08-23 11:53:30 -04:00
Zach Hilman
abfa173778
key_manager: Add support for KEK and SD seed derivation
2018-08-23 11:53:30 -04:00
Zach Hilman
25e7fc1b47
key_manager: Switch to boost flat_map for keys
...
Should make key gets marginally faster.
2018-08-23 11:53:30 -04:00
Zach Hilman
1369a56ec3
xts_encryption_layer: Implement XTSEncryptionLayer
2018-08-23 11:52:44 -04:00
Zach Hilman
ec14bb18c9
aes_util: Make XTSTranscode stricter about sizes
...
XTS with Nintendo Tweak will fail mysteriously if the sector size is not 0x4000. Upgrade the critical log to an assert to prevent undefined behavior.
2018-08-23 11:52:44 -04:00
Zach Hilman
abb0f6cac9
ctr_encryption_layer: Fix bug when transcoding small data
...
Fixes a bug where data lengths of less than size 0x10 will fail or have misleading return values.
2018-08-23 11:52:44 -04:00
Lioncash
890507ecf1
common: Namespace hex_util.h/.cpp
...
It's in the common code, so it should be under the Common namespace like
everything else.
2018-08-15 23:24:00 -04:00
Zach Hilman
f2c489b940
crypto: Remove hex utilities from key_manager
...
Move to hex_util.h in common
2018-08-11 22:50:08 -04:00
Lioncash
c8617a1465
aes_util: Add static assertion to Transcode() and XTSTranscode() to ensure well-defined behavior
...
These functions should only be given trivially-copyable types.
2018-08-04 17:30:52 -04:00
Lioncash
f0a2d4da2b
aes_util: Make CalculateNintendoTweak() an internally linked function
...
This function doesn't directly depend on class state, so it can be
hidden entirely from the interface in the cpp file.
2018-08-04 17:30:48 -04:00
Lioncash
1fb5027501
aes_util: Make Transcode() a const member function
...
This doesn't modify member state, so it can be made const.
2018-08-04 16:49:42 -04:00