One Thing Stood Between us and a $100,000 Prize …
… Elliptic Curve Cryptography on iOS — at least that’s how we saw it. Stealthy IM is built atop Blockstack — a decentralized platform providing identity on the Bitcoin blockchain, elliptic curve cryptography, and GAIA, a decentralized storage system.
“Naively, we assumed everything would work out of the box …”
In April of 2018, Blockstack released mobile APIs for Android and iOS, enabling us to build Stealthy IM for phones. Naively, we assumed everything would work out of the box, but quickly realized there was at least one major issue. The elliptic curve cryptography features were not yet supported on Blockstack’s iOS API, and without them Stealthy IM on a phone was dead in the water. This is because all of Stealthy’s personal messaging is encrypted, as shown below in Figure 1.0.
“We couldn’t afford to wait on a solution that was beyond our control.”
Should we wait until the Blockstack team were able to address the situation? We grappled with this decision for a while, but ultimately being chosen to compete in Techcrunch Disrupt 2018 made the decision for us. We now had until early September to finish developing our mobile product, where it would gain significant media exposure and give us the chance of winning $100,000. We couldn’t afford to wait on a solution that was beyond our control.
Meet Stealthy a new messaging app that leverages Blockstack's decentralized application platform to build a messaging…techcrunch.com
It’s important to mention that neither of Stealthy’s founders are experts in cryptography — it was in fact relatively new to both of us. Initially it seemed it might be possible to use Apple’s own cryptographic functions for iOS. Blockstack’s ECIES cryptography centers around the SECP256K1 curve made popular by Bitcoin and Apple’s libraries support both this curve and some aspects of elliptic curve cryptography.
secp256k1 was almost never used before Bitcoin became popular, but it is now gaining in popularity due to its several…en.bitcoin.it
However, much time was spent just trying to get a user’s Blockstack public and private keys into the correct data structure to work with Apple’s libraries. The process involved iterations of trial and error and reading Apple’s Developer Forum and Stack Overflow — largely because of some catch-all error messaging that didn’t give much of an indication about what was going wrong. Eventually after reading several posts from Quinn “The Eskimo”, a resident expert in Apple’s Developer Forum, we elected to ask him for help. To summarize he essentially said “read Apple’s code” — not bad advice.
After making little progress over a couple of days, defeating a small portion of the cryptography learning curve and getting the public key into the right Apple data structure, it was time to try something else. Further comparison of Apple’s system and the Blockstack one seemed to confirm this, as it appeared there would be many more challenges.
“This is when we broke one of our cardinal start-up rules. For years we told friends never to join a startup working in C++.”
This is when we broke one of our cardinal start-up rules. For years we told friends never to join a startup working in C++. Nothing against the language, it just requires a high degree of skill and takes longer to develop solutions with. Yet here was a good reason to work in C++: the Crypto++ library.
Crypto++ is a free C++ cryptography library with lots of documentation and examples. It is well maintained and there is even a forum where you can reach out for support. However, what’s really interesting about Crypto++ is the original author:
Wei Dai … is a computer engineer best known as the creator of the Bitcoin predecessor “b-money” and as the developer of the Crypto++ library.
His b-money paper sets the groundwork for Bitcoin — in 1998! Proof of work, collective bookkeeping, and authentication with cryptographic hashes are all described. The paper is referenced in Satoshi Nakamoto’s original Bitcoin whitepaper.
With clearer documentation and some useful example code, we created a testbench using data from the desktop version of Stealthy and a prototype ECIES solution using Crypto++. Much of the learning curve was in getting familiar with the data types and basic cryptographic principles (i.e. uncompressing a compressed key, deriving a shared secret, and mapping what we understood from the Blockstack ECIES implementation to the examples found in the Crypto++ forums and documentation).
It took about four days, but now we had a prototype that could encrypt and decrypt data interoperably with our desktop Stealthy release. The remaining challenge was plumbing these cryptography methods into the Stealthy iOS product.
A Github repository of our Blockstack compatible Crypto++ ECIES implementation can be found here:
Crypto++ Implementation of ECIES Cryptography on the SECP1256K1 Curve - stealthyim/ECIES-Encryptiongithub.com
While there are many things we might do differently now that we have more experience, this work got us on stage at Techcrunch Disrupt 2018 to release our mobile product. It allowed our users to send and receive messages between our iOS, Android, and desktop versions of Stealthy seamlessly and securely.
Going forward we hope to get feedback from the Crypto++ maintainers on our implementation, possibly providing it as a complete ECIES implementation example.
Special thanks to the fine folks maintaining and documenting Crypto++. It’s a wonderful project that we found immensely useful.