libaaruformat 1.0
Aaru Data Preservation Suite - Format Library
Loading...
Searching...
No Matches
wiiu_crypto.h
Go to the documentation of this file.
1/*
2 * This file is part of the Aaru Data Preservation Suite.
3 * Copyright (c) 2019-2026 Natalia Portillo.
4 *
5 * This library is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as
7 * published by the Free Software Foundation; version 2.1 of the License.
8 *
9 * This library is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, see
16 * <https://www.gnu.org/licenses/>.
17 *
18 * Wii U disc encryption: partition key map, encrypt/decrypt, serialization.
19 */
20
21#ifndef LIBAARUFORMAT_WIIU_CRYPTO_H
22#define LIBAARUFORMAT_WIIU_CRYPTO_H
23
24#include <stdbool.h>
25#include <stdint.h>
26
27/* Forward declaration */
29
30#ifdef __cplusplus
31extern "C"
32{
33#endif
34
35#define WIIU_CRYPTO_SECTOR_SIZE 0x8000
36#define WIIU_LOGICAL_PER_PHYSICAL 16
37#define WIIU_HEADER_PHYSICAL_SECTORS 3
38#define WIIU_MAX_PARTITIONS 8
39
48 typedef struct WiiuPartitionRegion
49 {
50 uint32_t start_sector;
51 uint32_t end_sector;
52 uint8_t key[16];
54
66 const uint8_t *wiiu_get_sector_key(const WiiuPartitionRegion *regions, uint32_t region_count,
67 uint64_t logical_sector);
68
77 bool wiiu_is_sector_encrypted(const WiiuPartitionRegion *regions, uint32_t region_count, uint64_t logical_sector);
78
88 void wiiu_encrypt_physical_sector(const uint8_t key[16], uint8_t *data, uint32_t length);
89
99 void wiiu_decrypt_physical_sector(const uint8_t key[16], uint8_t *data, uint32_t length);
100
117 int32_t wiiu_serialize_partition_key_map(const WiiuPartitionRegion *regions, uint32_t count, uint8_t **out_data,
118 uint32_t *out_len);
119
129 int32_t wiiu_deserialize_partition_key_map(const uint8_t *data, uint32_t data_len, WiiuPartitionRegion **regions,
130 uint32_t *count);
131
141
142#ifdef __cplusplus
143}
144#endif
145
146#endif /* LIBAARUFORMAT_WIIU_CRYPTO_H */
A Wii U partition region entry (in-memory representation).
Definition wiiu_crypto.h:49
uint8_t key[16]
AES-128 key for encrypted sectors in this partition.
Definition wiiu_crypto.h:52
uint32_t start_sector
First physical sector of partition (plaintext header).
Definition wiiu_crypto.h:50
uint32_t end_sector
End physical sector (exclusive).
Definition wiiu_crypto.h:51
Master context representing an open or in‑creation Aaru image.
Definition context.h:175
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.
Definition wiiu_crypto.c:72
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.
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.
Definition wiiu_crypto.c:79
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.
Definition wiiu_crypto.c:86
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).
Definition wiiu_crypto.c:43
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.
Definition wiiu_crypto.c:69