|
libaaruformat 1.0
Aaru Data Preservation Suite - Format Library
|
#include <stdbool.h>#include <stdint.h>Go to the source code of this file.
Data Structures | |
| struct | WiiuPartitionRegion |
| A Wii U partition region entry (in-memory representation). More... | |
Macros | |
| #define | WIIU_CRYPTO_SECTOR_SIZE 0x8000 |
| Wii U physical sector size (32 KiB). | |
| #define | WIIU_LOGICAL_PER_PHYSICAL 16 |
| Number of 2048-byte logical sectors per physical sector. | |
| #define | WIIU_HEADER_PHYSICAL_SECTORS 3 |
| Disc header occupies physical sectors 0-2 (plaintext). | |
| #define | WIIU_MAX_PARTITIONS 8 |
| Maximum number of partitions supported. | |
Typedefs | |
| typedef struct WiiuPartitionRegion | WiiuPartitionRegion |
| A Wii U partition region entry (in-memory representation). | |
Functions | |
| const uint8_t * | wiiu_get_sector_key (const WiiuPartitionRegion *regions, uint32_t region_count, uint64_t logical_sector) |
| Get the encryption key for a given logical sector (2048-byte). | |
| bool | wiiu_is_sector_encrypted (const WiiuPartitionRegion *regions, uint32_t region_count, uint64_t logical_sector) |
| Check if a logical sector (2048-byte) is in an encrypted region. | |
| void | wiiu_encrypt_physical_sector (const uint8_t key[16], uint8_t *data, uint32_t length) |
| Encrypt a full 0x8000-byte physical sector in-place. | |
| void | wiiu_decrypt_physical_sector (const uint8_t key[16], uint8_t *data, uint32_t length) |
| Decrypt a full 0x8000-byte physical sector in-place. | |
| int32_t | wiiu_serialize_partition_key_map (const WiiuPartitionRegion *regions, uint32_t count, uint8_t **out_data, uint32_t *out_len) |
| Serialize a partition key map for storage as a media tag. | |
| int32_t | wiiu_deserialize_partition_key_map (const uint8_t *data, uint32_t data_len, WiiuPartitionRegion **regions, uint32_t *count) |
| Deserialize a partition key map from a media tag buffer. | |
| void | wiiu_lazy_init (aaruformat_context *ctx) |
| Lazy initialization: load disc key and partition key map from media tags. | |
| #define WIIU_CRYPTO_SECTOR_SIZE 0x8000 |
Wii U physical sector size (32 KiB).
Definition at line 35 of file wiiu_crypto.h.
Referenced by aaruf_read_sector(), and wiiu_lazy_init().
| #define WIIU_HEADER_PHYSICAL_SECTORS 3 |
Disc header occupies physical sectors 0-2 (plaintext).
Definition at line 37 of file wiiu_crypto.h.
Referenced by wiiu_get_sector_key().
| #define WIIU_LOGICAL_PER_PHYSICAL 16 |
Number of 2048-byte logical sectors per physical sector.
Definition at line 36 of file wiiu_crypto.h.
Referenced by aaruf_read_sector(), and wiiu_get_sector_key().
| #define WIIU_MAX_PARTITIONS 8 |
Maximum number of partitions supported.
Definition at line 38 of file wiiu_crypto.h.
Referenced by wiiu_deserialize_partition_key_map(), and wiiu_serialize_partition_key_map().
| typedef struct WiiuPartitionRegion WiiuPartitionRegion |
A Wii U partition region entry (in-memory representation).
Stores the physical sector range and AES-128 key for one partition. Physical sector numbers are in 0x8000-byte units (matching disc TOC). By convention, the partition's start_sector is a plaintext header; sectors [start_sector+1, end_sector) are encrypted with key.
| void wiiu_decrypt_physical_sector | ( | const uint8_t | key[16], |
| uint8_t * | data, | ||
| uint32_t | length ) |
Decrypt a full 0x8000-byte physical sector in-place.
Uses AES-128-CBC with IV=0 (Wii U scheme).
| key | 16-byte AES-128 key. |
| data | Buffer to decrypt in-place (must be 0x8000 bytes). |
| length | Number of bytes (must be 0x8000). |
Definition at line 79 of file wiiu_crypto.c.
References aes128_cbc_decrypt(), and wiiu_decrypt_physical_sector().
Referenced by wiiu_decrypt_physical_sector().
| int32_t wiiu_deserialize_partition_key_map | ( | const uint8_t * | data, |
| uint32_t | data_len, | ||
| WiiuPartitionRegion ** | regions, | ||
| uint32_t * | count ) |
Deserialize a partition key map from a media tag buffer.
| data | Serialized data buffer. |
| data_len | Length of the data buffer. |
| regions | Output: malloc'd array of WiiuPartitionRegion (caller must free). |
| count | Output: number of regions. |
< Maximum number of partitions supported.
Definition at line 112 of file wiiu_crypto.c.
References WiiuPartitionRegion::end_sector, read_le32(), WiiuPartitionRegion::start_sector, wiiu_deserialize_partition_key_map(), and WIIU_MAX_PARTITIONS.
Referenced by wiiu_deserialize_partition_key_map(), and wiiu_lazy_init().
| void wiiu_encrypt_physical_sector | ( | const uint8_t | key[16], |
| uint8_t * | data, | ||
| uint32_t | length ) |
Encrypt a full 0x8000-byte physical sector in-place.
Uses AES-128-CBC with IV=0 (Wii U scheme).
| key | 16-byte AES-128 key. |
| data | Buffer to encrypt in-place (must be 0x8000 bytes). |
| length | Number of bytes (must be 0x8000). |
Definition at line 72 of file wiiu_crypto.c.
References aes128_cbc_encrypt(), and wiiu_encrypt_physical_sector().
Referenced by aaruf_read_sector(), and wiiu_encrypt_physical_sector().
| const uint8_t * wiiu_get_sector_key | ( | const WiiuPartitionRegion * | regions, |
| uint32_t | region_count, | ||
| uint64_t | logical_sector ) |
Get the encryption key for a given logical sector (2048-byte).
Converts the logical sector address to a physical sector address, then looks up which partition it belongs to and whether it is encrypted.
| regions | Array of partition regions. |
| region_count | Number of partition regions. |
| logical_sector | Logical sector address (2048-byte units). |
< Number of 2048-byte logical sectors per physical sector.
< Disc header occupies physical sectors 0-2 (plaintext).
Definition at line 43 of file wiiu_crypto.c.
References WiiuPartitionRegion::key, wiiu_get_sector_key(), WIIU_HEADER_PHYSICAL_SECTORS, and WIIU_LOGICAL_PER_PHYSICAL.
Referenced by aaruf_read_sector(), wiiu_get_sector_key(), and wiiu_is_sector_encrypted().
| bool wiiu_is_sector_encrypted | ( | const WiiuPartitionRegion * | regions, |
| uint32_t | region_count, | ||
| uint64_t | logical_sector ) |
Check if a logical sector (2048-byte) is in an encrypted region.
| regions | Array of partition regions. |
| region_count | Number of partition regions. |
| logical_sector | Logical sector address (2048-byte units). |
Definition at line 69 of file wiiu_crypto.c.
References wiiu_get_sector_key(), and wiiu_is_sector_encrypted().
Referenced by wiiu_is_sector_encrypted().
| void wiiu_lazy_init | ( | aaruformat_context * | ctx | ) |
Lazy initialization: load disc key and partition key map from media tags.
Populates ctx->wiiu_disc_key and ctx->wiiu_partition_regions from media tags. Allocates ctx->wiiu_encrypted_block_cache if needed.
| ctx | AaruFormat context. |
< Wii U physical sector size (32 KiB).
Definition at line 155 of file wiiu_crypto.c.
References mediaTagEntry::data, kMediaTagWiiUDiscKey, kMediaTagWiiUPartitionKeyMap, mediaTagEntry::length, aaruformat_context::mediaTags, aaruformat_context::wiiu_cache_valid, WIIU_CRYPTO_SECTOR_SIZE, wiiu_deserialize_partition_key_map(), aaruformat_context::wiiu_disc_key, aaruformat_context::wiiu_encrypted_block_cache, wiiu_lazy_init(), aaruformat_context::wiiu_partition_region_count, and aaruformat_context::wiiu_partition_regions.
Referenced by aaruf_read_sector(), and wiiu_lazy_init().
| int32_t wiiu_serialize_partition_key_map | ( | const WiiuPartitionRegion * | regions, |
| uint32_t | count, | ||
| uint8_t ** | out_data, | ||
| uint32_t * | out_len ) |
Serialize a partition key map for storage as a media tag.
Format (all little-endian): [4 bytes] partition_count For each partition (24 bytes): [4 bytes] start_sector [4 bytes] end_sector [16 bytes] key
| regions | Array of partition regions. |
| count | Number of regions. |
| out_data | Output: malloc'd buffer (caller must free). |
| out_len | Output: length of the buffer. |
< Maximum number of partitions supported.
Definition at line 86 of file wiiu_crypto.c.
References WIIU_MAX_PARTITIONS, wiiu_serialize_partition_key_map(), and write_le32().
Referenced by wiiu_serialize_partition_key_map().