I’m wondering if it is more secure to do the cryptographic functions in native code.
Using Java you can’t be sure if the GC re-sorts the memory and leaves shallow copies of your keys in the memory, even if you zero out the key immediately after en/decryption.
Maybe this is a stupid question, but I couldn’t find any information.
The native code is still running sandboxed and within the VM, so could the GC/VM/system re-sort the memory and therefore leave a shallow copy? So are the stack and heap static or can they be moved?
AFAIK they have virtual addresses, so this could be done.
Thank you and best regards
The Native code is compiled for ARM (and now intel I think), not Dalvik VM, and it runs directly on the processor, it is loaded and invoked by the Dalvik, yet it is not directly controlled by it. The stack and heap of the native code are real. calling memcpy/memset will change the memory for good.
All modern systems have virtual memory too, so this is as far as you’ll probably get regarding security.