Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Suyu
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
many-archive
Suyu
Commits
cde665c5
There was an error fetching the commit references. Please try again later.
Commit
cde665c5
authored
6 years ago
by
Zach Hilman
Browse files
Options
Downloads
Patches
Plain Diff
key_manager: Switch to boost flat_map for keys
Should make key gets marginally faster.
parent
60b7a3b9
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/core/crypto/key_manager.cpp
+3
-2
3 additions, 2 deletions
src/core/crypto/key_manager.cpp
src/core/crypto/key_manager.h
+11
-30
11 additions, 30 deletions
src/core/crypto/key_manager.h
with
14 additions
and
32 deletions
src/core/crypto/key_manager.cpp
+
3
−
2
View file @
cde665c5
...
@@ -125,7 +125,8 @@ bool KeyManager::KeyFileExists(bool title) {
...
@@ -125,7 +125,8 @@ bool KeyManager::KeyFileExists(bool title) {
FileUtil
::
Exists
(
yuzu_keys_dir
+
DIR_SEP
+
"prod.keys"
);
FileUtil
::
Exists
(
yuzu_keys_dir
+
DIR_SEP
+
"prod.keys"
);
}
}
const
std
::
unordered_map
<
std
::
string
,
KeyIndex
<
S128KeyType
>>
KeyManager
::
s128_file_id
=
{
void
KeyManager
::
DeriveSDSeedLazy
()
{
const
boost
::
container
::
flat_map
<
std
::
string
,
KeyIndex
<
S128KeyType
>>
KeyManager
::
s128_file_id
=
{
{
"master_key_00"
,
{
S128KeyType
::
Master
,
0
,
0
}},
{
"master_key_00"
,
{
S128KeyType
::
Master
,
0
,
0
}},
{
"master_key_01"
,
{
S128KeyType
::
Master
,
1
,
0
}},
{
"master_key_01"
,
{
S128KeyType
::
Master
,
1
,
0
}},
{
"master_key_02"
,
{
S128KeyType
::
Master
,
2
,
0
}},
{
"master_key_02"
,
{
S128KeyType
::
Master
,
2
,
0
}},
...
@@ -169,7 +170,7 @@ const std::unordered_map<std::string, KeyIndex<S128KeyType>> KeyManager::s128_fi
...
@@ -169,7 +170,7 @@ const std::unordered_map<std::string, KeyIndex<S128KeyType>> KeyManager::s128_fi
{
"key_area_key_system_04"
,
{
S128KeyType
::
KeyArea
,
4
,
static_cast
<
u64
>
(
KeyAreaKeyType
::
System
)}},
{
"key_area_key_system_04"
,
{
S128KeyType
::
KeyArea
,
4
,
static_cast
<
u64
>
(
KeyAreaKeyType
::
System
)}},
};
};
const
st
d
::
unordered
_map
<
std
::
string
,
KeyIndex
<
S256KeyType
>>
KeyManager
::
s256_file_id
=
{
const
boo
st
::
container
::
flat
_map
<
std
::
string
,
KeyIndex
<
S256KeyType
>>
KeyManager
::
s256_file_id
=
{
{
"header_key"
,
{
S256KeyType
::
Header
,
0
,
0
}},
{
"header_key"
,
{
S256KeyType
::
Header
,
0
,
0
}},
{
"sd_card_save_key"
,
{
S256KeyType
::
SDSave
,
0
,
0
}},
{
"sd_card_save_key"
,
{
S256KeyType
::
SDSave
,
0
,
0
}},
{
"sd_card_nca_key"
,
{
S256KeyType
::
SDNCA
,
0
,
0
}},
{
"sd_card_nca_key"
,
{
S256KeyType
::
SDNCA
,
0
,
0
}},
...
...
This diff is collapsed.
Click to expand it.
src/core/crypto/key_manager.h
+
11
−
30
View file @
cde665c5
...
@@ -7,10 +7,11 @@
...
@@ -7,10 +7,11 @@
#include
<array>
#include
<array>
#include
<string>
#include
<string>
#include
<type_traits>
#include
<type_traits>
#include
<unordered_map>
#include
<vector>
#include
<vector>
#include
<boost/container/flat_map.hpp>
#include
<fmt/format.h>
#include
<fmt/format.h>
#include
"common/common_types.h"
#include
"common/common_types.h"
#include
"core/loader/loader.h"
namespace
Core
::
Crypto
{
namespace
Core
::
Crypto
{
...
@@ -59,34 +60,14 @@ struct KeyIndex {
...
@@ -59,34 +60,14 @@ struct KeyIndex {
}
}
};
};
// The following two (== and hash) are so KeyIndex can be a key in unordered_map
// boost flat_map requires operator< for O(log(n)) lookups.
template
<
typename
KeyType
>
bool
operator
==
(
const
KeyIndex
<
KeyType
>&
lhs
,
const
KeyIndex
<
KeyType
>&
rhs
)
{
return
std
::
tie
(
lhs
.
type
,
lhs
.
field1
,
lhs
.
field2
)
==
std
::
tie
(
rhs
.
type
,
rhs
.
field1
,
rhs
.
field2
);
}
template
<
typename
KeyType
>
template
<
typename
KeyType
>
bool
operator
!=
(
const
KeyIndex
<
KeyType
>&
lhs
,
const
KeyIndex
<
KeyType
>&
rhs
)
{
bool
operator
<
(
const
KeyIndex
<
KeyType
>&
lhs
,
const
KeyIndex
<
KeyType
>&
rhs
)
{
return
!
operator
==
(
lhs
,
rhs
);
return
(
static_cast
<
size_t
>
(
lhs
.
type
)
<
static_cast
<
size_t
>
(
rhs
.
type
))
||
(
lhs
.
type
==
rhs
.
type
&&
lhs
.
field1
<
rhs
.
field1
)
||
(
lhs
.
type
==
rhs
.
type
&&
lhs
.
field1
==
rhs
.
field1
&&
lhs
.
field2
<
rhs
.
field2
);
}
}
}
// namespace Core::Crypto
namespace
std
{
template
<
typename
KeyType
>
struct
hash
<
Core
::
Crypto
::
KeyIndex
<
KeyType
>>
{
size_t
operator
()(
const
Core
::
Crypto
::
KeyIndex
<
KeyType
>&
k
)
const
{
using
std
::
hash
;
return
((
hash
<
u64
>
()(
static_cast
<
u64
>
(
k
.
type
))
^
(
hash
<
u64
>
()(
k
.
field1
)
<<
1
))
>>
1
)
^
(
hash
<
u64
>
()(
k
.
field2
)
<<
1
);
}
};
}
// namespace std
namespace
Core
::
Crypto
{
class
KeyManager
{
class
KeyManager
{
public:
public:
KeyManager
();
KeyManager
();
...
@@ -103,15 +84,15 @@ public:
...
@@ -103,15 +84,15 @@ public:
static
bool
KeyFileExists
(
bool
title
);
static
bool
KeyFileExists
(
bool
title
);
private:
private:
st
d
::
unordered
_map
<
KeyIndex
<
S128KeyType
>
,
Key128
>
s128_keys
;
boo
st
::
container
::
flat
_map
<
KeyIndex
<
S128KeyType
>
,
Key128
>
s128_keys
;
st
d
::
unordered
_map
<
KeyIndex
<
S256KeyType
>
,
Key256
>
s256_keys
;
boo
st
::
container
::
flat
_map
<
KeyIndex
<
S256KeyType
>
,
Key256
>
s256_keys
;
bool
dev_mode
;
bool
dev_mode
;
void
LoadFromFile
(
const
std
::
string
&
filename
,
bool
is_title_keys
);
void
LoadFromFile
(
const
std
::
string
&
filename
,
bool
is_title_keys
);
void
AttemptLoadKeyFile
(
const
std
::
string
&
dir1
,
const
std
::
string
&
dir2
,
void
AttemptLoadKeyFile
(
const
std
::
string
&
dir1
,
const
std
::
string
&
dir2
,
const
std
::
string
&
filename
,
bool
title
);
const
std
::
string
&
filename
,
bool
title
);
static
const
st
d
::
unordered
_map
<
std
::
string
,
KeyIndex
<
S128KeyType
>>
s128_file_id
;
static
const
boo
st
::
container
::
flat
_map
<
std
::
string
,
KeyIndex
<
S128KeyType
>>
s128_file_id
;
static
const
st
d
::
unordered
_map
<
std
::
string
,
KeyIndex
<
S256KeyType
>>
s256_file_id
;
static
const
boo
st
::
container
::
flat
_map
<
std
::
string
,
KeyIndex
<
S256KeyType
>>
s256_file_id
;
};
};
}
// namespace Core::Crypto
}
// namespace Core::Crypto
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment