libs: begin adding capacity for doing crypto on generic os (using externally-preset keys)

This commit is contained in:
Michael Scire 2022-03-07 09:21:13 -08:00 committed by SciresM
parent 6368d8063a
commit 706b8492fd
28 changed files with 1305 additions and 33 deletions

View file

@ -125,7 +125,7 @@ namespace ams::fssystem {
size_t GetBytesFromOrder(s32 order) const {
AMS_ASSERT(m_free_lists != nullptr);
AMS_ASSERT(0 <= order);
AMS_ASSERT(order < this->GetOrderMax());
AMS_ASSERT(order <= this->GetOrderMax());
return (this->GetBlockSize() << order);
}

View file

@ -192,7 +192,11 @@ namespace ams::fssystem {
class NcaFileSystemDriver : public ::ams::fs::impl::Newable {
NON_COPYABLE(NcaFileSystemDriver);
NON_MOVEABLE(NcaFileSystemDriver);
#if defined(ATMOSPHERE_BOARD_NINTENDO_NX)
private:
#else
public:
#endif
struct StorageContext {
bool open_raw_storage;
std::shared_ptr<fs::IStorage> body_substorage;
@ -209,8 +213,11 @@ namespace ams::fssystem {
std::shared_ptr<fs::IStorage> fs_data_storage;
std::shared_ptr<fs::IStorage> compressed_storage_meta_storage;
std::shared_ptr<fssystem::CompressedStorage> compressed_storage;
};
/* For tools. */
std::shared_ptr<fs::IStorage> external_original_storage;
};
private:
enum AlignmentStorageRequirement {
/* TODO */
AlignmentStorageRequirement_CacheBlockSize = 0,
@ -235,7 +242,15 @@ namespace ams::fssystem {
AMS_ASSERT(m_hash_generator_factory_selector != nullptr);
}
Result OpenStorage(std::shared_ptr<fs::IStorage> *out, std::shared_ptr<IAsynchronousAccessSplitter> *out_splitter, NcaFsHeaderReader *out_header_reader, s32 fs_index);
Result OpenStorageWithContext(std::shared_ptr<fs::IStorage> *out, std::shared_ptr<IAsynchronousAccessSplitter> *out_splitter, NcaFsHeaderReader *out_header_reader, s32 fs_index, StorageContext *ctx);
Result OpenStorage(std::shared_ptr<fs::IStorage> *out, std::shared_ptr<IAsynchronousAccessSplitter> *out_splitter, NcaFsHeaderReader *out_header_reader, s32 fs_index) {
/* Create a storage context. */
StorageContext ctx{};
/* Open the storage. */
R_RETURN(OpenStorageWithContext(out, out_splitter, out_header_reader, fs_index, std::addressof(ctx)));
}
private:
Result OpenStorageImpl(std::shared_ptr<fs::IStorage> *out, NcaFsHeaderReader *out_header_reader, s32 fs_index, StorageContext *ctx);

View file

@ -37,7 +37,7 @@ namespace ams::spl::smc {
Result GenerateRandomBytes(void *out, size_t size);
Result GenerateAesKek(AccessKey *out, const KeySource &source, u32 generation, u32 option);
Result LoadAesKey(u32 keyslot, const AccessKey &access_key, const KeySource &source);
Result ComputeAes(AsyncOperationKey *out_op, u32 dst_addr, u32 mode, const IvCtr &iv_ctr, u32 src_addr, size_t size);
Result ComputeAes(AsyncOperationKey *out_op, u64 dst_addr, u32 mode, const IvCtr &iv_ctr, u64 src_addr, size_t size);
Result GenerateSpecificAesKey(AesKey *out_key, const KeySource &source, u32 generation, u32 which);
Result ComputeCmac(Cmac *out_mac, u32 keyslot, const void *data, size_t size);
Result ReencryptDeviceUniqueData(void *data, size_t size, const AccessKey &access_key_dec, const KeySource &source_dec, const AccessKey &access_key_enc, const KeySource &source_enc, u32 option);
@ -68,4 +68,8 @@ namespace ams::spl::smc {
return SetConfig(key, std::addressof(value), 1);
}
#if !defined(ATMOSPHERE_OS_HORIZON)
void PresetInternalKey(const AesKey *key, u32 generation, bool device);
#endif
}