BouncyCastle SCrypt using more memory than native impls?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

BouncyCastle SCrypt using more memory than native impls?

Andreas Schildbach
I recently switched out the SCrypt implementation in my app. I had been
using native code: https://github.com/wg/scrypt. For reference, the code
I had been using was removed via this commit:
https://github.com/bitcoin-wallet/bitcoin-wallet/commit/83210d60461182188be8e13133a9bee40eefd1da

I'm now using BouncyCastle org.spongycastle.crypto.generators.SCrypt
(artifact: org.bouncycastle:bcprov-jdk15on:1.60)

I now have the problem that on low-end Android devices my app gets a lot
of OutOfMemoryErrors. I wonder if the BouncyCastle implementation
somehow uses more memory than it should, e.g. by copying buffers?

Is this maybe a known problem? I scanned the BCs issues at GitHub but
didn't find much about SCrypt at all.

By the way: on modern Android devices (Pixel 2, Android 9, 64 bit) the
BouncyCastle implementation actually runs faster than the native code
before!


Reply | Threaded
Open this post in threaded view
|

Re: BouncyCastle SCrypt using more memory than native impls?

Peter Dettman-3
Hi Andreas,
At a quick glance there appears to be room for improvement, I'll look
into it further. To make things concrete, what SCrypt parameters are you
using?

Regards,
Pete Dettman

On 20/7/19 5:06 pm, Andreas Schildbach wrote:

> I recently switched out the SCrypt implementation in my app. I had been
> using native code: https://github.com/wg/scrypt. For reference, the code
> I had been using was removed via this commit:
> https://github.com/bitcoin-wallet/bitcoin-wallet/commit/83210d60461182188be8e13133a9bee40eefd1da
>
> I'm now using BouncyCastle org.spongycastle.crypto.generators.SCrypt
> (artifact: org.bouncycastle:bcprov-jdk15on:1.60)
>
> I now have the problem that on low-end Android devices my app gets a lot
> of OutOfMemoryErrors. I wonder if the BouncyCastle implementation
> somehow uses more memory than it should, e.g. by copying buffers?
>
> Is this maybe a known problem? I scanned the BCs issues at GitHub but
> didn't find much about SCrypt at all.
>
> By the way: on modern Android devices (Pixel 2, Android 9, 64 bit) the
> BouncyCastle implementation actually runs faster than the native code
> before!
>
>


Reply | Threaded
Open this post in threaded view
|

Re: BouncyCastle SCrypt using more memory than native impls?

Andreas Schildbach
On 20/07/2019 16.58, Peter Dettman wrote:

> At a quick glance there appears to be room for improvement, I'll look
> into it further. To make things concrete, what SCrypt parameters are you
> using?

n = 65536
r = 8
p = 1

For the affected hardware, I'm now trying to dial back to n = 32768 as a
quick workaround.