Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[React Native][iOS] Long-running sodium methods #42

Open
kaxline opened this issue Dec 21, 2021 · 0 comments
Open

[React Native][iOS] Long-running sodium methods #42

kaxline opened this issue Dec 21, 2021 · 0 comments

Comments

@kaxline
Copy link
Contributor

kaxline commented Dec 21, 2021

I'm trying to create an Item with 1MB of binary content in React Native, and there are two methods running over 13 seconds each:

CryptoManager.encrypt

public encrypt(message: Uint8Array, additionalData: Uint8Array | null = null): Uint8Array {

and

CryptoManager.calculateMac

public calculateMac(message: Uint8Array, withKey = true) {

I believe it's due to the sodium methods being called:

sodium.crypto_aead_xchacha20poly1305_ietf_encrypt

sodium.crypto_generichash

I'm attempting fix this with a PR, by detecting the React Native environment similar to how the library already detects it here:

if (rnsodium) {

But I'm unsure which methods from react-native-sodium to use and how to implement them. I tried swapping in rnsodium.crypto_secretbox_easy for crypto_aead_xchacha20poly1305_ietf_encrypt, but getting an unhelpful FAILURE error, even after converting all Uint8Arrays to base64.

Any suggestions here? Is this the right approach? Can you think of what the issue might be with using crypto_secretbox_easy?

It looks like the error comes from this line in react-native-sodium:

https://github.com/lyubo/react-native-sodium/blob/41c8a0e785ec136f487ab85a27202919a0b2222c/ios/RCTSodium/RCTSodium.m#L138

Which points towards me not converting the data properly.

Any help is appreciated, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant