diff --git a/include/arm9/hardware/crypto.h b/include/arm9/hardware/crypto.h index 51f474c..fbe7397 100644 --- a/include/arm9/hardware/crypto.h +++ b/include/arm9/hardware/crypto.h @@ -273,22 +273,23 @@ ////////////////////////////////// // REG_RSA_CNT -#define RSA_ENABLE (1u) -#define RSA_UNK_BIT1 (1u<<1) -#define RSA_KEYSLOT(k) ((k)<<4) -#define RSA_GET_KEYSLOT ((REG_RSA_CNT & RSA_KEYSLOT(0xFu))>>4) -#define RSA_INPUT_BIG (1u<<8) -#define RSA_INPUT_LITTLE (0u) -#define RSA_INPUT_NORMAL (1u<<9) -#define RSA_INPUT_REVERSED (0u) +#define RSA_CNT_ENABLE (1u) +#define RSA_CNT_IRQ_ENABLE (1u<<1) +#define RSA_CNT_KEYSLOT_SHIFT (4u) +#define RSA_CNT_KEYSLOT_MASK (3u<REG_RSA_SLOTCNT & RSA_KEY_WR_PROT) return false; - // Unset key if bit 31 is not set. No idea why but boot9 does this. - if(!(slot->REG_RSA_SLOTCNT & RSA_KEY_UNK_BIT31)) slot->REG_RSA_SLOTCNT &= ~RSA_KEY_STAT_SET; + RsaSlot *const slot = &((RsaSlot*)REGs_RSA_SLOT0)[keyslot]; + if(slot->REG_RSA_SLOTCNT & RSA_SLOTCNT_WR_PROT) return false; + if(!(slot->REG_RSA_SLOTCNT & RSA_SLOTCNT_BIT31)) slot->REG_RSA_SLOTCNT &= ~RSA_SLOTCNT_SET; - REG_RSA_CNT = RSA_INPUT_NORMAL | RSA_INPUT_BIG | RSA_KEYSLOT(keyslot); + REG_RSA_CNT = RSA_CNT_INPUT_NORMAL | RSA_CNT_INPUT_BIG | keyslot<>2) - 1] = exp; @@ -678,15 +681,15 @@ fb_assert(decSig != NULL); fb_assert(encSig != NULL); - const u8 keyslot = RSA_GET_KEYSLOT; - rsaWaitBusy(); // TODO: IRQs? - if(!(rsaSlots[keyslot].REG_RSA_SLOTCNT & RSA_KEY_STAT_SET)) return false; + const u8 keyslot = (REG_RSA_CNT & RSA_CNT_KEYSLOT_MASK)>>RSA_CNT_KEYSLOT_SHIFT; + RsaSlot *const slot = &((RsaSlot*)REGs_RSA_SLOT0)[keyslot]; + if(!(slot->REG_RSA_SLOTCNT & RSA_SLOTCNT_SET)) return false; - REG_RSA_CNT |= RSA_INPUT_NORMAL | RSA_INPUT_BIG; + REG_RSA_CNT = (REG_RSA_CNT & ~RSA_CNT_INPUT_MASK) | RSA_CNT_INPUT_NORMAL | RSA_CNT_INPUT_BIG; iomemcpy(REGs_RSA_TXT, encSig, 0x100); - REG_RSA_CNT |= RSA_ENABLE; - rsaWaitBusy(); + REG_RSA_CNT |= RSA_CNT_IRQ_ENABLE | RSA_CNT_ENABLE; + rsaWaitBusyIrq(); iomemcpy(decSig, REGs_RSA_TXT, 0x100); return true;