mirror of
https://github.com/xprism1/ntool.git
synced 2025-06-18 16:15:32 -04:00
ntr_twl_srl: simplify AES-CTR operation
This commit is contained in:
parent
b963b12ba2
commit
3b13a65d1a
35
lib/keys.py
35
lib/keys.py
File diff suppressed because one or more lines are too long
@ -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()
|
||||
|
7
utils.py
7
utils.py
@ -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')
|
||||
|
Loading…
Reference in New Issue
Block a user