Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,36 @@ This project is a monorepo managed using [Yarn workspaces](https://yarnpkg.com/f
- The library package in the root directory.
- An example app in the `example/` directory.

To get started with the project, run `yarn` in the root directory to install the required dependencies for each package:
To get started with the project, make sure you have the correct version of [Node.js](https://nodejs.org/) installed. See the [`.nvmrc`](./.nvmrc) file for the version used in this project.

Run `yarn` in the root directory to install the required dependencies for each package:

```sh
yarn
```

> Since the project relies on Yarn workspaces, you cannot use [`npm`](https://github.com/npm/cli) for development.
> Since the project relies on Yarn workspaces, you cannot use [`npm`](https://github.com/npm/cli) for development without manually migrating.

This project uses Nitro Modules. If you're not familiar with how Nitro works, make sure to check the [Nitro Modules Docs](https://nitro.margelo.com/).

You need to run [Nitrogen](https://nitro.margelo.com/docs/nitrogen) to generate the boilerplate code required for this project. The example app will not build without this step.

Run **Nitrogen** in following cases:

- When you make changes to any `*.nitro.ts` files.
- When running the project for the first time (since the generated files are not committed to the repository).

To invoke **Nitrogen**, use the following command:

```sh
yarn nitrogen
```

The [example app](/example/) demonstrates usage of the library. You need to run it to test any changes you make.

It is configured to use the local version of the library, so any changes you make to the library's source code will be reflected in the example app. Changes to the library's JavaScript code will be reflected in the example app without a rebuild, but native code changes will require a rebuild of the example app.

If you want to use Android Studio or XCode to edit the native code, you can open the `example/android` or `example/ios` directories respectively in those editors. To edit the Objective-C or Swift files, open `example/ios/TurboEncryptionExample.xcworkspace` in XCode and find the source files at `Pods > Development Pods > react-native-turbo-encryption`.
If you want to use Android Studio or Xcode to edit the native code, you can open the `example/android` or `example/ios` directories respectively in those editors. To edit the Objective-C or Swift files, open `example/ios/TurboEncryptionExample.xcworkspace` in Xcode and find the source files at `Pods > Development Pods > react-native-turbo-encryption`.

To edit the Java or Kotlin files, open `example/android` in Android studio and find the source files at `react-native-turbo-encryption` under `Android`.

Expand Down Expand Up @@ -81,7 +98,7 @@ We follow the [conventional commits specification](https://www.conventionalcommi
- `fix`: bug fixes, e.g. fix crash due to deprecated method.
- `feat`: new features, e.g. add new method to the module.
- `refactor`: code refactor, e.g. migrate from class components to hooks.
- `docs`: changes into documentation, e.g. add usage example for the module..
- `docs`: changes into documentation, e.g. add usage example for the module.
- `test`: adding or updating tests, e.g. add integration tests using detox.
- `chore`: tooling changes, e.g. change CI config.

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2024 Ritesh Shukla
Copyright (c) 2025 riteshshukla04
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
Expand Down
81 changes: 2 additions & 79 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

✨ **Written 100% in C++** with ⚡ blazing-fast performance and **direct bindings** to JavaScript! 🚀

**Requires new arch to be set to true**
**react-native-turbo-encryption is now a [Nitro Module](https://github.com/mrousavy/nitro) 🚀**

## 💻 Features

Expand All @@ -19,7 +19,7 @@
## Installation

```sh
npm install react-native-turbo-encryption
yarn add react-native-turbo-encryption react-native-nitro-modules
```

## Usage
Expand Down Expand Up @@ -94,80 +94,3 @@ const decryptedResultAsync = await decrypt256Async(encryptedResultAsync, key); /
| ----------------------------- | ------------------------ |
| react-native-turbo-encryption | _5 ms_ |
| react-native-aes-crypto | _30 ms_ |

Note: react-native-aes-crypto has better security features than this. Prefer using that if security is your top priority.

## 🔧 Technical Details

This module uses the [tinyaes](https://github.com/kokke/tiny-AES-C) C library as a submodule for AES encryption. The library has been modified to support both AES-128 and AES-256 encryption modes.

### Submodule Modifications

The `tinyaes` submodule has been modified to enable AES-256 support:

- Enabled `AES256` macro in `cpp/tinyaes/aes.h`
- Configured key sizes to support both AES-128 and AES-256
- Added proper key handling for both encryption modes

**Note**: Since the submodule code has been modified, you may need to handle submodule updates carefully. Consider forking the tinyaes repository if you need to maintain these changes long-term.

### Handling Submodule Changes

Since we've modified the `tinyaes` submodule code, here are the recommended approaches:

1. **Fork the tinyaes repository** and point the submodule to your fork
2. **Document the changes** in this README (as done above)
3. **Create a patch file** for the modifications ✅ (done)
4. **Consider contributing** the AES-256 support back to the original tinyaes project

**Recommended workflow for future updates:**

1. **Fork the tinyaes repository** on GitHub
2. **Apply the patch** to your fork
3. **Update the submodule** to point to your fork
4. **Test thoroughly** to ensure compatibility

This way, you maintain control over the modifications while still being able to receive updates from the original repository.

To track these changes, you can:

```bash
# Check the current submodule status
git submodule status

# See what changes have been made to the submodule
cd cpp/tinyaes
git status
git diff

# Commit the submodule changes
git add .
git commit -m "Enable AES-256 support"
```

### Patch File

A patch file has been created (`aes256-support.patch`) that contains the exact changes made to the tinyaes submodule. This can be used to:

- Apply the same changes to future versions of the submodule
- Share the modifications with others
- Document the exact changes made

To apply this patch to a fresh submodule:

```bash
cd cpp/tinyaes
git apply ../../aes256-support.patch
```

### Current Submodule Status

The tinyaes submodule is currently at commit `3dec066` with the AES-256 support changes committed. The submodule is in a detached HEAD state, which is normal for submodules.

**Current submodule commit**: `3dec066e9b9c21aa66d98563b6247d28971d2cc4`
**Changes**: Enabled AES-256 support and configured key sizes for dual AES-128/AES-256 compatibility

### Screenshot of Performance Results:

![Performance Comparison Turbo](./assets/turbo.png)
![Performance Comparison](./assets/aes.png)
37 changes: 37 additions & 0 deletions TurboEncryption.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require "json"

package = JSON.parse(File.read(File.join(__dir__, "package.json")))

Pod::Spec.new do |s|
s.name = "TurboEncryption"
s.version = package["version"]
s.summary = package["description"]
s.homepage = package["homepage"]
s.license = package["license"]
s.authors = package["author"]

s.platforms = { :ios => min_ios_version_supported }
s.source = { :git => "https://github.com/riteshshukla04/react-native-turbo-encryption.git", :tag => "#{s.version}" }


s.source_files = [
"ios/**/*.{swift}",
"ios/**/*.{m,mm}",
"cpp/**/*.{hpp,cpp,h,c}",
]

s.dependency 'React-jsi'
s.dependency 'React-callinvoker'

s.pod_target_xcconfig = {
"HEADER_SEARCH_PATHS" => ["${PODS_ROOT}/RCT-Folly"],
"GCC_PREPROCESSOR_DEFINITIONS" => "$(inherited) FOLLY_NO_CONFIG FOLLY_CFG_NO_COROUTINES",
"OTHER_CPLUSPLUSFLAGS" => "$(inherited) -DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1"
}


load 'nitrogen/generated/ios/TurboEncryption+autolinking.rb'
add_nitrogen_files(s)

install_modules_dependencies(s)
end
1 change: 0 additions & 1 deletion aes256-support.patch
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,3 @@ index b29b668..93565c1 100644
{
--
2.39.5 (Apple Git-154)

65 changes: 34 additions & 31 deletions android/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,46 +1,49 @@
cmake_minimum_required(VERSION 3.4.1)
project(TurboEncryption)
project(turboencryption)
cmake_minimum_required(VERSION 3.9.0)



set (CMAKE_VERBOSE_MAKEFILE ON)
set(PACKAGE_NAME turboencryption)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_CXX_STANDARD 20)


add_library(react-native-turbo-encryption
STATIC
../cpp/NativeTurboEncryptionTurboModule.cpp
../cpp/tinyaes/aes.c
../cpp/tinyaes/aes.h
../cpp/tinyaes/aes.hpp
../cpp/AESWrapper.cpp
../cpp/AESWrapper.hpp
# Find all C++ files (shared and platform specifics)
file(GLOB_RECURSE shared_files RELATIVE ${CMAKE_SOURCE_DIR}
"../cpp/**.cpp"
)

target_include_directories(react-native-turbo-encryption
PUBLIC
../cpp
file(GLOB_RECURSE android_files RELATIVE ${CMAKE_SOURCE_DIR}
"src/main/cpp/**.cpp"
)


target_include_directories(react-native-turbo-encryption
PUBLIC
../cpp/tinyaes
# Define C++ library and add all sources
add_library(${PACKAGE_NAME} SHARED
src/main/cpp/cpp-adapter.cpp
../cpp/TurboEncryption.cpp
../cpp/tinyaes/aes.c
../cpp/tinyaes/aes.h
../cpp/tinyaes/aes.hpp
../cpp/AESWrapper.cpp
../cpp/AESWrapper.hpp
)


find_library( # Sets the name of the path variable.
log-lib
include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/turboencryption+autolinking.cmake)

# Specifies the name of the NDK library that
# you want CMake to locate.
log )

target_include_directories(${PACKAGE_NAME}
PUBLIC
../cpp/tinyaes
)


# Set up local includes
include_directories(
"src/main/cpp"
"../cpp"
)
find_library(LOG_LIB log)

target_link_libraries(react-native-turbo-encryption
jsi
${log-lib}
react_codegen_RNTurboEncryptionSpec
# Link all libraries together
target_link_libraries(
${PACKAGE_NAME}
${LOG_LIB}
android # <-- Android core
)
Loading