5
votes

Does anyone know if there is an implementation of Elliptic Curve Diffie Hellman cryptography (ECDH) for React Native?

I found some libraries for this. each of them has some issues:

  1. react-native-ecc: it only generates key pairs and does not implement generating shared key(secret key) from private and public key for encryption
  2. react-native-crypto: it uses some hacks and changes node_modules recursively and i think it's not stable.
  3. elliptic : it's in a plain javascript implementation and it does not work in react native
1
To add one more non-solution, noble-secp256k1 depends on the BigInt class and uses n big integer suffix syntax.Diomidis Spinellis
Also note that react-native-crypto internally depends on create-ecdh, which in non-node environments is a wrapper around elliptic whose brorand-based random number generation fails on React Native.Diomidis Spinellis

1 Answers

2
votes

To the best of my knowledge, there is none (in Feb 2020).

In a project that I'm working on, we evaluated known libraries but could not find any for iOS. Operations that we need include ECDH (with the P-256 curve).

It is still work in progress, but our idea is to build the crypto operations natively in Swift, expose them with a bridge to fill in the missing parts of the crypto.subtle API.

Update: The code is open-source (part of the Cliqz browser for iOS):

JavaScript (ReactNative):

Swift (native code built on the CryptoKit library):

That was the code to provide the window.crypto.subtle functionality, as you would expect it on a Desktop browser like Firefox or Chrome. To see how it was used, you can look at the actual usage, or - maybe easier - at the commented-out example.

I'll added the links here in the hope that it provides entry points for someone facing the same problem. Please note that the Cliqz project has been discontinued, so be careful if you copy-paste the solution, as it will not receive security patches.