ntr_twl_srl: simplify AES-CTR operation

This commit is contained in:
xprism1 2023-10-20 00:18:19 +08:00
parent b963b12ba2
commit 3b13a65d1a
3 changed files with 12 additions and 37 deletions

File diff suppressed because one or more lines are too long

View File

@ -543,11 +543,10 @@ class SRLReader:
f.seek(i['offset'])
g.seek(i['offset'])
counter = bytearray(i['counter'])
counter = Counter.new(128, initial_value=readbe(i['counter']))
cipher = AES.new(i['key'], AES.MODE_CTR, counter=counter)
for data in read_chunks(f, i['size']):
for j in range(len(data) // 16):
output, counter = TWL.aes_ctr_block(i['key'], counter, data[j * 16:(j + 1) * 16])
g.write(output)
g.write(TWL.aes_ctr(cipher, data))
print(f'Decrypted {i["name"]}')
g.close()

View File

@ -38,11 +38,10 @@ def srl_retail2dev(path, out=''):
f.seek(i['offset'])
g.seek(i['offset'])
counter = bytearray(i['counter'])
counter = Counter.new(128, initial_value=readbe(i['counter']))
cipher = AES.new(key, AES.MODE_CTR, counter=counter)
for data in read_chunks(f, i['size']):
for j in range(len(data) // 16):
output, counter = TWL.aes_ctr_block(key, counter, data[j * 16:(j + 1) * 16])
g.write(output)
g.write(TWL.aes_ctr(cipher, data))
g.close()
f.close()
os.remove('decrypted.nds')