libctr9
Nintendo 3DS ARM9 library
ctr_nand_crypto_interface.h
Go to the documentation of this file.
1 /*******************************************************************************
2  * Copyright (C) 2016 Gabriel Marcano
3  *
4  * Refer to the COPYING.txt file at the top of the project directory. If that is
5  * missing, this file is licensed under the GPL version 2.0 or later.
6  *
7  ******************************************************************************/
8 
11 #ifndef CTR_NAND_CRYPTO_INTERFACE_H_
12 #define CTR_NAND_CRYPTO_INTERFACE_H_
13 
14 #include "ctr_io_interface.h"
15 #include "sdmmc/sdmmc.h"
16 
17 #include <stdint.h>
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 typedef enum
24 {
25  NAND_CTR, NAND_TWL
26 } ctr_nand_crypto_type;
27 
30 typedef struct
31 {
32  ctr_io_interface base;
33  ctr_io_interface *lower_io;
34 
35  uint8_t keySlot;
36  uint8_t ctr[16];
37  uint32_t mode;
38 
40 
55 int ctr_nand_crypto_interface_initialize(ctr_nand_crypto_interface *io, uint8_t key_slot, ctr_nand_crypto_type crypto_type, ctr_io_interface* lower_io);
56 
66 
77 int ctr_nand_crypto_interface_read(void *io, void *buffer, size_t buffer_size, uint64_t position, size_t count);
78 
89 int ctr_nand_crypto_interface_write(void *io, const void *buffer, size_t buffer_size, uint64_t position);
90 
103 int ctr_nand_crypto_interface_read_sector(void *io, void *buffer, size_t buffer_size, size_t sector, size_t count);
104 
119 int ctr_nand_crypto_interface_write_sector(void *io, const void *buffer, size_t buffer_size, size_t sector);
120 
125 uint64_t ctr_nand_crypto_interface_disk_size(void *io);
126 
132 
133 #ifdef __cplusplus
134 }
135 #endif
136 
137 #endif//CTR_NAND_CRYPTO_INTERFACE_H_
138 
int ctr_nand_crypto_interface_write_sector(void *io, const void *buffer, size_t buffer_size, size_t sector)
Writes sectors from the given io interface.
int ctr_nand_crypto_interface_initialize(ctr_nand_crypto_interface *io, uint8_t key_slot, ctr_nand_crypto_type crypto_type, ctr_io_interface *lower_io)
Initialize the given NAND crypto io interface object.
int ctr_nand_crypto_interface_read(void *io, void *buffer, size_t buffer_size, uint64_t position, size_t count)
Reads bytes from the given io interface.
size_t ctr_nand_crypto_interface_sector_size(void *io)
Returns the size of the sectors used by the underlying io interface.
int ctr_nand_crypto_interface_read_sector(void *io, void *buffer, size_t buffer_size, size_t sector, size_t count)
Reads sectors from the given io interface.
uint64_t ctr_nand_crypto_interface_disk_size(void *io)
Returns the size of the underlying disk for the given io interface.
Filter io interface to apply encryption while reading NAND.
Definition: ctr_nand_crypto_interface.h:30
Virtual table for io interface dispatching.
Definition: ctr_io_interface.h:89
int ctr_nand_crypto_interface_write(void *io, const void *buffer, size_t buffer_size, uint64_t position)
Writes bytes to the given io interface.
void ctr_nand_crypto_interface_destroy(ctr_nand_crypto_interface *io)
Destroys the given NAND crypto io interface object.