#ifndef RC_HASH_H
#define RC_HASH_H
#include <stddef.h>
#include <stdio.h>
#include <stdint.h>
#include "rc_consoles.h"
RC_BEGIN_C_DECLS
typedef void (RC_CCONV *rc_hash_message_callback)(const char*);
RC_EXPORT void RC_CCONV rc_hash_init_error_message_callback(rc_hash_message_callback callback);
RC_EXPORT void rc_hash_init_verbose_message_callback(rc_hash_message_callback callback);
typedef void* (RC_CCONV *rc_hash_filereader_open_file_handler)(const char* path_utf8);
typedef void (RC_CCONV *rc_hash_filereader_seek_handler)(void* file_handle, int64_t offset, int origin);
typedef int64_t (RC_CCONV *rc_hash_filereader_tell_handler)(void* file_handle);
typedef size_t (RC_CCONV *rc_hash_filereader_read_handler)(void* file_handle, void* buffer, size_t requested_bytes);
typedef void (RC_CCONV *rc_hash_filereader_close_file_handler)(void* file_handle);
typedef struct rc_hash_filereader
{
rc_hash_filereader_open_file_handler open;
rc_hash_filereader_seek_handler seek;
rc_hash_filereader_tell_handler tell;
rc_hash_filereader_read_handler read;
rc_hash_filereader_close_file_handler close;
} rc_hash_filereader_t;
RC_EXPORT void RC_CCONV rc_hash_init_custom_filereader(struct rc_hash_filereader* reader);
#define RC_HASH_CDTRACK_FIRST_DATA ((uint32_t)-1)
#define RC_HASH_CDTRACK_LAST ((uint32_t)-2)
#define RC_HASH_CDTRACK_LARGEST ((uint32_t)-3)
#define RC_HASH_CDTRACK_FIRST_OF_SECOND_SESSION ((uint32_t)-4)
typedef void* (RC_CCONV *rc_hash_cdreader_open_track_handler)(const char* path, uint32_t track);
typedef void* (RC_CCONV* rc_hash_cdreader_open_track_filereader_handler)(const char* path, uint32_t track, const rc_hash_filereader_t* filereader);
typedef size_t (RC_CCONV *rc_hash_cdreader_read_sector_handler)(void* track_handle, uint32_t sector, void* buffer, size_t requested_bytes);
typedef void (RC_CCONV *rc_hash_cdreader_close_track_handler)(void* track_handle);
typedef uint32_t(RC_CCONV *rc_hash_cdreader_first_track_sector_handler)(void* track_handle);
typedef struct rc_hash_cdreader
{
rc_hash_cdreader_open_track_handler open_track;
rc_hash_cdreader_read_sector_handler read_sector;
rc_hash_cdreader_close_track_handler close_track;
rc_hash_cdreader_first_track_sector_handler first_track_sector;
rc_hash_cdreader_open_track_filereader_handler open_track_filereader;
} rc_hash_cdreader_t;
RC_EXPORT void RC_CCONV rc_hash_get_default_cdreader(struct rc_hash_cdreader* cdreader);
RC_EXPORT void RC_CCONV rc_hash_init_default_cdreader(void);
RC_EXPORT void RC_CCONV rc_hash_init_custom_cdreader(struct rc_hash_cdreader* reader);
#ifndef RC_HASH_NO_ENCRYPTED
typedef int (RC_CCONV *rc_hash_3ds_get_cia_normal_key_func)(uint8_t common_key_index, uint8_t out_normal_key[16]);
RC_EXPORT void RC_CCONV rc_hash_init_3ds_get_cia_normal_key_func(rc_hash_3ds_get_cia_normal_key_func func);
typedef int (RC_CCONV *rc_hash_3ds_get_ncch_normal_keys_func)(uint8_t primary_key_y[16], uint8_t secondary_key_x_slot, uint8_t* optional_program_id,
uint8_t out_primary_key[16], uint8_t out_secondary_key[16]);
RC_EXPORT void RC_CCONV rc_hash_init_3ds_get_ncch_normal_keys_func(rc_hash_3ds_get_ncch_normal_keys_func func);
#endif
typedef struct rc_hash_callbacks {
rc_hash_message_callback verbose_message;
rc_hash_message_callback error_message;
rc_hash_filereader_t filereader;
rc_hash_cdreader_t cdreader;
#ifndef RC_HASH_NO_ENCRYPTED
struct rc_hash_encryption_callbacks {
rc_hash_3ds_get_cia_normal_key_func get_3ds_cia_normal_key;
rc_hash_3ds_get_ncch_normal_keys_func get_3ds_ncch_normal_keys;
} encryption;
#endif
} rc_hash_callbacks_t;
typedef struct rc_hash_iterator {
const uint8_t* buffer;
size_t buffer_size;
uint8_t consoles[12];
int index;
const char* path;
rc_hash_callbacks_t callbacks;
} rc_hash_iterator_t;
RC_EXPORT void RC_CCONV rc_hash_initialize_iterator(rc_hash_iterator_t* iterator, const char* path, const uint8_t* buffer, size_t buffer_size);
RC_EXPORT void RC_CCONV rc_hash_destroy_iterator(rc_hash_iterator_t* iterator);
RC_EXPORT int RC_CCONV rc_hash_iterate(char hash[33], rc_hash_iterator_t* iterator);
RC_EXPORT int RC_CCONV rc_hash_generate(char hash[33], uint32_t console_id, const rc_hash_iterator_t* iterator);
RC_EXPORT int RC_CCONV rc_hash_generate_from_buffer(char hash[33], uint32_t console_id, const uint8_t* buffer, size_t buffer_size);
RC_EXPORT int RC_CCONV rc_hash_generate_from_file(char hash[33], uint32_t console_id, const char* path);
RC_END_C_DECLS
#endif