I am generating a random number of 32 bytes (which from Microchip PIC24F). When the Android devices receives the random 32 bytes from the PIC24F via the Android USB accessory framework, I would like to create a RSA key. Is it possible to create a public & private key through the random 32 byte?
32 bytes is relatively weak as I had some knowledge on how RSA works. Large RSA may require a lot of computing power! I am only running this on a Android mobile.
If possible I would want to know what the limitation of the computing power to calculate an secure RSA key (I do know that different phone manufacturer with different resource may vary). What is largest key I can generate with reasonable resource on the Android mobile (To the extend that the application I program will not crash/not respond/force close)
Tools Used:
Nexus One (Android 2.3.4)
I know very little about the Android API, but I can tell you how you would go about doing this. I doubt there is a way in the API to do this directly, but maybe this information will be enough for you to piece together what to do.
In order to generate an RSA key, you need to generate two relatively large prime numbers. I would generate two numbers with no less than 768 bits apiece.
The technique for generating these primes is to use a cryptographically secure pseudo-random number generator (PRNG) to generate 766 bit values. Basically, generate 96 bytes and throw away the upper 2 bits. Then you shift the value up by a bit, and set the lowest and highest bit so you have an odd number that’s >=
2**767 + 1(and therefor requires 768 bits to represent). Then you feed the generated number into a probabilistic prime test. First you test for divisibility by the first few odd primes, so 3, 5, 7, 11, 13 and 17. Then you run a few iterations of Miller-Rabin.If the number passes these tests, you most likely have a prime number, if it doesn’t you start over and generate a new number.
Generate two such prime numbers, and you have an RSA key.
In order to generate these primes from 32 bytes of random data, you need to seed the PRNG with this data.
Personally, I would recommend getting 128 bytes of random data. You seed the PRNG with the first 64 bytes, and then every time you call it, you add one more byte of your random data to the entropy pool of your PRNG. Any cryptographically secure PRNG will have a method for doing this.