From 9042cc406862e9577c70eebc3c1333ba33c83228 Mon Sep 17 00:00:00 2001 From: masterzorag Date: Wed, 23 Jul 2014 22:44:07 +0200 Subject: [PATCH] Update sce.cpp Last 2 bytes of IV gets altered, a deeper look is needed. Simply backup IV, run decryption and if IV has changed, restore back. This fixes the computed digest of data, that can succesfully validate a signature or not. Probably aes encrypt suffers the same. --- sce.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sce.cpp b/sce.cpp index dd647cf..1adbfbe 100644 --- a/sce.cpp +++ b/sce.cpp @@ -850,6 +850,10 @@ BOOL sce_decrypt_header(sce_buffer_ctxt_t *ctxt, u8 *metadata_info, u8 *keyset) if(ctxt->metai->key_pad[0] != 0x00 || ctxt->metai->iv_pad[0] != 0x00) return FALSE; + //Backup IV, next aes_crypt_ctr alters last 2 bytes + u8 biv[0x10]; + memcpy(&biv, ctxt->metai->iv, 0x10); + //Decrypt metadata header, metadata section headers and keys. nc_off = 0; aes_setkey_enc(&aes_ctxt, ctxt->metai->key, METADATA_INFO_KEYBITS); @@ -857,6 +861,10 @@ BOOL sce_decrypt_header(sce_buffer_ctxt_t *ctxt, u8 *metadata_info, u8 *keyset) ctxt->sceh->header_len - (sizeof(sce_header_t) + ctxt->sceh->metadata_offset + sizeof(metadata_info_t)), &nc_off, ctxt->metai->iv, sblk, (u8 *)ctxt->metah, (u8 *)ctxt->metah); + //Restore IV from its backup if changed + if(memcmp(ctxt->metai->iv, biv, 0x10) != 0) + memcpy(ctxt->metai->iv, &biv, 0x10); + //Fixup headers. _es_metadata_header(ctxt->metah); for(i = 0; i < ctxt->metah->section_count; i++)