I used latest sources of Bouncy Castle to implement Serpent GCM encryption.
public byte[] encrypt(byte[] key, byte[] iv, byte[] pt, byte[] aad,
int tagLength) throws InvalidCipherTextException {
GCMBlockCipher c = new GCMBlockCipher(new SerpentEngine());
c.init(true,
new AEADParameters(new KeyParameter(key), tagLength, iv, aad));
int outsize = c.getOutputSize(pt.length);
byte[] out = new byte[outsize];
int len = c.processBytes(pt, 0, pt.length, out, 0);
c.doFinal(out, len);
return out;
}
It works perfectly on my desktop machine (Windows Core i7). It takes about 190 milliseconds to encrypt 5Mb file. But all of a sudden the same code deployed on Samsung galaxy 4 tablet (Android 5.0.1) takes 40 seconds to do the same encryption of the same file. We tried Huawei Acend G300 (Android 2.3.6) and it takes only 17 seconds.
Also we tested the same encryption with Spongy Castle, unfortunately we did not get better performance.
- Could you please give me an idea why it's so dramatically different from Desktop and why the encryption time is faster on much less powerfull device Huawei than on Samsung galaxy s4 tablet?
- If there is any way to improve the performance of the code on Android?
Thank you very much in advance for your help!