John-K / pspdecrypt

Simple tool to decrypt PSP binaries
GNU General Public License v3.0
103 stars 22 forks source link

Extracting (decrypting?) 6.3x PSARs is frigging slow #14

Closed artart78 closed 3 years ago

artart78 commented 3 years ago

Why???

John-K commented 3 years ago

Did some quick profiling: 6.31:

(pprof) top
Total: 24998 samples
   19005  76.0%  76.0%    23452  93.8% bn_mon_muladd_dig
    4132  16.5%  92.6%     4132  16.5% bn_sub_1
     512   2.0%  94.6%    24089  96.4% bn_mon_mul

6.61:

(pprof) top
Total: 499 samples
     133  26.7%  26.7%      160  32.1% bn_mon_muladd_dig
      98  19.6%  46.3%       98  19.6% read_bit
      44   8.8%  55.1%       44   8.8% rijndaelEncrypt

So, 2x the magnitude of bignum operations.

I bet something weird is going on with how we enumerate files causing us to visit files multiple times? Might need to instrument things to figure it out.

To reproduce:

artart78 commented 3 years ago

bignum functions are only used for ECDSA checking IIRC, was ECDSA checking enabled for all modules in 6.3x but removed in 6.6x?

artart78 commented 3 years ago

I tried commenting ecdsa_verify, and indeed it becomes a lot faster. It could probably be disabled by default since I doubt it's functional anyway.

John-K commented 3 years ago

Might be nice to add a flag to enable that behavior and have it disabled by default?

artart78 commented 3 years ago

Yep, related to #13, I'm even considering disabling it for now as I doubt it works...