libaaruformat 1.0
Aaru Data Preservation Suite - Format Library
Loading...
Searching...
No Matches
wii_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 * Nintendo Wii disc encryption: partition key map, group encrypt/decrypt.
19 */
20
21#ifndef LIBAARUFORMAT_NGCW_WII_CRYPTO_H
22#define LIBAARUFORMAT_NGCW_WII_CRYPTO_H
23
24#include <stdbool.h>
25#include <stdint.h>
26
27/* Forward declaration — guard against redefinition when aaruformat.h is also included */
28#ifndef AARUFORMAT_CONTEXT_DECLARED
29#define AARUFORMAT_CONTEXT_DECLARED
31#endif
32
33#ifdef __cplusplus
34extern "C"
35{
36#endif
37
38#define WII_GROUP_SIZE 0x8000
39#define WII_GROUP_HASH_SIZE 0x0400
40#define WII_GROUP_DATA_SIZE 0x7C00
41#define WII_LOGICAL_PER_GROUP 16
42#define WII_SECTOR_SIZE 2048
43#define WII_MAX_PARTITIONS 32
44
51 typedef struct WiiPartitionRegion
52 {
53 uint32_t start_sector;
54 uint32_t end_sector;
55 uint8_t key[16];
57
69 const uint8_t *wii_get_sector_key(const WiiPartitionRegion *regions, uint32_t region_count,
70 uint64_t logical_sector);
71
75 bool wii_is_sector_encrypted(const WiiPartitionRegion *regions, uint32_t region_count, uint64_t logical_sector);
76
88 void wii_encrypt_group(const uint8_t key[16], const uint8_t *hash_block, const uint8_t *data_in, uint8_t *out);
89
98 void wii_decrypt_group(const uint8_t key[16], const uint8_t *in, uint8_t *hash_block, uint8_t *data_out);
99
107 int32_t wii_serialize_partition_key_map(const WiiPartitionRegion *regions, uint32_t count, uint8_t **out_data,
108 uint32_t *out_len);
109
113 int32_t wii_deserialize_partition_key_map(const uint8_t *data, uint32_t data_len, WiiPartitionRegion **regions,
114 uint32_t *count);
115
124
125#ifdef __cplusplus
126}
127#endif
128
129#endif /* LIBAARUFORMAT_NGCW_WII_CRYPTO_H */
A Wii partition region entry (in-memory representation).
Definition wii_crypto.h:52
uint32_t start_sector
First physical sector of partition.
Definition wii_crypto.h:53
uint8_t key[16]
AES-128 partition key.
Definition wii_crypto.h:55
uint32_t end_sector
End physical sector (exclusive).
Definition wii_crypto.h:54
Master context representing an open or in‑creation Aaru image.
Definition context.h:175
const uint8_t * wii_get_sector_key(const WiiPartitionRegion *regions, uint32_t region_count, uint64_t logical_sector)
Get the encryption key for a given logical sector (2048-byte).
Definition wii_crypto.c:45
int32_t wii_deserialize_partition_key_map(const uint8_t *data, uint32_t data_len, WiiPartitionRegion **regions, uint32_t *count)
Deserialize a Wii partition key map from a media tag buffer.
Definition wii_crypto.c:132
int32_t wii_serialize_partition_key_map(const WiiPartitionRegion *regions, uint32_t count, uint8_t **out_data, uint32_t *out_len)
Serialize a Wii partition key map for storage as a media tag.
Definition wii_crypto.c:105
void wii_encrypt_group(const uint8_t key[16], const uint8_t *hash_block, const uint8_t *data_in, uint8_t *out)
Encrypt a Wii group (0x8000 bytes) from separate hash_block + data.
Definition wii_crypto.c:71
bool wii_is_sector_encrypted(const WiiPartitionRegion *regions, uint32_t region_count, uint64_t logical_sector)
Check if a logical sector is in an encrypted region.
Definition wii_crypto.c:66
void wii_decrypt_group(const uint8_t key[16], const uint8_t *in, uint8_t *hash_block, uint8_t *data_out)
Decrypt a Wii group (0x8000 bytes) into separate hash_block + data.
Definition wii_crypto.c:87
void wii_lazy_init(aaruformat_context *ctx)
Lazy initialization: load partition key map from media tags.
Definition wii_crypto.c:180