Wanted to post an update/cry for help 
The main issue with using the nrf51822 (as I have already documented) is lack of RAM. There is only 8K, and this just isn’t enough to do RSA encrypt/decrypt on the key sizes Spark Cloud uses with the TropicSSL library. To solve this, there are a few hardware ways I can think of:
- Add a second, big MCU that controls the nrf51822 similar to how the STM32 controls the TI CC3000 in Spark Core
- Add a second, smaller MCU that only does the RSA encrypt/decrypt (the “handshake MCU”)
- Push the RSA encrypt/decrypt to the gateway
- Add more SRAM (though the nrf51822 does not natively support this, so it would be extremely difficult)
- Any other ideas?
There are various pros and cons to all of these, but if I was forced to choose I would go with number 2 since it has the lowest implications on cost, size and battery life while maintaining simplicity, ease-of-use and security. I still don’t like it though…
So, I broke out my textbooks from college and really tried to dig into the TropicSSL library and see if it is possible to do RSA cryptography with less RAM (spoiler alert: public key cryptography and efficient ways of doing it is not my area of expertise, I have read more about this in the last few days than I have in the past 8 years).
My short answer is, it appears very difficult, but may be possible. There are many papers on how to fit RSA into tiny MCU’s (here and here for example), but I haven’t been able to get much working so far.
I ran some tests on the current FW during the handshake and I see about 5076 bytes of RAM being allocated on the public server key encrypt and up to 6824 bytes on the private key decrypt. That is a lot. So I was trying to find ways to change how the math works so it is optimized for RAM and not speed (not gonna care too much if it takes a few seconds). I think I would have to realistically get this under 2K for it to be feasible in SparkLE, and I know that is asking a lot (and may not be possible).
Anyway, anyone know a library or better way? Any volunteers to help try?
Any savings we could find here would help this project, but would also help Spark Core since it uses the same method. More RAM for everyone!
I am going to back-burner this for a bit and move on with SparkLE with the handshake MCU so I can continue moving it forward. Any solution can just drop in in the future, so if anyone wants to help in pursuing this, let me know.
Alternatively, is there any intention or desire from the Spark team to move to ECC encryption? Again, I am no expert on this, but it seems to be more conducive to resource constrained devices.