Cryptography Stack Exchange is a question and answer site for software developers, mathematicians and others interested in cryptography. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Bitcoin uses SHA-256, Base58Check, ECDSA (Sep256k1) and RIPEMD-160 as the basis of its encryption (see this article for a short guide on how addresses are created).

I would like to create an iOS-based wallet app that offers reasonable security.

  • OpenSSL is not available on iOS, and is quite a large dependency. What I'm looking for are specialized libraries that mainly focus on the Bitcoin algorithms. The OpenSSL code also is very hard to understand, making me wonder if there is really no better way.

    • libbitcoin and the official Bitcoin-Qt client both use OpenSSL.
    • OpenSSL generally has a mixed reception.
    • OpenSSL also added to the transaction malleability problem that recently made its round in the news, as OpenSSL has more relaxed criteria to accept a signature than strictly necessary.
  • bitcoinj uses Spongy Castle, also a large collection of algorithms.

  • Another option of an algorithm collection is Crypto++ which I haven't seen in existing Bitcoin clients so far.

  • Apple's Security framework only supports RSA on iOS.

  • Chromium includes Go-sources for ECDSA.

  • There is sipa's implementation for Sep256k1 that has a reputation of being very efficient. It is also listed under gh/bitcoin.

Many recent attacks in publications used side-channel attacks, making it necessary to have algorithms with constant-time execution (to avoid timing-related attacks) and additional protections against cache-based attacks and recently even audio-related attacks where noise that the hardware itself produces can be used to gain knowledge of the private key.

Even though many attacks require gathering of multiple signatures, one cannot know how the app will be used by the end-user. I do not want to rely on the assumption that the users doing transactions only a few times per day in different shops and exchange their Bitcoin addresses frequently.

My questions are:

  • Is there a "sane" implementation of the algorithms used by bitcoin? e.g. are there high-quality implementations available that incorporate defenses against side channel attacks?

  • Does OpenSSL already protects against side-channel attacks?

    • A mobile app is more open to side-channel attacks than the desktop PC standing at home, so what's reasonably secure on a desktop machine may not be secure enough for a mobile app.
    • As OpenSSL is probably the most used cryptographic library, it's probably also the most attacked one, and therefore, ahead when looking at general security. However, specialized libraries may have a higher quality for the few algorithms they implement, as the code base is much smaller and easier to understand.
  • How can I train myself to evaluate whether an existing implementation is vulnerable to certain types of attacks?

    • Cryptographic algorithm implementations are often only poorly documented and optimized to a point where the code consists of magic numbers chained together with arbitrarily seeming operators.
    • One aspect I already mentioned is the concept of constant execution time, which counters timing-related attacks.
  • Are there good resources that explain how to implement those algorithms myself? I do not intend to use my own implementation for the app, but I am interested in understanding how the stuff works I'm using. Entry-bar seems quite high. Can the "Guide to Elliptic Curve Cryptography" book be recommended?

PS: I know that Apple doesn't favorably treat Bitcoin-related apps in their store. However, this discussion is out of scope of this question.

PS2: Base58Check is only used as a special encoding to make Bitcoin addresses and keys more readable to the enduser. There is no cryptography involved there, and it's easy to implement - I only included it here for completeness.

share|improve this question
Most operations don't need side channel resistance - they operate on public data. ECDSA signing is the major one, but even it is relatively hard to attack since you can't easily get high precision timing information. – CodesInChaos Mar 10 '14 at 19:33
In Bitcoin, only the address RIPEMD(SHA256(public-key) and its Base58Check encoding are public. The public key is only revealed when a transaction is created that spends coins that were previously sent to the address. I agree with you, that ECDSA signing is the major operation to protect, but ECDSA scalar multiplication is also important as a Bitcoin wallet usually generates a new keypair for every transaction to receive the change. Regarding ECDSA side channels: a second app in background could perform a cache-based attack: – Etan Mar 10 '14 at 21:22
What exactly is "mixed reception", if I may? Is it DER-encoding only? – Vadym Fedyukovych May 10 '15 at 21:24
It's more meant like it's known for being an over-sized mess that people tend to include because there's no real alternative :-/ – Etan May 11 '15 at 7:18

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.