Very slow key generation on certain Android versions (Java)

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Very slow key generation on certain Android versions (Java)

This post was updated on .
I am building an app in which I use the boucycastle (spongycastle, but its
the same thing) and when I try to derivate a key for decryption or
encryption with AES (AES/GCM/NoPadding) and use the following:

KeyParameter key = (KeyParameter)
generator.generateDerivedMacParameters(keyLength * 8); // key length in bits

and build it on any phone which has OS 6.0 or below the operation is
extremely slow. The 'for' cycle in 'F' method (PKCS5S2ParametersGenerator
class) runs through very slowly. The iteration count is always 800000
because I need it to be very secure, but the process to execute this code
takes almost 5 minutes on these devices. The interesting part is that on API
4.4 it only takes about a minute. So, is there any workaround for this
without reducing the iteration count, or should I try to use another key
derivation method? Also - what are the differences between
generateDerivedParameters and generateDerivedMacParameters as the latter
just returns the call for the first method? Thanks in advance.

Sent from: