Skip to content

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

@kaxline

Description

@kaxline

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions