Skip to content

Commit

Permalink
Add 3DS hashing support (#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
CasualPokePlayer authored Jan 17, 2024
1 parent ae21f7c commit a5c6aff
Show file tree
Hide file tree
Showing 6 changed files with 1,216 additions and 0 deletions.
22 changes: 22 additions & 0 deletions include/rc_hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,28 @@ RC_BEGIN_C_DECLS
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);

/* specifies a function called to obtain a 3DS CIA decryption normal key.
* this key would be derived from slot0x3DKeyX and the common key specified by the passed index.
* the normal key should be written in big endian format
* returns non-zero on success, or zero on failure.
*/
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);

/* specifies a function called to obtain 3DS NCCH decryption normal keys.
* the primary key will always use slot0x2CKeyX and the passed primary KeyY.
* the secondary key will use the KeyX slot passed
* the secondary KeyY will be identical to the primary keyY if the passed program id is NULL
* if the program id is not null, then the secondary KeyY will be obtained with "seed crypto"
* with "seed crypto" the 8 byte program id can be used to obtain a 16 byte "seed" within the seeddb.bin firmware file
* the primary KeyY then the seed will then be hashed with SHA256, and the upper 16 bytes of the digest will be the secondary KeyY used
* the normal keys should be written in big endian format
* returns non-zero on success, or zero on failure.
*/
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);

/* ===================================================== */

RC_END_C_DECLS
Expand Down
Loading

0 comments on commit a5c6aff

Please sign in to comment.