Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg.py: update key with fast crypt implementation #141

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions tools/ps3py/pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,25 @@ def setContextNum(key, tmpnum):
key[0x3e] = ord(tmpchrs[6:7])
key[0x3f] = ord(tmpchrs[7:8])

def SHA1(data):
m = hashlib.sha1()
m.update(data)
return m.digest()

import pkgcrypt
pkgcrypt.register_sha1_callback(SHA1)

def fastcrypt(key, inbuf, length):
keystr = listToString(key)
result = pkgcrypt.pkgcrypt(keystr, inbuf, length)
key[:] = list(keystr)[:]
return result

def crypt(key, inbuf, length):
if not isinstance(key, list):
return ""
# Call our ultra fast c implemetation
return pkgcrypt.pkgcrypt(listToString(key), inbuf, length);
return fastcrypt(key, inbuf, length)

# Original python (slow) implementation
ret = ""
Expand All @@ -255,13 +267,7 @@ def crypt(key, inbuf, length):
manipulate(key)
length -= bytes_to_dump
return ret
def SHA1(data):
m = hashlib.sha1()
m.update(data)
return m.digest()

pkgcrypt.register_sha1_callback(SHA1)

def listPkg(filename):
with open(filename, 'rb') as fp:
data = fp.read()
Expand Down