mirror of
https://github.com/fail0verflow/mini.git
synced 2024-11-30 23:24:19 +01:00
Add AES and SHA-1 to AHB stuff, move cache ops to crypto.c
This commit is contained in:
parent
689f718c64
commit
287248e77c
4
boot2.c
4
boot2.c
@ -62,9 +62,7 @@ void boot2_init() {
|
|||||||
aes_set_iv(iv);
|
aes_set_iv(iv);
|
||||||
aes_set_key(otp.common_key);
|
aes_set_key(otp.common_key);
|
||||||
memcpy(key, tikptr+0x1bf, 16);
|
memcpy(key, tikptr+0x1bf, 16);
|
||||||
dc_flushrange(key, 32);
|
|
||||||
aes_decrypt(key, key, 1, 0);
|
aes_decrypt(key, key, 1, 0);
|
||||||
dc_invalidaterange(key, 32);
|
|
||||||
|
|
||||||
memcpy(&datalen, tmdptr+0x1e4+8+4, 4);
|
memcpy(&datalen, tmdptr+0x1e4+8+4, 4);
|
||||||
memset(iv, 0, 16);
|
memset(iv, 0, 16);
|
||||||
@ -73,9 +71,7 @@ void boot2_init() {
|
|||||||
aes_reset();
|
aes_reset();
|
||||||
aes_set_iv(iv);
|
aes_set_iv(iv);
|
||||||
aes_set_key(key);
|
aes_set_key(key);
|
||||||
dc_flushrange(cntptr, ALIGN_FORWARD(datalen, 16));
|
|
||||||
aes_decrypt(cntptr, cntptr, ALIGN_FORWARD(datalen, 16)/16, 0);
|
aes_decrypt(cntptr, cntptr, ALIGN_FORWARD(datalen, 16)/16, 0);
|
||||||
dc_invalidaterange(cntptr, ALIGN_FORWARD(datalen, 16));
|
|
||||||
|
|
||||||
memcpy(boot2, cntptr, datalen);
|
memcpy(boot2, cntptr, datalen);
|
||||||
boot2_initialized = 1;
|
boot2_initialized = 1;
|
||||||
|
11
crypto.c
11
crypto.c
@ -115,7 +115,14 @@ void aes_decrypt(u8 *src, u8 *dst, u32 blocks, u8 keep_iv)
|
|||||||
|
|
||||||
write32(AES_SRC, dma_addr(src));
|
write32(AES_SRC, dma_addr(src));
|
||||||
write32(AES_DEST, dma_addr(dst));
|
write32(AES_DEST, dma_addr(dst));
|
||||||
|
|
||||||
|
dc_flushrange(src, blocks * 16);
|
||||||
|
dc_invalidaterange(src, blocks * 16);
|
||||||
|
|
||||||
|
ahb_flush_to(AHB_AES);
|
||||||
aes_command(AES_CMD_DECRYPT, keep_iv, this_blocks);
|
aes_command(AES_CMD_DECRYPT, keep_iv, this_blocks);
|
||||||
|
ahb_flush_from(AHB_AES);
|
||||||
|
ahb_flush_to(AHB_STARLET);
|
||||||
|
|
||||||
blocks -= this_blocks;
|
blocks -= this_blocks;
|
||||||
src += this_blocks<<4;
|
src += this_blocks<<4;
|
||||||
@ -138,12 +145,8 @@ void aes_ipc(volatile ipc_request *req)
|
|||||||
aes_set_key((u8 *)req->args);
|
aes_set_key((u8 *)req->args);
|
||||||
break;
|
break;
|
||||||
case IPC_AES_DECRYPT:
|
case IPC_AES_DECRYPT:
|
||||||
dc_invalidaterange((u8 *)req->args[0],
|
|
||||||
(req->args[3]+1)*16);
|
|
||||||
aes_decrypt((u8 *)req->args[0], (u8 *)req->args[1],
|
aes_decrypt((u8 *)req->args[0], (u8 *)req->args[1],
|
||||||
req->args[2], req->args[3]);
|
req->args[2], req->args[3]);
|
||||||
dc_flushrange((u8 *)req->args[1],
|
|
||||||
(req->args[3]+1)*16);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
gecko_printf("IPC: unknown SLOW AES request %04x\n",
|
gecko_printf("IPC: unknown SLOW AES request %04x\n",
|
||||||
|
10
memory.c
10
memory.c
@ -69,8 +69,8 @@ void _ahb_flush_to(enum AHBDEV dev) {
|
|||||||
case AHB_1: mask = 0x4000; break;
|
case AHB_1: mask = 0x4000; break;
|
||||||
//case 2: mask = 0x0001; break;
|
//case 2: mask = 0x0001; break;
|
||||||
case AHB_NAND: mask = 0x0002; break;
|
case AHB_NAND: mask = 0x0002; break;
|
||||||
//case 4: mask = 0x0004; break;
|
case AHB_AES: mask = 0x0004; break;
|
||||||
//case 5: mask = 0x0008; break;
|
case AHB_SHA1: mask = 0x0008; break;
|
||||||
//case 6: mask = 0x0010; break;
|
//case 6: mask = 0x0010; break;
|
||||||
//case 7: mask = 0x0020; break;
|
//case 7: mask = 0x0020; break;
|
||||||
//case 8: mask = 0x0040; break;
|
//case 8: mask = 0x0040; break;
|
||||||
@ -88,6 +88,8 @@ void _ahb_flush_to(enum AHBDEV dev) {
|
|||||||
switch(dev) {
|
switch(dev) {
|
||||||
// 2 to 10 in IOS, add more
|
// 2 to 10 in IOS, add more
|
||||||
case AHB_NAND:
|
case AHB_NAND:
|
||||||
|
case AHB_AES:
|
||||||
|
case AHB_SHA1:
|
||||||
case AHB_SDHC:
|
case AHB_SDHC:
|
||||||
while((read32(HW_18C) & 0xF) == 9)
|
while((read32(HW_18C) & 0xF) == 9)
|
||||||
set32(HW_188, 0x10000);
|
set32(HW_188, 0x10000);
|
||||||
@ -155,6 +157,10 @@ void ahb_flush_from(enum AHBDEV dev)
|
|||||||
case AHB_1:
|
case AHB_1:
|
||||||
req = 1;
|
req = 1;
|
||||||
break;
|
break;
|
||||||
|
case AHB_AES:
|
||||||
|
case AHB_SHA1:
|
||||||
|
req = 2;
|
||||||
|
break;
|
||||||
case AHB_NAND:
|
case AHB_NAND:
|
||||||
case AHB_SDHC:
|
case AHB_SDHC:
|
||||||
req = 8;
|
req = 8;
|
||||||
|
6
memory.h
6
memory.h
@ -10,9 +10,11 @@
|
|||||||
((typeof(x))(((u32)(x)) & (~(align-1))))
|
((typeof(x))(((u32)(x)) & (~(align-1))))
|
||||||
|
|
||||||
enum AHBDEV {
|
enum AHBDEV {
|
||||||
AHB_STARLET = 0, //or MEM2??
|
AHB_STARLET = 0, //or MEM2 or some controller or bus or ??
|
||||||
AHB_1 = 1, //or MEM1??
|
AHB_1 = 1, //ppc or something else???
|
||||||
AHB_NAND = 3,
|
AHB_NAND = 3,
|
||||||
|
AHB_AES = 4,
|
||||||
|
AHB_SHA1 = 5,
|
||||||
AHB_SDHC = 9,
|
AHB_SDHC = 9,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user