Use cal0 struct, improve style consistency
This commit is contained in:
		| @@ -736,14 +736,14 @@ get_titlekeys: | ||||
|  | ||||
|     se_aes_xts_crypt(1, 0, 0, 0, buffer, buffer, 0x4000, 1); | ||||
|  | ||||
|     if (_read_le_u32(buffer, 0) != 0x304C4143) { | ||||
|     nx_emmc_cal0_t *cal0 = (nx_emmc_cal0_t *)buffer; | ||||
|     if (cal0->magic != 0x304C4143) { | ||||
|         EPRINTF("CAL0 magic not found. Check BIS key 0."); | ||||
|         goto dismount; | ||||
|     } | ||||
|  | ||||
|     u32 cal_version = _read_le_u32(buffer, 4); | ||||
|     u32 keypair_generation = _read_le_u32(buffer, 0x3AD0); | ||||
|     if (cal_version <= 8) | ||||
|     u32 keypair_generation = cal0->ext_ecc_rsa2048_eticket_key_ver; | ||||
|     if (cal0->version <= 8) | ||||
|         keypair_generation = 0; // settings zeroes this out below cal version 9 | ||||
|  | ||||
|     if (keypair_generation) { | ||||
| @@ -760,7 +760,7 @@ get_titlekeys: | ||||
|     } | ||||
|  | ||||
|     se_aes_key_set(6, temp_key, 0x10); | ||||
|     se_aes_crypt_ctr(6, keypair, 0x230, buffer + 0x38a0, 0x230, buffer + 0x3890); | ||||
|     se_aes_crypt_ctr(6, keypair, 0x230, cal0->ext_ecc_rsa2048_eticket_key + 0x10, 0x230, cal0->ext_ecc_rsa2048_eticket_key); | ||||
|  | ||||
|     u8 *D = keypair, *N = keypair + 0x100, *E = keypair + 0x200; | ||||
|  | ||||
|   | ||||
| @@ -35,74 +35,74 @@ | ||||
| /* Get Drive Status                                                      */ | ||||
| /*-----------------------------------------------------------------------*/ | ||||
| DSTATUS disk_status ( | ||||
|     BYTE pdrv /* Physical drive number to identify the drive */ | ||||
| 	BYTE pdrv /* Physical drive number to identify the drive */ | ||||
| ) | ||||
| { | ||||
|     return 0; | ||||
| 	return 0; | ||||
| } | ||||
|  | ||||
| /*-----------------------------------------------------------------------*/ | ||||
| /* Inidialize a Drive                                                    */ | ||||
| /*-----------------------------------------------------------------------*/ | ||||
| DSTATUS disk_initialize ( | ||||
|     BYTE pdrv /* Physical drive number to identify the drive */ | ||||
| 	BYTE pdrv /* Physical drive number to identify the drive */ | ||||
| ) | ||||
| { | ||||
|     return 0; | ||||
| 	return 0; | ||||
| } | ||||
|  | ||||
| /*-----------------------------------------------------------------------*/ | ||||
| /* Read Sector(s)                                                        */ | ||||
| /*-----------------------------------------------------------------------*/ | ||||
| DRESULT disk_read ( | ||||
|     BYTE pdrv,		/* Physical drive number to identify the drive */ | ||||
|     BYTE *buff,		/* Data buffer to store read data */ | ||||
|     DWORD sector,	/* Start sector in LBA */ | ||||
|     UINT count		/* Number of sectors to read */ | ||||
| 	BYTE pdrv,		/* Physical drive number to identify the drive */ | ||||
| 	BYTE *buff,		/* Data buffer to store read data */ | ||||
| 	DWORD sector,	/* Start sector in LBA */ | ||||
| 	UINT count		/* Number of sectors to read */ | ||||
| ) | ||||
| { | ||||
|     switch (pdrv) | ||||
|     { | ||||
|     case DRIVE_SD: | ||||
|         return sdmmc_storage_read(&sd_storage, sector, count, buff) ? RES_OK : RES_ERROR; | ||||
| 	switch (pdrv) | ||||
| 	{ | ||||
| 	case DRIVE_SD: | ||||
| 		return sdmmc_storage_read(&sd_storage, sector, count, buff) ? RES_OK : RES_ERROR; | ||||
|  | ||||
|     case DRIVE_BIS: | ||||
|         return nx_emmc_bis_read(sector, count, buff); | ||||
|     } | ||||
| 	case DRIVE_BIS: | ||||
| 		return nx_emmc_bis_read(sector, count, buff); | ||||
| 	} | ||||
|  | ||||
|     return RES_ERROR; | ||||
| 	return RES_ERROR; | ||||
| } | ||||
|  | ||||
| /*-----------------------------------------------------------------------*/ | ||||
| /* Write Sector(s)                                                       */ | ||||
| /*-----------------------------------------------------------------------*/ | ||||
| DRESULT disk_write ( | ||||
|     BYTE pdrv,			/* Physical drive number to identify the drive */ | ||||
|     const BYTE *buff,	/* Data to be written */ | ||||
|     DWORD sector,		/* Start sector in LBA */ | ||||
|     UINT count			/* Number of sectors to write */ | ||||
| 	BYTE pdrv,			/* Physical drive number to identify the drive */ | ||||
| 	const BYTE *buff,	/* Data to be written */ | ||||
| 	DWORD sector,		/* Start sector in LBA */ | ||||
| 	UINT count			/* Number of sectors to write */ | ||||
| ) | ||||
| { | ||||
|     switch (pdrv) | ||||
|     { | ||||
|     case DRIVE_SD: | ||||
|         return sdmmc_storage_write(&sd_storage, sector, count, (void *)buff) ? RES_OK : RES_ERROR; | ||||
| 	switch (pdrv) | ||||
| 	{ | ||||
| 	case DRIVE_SD: | ||||
| 		return sdmmc_storage_write(&sd_storage, sector, count, (void *)buff) ? RES_OK : RES_ERROR; | ||||
|  | ||||
|     case DRIVE_BIS: | ||||
|         return RES_WRPRT; | ||||
|     } | ||||
| 	case DRIVE_BIS: | ||||
| 		return RES_WRPRT; | ||||
| 	} | ||||
|  | ||||
|     return RES_ERROR; | ||||
| 	return RES_ERROR; | ||||
| } | ||||
|  | ||||
| /*-----------------------------------------------------------------------*/ | ||||
| /* Miscellaneous Functions                                               */ | ||||
| /*-----------------------------------------------------------------------*/ | ||||
| DRESULT disk_ioctl ( | ||||
|     BYTE pdrv,		/* Physical drive number (0..) */ | ||||
|     BYTE cmd,		/* Control code */ | ||||
|     void *buff		/* Buffer to send/receive control data */ | ||||
| 	BYTE pdrv,		/* Physical drive number (0..) */ | ||||
| 	BYTE cmd,		/* Control code */ | ||||
| 	void *buff		/* Buffer to send/receive control data */ | ||||
| ) | ||||
| { | ||||
|     return RES_OK; | ||||
| 	return RES_OK; | ||||
| } | ||||
|   | ||||
| @@ -54,7 +54,8 @@ static void _gf256_mul_x_le(void *block) | ||||
| 	u32 *pdata = (u32 *)block; | ||||
| 	u32 carry = 0; | ||||
|  | ||||
| 	for (u32 i = 0; i < 4; i++) { | ||||
| 	for (u32 i = 0; i < 4; i++) | ||||
| 	{ | ||||
| 		u32 b = pdata[i]; | ||||
| 		pdata[i] = (b << 1) | carry; | ||||
| 		carry = b >> 31; | ||||
| @@ -215,7 +216,8 @@ int nx_emmc_bis_read(u32 sector, u32 count, void *buff) | ||||
| 	return res; | ||||
| } | ||||
|  | ||||
| void nx_emmc_bis_cluster_cache_init() { | ||||
| void nx_emmc_bis_cluster_cache_init() | ||||
| { | ||||
| 	// Clear cluster lookup table and reset end index. | ||||
| 	memset(cluster_lookup, -1, (system_part->lba_end - system_part->lba_start + 1) / SECTORS_PER_CLUSTER * sizeof(*cluster_lookup)); | ||||
| 	cluster_cache_end_index = 0; | ||||
|   | ||||
| @@ -164,7 +164,8 @@ typedef struct _nx_emmc_cal0_t | ||||
| 	u8   ext_ecc_b233_eticket_key[0x50]; | ||||
| 	u8   crc16_pad37[0x10]; | ||||
| 	u8   ext_ecc_rsa2048_eticket_key[0x240]; | ||||
| 	u8   crc16_pad38[0x10]; | ||||
| 	u32  ext_ecc_rsa2048_eticket_key_ver; | ||||
| 	u8   crc16_pad38[0xC]; | ||||
| 	u8   ext_ssl_key[0x130]; | ||||
| 	u8   crc16_pad39[0x10]; | ||||
| 	u8   ext_gc_key[0x130]; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user